Skip to content

Commit

Permalink
Add client/AccountID support into Adoppler adapter. (#1535)
Browse files Browse the repository at this point in the history
  • Loading branch information
vchimishuk authored Nov 5, 2020
1 parent d821b3b commit d044a93
Show file tree
Hide file tree
Showing 19 changed files with 1,003 additions and 235 deletions.
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)
}
80 changes: 80 additions & 0 deletions adapters/adoppler/adopplertest/exemplary/custom-client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"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":200,
"body":{
"id":"req1-unit1",
"seatbid":[
{
"bid":[
{
"id":"req1-unit1-bid1",
"impid":"imp1",
"price":0.12,
"adm":"<b>An ad</b>"
}
]
}
],
"cur":"USD"
}
}
}
],
"expectedBidResponses":[
{
"currency":"USD",
"bids":[
{
"bid":{
"id":"req1-unit1-bid1",
"impid":"imp1",
"price":0.12,
"adm":"<b>An ad</b>"
},
"type":"banner"
}
]
}
]
}
78 changes: 78 additions & 0 deletions adapters/adoppler/adopplertest/exemplary/default-client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"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":200,
"body":{
"id":"req1-unit1",
"seatbid":[
{
"bid":[
{
"id":"req1-unit1-bid1",
"impid":"imp1",
"price":0.12,
"adm":"<b>An ad</b>"
}
]
}
],
"cur":"USD"
}
}
}
],
"expectedBidResponses":[
{
"currency":"USD",
"bids":[
{
"bid":{
"id":"req1-unit1-bid1",
"impid":"imp1",
"price":0.12,
"adm":"<b>An ad</b>"
},
"type":"banner"
}
]
}
]
}
60 changes: 0 additions & 60 deletions adapters/adoppler/adopplertest/exemplary/multibid.json

This file was deleted.

Loading

0 comments on commit d044a93

Please sign in to comment.