Skip to content

Commit

Permalink
more requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-tappx committed Nov 12, 2019
1 parent 1ca51f1 commit 2085aac
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 28 deletions.
42 changes: 16 additions & 26 deletions adapters/tappx/tappx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewTappxBidder(client *http.Client, endpointTemplate string) *TappxAdapter
a := &adapters.HTTPAdapter{Client: client}
template, err := template.New("endpointTemplate").Parse(endpointTemplate)
if err != nil {
glog.Fatal("Unable to parse endpoint url template")
glog.Fatal("Unable to parse endpoint url template: " + err.Error())
return nil
}
return &TappxAdapter{
Expand Down Expand Up @@ -98,56 +98,46 @@ func (a *TappxAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapte

// Builds enpoint url based on adapter-specific pub settings from imp.ext
func (a *TappxAdapter) buildEndpointURL(params *openrtb_ext.ExtImpTappx, test int) (string, error) {
reqHost, reqKey, reqEndpoint := "", "", ""
if params.Host != "" {
reqHost = params.Host
}
if params.Endpoint != "" {
reqEndpoint = params.Endpoint
}
if params.TappxKey != "" {
reqKey = params.TappxKey
}

if reqHost == "" {
if params.Host == "" {
return "", &errortypes.BadInput{
Message: "Tappx host undefined",
}
}

endpointParams := macros.EndpointTemplateParams{Host: reqHost}
host, err := macros.ResolveMacros(a.endpointTemplate, endpointParams)
if params.Endpoint == "" {
return "", &errortypes.BadInput{
Message: "Tappx endpoint undefined",
}
}

if err != nil {
if params.TappxKey == "" {
return "", &errortypes.BadInput{
Message: "Unable to parse endpoint url template",
Message: "Tappx key undefined",
}
}

thisURI, err := url.Parse(host)
endpointParams := macros.EndpointTemplateParams{Host: params.Host}
host, err := macros.ResolveMacros(a.endpointTemplate, endpointParams)

if err != nil {
return "", &errortypes.BadInput{
Message: "Malformed URL: check host parameter",
Message: "Unable to parse endpoint url template: " + err.Error(),
}
}

if reqEndpoint == "" {
thisURI, err := url.Parse(host)

if err != nil {
return "", &errortypes.BadInput{
Message: "Tappx endpoint undefined",
Message: "Malformed URL: " + err.Error(),
}
}

thisURI.Path += params.Endpoint

queryParams := url.Values{}

if reqKey == "" {
return "", &errortypes.BadInput{
Message: "Tappx key undefined",
}
}

queryParams.Add("tappxkey", params.TappxKey)

if test == 0 {
Expand Down
5 changes: 3 additions & 2 deletions adapters/tappx/tappx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ func TestTsValue(t *testing.T) {

url, err := adapter.buildEndpointURL(&tappxExt, test)

match, err := regexp.MatchString(`&ts=[0-9]{13}`, url)
match, err := regexp.MatchString(`https://example\.host\.tappx\.com/DUMMYENDPOINT\?tappxkey=dummy-tappx-key&ts=[0-9]{13}&type_cnn=prebid&v=1\.1`, url)
if err != nil {
//something happened during regex validation
t.Errorf("Error while running regex validation: %s", err.Error())
return
}
assert.True(t, match)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"mockBidRequest": {
"id": "0000000000001",
"imp": [
{
"id": "adunit-1",
"banner": {
"w": 300,
"h": 250
},
"ext": {
"bidder": {
"host": "example.ho%st.tappx.com",
"endpoint": "PREBIDTEMPLATE",
"tappxkey": "pub-12345-android-9876"
}
}
}
],
"app": {
"id": "app_001",
"bundle": "com.rovio.angrybirds",
"publisher": {
"id": "2"
}
},
"user": {
"buyeruid": "A-38327932832"
}
},

"expectedMakeRequestsErrors": [
{
"value": "Malformed URL: parse https://example.ho%st.tappx.com: invalid URL escape \"%st\"",
"comparison": "literal"
}
]

}

0 comments on commit 2085aac

Please sign in to comment.