From b0408f3146c12cd2cdc348c12da5c80301841adc Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Tue, 25 Jun 2019 18:00:34 -0700 Subject: [PATCH 01/11] Submitting Prebid Server --- adapters/advangelists/advangelists.go | 136 ++++++++++++++++++ adapters/advangelists/advangelists_test.go | 10 ++ .../advangeliststest/exemplary/banner.json | 98 +++++++++++++ .../advangeliststest/params/race/banner.json | 3 + adapters/advangelists/params_test.go | 45 ++++++ config/config.go | 1 + exchange/adapter_map.go | 10 +- openrtb_ext/bidders.go | 2 + openrtb_ext/imp_advangelists.go | 5 + static/bidder-info/advangelists.yaml | 11 ++ static/bidder-params/advangelists.json | 14 ++ 11 files changed, 331 insertions(+), 4 deletions(-) create mode 100644 adapters/advangelists/advangelists.go create mode 100644 adapters/advangelists/advangelists_test.go create mode 100644 adapters/advangelists/advangeliststest/exemplary/banner.json create mode 100644 adapters/advangelists/advangeliststest/params/race/banner.json create mode 100644 adapters/advangelists/params_test.go create mode 100644 openrtb_ext/imp_advangelists.go create mode 100644 static/bidder-info/advangelists.yaml create mode 100644 static/bidder-params/advangelists.json diff --git a/adapters/advangelists/advangelists.go b/adapters/advangelists/advangelists.go new file mode 100644 index 00000000000..48a9b64b7f7 --- /dev/null +++ b/adapters/advangelists/advangelists.go @@ -0,0 +1,136 @@ +package advangelists + +import ( + "encoding/json" + "fmt" + "github.com/mxmCherry/openrtb" + "github.com/prebid/prebid-server/adapters" + "github.com/prebid/prebid-server/errortypes" + "github.com/prebid/prebid-server/openrtb_ext" + "net/http" +) + +type AdvangelistsAdapter struct { + URI string +} + +func (g *AdvangelistsAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { + var validImps []openrtb.Imp + var trackingId string + + numRequests := len(request.Imp) + errs := make([]error, 0, numRequests) + + for i := 0; i < numRequests; i++ { + + imp := request.Imp[i] + zone, err := preprocess(&imp) + if err != nil { + errs = append(errs, err) + } else { + if request.Imp[i].Banner != nil { + bannerCopy := *request.Imp[i].Banner + if bannerCopy.W == nil && bannerCopy.H == nil && len(bannerCopy.Format) > 0 { + format := bannerCopy.Format[0] + bannerCopy.W = &(format.W) + bannerCopy.H = &(format.H) + } + request.Imp[i].Banner = &bannerCopy + validImps = append(validImps, request.Imp[i]) + trackingId = zone + } + } + } + + if len(validImps) == 0 { + return nil, errs + } + + request.Imp = validImps + + if request.Site != nil { + siteCopy := *request.Site + siteCopy.ID = trackingId + request.Site = &siteCopy + } + + reqJSON, err := json.Marshal(request) + if err != nil { + errs = append(errs, err) + return nil, errs + } + + headers := http.Header{} + headers.Add("Content-Type", "application/json;charset=utf-8") + headers.Add("Accept", "application/json") + return []*adapters.RequestData{{ + Method: "POST", + Uri: g.URI, + Body: reqJSON, + Headers: headers, + }}, errs +} + +func (g *AdvangelistsAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { + if response.StatusCode == http.StatusNoContent { + return nil, nil + } + + if response.StatusCode == http.StatusBadRequest { + return nil, []error{&errortypes.BadInput{ + Message: fmt.Sprintf("Bad user input: HTTP status %d", response.StatusCode), + }} + } + + if response.StatusCode != http.StatusOK { + return nil, []error{&errortypes.BadServerResponse{ + Message: fmt.Sprintf("Bad server response: HTTP status %d", response.StatusCode), + }} + } + var bidResp openrtb.BidResponse + if err := json.Unmarshal(response.Body, &bidResp); err != nil { + return nil, []error{&errortypes.BadServerResponse{ + Message: fmt.Sprintf("Bad server response: %d. ", err), + }} + } + + var errs []error + bidResponse := adapters.NewBidderResponseWithBidsCapacity(5) + + for _, sb := range bidResp.SeatBid { + for i := range sb.Bid { + bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ + Bid: &sb.Bid[i], + BidType: openrtb_ext.BidTypeBanner, + }) + } + } + return bidResponse, errs +} + +func preprocess(imp *openrtb.Imp) (string, error) { + var bidderExt adapters.ExtImpBidder + if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { + err = &errortypes.BadInput{ + Message: err.Error(), + } + return "", err + } + + var advangelistsExt openrtb_ext.ExtImpAdvangelists + if err := json.Unmarshal(bidderExt.Bidder, &advangelistsExt); err != nil { + err = &errortypes.BadInput{ + Message: err.Error(), + } + return "", err + } + + pub := advangelistsExt.Pub + return pub, nil +} + +func NewAdvangelistsBidder(endpoint string) *AdvangelistsAdapter { + return &AdvangelistsAdapter{ + URI: endpoint, + } +} diff --git a/adapters/advangelists/advangelists_test.go b/adapters/advangelists/advangelists_test.go new file mode 100644 index 00000000000..eeb065527d9 --- /dev/null +++ b/adapters/advangelists/advangelists_test.go @@ -0,0 +1,10 @@ +package advangelists + +import ( + "github.com/prebid/prebid-server/adapters/adapterstest" + "testing" +) + +func TestJsonSamples(t *testing.T) { + adapterstest.RunJSONBidderTest(t, "advangeliststest", NewAdvangelistsBidder("http://nep.advangelists.com/xp/get?pubid=19f1b372c7548ec1fe734d2c9f8dc688")) +} diff --git a/adapters/advangelists/advangeliststest/exemplary/banner.json b/adapters/advangelists/advangeliststest/exemplary/banner.json new file mode 100644 index 00000000000..608f5b13426 --- /dev/null +++ b/adapters/advangelists/advangeliststest/exemplary/banner.json @@ -0,0 +1,98 @@ +{ + "mockBidRequest": { + "id": "testid", + "imp": [ + { + "id": "testimpid", + "banner": { + "format": [ + { + "w": 320, + "h": 250 + }, + { + "w": 320, + "h": 300 + } + ], + "w": 320, + "h": 250 + }, + "ext": { + "bidder": { + "pubid": "19f1b372c7548ec1fe734d2c9f8dc688" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://nep.advangelists.com/xp/get?pubid=19f1b372c7548ec1fe734d2c9f8dc688", + "body":{ + "id": "testid", + "imp": [{ + "id": "testimpid", + "banner": { + "format": [{ + "w": 320, + "h": 250 + }, { + "w": 320, + "h": 300 + }], + "w": 320, + "h": 250 + }, + "ext": { + "bidder": { + "pubid": "19f1b372c7548ec1fe734d2c9f8dc688" + } + } + }] + } + }, + "mockResponse": { + "status": 200, + "body": { + "seatbid": [ + { + "bid": [ + { + "crid": "24080", + "adid": "2068416", + "price": 0.01, + "id": "testid", + "impid": "testimpid", + "cid": "8048" + } + ] + } + ] + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "crid": "24080", + "adid": "2068416", + "price": 0.01, + "id": "testid", + "impid": "testimpid", + "cid": "8048" + }, + "type": "banner" + } + ] + } + ] + } + \ No newline at end of file diff --git a/adapters/advangelists/advangeliststest/params/race/banner.json b/adapters/advangelists/advangeliststest/params/race/banner.json new file mode 100644 index 00000000000..7d904b2a891 --- /dev/null +++ b/adapters/advangelists/advangeliststest/params/race/banner.json @@ -0,0 +1,3 @@ +{ + "pubid": "2621084b0cd698cf2f7dfcd0f2e9cf9a" +} diff --git a/adapters/advangelists/params_test.go b/adapters/advangelists/params_test.go new file mode 100644 index 00000000000..a58217a0ffd --- /dev/null +++ b/adapters/advangelists/params_test.go @@ -0,0 +1,45 @@ +package advangelists + +import ( + "encoding/json" + "github.com/prebid/prebid-server/openrtb_ext" + "testing" +) + +func TestValidParams(t *testing.T) { + validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") + if err != nil { + t.Fatalf("Failed to fetch the json-schemas. %v", err) + } + + for _, validParam := range validParams { + if err := validator.Validate(openrtb_ext.BidderAdvangelists, json.RawMessage(validParam)); err != nil { + t.Errorf("Schema rejected Advangelists params: %s", validParam) + } + } +} + +func TestInvalidParams(t *testing.T) { + validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") + if err != nil { + t.Fatalf("Failed to fetch the json-schemas. %v", err) + } + + for _, invalidParam := range invalidParams { + if err := validator.Validate(openrtb_ext.BidderAdvangelists, json.RawMessage(invalidParam)); err == nil { + t.Errorf("Schema allowed unexpected params: %s", invalidParam) + } + } +} + +var validParams = []string{ + `{"pubid": "19f1b372c7548ec1fe734d2c9f8dc688"}`, +} + +var invalidParams = []string{ + `null`, + `nil`, + ``, + `[]`, + `true`, +} diff --git a/config/config.go b/config/config.go index 00e45e4907b..0928594eb5a 100644 --- a/config/config.go +++ b/config/config.go @@ -581,6 +581,7 @@ func SetupViper(v *viper.Viper, filename string) { v.SetDefault("adapters.adtelligent.endpoint", "http://hb.adtelligent.com/auction") v.SetDefault("adapters.adform.endpoint", "http://adx.adform.net/adx") v.SetDefault("adapters.appnexus.endpoint", "http://ib.adnxs.com/openrtb2") // Docs: https://wiki.appnexus.com/display/supply/Incoming+Bid+Request+from+SSPs + v.SetDefault("adapters.advangelists.endpoint", "http://nep.advangelists.com/xp/get?pubid=0cf8d6d643e13d86a5b6374148a4afac") v.SetDefault("adapters.beachfront.endpoint", "https://display.bfmio.com/prebid_display") v.SetDefault("adapters.beachfront.platform_id", "155") v.SetDefault("adapters.brightroll.endpoint", "http://east-bid.ybp.yahoo.com/bid/appnexuspbs") diff --git a/exchange/adapter_map.go b/exchange/adapter_map.go index 6bce21f0202..d3e1d77a5a9 100644 --- a/exchange/adapter_map.go +++ b/exchange/adapter_map.go @@ -10,6 +10,7 @@ import ( "github.com/prebid/prebid-server/adapters/adform" "github.com/prebid/prebid-server/adapters/adkernelAdn" "github.com/prebid/prebid-server/adapters/adtelligent" + "github.com/prebid/prebid-server/adapters/advangelists" "github.com/prebid/prebid-server/adapters/appnexus" "github.com/prebid/prebid-server/adapters/audienceNetwork" "github.com/prebid/prebid-server/adapters/beachfront" @@ -46,10 +47,11 @@ import ( func newAdapterMap(client *http.Client, cfg *config.Configuration, infos adapters.BidderInfos) map[openrtb_ext.BidderName]adaptedBidder { ortbBidders := map[openrtb_ext.BidderName]adapters.Bidder{ - openrtb_ext.BidderAdform: adform.NewAdformBidder(client, cfg.Adapters[string(openrtb_ext.BidderAdform)].Endpoint), - openrtb_ext.BidderAdkernelAdn: adkernelAdn.NewAdkernelAdnAdapter(cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderAdkernelAdn))].Endpoint), - openrtb_ext.BidderAdtelligent: adtelligent.NewAdtelligentBidder(cfg.Adapters[string(openrtb_ext.BidderAdtelligent)].Endpoint), - openrtb_ext.BidderAppnexus: appnexus.NewAppNexusBidder(client, cfg.Adapters[string(openrtb_ext.BidderAppnexus)].Endpoint), + openrtb_ext.BidderAdform: adform.NewAdformBidder(client, cfg.Adapters[string(openrtb_ext.BidderAdform)].Endpoint), + openrtb_ext.BidderAdkernelAdn: adkernelAdn.NewAdkernelAdnAdapter(cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderAdkernelAdn))].Endpoint), + openrtb_ext.BidderAdtelligent: adtelligent.NewAdtelligentBidder(cfg.Adapters[string(openrtb_ext.BidderAdtelligent)].Endpoint), + openrtb_ext.BidderAdvangelists: advangelists.NewAdvangelistsBidder(cfg.Adapters[string(openrtb_ext.BidderAdvangelists)].Endpoint), + openrtb_ext.BidderAppnexus: appnexus.NewAppNexusBidder(client, cfg.Adapters[string(openrtb_ext.BidderAppnexus)].Endpoint), // TODO #615: Update the config setup so that the Beachfront URLs can be configured, and use those in TestRaceIntegration in exchange_test.go openrtb_ext.BidderBeachfront: beachfront.NewBeachfrontBidder(), openrtb_ext.BidderBrightroll: brightroll.NewBrightrollBidder(cfg.Adapters[string(openrtb_ext.BidderBrightroll)].Endpoint), diff --git a/openrtb_ext/bidders.go b/openrtb_ext/bidders.go index 22e165762c1..10a63a500e9 100644 --- a/openrtb_ext/bidders.go +++ b/openrtb_ext/bidders.go @@ -24,6 +24,7 @@ const ( BidderAdkernelAdn BidderName = "adkernelAdn" BidderAdtelligent BidderName = "adtelligent" BidderAdform BidderName = "adform" + BidderAdvangelists BidderName = "advangelists" BidderAppnexus BidderName = "appnexus" BidderBeachfront BidderName = "beachfront" BidderBrightroll BidderName = "brightroll" @@ -59,6 +60,7 @@ var BidderMap = map[string]BidderName{ "adkernelAdn": BidderAdkernelAdn, "adtelligent": BidderAdtelligent, "adform": BidderAdform, + "advangelists": BidderAdvangelists, "appnexus": BidderAppnexus, "beachfront": BidderBeachfront, "audienceNetwork": BidderFacebook, diff --git a/openrtb_ext/imp_advangelists.go b/openrtb_ext/imp_advangelists.go new file mode 100644 index 00000000000..21eb236c83a --- /dev/null +++ b/openrtb_ext/imp_advangelists.go @@ -0,0 +1,5 @@ +package openrtb_ext + +type ExtImpAdvangelists struct { + Pub string `json:"pubid"` +} diff --git a/static/bidder-info/advangelists.yaml b/static/bidder-info/advangelists.yaml new file mode 100644 index 00000000000..e3eba4aaf5e --- /dev/null +++ b/static/bidder-info/advangelists.yaml @@ -0,0 +1,11 @@ +maintainer: + email: "lokesh@advangelists.com" +capabilities: + site: + mediaTypes: + - banner + + app: + mediaTypes: + - banner + diff --git a/static/bidder-params/advangelists.json b/static/bidder-params/advangelists.json new file mode 100644 index 00000000000..c1b13d21767 --- /dev/null +++ b/static/bidder-params/advangelists.json @@ -0,0 +1,14 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Advangelists Adapter Params", + "description": "A schema which validates params accepted by the Advangelists adapter", + "type": "object", + "properties": { + "pubid": { + "type": "string", + "description": "An id used to identify Advangelists publisher.", + "minLength": 8 + } + }, + "required": ["pubid"] +} From 918aeb5552cc65175e6e976c3d6df2e0f07f0807 Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Tue, 2 Jul 2019 15:20:15 -0700 Subject: [PATCH 02/11] Update Advangelists bidder code --- adapters/advangelists/advangelists.go | 289 +++++++++++++----- adapters/advangelists/advangelists_test.go | 2 +- .../advangeliststest/exemplary/banner.json | 7 +- .../advangeliststest/params/race/banner.json | 2 +- adapters/advangelists/usersync.go | 12 + adapters/advangelists/usersync_test.go | 19 ++ config/config.go | 7 +- macros/macros.go | 1 + openrtb_ext/imp_advangelists.go | 2 +- usersync/usersyncers/syncer.go | 2 + usersync/usersyncers/syncer_test.go | 1 + 11 files changed, 256 insertions(+), 88 deletions(-) create mode 100644 adapters/advangelists/usersync.go create mode 100644 adapters/advangelists/usersync_test.go diff --git a/adapters/advangelists/advangelists.go b/adapters/advangelists/advangelists.go index 48a9b64b7f7..3930071baf8 100644 --- a/adapters/advangelists/advangelists.go +++ b/adapters/advangelists/advangelists.go @@ -3,134 +3,267 @@ package advangelists import ( "encoding/json" "fmt" + "net/http" + "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" - "net/http" ) +const defaultDomain string = "nep.advangelists.com" + type AdvangelistsAdapter struct { - URI string + EndpointTemplate template.Template } -func (g *AdvangelistsAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { - var validImps []openrtb.Imp - var trackingId string - - numRequests := len(request.Imp) - errs := make([]error, 0, numRequests) - - for i := 0; i < numRequests; i++ { +//MakeRequests prepares request information for prebid-server core +func (adapter *AdvangelistsAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { + errs := make([]error, 0, len(request.Imp)) + if len(request.Imp) == 0 { + errs = append(errs, newBadInputError("No impression in the bid request")) + return nil, errs + } + imps, impExts, err := getImpressionsInfo(request.Imp) + if len(imps) == 0 { + return nil, err + } + errs = append(errs, err...) - imp := request.Imp[i] - zone, err := preprocess(&imp) + pub2impressions, dispErrors := dispatchImpressions(imps, impExts) + if len(dispErrors) > 0 { + errs = append(errs, dispErrors...) + } + if len(pub2impressions) == 0 { + return nil, errs + } + result := make([]*adapters.RequestData, 0, len(pub2impressions)) + for k, imps := range pub2impressions { + bidRequest, err := adapter.buildAdapterRequest(request, &k, imps) if err != nil { errs = append(errs, err) } else { - if request.Imp[i].Banner != nil { - bannerCopy := *request.Imp[i].Banner - if bannerCopy.W == nil && bannerCopy.H == nil && len(bannerCopy.Format) > 0 { - format := bannerCopy.Format[0] - bannerCopy.W = &(format.W) - bannerCopy.H = &(format.H) - } - request.Imp[i].Banner = &bannerCopy - validImps = append(validImps, request.Imp[i]) - trackingId = zone - } + result = append(result, bidRequest) } } + return result, errs +} + +// getImpressionsInfo checks each impression for validity and returns impressions copy with corresponding exts +func getImpressionsInfo(imps []openrtb.Imp) ([]openrtb.Imp, []openrtb_ext.ExtImpAdvangelists, []error) { + impsCount := len(imps) + errors := make([]error, 0, impsCount) + resImps := make([]openrtb.Imp, 0, impsCount) + resImpExts := make([]openrtb_ext.ExtImpAdvangelists, 0, impsCount) + + for _, imp := range imps { + impExt, err := getImpressionExt(&imp) + if err != nil { + errors = append(errors, err) + continue + } + if err := validateImpression(&imp, impExt); err != nil { + errors = append(errors, err) + continue + } + resImps = append(resImps, imp) + resImpExts = append(resImpExts, *impExt) - if len(validImps) == 0 { - return nil, errs } + return resImps, resImpExts, errors +} - request.Imp = validImps +func validateImpression(imp *openrtb.Imp, impExt *openrtb_ext.ExtImpAdvangelists) error { + if impExt.Pubid == "" { + return newBadInputError(fmt.Sprintf("Invalid pubId value. Ignoring imp id=%s", imp.ID)) + } + return nil +} + +//Group impressions by advangelists-specific parameters `pubid +func dispatchImpressions(imps []openrtb.Imp, impsExt []openrtb_ext.ExtImpAdvangelists) (map[openrtb_ext.ExtImpAdvangelists][]openrtb.Imp, []error) { + res := make(map[openrtb_ext.ExtImpAdvangelists][]openrtb.Imp) + errors := make([]error, 0) + for idx := range imps { + imp := imps[idx] + err := compatImpression(&imp) + if err != nil { + errors = append(errors, err) + continue + } + impExt := impsExt[idx] + if res[impExt] == nil { + res[impExt] = make([]openrtb.Imp, 0) + } + res[impExt] = append(res[impExt], imp) - if request.Site != nil { - siteCopy := *request.Site - siteCopy.ID = trackingId - request.Site = &siteCopy } + return res, errors +} + +//Alter impression info to comply with advangelists platform requirements +func compatImpression(imp *openrtb.Imp) error { + imp.Ext = nil //do not forward ext to advangelists platform + if imp.Banner != nil { + return compatBannerImpression(imp) + } + return nil +} + +func compatBannerImpression(imp *openrtb.Imp) error { + // Create a copy of the banner, since imp is a shallow copy of the original. + bannerCopy := *imp.Banner + banner := &bannerCopy + //As banner.w/h are required fields for advangelistsAdn platform - take the first format entry + if banner.W == nil && banner.H == nil { + if len(banner.Format) == 0 { + return newBadInputError(fmt.Sprintf("Expected at least one banner.format entry or explicit w/h")) + } + format := banner.Format[0] + banner.Format = banner.Format[1:] + banner.W = &format.W + banner.H = &format.H + imp.Banner = banner + } + return nil +} + +func getImpressionExt(imp *openrtb.Imp) (*openrtb_ext.ExtImpAdvangelists, error) { + var bidderExt adapters.ExtImpBidder + if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { + return nil, &errortypes.BadInput{ + Message: err.Error(), + } + } + var advangelistsExt openrtb_ext.ExtImpAdvangelists + if err := json.Unmarshal(bidderExt.Bidder, &advangelistsExt); err != nil { + return nil, &errortypes.BadInput{ + Message: err.Error(), + } + } + return &advangelistsExt, nil +} - reqJSON, err := json.Marshal(request) +func (adapter *AdvangelistsAdapter) buildAdapterRequest(prebidBidRequest *openrtb.BidRequest, params *openrtb_ext.ExtImpAdvangelists, imps []openrtb.Imp) (*adapters.RequestData, error) { + newBidRequest := createBidRequest(prebidBidRequest, params, imps) + reqJSON, err := json.Marshal(newBidRequest) if err != nil { - errs = append(errs, err) - return nil, errs + return nil, err } headers := http.Header{} headers.Add("Content-Type", "application/json;charset=utf-8") headers.Add("Accept", "application/json") - return []*adapters.RequestData{{ + headers.Add("x-openrtb-version", "2.5") + + url, err := adapter.buildEndpointURL(params) + if err != nil { + return nil, err + } + + return &adapters.RequestData{ Method: "POST", - Uri: g.URI, + Uri: url, Body: reqJSON, - Headers: headers, - }}, errs + Headers: headers}, nil } -func (g *AdvangelistsAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { - if response.StatusCode == http.StatusNoContent { - return nil, nil +func createBidRequest(prebidBidRequest *openrtb.BidRequest, params *openrtb_ext.ExtImpAdvangelists, imps []openrtb.Imp) *openrtb.BidRequest { + bidRequest := *prebidBidRequest + bidRequest.Imp = imps + for idx := range bidRequest.Imp { + imp := &bidRequest.Imp[idx] + imp.TagID = imp.ID } - - if response.StatusCode == http.StatusBadRequest { - return nil, []error{&errortypes.BadInput{ - Message: fmt.Sprintf("Bad user input: HTTP status %d", response.StatusCode), - }} + if bidRequest.Site != nil { + // Need to copy Site as Request is a shallow copy + siteCopy := *bidRequest.Site + bidRequest.Site = &siteCopy + bidRequest.Site.Publisher = nil + bidRequest.Site.Domain = "" } + if bidRequest.App != nil { + // Need to copy App as Request is a shallow copy + appCopy := *bidRequest.App + bidRequest.App = &appCopy + bidRequest.App.Publisher = nil + } + return &bidRequest +} + +// Builds enpoint url based on adapter-specific pub settings from imp.ext +func (adapter *AdvangelistsAdapter) buildEndpointURL(params *openrtb_ext.ExtImpAdvangelists) (string, error) { + + endpointParams := macros.EndpointTemplateParams{Pubid: params.Pubid} + return macros.ResolveMacros(adapter.EndpointTemplate, endpointParams) +} +//MakeBids translates advangelists bid response to prebid-server specific format +func (adapter *AdvangelistsAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { + if response.StatusCode == http.StatusNoContent { + return nil, nil + } if response.StatusCode != http.StatusOK { - return nil, []error{&errortypes.BadServerResponse{ - Message: fmt.Sprintf("Bad server response: HTTP status %d", response.StatusCode), - }} + return nil, []error{ + newBadServerResponseError(fmt.Sprintf("Unexpected http status code: %d", response.StatusCode)), + } } var bidResp openrtb.BidResponse if err := json.Unmarshal(response.Body, &bidResp); err != nil { - return nil, []error{&errortypes.BadServerResponse{ - Message: fmt.Sprintf("Bad server response: %d. ", err), - }} + return nil, []error{ + newBadServerResponseError(fmt.Sprintf("Bad server response: %d", err)), + } + } + if len(bidResp.SeatBid) != 1 { + return nil, []error{ + newBadServerResponseError(fmt.Sprintf("Invalid SeatBids count: %d", len(bidResp.SeatBid))), + } } - var errs []error - bidResponse := adapters.NewBidderResponseWithBidsCapacity(5) + seatBid := bidResp.SeatBid[0] + bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(bidResp.SeatBid[0].Bid)) - for _, sb := range bidResp.SeatBid { - for i := range sb.Bid { - bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ - Bid: &sb.Bid[i], - BidType: openrtb_ext.BidTypeBanner, - }) - } + for i := 0; i < len(seatBid.Bid); i++ { + bid := seatBid.Bid[i] + bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ + Bid: &bid, + BidType: getMediaTypeForImpID(bid.ImpID, internalRequest.Imp), + }) } - return bidResponse, errs + return bidResponse, nil } -func preprocess(imp *openrtb.Imp) (string, error) { - var bidderExt adapters.ExtImpBidder - if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { - err = &errortypes.BadInput{ - Message: err.Error(), +// getMediaTypeForImp figures out which media type this bid is for +func getMediaTypeForImpID(impID string, imps []openrtb.Imp) openrtb_ext.BidType { + for _, imp := range imps { + if imp.ID == impID && imp.Video != nil { + return openrtb_ext.BidTypeVideo } - return "", err } + return openrtb_ext.BidTypeBanner +} - var advangelistsExt openrtb_ext.ExtImpAdvangelists - if err := json.Unmarshal(bidderExt.Bidder, &advangelistsExt); err != nil { - err = &errortypes.BadInput{ - Message: err.Error(), - } - return "", err +func newBadInputError(message string) error { + return &errortypes.BadInput{ + Message: message, } +} - pub := advangelistsExt.Pub - return pub, nil +func newBadServerResponseError(message string) error { + return &errortypes.BadServerResponse{ + Message: message, + } } -func NewAdvangelistsBidder(endpoint string) *AdvangelistsAdapter { - return &AdvangelistsAdapter{ - URI: endpoint, +// NewAdvangelistsAdapter to be called in prebid-server core to create advangelists adapter instance +func NewAdvangelistsBidder(endpointTemplate string) adapters.Bidder { + template, err := template.New("endpointTemplate").Parse(endpointTemplate) + if err != nil { + glog.Fatal("Unable to parse endpoint url template") + return nil } + return &AdvangelistsAdapter{EndpointTemplate: *template} } diff --git a/adapters/advangelists/advangelists_test.go b/adapters/advangelists/advangelists_test.go index eeb065527d9..e4c6636bd06 100644 --- a/adapters/advangelists/advangelists_test.go +++ b/adapters/advangelists/advangelists_test.go @@ -6,5 +6,5 @@ import ( ) func TestJsonSamples(t *testing.T) { - adapterstest.RunJSONBidderTest(t, "advangeliststest", NewAdvangelistsBidder("http://nep.advangelists.com/xp/get?pubid=19f1b372c7548ec1fe734d2c9f8dc688")) + adapterstest.RunJSONBidderTest(t, "advangeliststest", NewAdvangelistsBidder("http://nep.advangelists.com/xp/get?pubid={{.Pubid}}")) } diff --git a/adapters/advangelists/advangeliststest/exemplary/banner.json b/adapters/advangelists/advangeliststest/exemplary/banner.json index 608f5b13426..1ad4e56245d 100644 --- a/adapters/advangelists/advangeliststest/exemplary/banner.json +++ b/adapters/advangelists/advangeliststest/exemplary/banner.json @@ -35,6 +35,7 @@ "id": "testid", "imp": [{ "id": "testimpid", + "tagid": "testimpid", "banner": { "format": [{ "w": 320, @@ -45,12 +46,8 @@ }], "w": 320, "h": 250 - }, - "ext": { - "bidder": { - "pubid": "19f1b372c7548ec1fe734d2c9f8dc688" - } } + }] } }, diff --git a/adapters/advangelists/advangeliststest/params/race/banner.json b/adapters/advangelists/advangeliststest/params/race/banner.json index 7d904b2a891..d4305090b14 100644 --- a/adapters/advangelists/advangeliststest/params/race/banner.json +++ b/adapters/advangelists/advangeliststest/params/race/banner.json @@ -1,3 +1,3 @@ { - "pubid": "2621084b0cd698cf2f7dfcd0f2e9cf9a" + "pubid": "19f1b372c7548ec1fe734d2c9f8dc688" } diff --git a/adapters/advangelists/usersync.go b/adapters/advangelists/usersync.go new file mode 100644 index 00000000000..6167a2e39d9 --- /dev/null +++ b/adapters/advangelists/usersync.go @@ -0,0 +1,12 @@ +package advangelists + +import ( + "text/template" + + "github.com/prebid/prebid-server/adapters" + "github.com/prebid/prebid-server/usersync" +) + +func NewAdvangelistsSyncer(temp *template.Template) usersync.Usersyncer { + return adapters.NewSyncer("advangelists", 61, temp, adapters.SyncTypeIframe) +} diff --git a/adapters/advangelists/usersync_test.go b/adapters/advangelists/usersync_test.go new file mode 100644 index 00000000000..8880788ccf1 --- /dev/null +++ b/adapters/advangelists/usersync_test.go @@ -0,0 +1,19 @@ +package advangelists + +import ( + "testing" + "text/template" + + "github.com/stretchr/testify/assert" +) + +func TestAdvangelistsSyncer(t *testing.T) { + temp := template.Must(template.New("sync-template").Parse("https://nep.advangelists.com/xp/user-sync?acctid={aid}&&redirect=localhost/setuid?bidder=advangelists&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&uid=$UID")) + syncer := NewAdvangelistsSyncer(temp) + syncInfo, err := syncer.GetUsersyncInfo("1", "BOPVK28OVJoTBABABAENBs-AAAAhuAKAANAAoACwAGgAPAAxAB0AHgAQAAiABOADkA") + assert.NoError(t, err) + assert.Equal(t, "https://nep.advangelists.com/xp/user-sync?acctid={aid}&&redirect=localhost/setuid?bidder=advangelists&gdpr=1&gdpr_consent=BOPVK28OVJoTBABABAENBs-AAAAhuAKAANAAoACwAGgAPAAxAB0AHgAQAAiABOADkA&uid=$UID", syncInfo.URL) + assert.Equal(t, "iframe", syncInfo.Type) + assert.EqualValues(t, 61, syncer.GDPRVendorID()) + assert.Equal(t, false, syncInfo.SupportCORS) +} diff --git a/config/config.go b/config/config.go index 0928594eb5a..05c9e611ba3 100644 --- a/config/config.go +++ b/config/config.go @@ -185,7 +185,9 @@ func (cfg *HostCookie) TTLDuration() time.Duration { const ( dummyHost string = "dummyhost.com" dummyPublisherID int = 12 + dummyPubid string = "dummypubid" dummyGDPR string = "0" + dummyGDPRConsent string = "someGDPRConsentString" ) @@ -229,7 +231,7 @@ 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}) + resolvedEndpoint, err := macros.ResolveMacros(*endpointTemplate, macros.EndpointTemplateParams{Host: dummyHost, PublisherID: dummyPublisherID, Pubid: dummyPubid}) if err != nil { return append(errs, fmt.Errorf("Unable to resolve endpoint: %s for adapter: %s. %v", endpoint, adapterName, err)) } @@ -422,6 +424,7 @@ func (cfg *Configuration) setDerivedDefaults() { setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderAdkernelAdn, "https://tag.adkernel.com/syncr?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&r="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3DadkernelAdn%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%7BUID%7D") setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderAdtelligent, "https://sync.adtelligent.com/csync?t=p&ep=0&redir="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dadtelligent%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%7Buid%7D") setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderAdform, "https://cm.adform.net/cookie?redirect_url="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dadform%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID") + setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderAdvangelists, "https://nep.advangelists.com/xp/user-sync?acctid={aid}&&redirect="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dadvangelists%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID") setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderAppnexus, "https://ib.adnxs.com/getuid?"+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dadnxs%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID") setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderBrightroll, "https://pr-bh.ybp.yahoo.com/sync/appnexusprebidserver/?gdpr={{.GDPR}}&euconsent={{.GDPRConsent}}&url="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dbrightroll%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID") setDefaultUsersync(cfg.Adapters, openrtb_ext.BidderBeachfront, "https://sync.bfmio.com/sync_s2s?gdpr={{.GDPR}}&url="+url.QueryEscape(externalURL)+"%2Fsetuid%3Fbidder%3Dbeachfront%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%5Bio_cid%5D") @@ -581,7 +584,7 @@ func SetupViper(v *viper.Viper, filename string) { v.SetDefault("adapters.adtelligent.endpoint", "http://hb.adtelligent.com/auction") v.SetDefault("adapters.adform.endpoint", "http://adx.adform.net/adx") v.SetDefault("adapters.appnexus.endpoint", "http://ib.adnxs.com/openrtb2") // Docs: https://wiki.appnexus.com/display/supply/Incoming+Bid+Request+from+SSPs - v.SetDefault("adapters.advangelists.endpoint", "http://nep.advangelists.com/xp/get?pubid=0cf8d6d643e13d86a5b6374148a4afac") + v.SetDefault("adapters.advangelists.endpoint", "http://nep.advangelists.com/xp/get?pubid={{.Pubid}}") v.SetDefault("adapters.beachfront.endpoint", "https://display.bfmio.com/prebid_display") v.SetDefault("adapters.beachfront.platform_id", "155") v.SetDefault("adapters.brightroll.endpoint", "http://east-bid.ybp.yahoo.com/bid/appnexuspbs") diff --git a/macros/macros.go b/macros/macros.go index d299a6f0d78..558f6f7947a 100644 --- a/macros/macros.go +++ b/macros/macros.go @@ -8,6 +8,7 @@ import ( // EndpointTemplateParams specifies params for an endpoint template type EndpointTemplateParams struct { Host string + Pubid string PublisherID int } diff --git a/openrtb_ext/imp_advangelists.go b/openrtb_ext/imp_advangelists.go index 21eb236c83a..f3a4827960f 100644 --- a/openrtb_ext/imp_advangelists.go +++ b/openrtb_ext/imp_advangelists.go @@ -1,5 +1,5 @@ package openrtb_ext type ExtImpAdvangelists struct { - Pub string `json:"pubid"` + Pubid string `json:"pubid"` } diff --git a/usersync/usersyncers/syncer.go b/usersync/usersyncers/syncer.go index b93f235a82b..330c400675f 100644 --- a/usersync/usersyncers/syncer.go +++ b/usersync/usersyncers/syncer.go @@ -9,6 +9,7 @@ import ( "github.com/prebid/prebid-server/adapters/adform" "github.com/prebid/prebid-server/adapters/adkernelAdn" "github.com/prebid/prebid-server/adapters/adtelligent" + "github.com/prebid/prebid-server/adapters/advangelists" "github.com/prebid/prebid-server/adapters/appnexus" "github.com/prebid/prebid-server/adapters/audienceNetwork" "github.com/prebid/prebid-server/adapters/beachfront" @@ -51,6 +52,7 @@ func NewSyncerMap(cfg *config.Configuration) map[openrtb_ext.BidderName]usersync insertIntoMap(cfg, syncers, openrtb_ext.BidderAdform, adform.NewAdformSyncer) insertIntoMap(cfg, syncers, openrtb_ext.BidderAdkernelAdn, adkernelAdn.NewAdkernelAdnSyncer) insertIntoMap(cfg, syncers, openrtb_ext.BidderAdtelligent, adtelligent.NewAdtelligentSyncer) + insertIntoMap(cfg, syncers, openrtb_ext.BidderAdvangelists, advangelists.NewAdvangelistsSyncer) insertIntoMap(cfg, syncers, openrtb_ext.BidderAppnexus, appnexus.NewAppnexusSyncer) insertIntoMap(cfg, syncers, openrtb_ext.BidderBeachfront, beachfront.NewBeachfrontSyncer) insertIntoMap(cfg, syncers, openrtb_ext.BidderBrightroll, brightroll.NewBrightrollSyncer) diff --git a/usersync/usersyncers/syncer_test.go b/usersync/usersyncers/syncer_test.go index 8f97400159c..b7756538187 100644 --- a/usersync/usersyncers/syncer_test.go +++ b/usersync/usersyncers/syncer_test.go @@ -17,6 +17,7 @@ func TestNewSyncerMap(t *testing.T) { string(openrtb_ext.BidderAdform): syncConfig, string(openrtb_ext.BidderAdkernelAdn): syncConfig, string(openrtb_ext.BidderAdtelligent): syncConfig, + string(openrtb_ext.BidderAdvangelists): syncConfig, string(openrtb_ext.BidderAppnexus): syncConfig, string(openrtb_ext.BidderBeachfront): syncConfig, string(openrtb_ext.BidderFacebook): syncConfig, From 227cd74607832ebc235e211f96f106bbfe6eeff0 Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Sat, 6 Jul 2019 20:44:18 -0700 Subject: [PATCH 03/11] Add video test files --- .../advangeliststest/exemplary/video.json | 82 +++++++++++++++++++ .../advangeliststest/params/race/video.json | 3 + static/bidder-info/advangelists.yaml | 2 + 3 files changed, 87 insertions(+) create mode 100644 adapters/advangelists/advangeliststest/exemplary/video.json create mode 100644 adapters/advangelists/advangeliststest/params/race/video.json diff --git a/adapters/advangelists/advangeliststest/exemplary/video.json b/adapters/advangelists/advangeliststest/exemplary/video.json new file mode 100644 index 00000000000..930b6f1e34c --- /dev/null +++ b/adapters/advangelists/advangeliststest/exemplary/video.json @@ -0,0 +1,82 @@ +{ + "mockBidRequest": { + "id": "testid", + "imp": [ + { + "id": "testimpid", + "video": { + "mimes": [ + "video/mp4" + ], + "w": 640, + "h": 480 + }, + "ext": { + "bidder": { + "pubid": "19f1b372c7548ec1fe734d2c9f8dc688" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://nep.advangelists.com/xp/get?pubid=19f1b372c7548ec1fe734d2c9f8dc688", + "body":{ + "id": "testid", + "imp": [{ + "id": "testimpid", + "tagid": "testimpid", + "video": { + "mimes": [ + "video/mp4" + ], + "w": 640, + "h": 480 + } + }] + } + }, + "mockResponse": { + "status": 200, + "body": { + "seatbid": [ + { + "bid": [ + { + "crid": "24080", + "adid": "2068416", + "price": 0.01, + "id": "testid", + "impid": "testimpid", + "cid": "8048" + } + ] + } + ] + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "crid": "24080", + "adid": "2068416", + "price": 0.01, + "id": "testid", + "impid": "testimpid", + "cid": "8048" + }, + "type": "video" + } + ] + } + ] +} \ No newline at end of file diff --git a/adapters/advangelists/advangeliststest/params/race/video.json b/adapters/advangelists/advangeliststest/params/race/video.json new file mode 100644 index 00000000000..d4305090b14 --- /dev/null +++ b/adapters/advangelists/advangeliststest/params/race/video.json @@ -0,0 +1,3 @@ +{ + "pubid": "19f1b372c7548ec1fe734d2c9f8dc688" +} diff --git a/static/bidder-info/advangelists.yaml b/static/bidder-info/advangelists.yaml index e3eba4aaf5e..e1bc6c0a19b 100644 --- a/static/bidder-info/advangelists.yaml +++ b/static/bidder-info/advangelists.yaml @@ -4,8 +4,10 @@ capabilities: site: mediaTypes: - banner + - video app: mediaTypes: - banner + - video From d11f5b27b53d831631b086f1450a2043fb8e1c42 Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Wed, 10 Jul 2019 21:56:35 -0700 Subject: [PATCH 04/11] Changes made as requested from Prebid Some more changes related to placement. --- adapters/advangelists/advangelists.go | 49 ++--- adapters/advangelists/advangelists_test.go | 2 +- .../advangeliststest/exemplary/banner.json | 172 +++++++++--------- .../advangeliststest/exemplary/video.json | 5 +- .../advangeliststest/params/race/banner.json | 3 +- .../advangeliststest/params/race/video.json | 3 +- config/config.go | 7 +- macros/macros.go | 2 +- openrtb_ext/imp_advangelists.go | 3 +- 9 files changed, 116 insertions(+), 130 deletions(-) diff --git a/adapters/advangelists/advangelists.go b/adapters/advangelists/advangelists.go index 3930071baf8..1f04672f2bb 100644 --- a/adapters/advangelists/advangelists.go +++ b/adapters/advangelists/advangelists.go @@ -14,8 +14,6 @@ import ( "github.com/prebid/prebid-server/openrtb_ext" ) -const defaultDomain string = "nep.advangelists.com" - type AdvangelistsAdapter struct { EndpointTemplate template.Template } @@ -24,7 +22,7 @@ type AdvangelistsAdapter struct { func (adapter *AdvangelistsAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { errs := make([]error, 0, len(request.Imp)) if len(request.Imp) == 0 { - errs = append(errs, newBadInputError("No impression in the bid request")) + errs = append(errs, &errortypes.BadInput{Message: "No impression in the bid request"}) return nil, errs } imps, impExts, err := getImpressionsInfo(request.Imp) @@ -34,12 +32,11 @@ func (adapter *AdvangelistsAdapter) MakeRequests(request *openrtb.BidRequest, re errs = append(errs, err...) pub2impressions, dispErrors := dispatchImpressions(imps, impExts) - if len(dispErrors) > 0 { - errs = append(errs, dispErrors...) - } if len(pub2impressions) == 0 { return nil, errs } + errs = append(errs, dispErrors...) + result := make([]*adapters.RequestData, 0, len(pub2impressions)) for k, imps := range pub2impressions { bidRequest, err := adapter.buildAdapterRequest(request, &k, imps) @@ -77,8 +74,8 @@ func getImpressionsInfo(imps []openrtb.Imp) ([]openrtb.Imp, []openrtb_ext.ExtImp } func validateImpression(imp *openrtb.Imp, impExt *openrtb_ext.ExtImpAdvangelists) error { - if impExt.Pubid == "" { - return newBadInputError(fmt.Sprintf("Invalid pubId value. Ignoring imp id=%s", imp.ID)) + if impExt.PubID == "" { + return &errortypes.BadInput{Message: "No pubid value provided"} } return nil } @@ -120,7 +117,7 @@ func compatBannerImpression(imp *openrtb.Imp) error { //As banner.w/h are required fields for advangelistsAdn platform - take the first format entry if banner.W == nil && banner.H == nil { if len(banner.Format) == 0 { - return newBadInputError(fmt.Sprintf("Expected at least one banner.format entry or explicit w/h")) + return &errortypes.BadInput{Message: "Expected at least one banner.format entry or explicit w/h"} } format := banner.Format[0] banner.Format = banner.Format[1:] @@ -176,7 +173,8 @@ func createBidRequest(prebidBidRequest *openrtb.BidRequest, params *openrtb_ext. bidRequest.Imp = imps for idx := range bidRequest.Imp { imp := &bidRequest.Imp[idx] - imp.TagID = imp.ID + imp.TagID = params.Placement + fmt.Printf(imp.TagID) } if bidRequest.Site != nil { // Need to copy Site as Request is a shallow copy @@ -196,31 +194,28 @@ func createBidRequest(prebidBidRequest *openrtb.BidRequest, params *openrtb_ext. // Builds enpoint url based on adapter-specific pub settings from imp.ext func (adapter *AdvangelistsAdapter) buildEndpointURL(params *openrtb_ext.ExtImpAdvangelists) (string, error) { - - endpointParams := macros.EndpointTemplateParams{Pubid: params.Pubid} + endpointParams := macros.EndpointTemplateParams{PubID: params.PubID} return macros.ResolveMacros(adapter.EndpointTemplate, endpointParams) } //MakeBids translates advangelists bid response to prebid-server specific format func (adapter *AdvangelistsAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { + var msg = "" if response.StatusCode == http.StatusNoContent { return nil, nil } if response.StatusCode != http.StatusOK { - return nil, []error{ - newBadServerResponseError(fmt.Sprintf("Unexpected http status code: %d", response.StatusCode)), - } + msg = fmt.Sprintf("Unexpected http status code: %d", response.StatusCode) + return nil, []error{&errortypes.BadServerResponse{Message: msg}} } var bidResp openrtb.BidResponse if err := json.Unmarshal(response.Body, &bidResp); err != nil { - return nil, []error{ - newBadServerResponseError(fmt.Sprintf("Bad server response: %d", err)), - } + msg = fmt.Sprintf("Bad server response: %d", err) + return nil, []error{&errortypes.BadServerResponse{Message: msg}} } if len(bidResp.SeatBid) != 1 { - return nil, []error{ - newBadServerResponseError(fmt.Sprintf("Invalid SeatBids count: %d", len(bidResp.SeatBid))), - } + var msg = fmt.Sprintf("Invalid SeatBids count: %d", len(bidResp.SeatBid)) + return nil, []error{&errortypes.BadServerResponse{Message: msg}} } seatBid := bidResp.SeatBid[0] @@ -246,18 +241,6 @@ func getMediaTypeForImpID(impID string, imps []openrtb.Imp) openrtb_ext.BidType return openrtb_ext.BidTypeBanner } -func newBadInputError(message string) error { - return &errortypes.BadInput{ - Message: message, - } -} - -func newBadServerResponseError(message string) error { - return &errortypes.BadServerResponse{ - Message: message, - } -} - // NewAdvangelistsAdapter to be called in prebid-server core to create advangelists adapter instance func NewAdvangelistsBidder(endpointTemplate string) adapters.Bidder { template, err := template.New("endpointTemplate").Parse(endpointTemplate) diff --git a/adapters/advangelists/advangelists_test.go b/adapters/advangelists/advangelists_test.go index e4c6636bd06..fdf08d88681 100644 --- a/adapters/advangelists/advangelists_test.go +++ b/adapters/advangelists/advangelists_test.go @@ -6,5 +6,5 @@ import ( ) func TestJsonSamples(t *testing.T) { - adapterstest.RunJSONBidderTest(t, "advangeliststest", NewAdvangelistsBidder("http://nep.advangelists.com/xp/get?pubid={{.Pubid}}")) + adapterstest.RunJSONBidderTest(t, "advangeliststest", NewAdvangelistsBidder("http://nep.advangelists.com/xp/get?pubid={{.PubID}}")) } diff --git a/adapters/advangelists/advangeliststest/exemplary/banner.json b/adapters/advangelists/advangeliststest/exemplary/banner.json index 1ad4e56245d..b011137cb9f 100644 --- a/adapters/advangelists/advangeliststest/exemplary/banner.json +++ b/adapters/advangelists/advangeliststest/exemplary/banner.json @@ -1,95 +1,95 @@ { - "mockBidRequest": { - "id": "testid", - "imp": [ - { - "id": "testimpid", - "banner": { - "format": [ - { + "mockBidRequest": { + "id": "testid", + "imp": [ + { + "id": "testimpid", + "banner": { + "format": [ + { + "w": 320, + "h": 250 + }, + { + "w": 320, + "h": 300 + } + ], + "w": 320, + "h": 250 + }, + "ext": { + "bidder": { + "pubid": "19f1b372c7548ec1fe734d2c9f8dc688", + "placement": "dummyplacement" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://nep.advangelists.com/xp/get?pubid=19f1b372c7548ec1fe734d2c9f8dc688", + "body":{ + "id": "testid", + "imp": [{ + "id": "testimpid", + "tagid": "dummyplacement", + "banner": { + "format": [{ "w": 320, "h": 250 - }, - { + }, { "w": 320, "h": 300 - } - ], - "w": 320, - "h": 250 - }, - "ext": { - "bidder": { - "pubid": "19f1b372c7548ec1fe734d2c9f8dc688" + }], + "w": 320, + "h": 250 } - } + + }] } - ] - }, - - "httpCalls": [ - { - "expectedRequest": { - "uri": "http://nep.advangelists.com/xp/get?pubid=19f1b372c7548ec1fe734d2c9f8dc688", - "body":{ - "id": "testid", - "imp": [{ - "id": "testimpid", - "tagid": "testimpid", - "banner": { - "format": [{ - "w": 320, - "h": 250 - }, { - "w": 320, - "h": 300 - }], - "w": 320, - "h": 250 - } - - }] - } - }, - "mockResponse": { - "status": 200, - "body": { - "seatbid": [ - { - "bid": [ - { - "crid": "24080", - "adid": "2068416", - "price": 0.01, - "id": "testid", - "impid": "testimpid", - "cid": "8048" - } - ] - } - ] - } + }, + "mockResponse": { + "status": 200, + "body": { + "seatbid": [ + { + "bid": [ + { + "crid": "24080", + "adid": "2068416", + "price": 0.01, + "id": "testid", + "impid": "testimpid", + "cid": "8048" + } + ] + } + ] } } - ], - - "expectedBidResponses": [ - { - "currency": "USD", - "bids": [ - { - "bid": { - "crid": "24080", - "adid": "2068416", - "price": 0.01, - "id": "testid", - "impid": "testimpid", - "cid": "8048" - }, - "type": "banner" - } - ] - } - ] - } - \ No newline at end of file + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "crid": "24080", + "adid": "2068416", + "price": 0.01, + "id": "testid", + "impid": "testimpid", + "cid": "8048" + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/advangelists/advangeliststest/exemplary/video.json b/adapters/advangelists/advangeliststest/exemplary/video.json index 930b6f1e34c..28a78753d80 100644 --- a/adapters/advangelists/advangeliststest/exemplary/video.json +++ b/adapters/advangelists/advangeliststest/exemplary/video.json @@ -13,7 +13,8 @@ }, "ext": { "bidder": { - "pubid": "19f1b372c7548ec1fe734d2c9f8dc688" + "pubid": "19f1b372c7548ec1fe734d2c9f8dc688", + "placement": "dummyplacement" } } } @@ -28,7 +29,7 @@ "id": "testid", "imp": [{ "id": "testimpid", - "tagid": "testimpid", + "tagid": "dummyplacement", "video": { "mimes": [ "video/mp4" diff --git a/adapters/advangelists/advangeliststest/params/race/banner.json b/adapters/advangelists/advangeliststest/params/race/banner.json index d4305090b14..201e96980de 100644 --- a/adapters/advangelists/advangeliststest/params/race/banner.json +++ b/adapters/advangelists/advangeliststest/params/race/banner.json @@ -1,3 +1,4 @@ { - "pubid": "19f1b372c7548ec1fe734d2c9f8dc688" + "pubid": "19f1b372c7548ec1fe734d2c9f8dc688", + "placement": "dummyplacement" } diff --git a/adapters/advangelists/advangeliststest/params/race/video.json b/adapters/advangelists/advangeliststest/params/race/video.json index d4305090b14..201e96980de 100644 --- a/adapters/advangelists/advangeliststest/params/race/video.json +++ b/adapters/advangelists/advangeliststest/params/race/video.json @@ -1,3 +1,4 @@ { - "pubid": "19f1b372c7548ec1fe734d2c9f8dc688" + "pubid": "19f1b372c7548ec1fe734d2c9f8dc688", + "placement": "dummyplacement" } diff --git a/config/config.go b/config/config.go index 05c9e611ba3..a8029899752 100644 --- a/config/config.go +++ b/config/config.go @@ -185,9 +185,8 @@ func (cfg *HostCookie) TTLDuration() time.Duration { const ( dummyHost string = "dummyhost.com" dummyPublisherID int = 12 - dummyPubid string = "dummypubid" + dummyPubID string = "dummyPubID" dummyGDPR string = "0" - dummyGDPRConsent string = "someGDPRConsentString" ) @@ -231,7 +230,7 @@ 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, Pubid: dummyPubid}) + resolvedEndpoint, err := macros.ResolveMacros(*endpointTemplate, macros.EndpointTemplateParams{Host: dummyHost, PublisherID: dummyPublisherID, PubID: dummyPubID}) if err != nil { return append(errs, fmt.Errorf("Unable to resolve endpoint: %s for adapter: %s. %v", endpoint, adapterName, err)) } @@ -584,7 +583,7 @@ func SetupViper(v *viper.Viper, filename string) { v.SetDefault("adapters.adtelligent.endpoint", "http://hb.adtelligent.com/auction") v.SetDefault("adapters.adform.endpoint", "http://adx.adform.net/adx") v.SetDefault("adapters.appnexus.endpoint", "http://ib.adnxs.com/openrtb2") // Docs: https://wiki.appnexus.com/display/supply/Incoming+Bid+Request+from+SSPs - v.SetDefault("adapters.advangelists.endpoint", "http://nep.advangelists.com/xp/get?pubid={{.Pubid}}") + v.SetDefault("adapters.advangelists.endpoint", "http://nep.advangelists.com/xp/get?pubid={{.PubID}}") v.SetDefault("adapters.beachfront.endpoint", "https://display.bfmio.com/prebid_display") v.SetDefault("adapters.beachfront.platform_id", "155") v.SetDefault("adapters.brightroll.endpoint", "http://east-bid.ybp.yahoo.com/bid/appnexuspbs") diff --git a/macros/macros.go b/macros/macros.go index 558f6f7947a..df94160ac54 100644 --- a/macros/macros.go +++ b/macros/macros.go @@ -8,7 +8,7 @@ import ( // EndpointTemplateParams specifies params for an endpoint template type EndpointTemplateParams struct { Host string - Pubid string + PubID string PublisherID int } diff --git a/openrtb_ext/imp_advangelists.go b/openrtb_ext/imp_advangelists.go index f3a4827960f..ed46517b4a4 100644 --- a/openrtb_ext/imp_advangelists.go +++ b/openrtb_ext/imp_advangelists.go @@ -1,5 +1,6 @@ package openrtb_ext type ExtImpAdvangelists struct { - Pubid string `json:"pubid"` + PubID string `json:"pubid"` + Placement string `json:"Placement,omitempty"` } From 7a9a9267cee32726f83f6ae745ac101d6cf3e86a Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Wed, 10 Jul 2019 22:08:20 -0700 Subject: [PATCH 05/11] Made required changes --- adapters/advangelists/advangeliststest/params/race/banner.json | 2 +- adapters/advangelists/advangeliststest/params/race/video.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adapters/advangelists/advangeliststest/params/race/banner.json b/adapters/advangelists/advangeliststest/params/race/banner.json index 201e96980de..2eed8f2ec4e 100644 --- a/adapters/advangelists/advangeliststest/params/race/banner.json +++ b/adapters/advangelists/advangeliststest/params/race/banner.json @@ -1,4 +1,4 @@ { "pubid": "19f1b372c7548ec1fe734d2c9f8dc688", "placement": "dummyplacement" -} +} \ No newline at end of file diff --git a/adapters/advangelists/advangeliststest/params/race/video.json b/adapters/advangelists/advangeliststest/params/race/video.json index 201e96980de..2eed8f2ec4e 100644 --- a/adapters/advangelists/advangeliststest/params/race/video.json +++ b/adapters/advangelists/advangeliststest/params/race/video.json @@ -1,4 +1,4 @@ { "pubid": "19f1b372c7548ec1fe734d2c9f8dc688", "placement": "dummyplacement" -} +} \ No newline at end of file From cca5df22fd1d8606413cdb76a00977db38c2e80b Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Wed, 10 Jul 2019 22:36:00 -0700 Subject: [PATCH 06/11] Correcting placement error --- openrtb_ext/imp_advangelists.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openrtb_ext/imp_advangelists.go b/openrtb_ext/imp_advangelists.go index ed46517b4a4..0c65dd66070 100644 --- a/openrtb_ext/imp_advangelists.go +++ b/openrtb_ext/imp_advangelists.go @@ -2,5 +2,5 @@ package openrtb_ext type ExtImpAdvangelists struct { PubID string `json:"pubid"` - Placement string `json:"Placement,omitempty"` + Placement string `json:"placement,omitempty"` } From dc57df4a2fda9ccd602da65906d4396c1d0a46cf Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Thu, 11 Jul 2019 09:14:47 -0700 Subject: [PATCH 07/11] Updating formatting --- openrtb_ext/imp_advangelists.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openrtb_ext/imp_advangelists.go b/openrtb_ext/imp_advangelists.go index 0c65dd66070..b1602977db1 100644 --- a/openrtb_ext/imp_advangelists.go +++ b/openrtb_ext/imp_advangelists.go @@ -1,6 +1,6 @@ package openrtb_ext type ExtImpAdvangelists struct { - PubID string `json:"pubid"` + PubID string `json:"pubid"` Placement string `json:"placement,omitempty"` } From 29e3e44e31c310a2dafc41dfb6a8bb414b366cee Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Thu, 11 Jul 2019 15:29:45 -0700 Subject: [PATCH 08/11] Updated as requested --- adapters/advangelists/advangelists.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adapters/advangelists/advangelists.go b/adapters/advangelists/advangelists.go index 1f04672f2bb..b806645db6a 100644 --- a/adapters/advangelists/advangelists.go +++ b/adapters/advangelists/advangelists.go @@ -32,16 +32,17 @@ func (adapter *AdvangelistsAdapter) MakeRequests(request *openrtb.BidRequest, re errs = append(errs, err...) pub2impressions, dispErrors := dispatchImpressions(imps, impExts) + errs = append(errs, dispErrors...) if len(pub2impressions) == 0 { return nil, errs } - errs = append(errs, dispErrors...) result := make([]*adapters.RequestData, 0, len(pub2impressions)) for k, imps := range pub2impressions { bidRequest, err := adapter.buildAdapterRequest(request, &k, imps) if err != nil { errs = append(errs, err) + return nil, errs } else { result = append(result, bidRequest) } @@ -115,7 +116,7 @@ func compatBannerImpression(imp *openrtb.Imp) error { bannerCopy := *imp.Banner banner := &bannerCopy //As banner.w/h are required fields for advangelistsAdn platform - take the first format entry - if banner.W == nil && banner.H == nil { + if banner.W == nil || banner.H == nil { if len(banner.Format) == 0 { return &errortypes.BadInput{Message: "Expected at least one banner.format entry or explicit w/h"} } @@ -174,7 +175,6 @@ func createBidRequest(prebidBidRequest *openrtb.BidRequest, params *openrtb_ext. for idx := range bidRequest.Imp { imp := &bidRequest.Imp[idx] imp.TagID = params.Placement - fmt.Printf(imp.TagID) } if bidRequest.Site != nil { // Need to copy Site as Request is a shallow copy From 1d59a4db2537a64cf6336a3d244a49428cc8a07c Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Sun, 21 Jul 2019 12:29:39 -0700 Subject: [PATCH 09/11] Updated highlighted memory allocation issues Updated highlighted memory allocation issues --- adapters/advangelists/advangelists.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/adapters/advangelists/advangelists.go b/adapters/advangelists/advangelists.go index b806645db6a..b2a29c087ad 100644 --- a/adapters/advangelists/advangelists.go +++ b/adapters/advangelists/advangelists.go @@ -52,10 +52,9 @@ func (adapter *AdvangelistsAdapter) MakeRequests(request *openrtb.BidRequest, re // getImpressionsInfo checks each impression for validity and returns impressions copy with corresponding exts func getImpressionsInfo(imps []openrtb.Imp) ([]openrtb.Imp, []openrtb_ext.ExtImpAdvangelists, []error) { - impsCount := len(imps) - errors := make([]error, 0, impsCount) - resImps := make([]openrtb.Imp, 0, impsCount) - resImpExts := make([]openrtb_ext.ExtImpAdvangelists, 0, impsCount) + errors := make([]error, 0, len(imps)) + resImps := make([]openrtb.Imp, 0, len(imps)) + resImpExts := make([]openrtb_ext.ExtImpAdvangelists, 0, len(imps)) for _, imp := range imps { impExt, err := getImpressionExt(&imp) @@ -85,8 +84,7 @@ func validateImpression(imp *openrtb.Imp, impExt *openrtb_ext.ExtImpAdvangelists func dispatchImpressions(imps []openrtb.Imp, impsExt []openrtb_ext.ExtImpAdvangelists) (map[openrtb_ext.ExtImpAdvangelists][]openrtb.Imp, []error) { res := make(map[openrtb_ext.ExtImpAdvangelists][]openrtb.Imp) errors := make([]error, 0) - for idx := range imps { - imp := imps[idx] + for idx, imp := range imps { err := compatImpression(&imp) if err != nil { errors = append(errors, err) From f14089dbe49f7f46e9edaa894ba51ee761cb94ef Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Tue, 23 Jul 2019 01:24:10 -0700 Subject: [PATCH 10/11] PubId macro changes --- adapters/adkernelAdn/adkernelAdn.go | 33 +++++++++++++++++-- .../supplemental/wrong-imp-ext-1.json | 2 +- adapters/advangelists/advangelists.go | 4 +-- adapters/advangelists/advangelists_test.go | 2 +- config/config.go | 7 ++-- macros/macros.go | 3 +- macros/macros_test.go | 2 +- openrtb_ext/imp_adkernelAdn.go | 2 +- openrtb_ext/imp_advangelists.go | 4 +-- 9 files changed, 42 insertions(+), 17 deletions(-) diff --git a/adapters/adkernelAdn/adkernelAdn.go b/adapters/adkernelAdn/adkernelAdn.go index 6629c63d3c8..8f6e0e73d7c 100644 --- a/adapters/adkernelAdn/adkernelAdn.go +++ b/adapters/adkernelAdn/adkernelAdn.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "net/http" + "reflect" + "strconv" "text/template" "github.com/golang/glog" @@ -20,6 +22,11 @@ type adkernelAdnAdapter struct { EndpointTemplate template.Template } +type structImpAdkernelAdn struct { + PubID int `json:"pubId"` + Host string `json:"host,omitempty"` +} + //MakeRequests prepares request information for prebid-server core func (adapter *adkernelAdnAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { errs := make([]error, 0, len(request.Imp)) @@ -77,10 +84,11 @@ func getImpressionsInfo(imps []openrtb.Imp) ([]openrtb.Imp, []openrtb_ext.ExtImp } func validateImpression(imp *openrtb.Imp, impExt *openrtb_ext.ExtImpAdkernelAdn) error { - if impExt.PublisherID < 1 { + pubId, err := strconv.Atoi(impExt.PublisherID) + if pubId < 1 { return newBadInputError(fmt.Sprintf("Invalid pubId value. Ignoring imp id=%s", imp.ID)) } - return nil + return err } //Group impressions by AdKernel-specific parameters `pubId` & `host` @@ -138,8 +146,27 @@ func getImpressionExt(imp *openrtb.Imp) (*openrtb_ext.ExtImpAdkernelAdn, error) Message: err.Error(), } } + //unmarshal to get pubid + var obj structImpAdkernelAdn + json.Unmarshal(bidderExt.Bidder, &obj) + val := obj.PubID + + //unmarshal to set pubid + objInterface := map[string]interface{}{} + json.Unmarshal([]byte(bidderExt.Bidder), &objInterface) + if reflect.TypeOf(val).String() == "int" { + objInterface["pubId"] = strconv.Itoa(val) + } + + //marshal back + js, err := json.Marshal(objInterface) + if err != nil { + return nil, &errortypes.BadInput{ + Message: err.Error(), + } + } var adkernelAdnExt openrtb_ext.ExtImpAdkernelAdn - if err := json.Unmarshal(bidderExt.Bidder, &adkernelAdnExt); err != nil { + if err := json.Unmarshal(js, &adkernelAdnExt); err != nil { return nil, &errortypes.BadInput{ Message: err.Error(), } diff --git a/adapters/adkernelAdn/adkerneladntest/supplemental/wrong-imp-ext-1.json b/adapters/adkernelAdn/adkerneladntest/supplemental/wrong-imp-ext-1.json index 4a0e1c4a117..e42fade647e 100644 --- a/adapters/adkernelAdn/adkerneladntest/supplemental/wrong-imp-ext-1.json +++ b/adapters/adkernelAdn/adkerneladntest/supplemental/wrong-imp-ext-1.json @@ -17,6 +17,6 @@ }, "expectedMakeRequestsErrors": [ - "json: cannot unmarshal string into Go struct field ExtImpAdkernelAdn.pubId of type int" + "Invalid pubId value. Ignoring imp id=malconfigured-adunit" ] } diff --git a/adapters/advangelists/advangelists.go b/adapters/advangelists/advangelists.go index b2a29c087ad..0ce33104ca7 100644 --- a/adapters/advangelists/advangelists.go +++ b/adapters/advangelists/advangelists.go @@ -74,7 +74,7 @@ func getImpressionsInfo(imps []openrtb.Imp) ([]openrtb.Imp, []openrtb_ext.ExtImp } func validateImpression(imp *openrtb.Imp, impExt *openrtb_ext.ExtImpAdvangelists) error { - if impExt.PubID == "" { + if impExt.PublisherID == "" { return &errortypes.BadInput{Message: "No pubid value provided"} } return nil @@ -192,7 +192,7 @@ func createBidRequest(prebidBidRequest *openrtb.BidRequest, params *openrtb_ext. // Builds enpoint url based on adapter-specific pub settings from imp.ext func (adapter *AdvangelistsAdapter) buildEndpointURL(params *openrtb_ext.ExtImpAdvangelists) (string, error) { - endpointParams := macros.EndpointTemplateParams{PubID: params.PubID} + endpointParams := macros.EndpointTemplateParams{PublisherID: params.PublisherID} return macros.ResolveMacros(adapter.EndpointTemplate, endpointParams) } diff --git a/adapters/advangelists/advangelists_test.go b/adapters/advangelists/advangelists_test.go index fdf08d88681..116a2c54ec6 100644 --- a/adapters/advangelists/advangelists_test.go +++ b/adapters/advangelists/advangelists_test.go @@ -6,5 +6,5 @@ import ( ) func TestJsonSamples(t *testing.T) { - adapterstest.RunJSONBidderTest(t, "advangeliststest", NewAdvangelistsBidder("http://nep.advangelists.com/xp/get?pubid={{.PubID}}")) + adapterstest.RunJSONBidderTest(t, "advangeliststest", NewAdvangelistsBidder("http://nep.advangelists.com/xp/get?pubid={{.PublisherID}}")) } diff --git a/config/config.go b/config/config.go index a8029899752..6f67a2a99ca 100644 --- a/config/config.go +++ b/config/config.go @@ -184,8 +184,7 @@ func (cfg *HostCookie) TTLDuration() time.Duration { const ( dummyHost string = "dummyhost.com" - dummyPublisherID int = 12 - dummyPubID string = "dummyPubID" + dummyPublisherID string = "12" dummyGDPR string = "0" dummyGDPRConsent string = "someGDPRConsentString" ) @@ -230,7 +229,7 @@ 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, PubID: dummyPubID}) + resolvedEndpoint, err := macros.ResolveMacros(*endpointTemplate, macros.EndpointTemplateParams{Host: dummyHost, PublisherID: dummyPublisherID}) if err != nil { return append(errs, fmt.Errorf("Unable to resolve endpoint: %s for adapter: %s. %v", endpoint, adapterName, err)) } @@ -583,7 +582,7 @@ func SetupViper(v *viper.Viper, filename string) { v.SetDefault("adapters.adtelligent.endpoint", "http://hb.adtelligent.com/auction") v.SetDefault("adapters.adform.endpoint", "http://adx.adform.net/adx") v.SetDefault("adapters.appnexus.endpoint", "http://ib.adnxs.com/openrtb2") // Docs: https://wiki.appnexus.com/display/supply/Incoming+Bid+Request+from+SSPs - v.SetDefault("adapters.advangelists.endpoint", "http://nep.advangelists.com/xp/get?pubid={{.PubID}}") + v.SetDefault("adapters.advangelists.endpoint", "http://nep.advangelists.com/xp/get?pubid={{.PublisherID}}") v.SetDefault("adapters.beachfront.endpoint", "https://display.bfmio.com/prebid_display") v.SetDefault("adapters.beachfront.platform_id", "155") v.SetDefault("adapters.brightroll.endpoint", "http://east-bid.ybp.yahoo.com/bid/appnexuspbs") diff --git a/macros/macros.go b/macros/macros.go index df94160ac54..6c28b6e6266 100644 --- a/macros/macros.go +++ b/macros/macros.go @@ -8,8 +8,7 @@ import ( // EndpointTemplateParams specifies params for an endpoint template type EndpointTemplateParams struct { Host string - PubID string - PublisherID int + PublisherID string } // UserSyncTemplateParams specifies params for an user sync URL template diff --git a/macros/macros_test.go b/macros/macros_test.go index 0f3bf73f1ae..cd8c4b557b9 100644 --- a/macros/macros_test.go +++ b/macros/macros_test.go @@ -18,7 +18,7 @@ func TestResolveMacros(t *testing.T) { result string hasError bool }{ - {aTemplate: *endpointTemplate, params: EndpointTemplateParams{Host: "SomeHost", PublisherID: 1}, result: "http://SomeHost/publisher/1", hasError: false}, + {aTemplate: *endpointTemplate, params: EndpointTemplateParams{Host: "SomeHost", PublisherID: "1"}, result: "http://SomeHost/publisher/1", hasError: false}, {aTemplate: *endpointTemplate, params: UserSyncTemplateParams{GDPR: "SomeGDPR", GDPRConsent: "SomeGDPRConsent"}, result: "", hasError: true}, } diff --git a/openrtb_ext/imp_adkernelAdn.go b/openrtb_ext/imp_adkernelAdn.go index 803f3fa4984..e16076f7389 100644 --- a/openrtb_ext/imp_adkernelAdn.go +++ b/openrtb_ext/imp_adkernelAdn.go @@ -2,6 +2,6 @@ package openrtb_ext // ExtImpAdkernelAdn defines the contract for bidrequest.imp[i].ext.adkernelAdn type ExtImpAdkernelAdn struct { - PublisherID int `json:"pubId"` + PublisherID string `json:"pubId"` Host string `json:"host,omitempty"` } diff --git a/openrtb_ext/imp_advangelists.go b/openrtb_ext/imp_advangelists.go index b1602977db1..375ec8ad27f 100644 --- a/openrtb_ext/imp_advangelists.go +++ b/openrtb_ext/imp_advangelists.go @@ -1,6 +1,6 @@ package openrtb_ext type ExtImpAdvangelists struct { - PubID string `json:"pubid"` - Placement string `json:"placement,omitempty"` + PublisherID string `json:"pubid"` + Placement string `json:"placement,omitempty"` } From 20c87c997f24d661cf8f863c4365773232ff97a5 Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Tue, 23 Jul 2019 09:14:02 -0700 Subject: [PATCH 11/11] PublisherID conversion to string on Adkernal adapter --- adapters/adkernelAdn/adkernelAdn.go | 35 +++---------------- .../supplemental/wrong-imp-ext-1.json | 2 +- openrtb_ext/imp_adkernelAdn.go | 2 +- 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/adapters/adkernelAdn/adkernelAdn.go b/adapters/adkernelAdn/adkernelAdn.go index 8f6e0e73d7c..9ddae379692 100644 --- a/adapters/adkernelAdn/adkernelAdn.go +++ b/adapters/adkernelAdn/adkernelAdn.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "net/http" - "reflect" "strconv" "text/template" @@ -22,11 +21,6 @@ type adkernelAdnAdapter struct { EndpointTemplate template.Template } -type structImpAdkernelAdn struct { - PubID int `json:"pubId"` - Host string `json:"host,omitempty"` -} - //MakeRequests prepares request information for prebid-server core func (adapter *adkernelAdnAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { errs := make([]error, 0, len(request.Imp)) @@ -84,11 +78,10 @@ func getImpressionsInfo(imps []openrtb.Imp) ([]openrtb.Imp, []openrtb_ext.ExtImp } func validateImpression(imp *openrtb.Imp, impExt *openrtb_ext.ExtImpAdkernelAdn) error { - pubId, err := strconv.Atoi(impExt.PublisherID) - if pubId < 1 { + if impExt.PublisherID < 1 { return newBadInputError(fmt.Sprintf("Invalid pubId value. Ignoring imp id=%s", imp.ID)) } - return err + return nil } //Group impressions by AdKernel-specific parameters `pubId` & `host` @@ -146,27 +139,8 @@ func getImpressionExt(imp *openrtb.Imp) (*openrtb_ext.ExtImpAdkernelAdn, error) Message: err.Error(), } } - //unmarshal to get pubid - var obj structImpAdkernelAdn - json.Unmarshal(bidderExt.Bidder, &obj) - val := obj.PubID - - //unmarshal to set pubid - objInterface := map[string]interface{}{} - json.Unmarshal([]byte(bidderExt.Bidder), &objInterface) - if reflect.TypeOf(val).String() == "int" { - objInterface["pubId"] = strconv.Itoa(val) - } - - //marshal back - js, err := json.Marshal(objInterface) - if err != nil { - return nil, &errortypes.BadInput{ - Message: err.Error(), - } - } var adkernelAdnExt openrtb_ext.ExtImpAdkernelAdn - if err := json.Unmarshal(js, &adkernelAdnExt); err != nil { + if err := json.Unmarshal(bidderExt.Bidder, &adkernelAdnExt); err != nil { return nil, &errortypes.BadInput{ Message: err.Error(), } @@ -227,7 +201,8 @@ func (adapter *adkernelAdnAdapter) buildEndpointURL(params *openrtb_ext.ExtImpAd if params.Host != "" { reqHost = params.Host } - endpointParams := macros.EndpointTemplateParams{Host: reqHost, PublisherID: params.PublisherID} + pubIDStr := strconv.Itoa(params.PublisherID) + endpointParams := macros.EndpointTemplateParams{Host: reqHost, PublisherID: pubIDStr} return macros.ResolveMacros(adapter.EndpointTemplate, endpointParams) } diff --git a/adapters/adkernelAdn/adkerneladntest/supplemental/wrong-imp-ext-1.json b/adapters/adkernelAdn/adkerneladntest/supplemental/wrong-imp-ext-1.json index e42fade647e..4a0e1c4a117 100644 --- a/adapters/adkernelAdn/adkerneladntest/supplemental/wrong-imp-ext-1.json +++ b/adapters/adkernelAdn/adkerneladntest/supplemental/wrong-imp-ext-1.json @@ -17,6 +17,6 @@ }, "expectedMakeRequestsErrors": [ - "Invalid pubId value. Ignoring imp id=malconfigured-adunit" + "json: cannot unmarshal string into Go struct field ExtImpAdkernelAdn.pubId of type int" ] } diff --git a/openrtb_ext/imp_adkernelAdn.go b/openrtb_ext/imp_adkernelAdn.go index e16076f7389..803f3fa4984 100644 --- a/openrtb_ext/imp_adkernelAdn.go +++ b/openrtb_ext/imp_adkernelAdn.go @@ -2,6 +2,6 @@ package openrtb_ext // ExtImpAdkernelAdn defines the contract for bidrequest.imp[i].ext.adkernelAdn type ExtImpAdkernelAdn struct { - PublisherID string `json:"pubId"` + PublisherID int `json:"pubId"` Host string `json:"host,omitempty"` }