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 all 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)
}
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