Skip to content

Commit

Permalink
Merge pull request #1072 from kriss-u/fix/use-headers-for-access-key
Browse files Browse the repository at this point in the history
Update the request for numverify scan
  • Loading branch information
sundowndev authored Jun 19, 2022
2 parents d7e6e84 + f3f280e commit fdd163d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
6 changes: 3 additions & 3 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ func TestApi(t *testing.T) {
LineType: "mobile",
}

gock.New("http://apilayer.net").
Get("/api/validate").
MatchParam("access_key", "5ad5554ac240e4d3d31107941b35a5eb").
gock.New("http://api.apilayer.com").
Get("/number_verification/validate").
MatchHeader("Apikey", "5ad5554ac240e4d3d31107941b35a5eb").
MatchParam("number", number).
Reply(200).
JSON(expectedResult)
Expand Down
13 changes: 11 additions & 2 deletions lib/remote/suppliers/numverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/sirupsen/logrus"
"net/http"
"os"

"github.com/sirupsen/logrus"
)

type NumverifySupplierInterface interface {
Expand Down Expand Up @@ -62,8 +63,16 @@ func (s *NumverifySupplier) Validate(internationalNumber string) (res *Numverify
WithField("scheme", scheme).
Debug("Running validate operation through Numverify API")


url := fmt.Sprintf("%s://api.apilayer.com/number_verification/validate?number=%s", scheme, internationalNumber)

// Build the request
response, err := http.Get(fmt.Sprintf("%s://apilayer.net/api/validate?access_key=%s&number=%s", scheme, s.ApiKey, internationalNumber))
client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("Apikey", s.ApiKey)

response, err := client.Do(req)

if err != nil {
return nil, err
}
Expand Down
24 changes: 12 additions & 12 deletions lib/remote/suppliers/numverify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func TestNumverifySupplierSuccess(t *testing.T) {
LineType: "mobile",
}

gock.New("https://apilayer.net").
Get("/api/validate").
MatchParam("access_key", "5ad5554ac240e4d3d31107941b35a5eb").
gock.New("https://api.apilayer.com").
Get("/number_verification/validate").
MatchHeader("Apikey", "5ad5554ac240e4d3d31107941b35a5eb").
MatchParam("number", number).
Reply(200).
JSON(expectedResult)
Expand Down Expand Up @@ -70,9 +70,9 @@ func TestNumverifySupplierWithoutSSL(t *testing.T) {
LineType: "mobile",
}

gock.New("http://apilayer.net").
Get("/api/validate").
MatchParam("access_key", "5ad5554ac240e4d3d31107941b35a5eb").
gock.New("http://api.apilayer.com").
Get("/number_verification/validate").
MatchHeader("Apikey", "5ad5554ac240e4d3d31107941b35a5eb").
MatchParam("number", number).
Reply(200).
JSON(expectedResult)
Expand Down Expand Up @@ -103,9 +103,9 @@ func TestNumverifySupplierError(t *testing.T) {
},
}

gock.New("http://apilayer.net").
Get("/api/validate").
MatchParam("access_key", "5ad5554ac240e4d3d31107941b35a5eb").
gock.New("http://api.apilayer.com").
Get("/number_verification/validate").
MatchHeader("Apikey", "5ad5554ac240e4d3d31107941b35a5eb").
MatchParam("number", number).
Reply(400).
JSON(expectedResult)
Expand All @@ -131,8 +131,8 @@ func TestNumverifySupplierHTTPError(t *testing.T) {

dummyError := errors.New("test")

gock.New("https://apilayer.net").
Get("/api/validate").
gock.New("https://api.apilayer.com").
Get("/number_verification/validate").
ReplyError(dummyError)

s := NewNumverifySupplier()
Expand All @@ -143,7 +143,7 @@ func TestNumverifySupplierHTTPError(t *testing.T) {
assert.Nil(t, got)
assert.Equal(t, &url.Error{
Op: "Get",
URL: "https://apilayer.net/api/validate?access_key=5ad5554ac240e4d3d31107941b35a5eb&number=11115551212",
URL: "https://api.apilayer.com/number_verification/validate?number=11115551212",
Err: dummyError,
}, err)
}
Expand Down

0 comments on commit fdd163d

Please sign in to comment.