Skip to content

Commit

Permalink
Add client/AccountID support into Adoppler adapter.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchimishuk committed Oct 12, 2020
1 parent c27ec73 commit 671f5a8
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 30 deletions.
29 changes: 25 additions & 4 deletions adapters/adoppler/adoppler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import (
"fmt"
"net/http"
"net/url"
"text/template"

"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 +32,13 @@ type adsImpExt struct {
}

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

func NewAdopplerBidder(endpoint string) *AdopplerAdapter {
return &AdopplerAdapter{endpoint}
e := endpoint + "/processHeaderBid/{{.AdUnit}}"

return &AdopplerAdapter{template.Must(template.New("endpoint").Parse(e))}
}

func (ads *AdopplerAdapter) MakeRequests(
Expand Down Expand Up @@ -65,8 +71,11 @@ 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 {
errs = append(errs, &errortypes.BadInput{err.Error()})
continue
}
data := &adapters.RequestData{
Method: "POST",
Uri: uri,
Expand Down Expand Up @@ -172,6 +181,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 = 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")
adapterstest.RunJSONBidderTest(t, "adopplertest", bidder)
}
15 changes: 15 additions & 0 deletions adapters/adoppler/adopplertest/exemplary/custom-client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{"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": []}
13 changes: 13 additions & 0 deletions adapters/adoppler/adopplertest/exemplary/default-client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{"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": []}
36 changes: 22 additions & 14 deletions adapters/adoppler/adopplertest/exemplary/multibid.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,31 @@
"ext": {"bidder": {"adunit": "unit2"}}},
{"id": "imp3",
"native": {"request": "{}"},
"ext": {"bidder": {"adunit": "unit3"}}}]},
"httpCalls": [{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit1",
"ext": {"bidder": {"adunit": "unit3"}}}],
"source": {"ext": {"schain": {"ver": "1.0"}}},
"regs": {"ext": {"us_privacy": "1YNY"}}},
"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"}}}]}},
"imp": [{"id": "imp1",
"banner": {"w": 100, "h": 200},
"ext": {"bidder": {"adunit": "unit1"}}}],
"source": {"ext": {"schain": {"ver": "1.0"}}},
"regs": {"ext": {"us_privacy": "1YNY"}}}},
"mockResponse": {"status": 200,
"body": {"id": "req1-imp1-resp1",
"seatbid": [{"bid": [{"id": "req1-imp1-bid1",
"impid": "imp1",
"price": 0.12,
"adm": "<b>a banner</b>"}]}],
"cur": "USD"}}},
{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit2",
{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit2",
"body": {"id": "req1-unit2",
"imp": [{"id": "imp2",
"video": {"minduration": 120,
"mimes": ["video/mp4"]},
"ext": {"bidder": {"adunit": "unit2"}}}]}},
"imp": [{"id": "imp2",
"video": {"minduration": 120,
"mimes": ["video/mp4"]},
"ext": {"bidder": {"adunit": "unit2"}}}],
"source": {"ext": {"schain": {"ver": "1.0"}}},
"regs": {"ext": {"us_privacy": "1YNY"}}}},
"mockResponse": {"status": 200,
"body": {"id": "req1-imp2-resp2",
"seatbid": [{"bid": [{"id": "req1-imp2-bid1",
Expand All @@ -37,11 +43,13 @@
"cat": ["IAB1", "IAB2"],
"ext": {"ads": {"video": {"duration": 121}}}}]}],
"cur": "USD"}}},
{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit3",
{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit3",
"body": {"id": "req1-unit3",
"imp": [{"id": "imp3",
"native": {"request": "{}"},
"ext": {"bidder": {"adunit": "unit3"}}}]}},
"imp": [{"id": "imp3",
"native": {"request": "{}"},
"ext": {"bidder": {"adunit": "unit3"}}}],
"source": {"ext": {"schain": {"ver": "1.0"}}},
"regs": {"ext": {"us_privacy": "1YNY"}}}},
"mockResponse": {"status": 204,
"body": ""}}],
"expectedBidResponses": [{"currency": "USD",
Expand Down
2 changes: 1 addition & 1 deletion adapters/adoppler/adopplertest/exemplary/no-bid.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"banner": {"w": 100,
"h": 200},
"ext": {"bidder": {"adunit": "unit1"}}}]},
"httpCalls": [{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit1",
"httpCalls": [{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit1",
"body": {"id": "req1-unit1",
"imp": [{"id": "imp1",
"banner": {"w": 100, "h": 200},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"banner": {"w": 100,
"h": 200},
"ext": {"bidder": {"adunit": "unit1"}}}]},
"httpCalls": [{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit1",
"httpCalls": [{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit1",
"body": {"id": "req1-unit1",
"imp": [{"id": "imp1",
"banner": {"w": 100, "h": 200},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"banner": {"w": 100,
"h": 200},
"ext": {"bidder": {"adunit": "unit2"}}}]},
"httpCalls": [{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit1",
"httpCalls": [{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit1",
"body": {"id": "req1-unit1",
"imp": [{"id": "imp1",
"banner": {"w": 100, "h": 200},
Expand All @@ -19,7 +19,7 @@
"price": 0.12,
"adm": "<b>a banner</b>"}]}],
"cur": "USD"}}},
{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit2",
{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit2",
"body": {"id": "req1-unit2",
"imp": [{"id": "imp1",
"banner": {"w": 100, "h": 200},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"banner": {"w": 100,
"h": 200},
"ext": {"bidder": {"adunit": "unit1"}}}]},
"httpCalls": [{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit1",
"httpCalls": [{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit1",
"body": {"id": "req1-unit1",
"imp": [{"id": "imp1",
"banner": {"w": 100, "h": 200},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"banner": {"w": 100,
"h": 200},
"ext": {"bidder": {"adunit": "unit1"}}}]},
"httpCalls": [{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit1",
"httpCalls": [{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit1",
"body": {"id": "req1-unit1",
"imp": [{"id": "imp1",
"banner": {"w": 100, "h": 200},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"video": {"minduration": 120,
"mimes": ["video/mp4"]},
"ext": {"bidder": {"adunit": "unit2"}}}]},
"httpCalls": [{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit1",
"httpCalls": [{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit1",
"body": {"id": "req1-unit1",
"imp": [{"id": "imp1",
"video": {"minduration": 120,
Expand All @@ -22,7 +22,7 @@
"cat": ["IAB1", "IAB2"],
"ext": {}}]}],
"cur": "USD"}}},
{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit2",
{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit2",
"body": {"id": "req1-unit2",
"imp": [{"id": "imp2",
"video": {"minduration": 120,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"banner": {"w": 100,
"h": 200},
"ext": {"bidder": {"adunit": "unit1"}}}]},
"httpCalls": [{"expectedRequest": {"uri": "http://adoppler.com/processHeaderBid/unit1",
"httpCalls": [{"expectedRequest": {"uri": "http://app.trustedmarketplace.com/processHeaderBid/unit1",
"body": {"id": "req1-unit1",
"imp": [{"id": "imp1",
"banner": {"w": 100, "h": 200},
Expand Down
8 changes: 6 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,11 @@ func validateAdapterEndpoint(endpoint string, adapterName string, errs configErr
return append(errs, fmt.Errorf("Invalid endpoint template: %s for adapter: %s. %v", endpoint, adapterName, err))
}
// Resolve macros (if any) in the endpoint URL
resolvedEndpoint, err := macros.ResolveMacros(*endpointTemplate, macros.EndpointTemplateParams{Host: dummyHost, PublisherID: dummyPublisherID, AccountID: dummyAccountID})
resolvedEndpoint, err := macros.ResolveMacros(*endpointTemplate, macros.EndpointTemplateParams{
Host: dummyHost,
PublisherID: dummyPublisherID,
AccountID: dummyAccountID,
})
if err != nil {
return append(errs, fmt.Errorf("Unable to resolve endpoint: %s for adapter: %s. %v", endpoint, adapterName, err))
}
Expand Down Expand Up @@ -925,7 +929,7 @@ func SetupViper(v *viper.Viper, filename string) {
v.SetDefault("adapters.adman.endpoint", "http://pub.admanmedia.com/?c=o&m=ortb")
v.SetDefault("adapters.admixer.endpoint", "http://inv-nets.admixer.net/pbs.aspx")
v.SetDefault("adapters.adocean.endpoint", "https://{{.Host}}")
v.SetDefault("adapters.adoppler.endpoint", "http://app.trustedmarketplace.io/ads")
v.SetDefault("adapters.adoppler.endpoint", "http://{{.AccountID}}.trustedmarketplace.io/ads")
v.SetDefault("adapters.adpone.endpoint", "http://rtb.adpone.com/bid-request?src=prebid_server")
v.SetDefault("adapters.adprime.endpoint", "http://delta.adprime.com/?c=o&m=ortb")
v.SetDefault("adapters.adtarget.endpoint", "http://ghb.console.adtarget.com.tr/pbs/ortb")
Expand Down
1 change: 1 addition & 0 deletions macros/macros.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type EndpointTemplateParams struct {
ZoneID string
SourceId string
AccountID string
AdUnit string
}

// UserSyncTemplateParams specifies params for an user sync URL template
Expand Down
1 change: 1 addition & 0 deletions openrtb_ext/imp_adoppler.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package openrtb_ext

type ExtImpAdoppler struct {
Client string `json:"client"`
AdUnit string `json:"adunit"`
}
4 changes: 4 additions & 0 deletions static/bidder-params/adoppler.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"adunit": {
"type": "string",
"description": "AdUnit to bid against to."
},
"client": {
"type": "string",
"description": "Client name."
}
},
"required": ["adunit"]
Expand Down

0 comments on commit 671f5a8

Please sign in to comment.