Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client/AccountID support into Adoppler adapter. #1535

Merged
merged 6 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions adapters/adoppler/adoppler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ import (
"fmt"
"net/http"
"net/url"
"text/template"

"github.com/golang/glog"
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/macros"
"github.com/prebid/prebid-server/openrtb_ext"
)

const DefaultClient = "app"

var bidHeaders http.Header = map[string][]string{
"Accept": {"application/json"},
"Content-Type": {"application/json;charset=utf-8"},
Expand All @@ -28,11 +33,17 @@ type adsImpExt struct {
}

type AdopplerAdapter struct {
endpoint string
endpoint *template.Template
}

func NewAdopplerBidder(endpoint string) *AdopplerAdapter {
return &AdopplerAdapter{endpoint}
t, err := template.New("endpoint").Parse(endpoint)
if err != nil {
glog.Fatalf("Unable to parse endpoint url template: %s", err)
return nil
}

return &AdopplerAdapter{t}
}

func (ads *AdopplerAdapter) MakeRequests(
Expand Down Expand Up @@ -65,8 +76,13 @@ func (ads *AdopplerAdapter) MakeRequests(
continue
}

uri := fmt.Sprintf("%s/processHeaderBid/%s",
ads.endpoint, url.PathEscape(ext.AdUnit))
uri, err := ads.bidUri(ext)
if err != nil {
e := fmt.Sprintf("Unable to build bid URI: %s",
err.Error())
errs = append(errs, &errortypes.BadInput{e})
continue
}
data := &adapters.RequestData{
Method: "POST",
Uri: uri,
Expand Down Expand Up @@ -172,6 +188,18 @@ func (ads *AdopplerAdapter) MakeBids(
return adsResp, nil
}

func (ads *AdopplerAdapter) bidUri(ext *openrtb_ext.ExtImpAdoppler) (string, error) {
params := macros.EndpointTemplateParams{}
params.AdUnit = url.PathEscape(ext.AdUnit)
if ext.Client == "" {
params.AccountID = DefaultClient
} else {
params.AccountID = url.PathEscape(ext.Client)
}

return macros.ResolveMacros(*ads.endpoint, params)
}

func unmarshalExt(ext json.RawMessage) (*openrtb_ext.ExtImpAdoppler, error) {
var bext adapters.ExtImpBidder
err := json.Unmarshal(ext, &bext)
Expand Down
2 changes: 1 addition & 1 deletion adapters/adoppler/adoppler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (
)

func TestJsonSamples(t *testing.T) {
bidder := NewAdopplerBidder("http://adoppler.com")
bidder := NewAdopplerBidder("http://{{.AccountID}}.trustedmarketplace.com/processHeaderBid/{{.AdUnit}}")
adapterstest.RunJSONBidderTest(t, "adopplertest", bidder)
}
52 changes: 52 additions & 0 deletions adapters/adoppler/adopplertest/exemplary/custom-client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"mockBidRequest":{
"id":"req1",
"imp":[
{
"id":"imp1",
"banner":{
"w":100,
"h":200
},
"ext":{
"bidder":{
"adunit":"unit1",
"client":"client1"
}
}
}
]
},
"httpCalls":[
{
"expectedRequest":{
"uri":"http://client1.trustedmarketplace.com/processHeaderBid/unit1",
"body":{
"id":"req1-unit1",
"imp":[
{
"id":"imp1",
"banner":{
"w":100,
"h":200
},
"ext":{
"bidder":{
"adunit":"unit1",
"client":"client1"
}
}
}
]
}
},
"mockResponse":{
"status":204,
"body":""
}
}
],
"expectedBidResponses":[

Copy link
Contributor

@mansinahar mansinahar Oct 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest adding valid expected bid responses for this and the next test rather than an empty response because that exercises the MakeBids code of your adapter.

]
}
50 changes: 50 additions & 0 deletions adapters/adoppler/adopplertest/exemplary/default-client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"mockBidRequest":{
"id":"req1",
"imp":[
{
"id":"imp1",
"banner":{
"w":100,
"h":200
},
"ext":{
"bidder":{
"adunit":"unit1"
}
}
}
]
},
"httpCalls":[
{
"expectedRequest":{
"uri":"http://app.trustedmarketplace.com/processHeaderBid/unit1",
"body":{
"id":"req1-unit1",
"imp":[
{
"id":"imp1",
"banner":{
"w":100,
"h":200
},
"ext":{
"bidder":{
"adunit":"unit1"
}
}
}
]
}
},
"mockResponse":{
"status":204,
"body":""
}
}
],
"expectedBidResponses":[

]
}
60 changes: 0 additions & 60 deletions adapters/adoppler/adopplertest/exemplary/multibid.json

This file was deleted.

Loading