From e35dbbbb938941f6f5c8d26bc1074f294884478d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E4=BA=91=E6=B3=A2?= Date: Tue, 25 May 2021 15:29:01 +0800 Subject: [PATCH 1/9] first commit AlgoriX Adapter --- adapters/algorix/algorix.go | 170 ++++++++++++++++++ adapters/algorix/algorix_test.go | 27 +++ .../algorixtest/exemplary/sample-banner.json | 83 +++++++++ .../algorixtest/exemplary/sample-native.json | 82 +++++++++ .../algorixtest/exemplary/sample-nobid.json | 53 ++++++ .../algorixtest/exemplary/sample-video.json | 89 +++++++++ .../algorixtest/params/race/banner.json | 4 + .../algorixtest/params/race/native.json | 4 + .../algorixtest/params/race/video.json | 4 + .../algorixtest/supplemental/bad_imp_ext.json | 21 +++ .../supplemental/bad_impext_bidder.json | 26 +++ .../supplemental/bad_impext_bidder_2.json | 23 +++ .../supplemental/bad_response.json | 57 ++++++ .../supplemental/no_imp_error.json | 13 ++ .../algorixtest/supplemental/status_400.json | 57 ++++++ .../algorixtest/supplemental/status_500.json | 57 ++++++ adapters/algorix/params_test.go | 47 +++++ config/config.go | 1 + exchange/adapter_builders.go | 2 + openrtb_ext/bidders.go | 2 + openrtb_ext/imp_algorix.go | 7 + static/bidder-info/algorix.yaml | 8 + static/bidder-params/algorix.json | 19 ++ usersync/usersyncers/syncer_test.go | 1 + 24 files changed, 857 insertions(+) create mode 100644 adapters/algorix/algorix.go create mode 100644 adapters/algorix/algorix_test.go create mode 100644 adapters/algorix/algorixtest/exemplary/sample-banner.json create mode 100644 adapters/algorix/algorixtest/exemplary/sample-native.json create mode 100644 adapters/algorix/algorixtest/exemplary/sample-nobid.json create mode 100644 adapters/algorix/algorixtest/exemplary/sample-video.json create mode 100644 adapters/algorix/algorixtest/params/race/banner.json create mode 100644 adapters/algorix/algorixtest/params/race/native.json create mode 100644 adapters/algorix/algorixtest/params/race/video.json create mode 100644 adapters/algorix/algorixtest/supplemental/bad_imp_ext.json create mode 100644 adapters/algorix/algorixtest/supplemental/bad_impext_bidder.json create mode 100644 adapters/algorix/algorixtest/supplemental/bad_impext_bidder_2.json create mode 100644 adapters/algorix/algorixtest/supplemental/bad_response.json create mode 100644 adapters/algorix/algorixtest/supplemental/no_imp_error.json create mode 100644 adapters/algorix/algorixtest/supplemental/status_400.json create mode 100644 adapters/algorix/algorixtest/supplemental/status_500.json create mode 100644 adapters/algorix/params_test.go create mode 100644 openrtb_ext/imp_algorix.go create mode 100644 static/bidder-info/algorix.yaml create mode 100644 static/bidder-params/algorix.json diff --git a/adapters/algorix/algorix.go b/adapters/algorix/algorix.go new file mode 100644 index 00000000000..ad21c14789a --- /dev/null +++ b/adapters/algorix/algorix.go @@ -0,0 +1,170 @@ +package algorix + +import ( + "encoding/json" + "fmt" + "github.com/prebid/prebid-server/errortypes" + "github.com/prebid/prebid-server/macros" + "net/http" + "text/template" + + "github.com/mxmCherry/openrtb/v15/openrtb2" + "github.com/prebid/prebid-server/adapters" + "github.com/prebid/prebid-server/config" + "github.com/prebid/prebid-server/openrtb_ext" +) + +type AlgoriXAdapter struct { + EndpointTemplate template.Template +} + +// Builder builds a new instance of the Foo adapter for the given bidder with the given config. +func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { + template, err := template.New("endpointTemplate").Parse(config.Endpoint) + if err != nil { + return nil, fmt.Errorf("unable to parse endpoint url template: %v", err) + } + bidder := &AlgoriXAdapter{ + EndpointTemplate: *template, + } + return bidder, nil +} + +// MakeRequests Make Requests +func (adapter *AlgoriXAdapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { + var adapterRequests []*adapters.RequestData + var errs []error + + adapterRequest, err := adapter.makeRequest(request) + if err == nil { + adapterRequests = append(adapterRequests, adapterRequest) + } else { + errs = append(errs, err) + } + return adapterRequests, errs +} + +func (adapter *AlgoriXAdapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestData, error) { + if len(request.Imp) == 0 { + return nil, &errortypes.BadInput{Message: "No impression in the request"} + } + + algorixExt := parseAlgoriXExt(request) + + if algorixExt == nil { + return nil, &errortypes.BadInput{Message: "Invalid ExtImpAlgoriX value"} + } + + endPoint, err := adapter.getEndPoint(algorixExt) + if err != nil { + return nil, err + } + + preProcess(request) + reqBody, err := json.Marshal(request) + if err != nil { + return nil, err + } + + headers := http.Header{} + headers.Add("Content-Type", "application/json;charset=utf-8") + headers.Add("Accept", "application/json") + headers.Add("x-openrtb-version", "2.5") + + return &adapters.RequestData{ + Method: "POST", + Uri: endPoint, + Body: reqBody, + Headers: headers, + }, nil +} + +//parseAlgoriXExt parse AlgoriX Ext +func parseAlgoriXExt(request *openrtb2.BidRequest) *openrtb_ext.ExtImpAlgorix { + var extImpAlgoriX openrtb_ext.ExtImpAlgorix + for _, imp := range request.Imp { + var extBidder adapters.ExtImpBidder + err := json.Unmarshal(imp.Ext, &extBidder) + if err != nil { + continue + } + err = json.Unmarshal(extBidder.Bidder, &extImpAlgoriX) + if err != nil || len(extImpAlgoriX.Sid) == 0 || len(extImpAlgoriX.Token) == 0 { + continue + } + return &extImpAlgoriX + } + return nil +} + +// getEndPoint get Endpoint +func (adapter *AlgoriXAdapter) getEndPoint(ext *openrtb_ext.ExtImpAlgorix) (string, error) { + endPointParams := macros.EndpointTemplateParams{SourceId: ext.Sid, AccountID: ext.Token} + return macros.ResolveMacros(adapter.EndpointTemplate, endPointParams) +} + +func preProcess(request *openrtb2.BidRequest) { + for i := range request.Imp { + if request.Imp[i].Banner != nil { + banner := *request.Imp[i].Banner + if (banner.W == nil || banner.H == nil || *banner.W == 0 || *banner.H == 0) && len(banner.Format) > 0 { + firstFormat := banner.Format[0] + bannerCopy := *request.Imp[i].Banner + bannerCopy.W = &firstFormat.W + bannerCopy.H = &firstFormat.H + request.Imp[i].Banner = &bannerCopy + } + } + } +} + +func (adapter *AlgoriXAdapter) MakeBids(internalRequest *openrtb2.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("Unexpected status code: %d.", response.StatusCode), + }} + } + + if response.StatusCode != http.StatusOK { + return nil, []error{&errortypes.BadServerResponse{ + Message: fmt.Sprintf("Unexpected status code: %d.", response.StatusCode), + }} + } + + var bidResp openrtb2.BidResponse + if err := json.Unmarshal(response.Body, &bidResp); err != nil { + return nil, []error{err} + } + + bidResponse := adapters.NewBidderResponseWithBidsCapacity(1) + + for _, seatBid := range bidResp.SeatBid { + for idx := range seatBid.Bid { + mediaType := getBidType(seatBid.Bid[idx].ImpID, internalRequest.Imp) + bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ + Bid: &seatBid.Bid[idx], + BidType: mediaType, + }) + } + } + return bidResponse, nil +} + +// getBidType get Bid Type +func getBidType(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { + for _, imp := range imps { + if imp.ID == impId { + if imp.Native != nil { + return openrtb_ext.BidTypeNative + } + if imp.Video != nil { + return openrtb_ext.BidTypeVideo + } + } + } + return openrtb_ext.BidTypeBanner +} diff --git a/adapters/algorix/algorix_test.go b/adapters/algorix/algorix_test.go new file mode 100644 index 00000000000..a33b054f738 --- /dev/null +++ b/adapters/algorix/algorix_test.go @@ -0,0 +1,27 @@ +package algorix + +import ( + "github.com/stretchr/testify/assert" + "testing" + + "github.com/prebid/prebid-server/adapters/adapterstest" + "github.com/prebid/prebid-server/config" + "github.com/prebid/prebid-server/openrtb_ext" +) + +func TestJsonSamples(t *testing.T) { + bidder, buildErr := Builder(openrtb_ext.BidderAlgorix, config.Adapter{ + Endpoint: "https://xyz.svr-algorix.com/rtb/sa?sid={{.SourceId}}&token={{.AccountID}}"}) + + if buildErr != nil { + t.Fatalf("Builder returned unexpected error %v", buildErr) + } + + adapterstest.RunJSONBidderTest(t, "algorixtest", bidder) +} + +func TestEndpointTemplateMalformed(t *testing.T) { + _, buildErr := Builder(openrtb_ext.BidderAlgorix, config.Adapter{Endpoint: "{{Malformed}}"}) + + assert.Error(t, buildErr) +} diff --git a/adapters/algorix/algorixtest/exemplary/sample-banner.json b/adapters/algorix/algorixtest/exemplary/sample-banner.json new file mode 100644 index 00000000000..4bec8139478 --- /dev/null +++ b/adapters/algorix/algorixtest/exemplary/sample-banner.json @@ -0,0 +1,83 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}] + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}], + "w": 320, + "h": 50 + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "ttx", + "bid": [{ + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-ads", + "crid": "crid_testid" + }] + } + ], + "cur": "USD" + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-ads", + "crid": "crid_testid" + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/algorix/algorixtest/exemplary/sample-native.json b/adapters/algorix/algorixtest/exemplary/sample-native.json new file mode 100644 index 00000000000..613d1428931 --- /dev/null +++ b/adapters/algorix/algorixtest/exemplary/sample-native.json @@ -0,0 +1,82 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}", + "ver": "1.2" + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + }, + "httpcalls": [ + { + "expectedRequest": { + "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "body": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "native": { + "request": "{\"ver\":\"1.2\",\"context\":1,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":2,\"required\":1,\"title\":{\"len\":90}},{\"id\":6,\"required\":1,\"img\":{\"type\":3,\"wmin\":128,\"hmin\":128,\"mimes\":[\"image/jpg\",\"image/jpeg\",\"image/png\"]}},{\"id\":7,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}", + "ver": "1.2" + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "bid": [ + { + "id": "8400d766-58b3-47d4-80d7-6658b337d403", + "impid": "test-imp-id", + "price": 1.2, + "adm": "some ads", + "crid": "crid_testid" + } + ] + } + ] + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8400d766-58b3-47d4-80d7-6658b337d403", + "impid": "test-imp-id", + "price": 1.2, + "adm": "some ads", + "crid": "crid_testid" + + }, + "type": "native" + } + ] + } + ] +} diff --git a/adapters/algorix/algorixtest/exemplary/sample-nobid.json b/adapters/algorix/algorixtest/exemplary/sample-nobid.json new file mode 100644 index 00000000000..26cec78ec3b --- /dev/null +++ b/adapters/algorix/algorixtest/exemplary/sample-nobid.json @@ -0,0 +1,53 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}] + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}], + "w": 320, + "h": 50 + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + } + }, + "mockResponse": { + "status": 204, + "body": {} + } + } + ], + + "expectedBidResponses": [] + +} diff --git a/adapters/algorix/algorixtest/exemplary/sample-video.json b/adapters/algorix/algorixtest/exemplary/sample-video.json new file mode 100644 index 00000000000..0f8145fdc8f --- /dev/null +++ b/adapters/algorix/algorixtest/exemplary/sample-video.json @@ -0,0 +1,89 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "video": { + "w": 320, + "h": 480, + "mimes": [ + "video/mp4" + ] + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "video": { + "w": 320, + "h": 480, + "mimes": [ + "video/mp4" + ] + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "ttx", + "bid": [{ + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 1.2, + "adm": "some-ads", + "crid": "crid_testid" + }] + } + ], + "cur": "USD" + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 1.2, + "adm": "some-ads", + "crid": "crid_testid" + }, + "type": "video" + } + ] + } + ] +} diff --git a/adapters/algorix/algorixtest/params/race/banner.json b/adapters/algorix/algorixtest/params/race/banner.json new file mode 100644 index 00000000000..ba35cad2eb6 --- /dev/null +++ b/adapters/algorix/algorixtest/params/race/banner.json @@ -0,0 +1,4 @@ +{ + "sid": "testSid", + "token": "testToken" +} diff --git a/adapters/algorix/algorixtest/params/race/native.json b/adapters/algorix/algorixtest/params/race/native.json new file mode 100644 index 00000000000..ba35cad2eb6 --- /dev/null +++ b/adapters/algorix/algorixtest/params/race/native.json @@ -0,0 +1,4 @@ +{ + "sid": "testSid", + "token": "testToken" +} diff --git a/adapters/algorix/algorixtest/params/race/video.json b/adapters/algorix/algorixtest/params/race/video.json new file mode 100644 index 00000000000..ba35cad2eb6 --- /dev/null +++ b/adapters/algorix/algorixtest/params/race/video.json @@ -0,0 +1,4 @@ +{ + "sid": "testSid", + "token": "testToken" +} diff --git a/adapters/algorix/algorixtest/supplemental/bad_imp_ext.json b/adapters/algorix/algorixtest/supplemental/bad_imp_ext.json new file mode 100644 index 00000000000..38abadb2d34 --- /dev/null +++ b/adapters/algorix/algorixtest/supplemental/bad_imp_ext.json @@ -0,0 +1,21 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}] + }, + "ext": "badExt" + } + ] + }, + + "expectedMakeRequestsErrors": [ + { + "value": "Invalid ExtImpAlgoriX value", + "comparison": "literal" + } + ] +} diff --git a/adapters/algorix/algorixtest/supplemental/bad_impext_bidder.json b/adapters/algorix/algorixtest/supplemental/bad_impext_bidder.json new file mode 100644 index 00000000000..46e0ceb6cde --- /dev/null +++ b/adapters/algorix/algorixtest/supplemental/bad_impext_bidder.json @@ -0,0 +1,26 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}] + }, + "ext": { + "bidder": { + "test1": 123, + "test2": 234 + } + } + } + ] + }, + + "expectedMakeRequestsErrors": [ + { + "value": "Invalid ExtImpAlgoriX value", + "comparison": "literal" + } + ] +} diff --git a/adapters/algorix/algorixtest/supplemental/bad_impext_bidder_2.json b/adapters/algorix/algorixtest/supplemental/bad_impext_bidder_2.json new file mode 100644 index 00000000000..669e22b081a --- /dev/null +++ b/adapters/algorix/algorixtest/supplemental/bad_impext_bidder_2.json @@ -0,0 +1,23 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}] + }, + "ext": { + "bidder": "badBidder" + } + } + ] + }, + + "expectedMakeRequestsErrors": [ + { + "value": "Invalid ExtImpAlgoriX value", + "comparison": "literal" + } + ] +} diff --git a/adapters/algorix/algorixtest/supplemental/bad_response.json b/adapters/algorix/algorixtest/supplemental/bad_response.json new file mode 100644 index 00000000000..f413b0876d0 --- /dev/null +++ b/adapters/algorix/algorixtest/supplemental/bad_response.json @@ -0,0 +1,57 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}] + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}], + "w": 320, + "h": 50 + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + } + }, + "mockResponse": { + "status": 200, + "body": "{\"id\":test-request-id" + } + } + ], + + "expectedMakeBidsErrors": [ + { + "comparison": "literal", + "value": "json: cannot unmarshal string into Go value of type openrtb2.BidResponse" + } + ] +} diff --git a/adapters/algorix/algorixtest/supplemental/no_imp_error.json b/adapters/algorix/algorixtest/supplemental/no_imp_error.json new file mode 100644 index 00000000000..6c6c363425a --- /dev/null +++ b/adapters/algorix/algorixtest/supplemental/no_imp_error.json @@ -0,0 +1,13 @@ +{ + "mockBidRequest": { + "id": "req-id", + "imp": [ + ] + }, + "expectedMakeRequestsErrors": [ + { + "value": "No impression in the request", + "comparison": "literal" + } + ] +} diff --git a/adapters/algorix/algorixtest/supplemental/status_400.json b/adapters/algorix/algorixtest/supplemental/status_400.json new file mode 100644 index 00000000000..9648ca9fdfa --- /dev/null +++ b/adapters/algorix/algorixtest/supplemental/status_400.json @@ -0,0 +1,57 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}] + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}], + "w": 320, + "h": 50 + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + } + }, + "mockResponse": { + "status": 400, + "body": {} + } + } + ], + + "expectedMakeBidsErrors": [ + { + "comparison": "literal", + "value": "Unexpected status code: 400." + } + ] +} diff --git a/adapters/algorix/algorixtest/supplemental/status_500.json b/adapters/algorix/algorixtest/supplemental/status_500.json new file mode 100644 index 00000000000..2a5fcd33eea --- /dev/null +++ b/adapters/algorix/algorixtest/supplemental/status_500.json @@ -0,0 +1,57 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}] + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}], + "w": 320, + "h": 50 + }, + "ext": { + "bidder": { + "sid": "testSid", + "token": "testToken" + } + } + } + ] + } + }, + "mockResponse": { + "status": 500, + "body": {} + } + } + ], + + "expectedMakeBidsErrors": [ + { + "comparison": "literal", + "value": "Unexpected status code: 500." + } + ] +} diff --git a/adapters/algorix/params_test.go b/adapters/algorix/params_test.go new file mode 100644 index 00000000000..18a2779fe4a --- /dev/null +++ b/adapters/algorix/params_test.go @@ -0,0 +1,47 @@ +package algorix + +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.BidderAlgorix, json.RawMessage(validParam)); err != nil { + t.Errorf("Schema rejected algoirx params: %s", validParam) + } + } +} + +// TestInvalidParams makes sure that the algorix schema rejects all the imp.ext fields we don't support. +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.BidderAlgorix, json.RawMessage(invalidParam)); err == nil { + t.Errorf("Schema allowed unexpected params: %s", invalidParam) + } + } +} + +var validParams = []string{ + `{"sid": "11233", "token": "sin"}`, + `{"sid": "11244", "token": "iad"}`, +} + +var invalidParams = []string{ + `{"sid": "11233"}`, + `{"token": "aaa"}`, + `{"sid": 123, "token": "sin"}`, + `{"sid": "", "token": "iad"}`, + `{"sid": "11233", "token": ""}`, +} diff --git a/config/config.go b/config/config.go index afb4ac8d74c..8b5f8438105 100644 --- a/config/config.go +++ b/config/config.go @@ -831,6 +831,7 @@ func SetupViper(v *viper.Viper, filename string) { v.SetDefault("adapters.adxcg.disabled", true) v.SetDefault("adapters.adyoulike.endpoint", "https://broker.omnitagjs.com/broker/bid?partnerId=19340f4f097d16f41f34fc0274981ca4") v.SetDefault("adapters.aja.endpoint", "https://ad.as.amanad.adtdp.com/v1/bid/4") + v.SetDefault("adapters.algorix.endpoint", "https://xyz.svr-algorix.com/rtb/sa?sid={{.SourceId}}&token={{.AccountID}}") v.SetDefault("adapters.amx.endpoint", "http://pbs.amxrtb.com/auction/openrtb") v.SetDefault("adapters.applogy.endpoint", "http://rtb.applogy.com/v1/prebid") v.SetDefault("adapters.appnexus.endpoint", "http://ib.adnxs.com/openrtb2") // Docs: https://wiki.appnexus.com/display/supply/Incoming+Bid+Request+from+SSPs diff --git a/exchange/adapter_builders.go b/exchange/adapter_builders.go index 8cee98429d8..39292ef9c0c 100755 --- a/exchange/adapter_builders.go +++ b/exchange/adapter_builders.go @@ -23,6 +23,7 @@ import ( "github.com/prebid/prebid-server/adapters/adxcg" "github.com/prebid/prebid-server/adapters/adyoulike" "github.com/prebid/prebid-server/adapters/aja" + "github.com/prebid/prebid-server/adapters/algorix" "github.com/prebid/prebid-server/adapters/amx" "github.com/prebid/prebid-server/adapters/applogy" "github.com/prebid/prebid-server/adapters/appnexus" @@ -140,6 +141,7 @@ func newAdapterBuilders() map[openrtb_ext.BidderName]adapters.Builder { openrtb_ext.BidderAdxcg: adxcg.Builder, openrtb_ext.BidderAdyoulike: adyoulike.Builder, openrtb_ext.BidderAJA: aja.Builder, + openrtb_ext.BidderAlgorix: algorix.Builder, openrtb_ext.BidderAMX: amx.Builder, openrtb_ext.BidderApplogy: applogy.Builder, openrtb_ext.BidderAppnexus: appnexus.Builder, diff --git a/openrtb_ext/bidders.go b/openrtb_ext/bidders.go index 1bc75d5f63e..ea10428f723 100755 --- a/openrtb_ext/bidders.go +++ b/openrtb_ext/bidders.go @@ -94,6 +94,7 @@ const ( BidderAdxcg BidderName = "adxcg" BidderAdyoulike BidderName = "adyoulike" BidderAJA BidderName = "aja" + BidderAlgorix BidderName = "algorix" BidderAMX BidderName = "amx" BidderApplogy BidderName = "applogy" BidderAppnexus BidderName = "appnexus" @@ -212,6 +213,7 @@ func CoreBidderNames() []BidderName { BidderAdxcg, BidderAdyoulike, BidderAJA, + BidderAlgorix, BidderAMX, BidderApplogy, BidderAppnexus, diff --git a/openrtb_ext/imp_algorix.go b/openrtb_ext/imp_algorix.go new file mode 100644 index 00000000000..e63a45ee11e --- /dev/null +++ b/openrtb_ext/imp_algorix.go @@ -0,0 +1,7 @@ +package openrtb_ext + +// ExtImpAlgoriX defines the contract for bidrequest.imp[i].ext.algorix +type ExtImpAlgorix struct { + Sid string `json:"sid"` + Token string `json:"token"` +} diff --git a/static/bidder-info/algorix.yaml b/static/bidder-info/algorix.yaml new file mode 100644 index 00000000000..b8301d6cb79 --- /dev/null +++ b/static/bidder-info/algorix.yaml @@ -0,0 +1,8 @@ +maintainer: + email: "xunyunbo@algorix.co" +capabilities: + app: + mediaTypes: + - banner + - video + - native \ No newline at end of file diff --git a/static/bidder-params/algorix.json b/static/bidder-params/algorix.json new file mode 100644 index 00000000000..732625f4549 --- /dev/null +++ b/static/bidder-params/algorix.json @@ -0,0 +1,19 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "AlgoriX Adapter Params", + "description": "A schema which validates params accepted by the AlgoriX adapter", + "type": "object", + "properties": { + "sid": { + "type": "string", + "description": "Your Sid", + "minLength": 1 + }, + "token": { + "type": "string", + "description": "Your Token", + "minLength": 1 + } + }, + "required": ["sid", "token"] +} \ No newline at end of file diff --git a/usersync/usersyncers/syncer_test.go b/usersync/usersyncers/syncer_test.go index 07e09695beb..dff43835e51 100755 --- a/usersync/usersyncers/syncer_test.go +++ b/usersync/usersyncers/syncer_test.go @@ -110,6 +110,7 @@ func TestNewSyncerMap(t *testing.T) { openrtb_ext.BidderAdoppler: true, openrtb_ext.BidderAdot: true, openrtb_ext.BidderAdprime: true, + openrtb_ext.BidderAlgorix: true, openrtb_ext.BidderApplogy: true, openrtb_ext.BidderBidmachine: true, openrtb_ext.BidderBidsCube: true, From aeffa0226158ef0ed581be5c7363e476f92bc254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E4=BA=91=E6=B3=A2?= Date: Wed, 26 May 2021 10:53:20 +0800 Subject: [PATCH 2/9] fix code for code review: change AlgorixAdapter to adapter and remove&&fix comments --- adapters/algorix/algorix.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/adapters/algorix/algorix.go b/adapters/algorix/algorix.go index ad21c14789a..1b4fbc13358 100644 --- a/adapters/algorix/algorix.go +++ b/adapters/algorix/algorix.go @@ -14,24 +14,24 @@ import ( "github.com/prebid/prebid-server/openrtb_ext" ) -type AlgoriXAdapter struct { +type Adapter struct { EndpointTemplate template.Template } // Builder builds a new instance of the Foo adapter for the given bidder with the given config. func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { - template, err := template.New("endpointTemplate").Parse(config.Endpoint) + endpoint, err := template.New("endpointTemplate").Parse(config.Endpoint) if err != nil { return nil, fmt.Errorf("unable to parse endpoint url template: %v", err) } - bidder := &AlgoriXAdapter{ - EndpointTemplate: *template, + bidder := &Adapter{ + EndpointTemplate: *endpoint, } return bidder, nil } // MakeRequests Make Requests -func (adapter *AlgoriXAdapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { +func (adapter *Adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { var adapterRequests []*adapters.RequestData var errs []error @@ -44,7 +44,7 @@ func (adapter *AlgoriXAdapter) MakeRequests(request *openrtb2.BidRequest, reques return adapterRequests, errs } -func (adapter *AlgoriXAdapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestData, error) { +func (adapter *Adapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestData, error) { if len(request.Imp) == 0 { return nil, &errortypes.BadInput{Message: "No impression in the request"} } @@ -97,12 +97,13 @@ func parseAlgoriXExt(request *openrtb2.BidRequest) *openrtb_ext.ExtImpAlgorix { return nil } -// getEndPoint get Endpoint -func (adapter *AlgoriXAdapter) getEndPoint(ext *openrtb_ext.ExtImpAlgorix) (string, error) { +// getEndPoint get Endpoint Target +func (adapter *Adapter) getEndPoint(ext *openrtb_ext.ExtImpAlgorix) (string, error) { endPointParams := macros.EndpointTemplateParams{SourceId: ext.Sid, AccountID: ext.Token} return macros.ResolveMacros(adapter.EndpointTemplate, endPointParams) } +// preProcess process Request check and modify banner imp func preProcess(request *openrtb2.BidRequest) { for i := range request.Imp { if request.Imp[i].Banner != nil { @@ -118,7 +119,7 @@ func preProcess(request *openrtb2.BidRequest) { } } -func (adapter *AlgoriXAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { +func (adapter *Adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { if response.StatusCode == http.StatusNoContent { return nil, nil } @@ -154,7 +155,7 @@ func (adapter *AlgoriXAdapter) MakeBids(internalRequest *openrtb2.BidRequest, ex return bidResponse, nil } -// getBidType get Bid Type +// getBidType get Bid Type default: BannerType func getBidType(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { for _, imp := range imps { if imp.ID == impId { From c41dea83b2c9d5686c73c0dcf3d76d345ff535ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E4=BA=91=E6=B3=A2?= Date: Thu, 27 May 2021 10:49:47 +0800 Subject: [PATCH 3/9] fix and update code for PR comments --- adapters/algorix/algorix.go | 24 ++++++++----------- .../algorixtest/params/race/banner.json | 4 ---- .../algorixtest/params/race/native.json | 4 ---- .../algorixtest/params/race/video.json | 4 ---- .../supplemental/bad_impext_bidder.json | 5 +--- .../supplemental/bad_impext_bidder_2.json | 23 ------------------ .../supplemental/no_imp_error.json | 13 ---------- 7 files changed, 11 insertions(+), 66 deletions(-) delete mode 100644 adapters/algorix/algorixtest/params/race/banner.json delete mode 100644 adapters/algorix/algorixtest/params/race/native.json delete mode 100644 adapters/algorix/algorixtest/params/race/video.json delete mode 100644 adapters/algorix/algorixtest/supplemental/bad_impext_bidder_2.json delete mode 100644 adapters/algorix/algorixtest/supplemental/no_imp_error.json diff --git a/adapters/algorix/algorix.go b/adapters/algorix/algorix.go index 1b4fbc13358..5d97734c04e 100644 --- a/adapters/algorix/algorix.go +++ b/adapters/algorix/algorix.go @@ -14,7 +14,7 @@ import ( "github.com/prebid/prebid-server/openrtb_ext" ) -type Adapter struct { +type adapter struct { EndpointTemplate template.Template } @@ -24,18 +24,18 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters if err != nil { return nil, fmt.Errorf("unable to parse endpoint url template: %v", err) } - bidder := &Adapter{ + bidder := &adapter{ EndpointTemplate: *endpoint, } return bidder, nil } // MakeRequests Make Requests -func (adapter *Adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { +func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { var adapterRequests []*adapters.RequestData var errs []error - adapterRequest, err := adapter.makeRequest(request) + adapterRequest, err := a.makeRequest(request) if err == nil { adapterRequests = append(adapterRequests, adapterRequest) } else { @@ -44,18 +44,14 @@ func (adapter *Adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo * return adapterRequests, errs } -func (adapter *Adapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestData, error) { - if len(request.Imp) == 0 { - return nil, &errortypes.BadInput{Message: "No impression in the request"} - } - +func (a *adapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestData, error) { algorixExt := parseAlgoriXExt(request) if algorixExt == nil { return nil, &errortypes.BadInput{Message: "Invalid ExtImpAlgoriX value"} } - endPoint, err := adapter.getEndPoint(algorixExt) + endPoint, err := a.getEndPoint(algorixExt) if err != nil { return nil, err } @@ -89,7 +85,7 @@ func parseAlgoriXExt(request *openrtb2.BidRequest) *openrtb_ext.ExtImpAlgorix { continue } err = json.Unmarshal(extBidder.Bidder, &extImpAlgoriX) - if err != nil || len(extImpAlgoriX.Sid) == 0 || len(extImpAlgoriX.Token) == 0 { + if err != nil { continue } return &extImpAlgoriX @@ -98,9 +94,9 @@ func parseAlgoriXExt(request *openrtb2.BidRequest) *openrtb_ext.ExtImpAlgorix { } // getEndPoint get Endpoint Target -func (adapter *Adapter) getEndPoint(ext *openrtb_ext.ExtImpAlgorix) (string, error) { +func (a *adapter) getEndPoint(ext *openrtb_ext.ExtImpAlgorix) (string, error) { endPointParams := macros.EndpointTemplateParams{SourceId: ext.Sid, AccountID: ext.Token} - return macros.ResolveMacros(adapter.EndpointTemplate, endPointParams) + return macros.ResolveMacros(a.EndpointTemplate, endPointParams) } // preProcess process Request check and modify banner imp @@ -119,7 +115,7 @@ func preProcess(request *openrtb2.BidRequest) { } } -func (adapter *Adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { +func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { if response.StatusCode == http.StatusNoContent { return nil, nil } diff --git a/adapters/algorix/algorixtest/params/race/banner.json b/adapters/algorix/algorixtest/params/race/banner.json deleted file mode 100644 index ba35cad2eb6..00000000000 --- a/adapters/algorix/algorixtest/params/race/banner.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "sid": "testSid", - "token": "testToken" -} diff --git a/adapters/algorix/algorixtest/params/race/native.json b/adapters/algorix/algorixtest/params/race/native.json deleted file mode 100644 index ba35cad2eb6..00000000000 --- a/adapters/algorix/algorixtest/params/race/native.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "sid": "testSid", - "token": "testToken" -} diff --git a/adapters/algorix/algorixtest/params/race/video.json b/adapters/algorix/algorixtest/params/race/video.json deleted file mode 100644 index ba35cad2eb6..00000000000 --- a/adapters/algorix/algorixtest/params/race/video.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "sid": "testSid", - "token": "testToken" -} diff --git a/adapters/algorix/algorixtest/supplemental/bad_impext_bidder.json b/adapters/algorix/algorixtest/supplemental/bad_impext_bidder.json index 46e0ceb6cde..669e22b081a 100644 --- a/adapters/algorix/algorixtest/supplemental/bad_impext_bidder.json +++ b/adapters/algorix/algorixtest/supplemental/bad_impext_bidder.json @@ -8,10 +8,7 @@ "format": [{"w": 320, "h": 50}] }, "ext": { - "bidder": { - "test1": 123, - "test2": 234 - } + "bidder": "badBidder" } } ] diff --git a/adapters/algorix/algorixtest/supplemental/bad_impext_bidder_2.json b/adapters/algorix/algorixtest/supplemental/bad_impext_bidder_2.json deleted file mode 100644 index 669e22b081a..00000000000 --- a/adapters/algorix/algorixtest/supplemental/bad_impext_bidder_2.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "mockBidRequest": { - "id": "test-request-id", - "imp": [ - { - "id": "test-imp-id", - "banner": { - "format": [{"w": 320, "h": 50}] - }, - "ext": { - "bidder": "badBidder" - } - } - ] - }, - - "expectedMakeRequestsErrors": [ - { - "value": "Invalid ExtImpAlgoriX value", - "comparison": "literal" - } - ] -} diff --git a/adapters/algorix/algorixtest/supplemental/no_imp_error.json b/adapters/algorix/algorixtest/supplemental/no_imp_error.json deleted file mode 100644 index 6c6c363425a..00000000000 --- a/adapters/algorix/algorixtest/supplemental/no_imp_error.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "mockBidRequest": { - "id": "req-id", - "imp": [ - ] - }, - "expectedMakeRequestsErrors": [ - { - "value": "No impression in the request", - "comparison": "literal" - } - ] -} From 24abbc793948bd84963254685b80b2a0187ffde3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E4=BA=91=E6=B3=A2?= Date: Tue, 1 Jun 2021 14:27:52 +0800 Subject: [PATCH 4/9] fix code for comments --- adapters/algorix/algorix_test.go | 2 +- adapters/algorix/algorixtest/exemplary/sample-banner.json | 2 +- adapters/algorix/algorixtest/exemplary/sample-native.json | 2 +- adapters/algorix/algorixtest/exemplary/sample-nobid.json | 2 +- adapters/algorix/algorixtest/exemplary/sample-video.json | 2 +- adapters/algorix/algorixtest/supplemental/bad_response.json | 2 +- adapters/algorix/algorixtest/supplemental/status_400.json | 2 +- adapters/algorix/algorixtest/supplemental/status_500.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/adapters/algorix/algorix_test.go b/adapters/algorix/algorix_test.go index a33b054f738..55c8b9ef58e 100644 --- a/adapters/algorix/algorix_test.go +++ b/adapters/algorix/algorix_test.go @@ -11,7 +11,7 @@ import ( func TestJsonSamples(t *testing.T) { bidder, buildErr := Builder(openrtb_ext.BidderAlgorix, config.Adapter{ - Endpoint: "https://xyz.svr-algorix.com/rtb/sa?sid={{.SourceId}}&token={{.AccountID}}"}) + Endpoint: "https://test.com?sid={{.SourceId}}&token={{.AccountID}}"}) if buildErr != nil { t.Fatalf("Builder returned unexpected error %v", buildErr) diff --git a/adapters/algorix/algorixtest/exemplary/sample-banner.json b/adapters/algorix/algorixtest/exemplary/sample-banner.json index 4bec8139478..118f89c1b3d 100644 --- a/adapters/algorix/algorixtest/exemplary/sample-banner.json +++ b/adapters/algorix/algorixtest/exemplary/sample-banner.json @@ -20,7 +20,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "uri": "https://test.com?sid=testSid&token=testToken", "body": { "id": "test-request-id", "imp": [ diff --git a/adapters/algorix/algorixtest/exemplary/sample-native.json b/adapters/algorix/algorixtest/exemplary/sample-native.json index 613d1428931..283e6a2bfb4 100644 --- a/adapters/algorix/algorixtest/exemplary/sample-native.json +++ b/adapters/algorix/algorixtest/exemplary/sample-native.json @@ -20,7 +20,7 @@ "httpcalls": [ { "expectedRequest": { - "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "uri": "https://test.com?sid=testSid&token=testToken", "body": { "id": "test-request-id", "imp": [ diff --git a/adapters/algorix/algorixtest/exemplary/sample-nobid.json b/adapters/algorix/algorixtest/exemplary/sample-nobid.json index 26cec78ec3b..4ea2e61e5d2 100644 --- a/adapters/algorix/algorixtest/exemplary/sample-nobid.json +++ b/adapters/algorix/algorixtest/exemplary/sample-nobid.json @@ -20,7 +20,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "uri": "https://test.com?sid=testSid&token=testToken", "body": { "id": "test-request-id", "imp": [ diff --git a/adapters/algorix/algorixtest/exemplary/sample-video.json b/adapters/algorix/algorixtest/exemplary/sample-video.json index 0f8145fdc8f..5507e6a9d38 100644 --- a/adapters/algorix/algorixtest/exemplary/sample-video.json +++ b/adapters/algorix/algorixtest/exemplary/sample-video.json @@ -24,7 +24,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "uri": "https://test.com?sid=testSid&token=testToken", "body": { "id": "test-request-id", "imp": [ diff --git a/adapters/algorix/algorixtest/supplemental/bad_response.json b/adapters/algorix/algorixtest/supplemental/bad_response.json index f413b0876d0..17d846733db 100644 --- a/adapters/algorix/algorixtest/supplemental/bad_response.json +++ b/adapters/algorix/algorixtest/supplemental/bad_response.json @@ -20,7 +20,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "uri": "https://test.com?sid=testSid&token=testToken", "body": { "id": "test-request-id", "imp": [ diff --git a/adapters/algorix/algorixtest/supplemental/status_400.json b/adapters/algorix/algorixtest/supplemental/status_400.json index 9648ca9fdfa..f384c3b9446 100644 --- a/adapters/algorix/algorixtest/supplemental/status_400.json +++ b/adapters/algorix/algorixtest/supplemental/status_400.json @@ -20,7 +20,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "uri": "https://test.com?sid=testSid&token=testToken", "body": { "id": "test-request-id", "imp": [ diff --git a/adapters/algorix/algorixtest/supplemental/status_500.json b/adapters/algorix/algorixtest/supplemental/status_500.json index 2a5fcd33eea..ca6cf14ba84 100644 --- a/adapters/algorix/algorixtest/supplemental/status_500.json +++ b/adapters/algorix/algorixtest/supplemental/status_500.json @@ -20,7 +20,7 @@ "httpCalls": [ { "expectedRequest": { - "uri": "https://xyz.svr-algorix.com/rtb/sa?sid=testSid&token=testToken", + "uri": "https://test.com?sid=testSid&token=testToken", "body": { "id": "test-request-id", "imp": [ From d7b115769bdbc2507c1a19c4d254b688ca0b7d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E4=BA=91=E6=B3=A2?= Date: Tue, 1 Jun 2021 14:57:25 +0800 Subject: [PATCH 5/9] fix clear comments --- adapters/algorix/algorix.go | 1 - 1 file changed, 1 deletion(-) diff --git a/adapters/algorix/algorix.go b/adapters/algorix/algorix.go index 5d97734c04e..cdb34366126 100644 --- a/adapters/algorix/algorix.go +++ b/adapters/algorix/algorix.go @@ -30,7 +30,6 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters return bidder, nil } -// MakeRequests Make Requests func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { var adapterRequests []*adapters.RequestData var errs []error From 7bfcf2ff10d26fc2954d70ee66fccfce6d839a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E4=BA=91=E6=B3=A2?= Date: Wed, 2 Jun 2021 12:08:08 +0800 Subject: [PATCH 6/9] fix code for comments and change parase ImpAlgorixExt for check and use first imp --- adapters/algorix/algorix.go | 56 ++++---- .../supplemental/check_first_imp.json | 123 ++++++++++++++++++ 2 files changed, 149 insertions(+), 30 deletions(-) create mode 100644 adapters/algorix/algorixtest/supplemental/check_first_imp.json diff --git a/adapters/algorix/algorix.go b/adapters/algorix/algorix.go index cdb34366126..b355f74a8f4 100644 --- a/adapters/algorix/algorix.go +++ b/adapters/algorix/algorix.go @@ -3,14 +3,14 @@ package algorix import ( "encoding/json" "fmt" - "github.com/prebid/prebid-server/errortypes" - "github.com/prebid/prebid-server/macros" "net/http" "text/template" "github.com/mxmCherry/openrtb/v15/openrtb2" "github.com/prebid/prebid-server/adapters" "github.com/prebid/prebid-server/config" + "github.com/prebid/prebid-server/errortypes" + "github.com/prebid/prebid-server/macros" "github.com/prebid/prebid-server/openrtb_ext" ) @@ -18,7 +18,7 @@ type adapter struct { EndpointTemplate template.Template } -// Builder builds a new instance of the Foo adapter for the given bidder with the given config. +// Builder builds a new instance of the AlgoriX adapter for the given bidder with the given config. func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { endpoint, err := template.New("endpointTemplate").Parse(config.Endpoint) if err != nil { @@ -44,9 +44,9 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte } func (a *adapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestData, error) { - algorixExt := parseAlgoriXExt(request) + algorixExt, err := getImpAlgoriXExt(&request.Imp[0]) - if algorixExt == nil { + if err != nil { return nil, &errortypes.BadInput{Message: "Invalid ExtImpAlgoriX value"} } @@ -74,41 +74,35 @@ func (a *adapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestDa }, nil } -//parseAlgoriXExt parse AlgoriX Ext -func parseAlgoriXExt(request *openrtb2.BidRequest) *openrtb_ext.ExtImpAlgorix { +// get ImpAlgoriXExt From First Imp. Only check and get first Imp.Ext.Bidder to ExtImpAlgorix +func getImpAlgoriXExt(imp *openrtb2.Imp) (*openrtb_ext.ExtImpAlgorix, error) { var extImpAlgoriX openrtb_ext.ExtImpAlgorix - for _, imp := range request.Imp { - var extBidder adapters.ExtImpBidder - err := json.Unmarshal(imp.Ext, &extBidder) - if err != nil { - continue - } - err = json.Unmarshal(extBidder.Bidder, &extImpAlgoriX) - if err != nil { - continue - } - return &extImpAlgoriX + var extBidder adapters.ExtImpBidder + err := json.Unmarshal(imp.Ext, &extBidder) + if err != nil { + return nil, err + } + err = json.Unmarshal(extBidder.Bidder, &extImpAlgoriX) + if err != nil { + return nil, err } - return nil + return &extImpAlgoriX, nil } -// getEndPoint get Endpoint Target func (a *adapter) getEndPoint(ext *openrtb_ext.ExtImpAlgorix) (string, error) { endPointParams := macros.EndpointTemplateParams{SourceId: ext.Sid, AccountID: ext.Token} return macros.ResolveMacros(a.EndpointTemplate, endPointParams) } -// preProcess process Request check and modify banner imp func preProcess(request *openrtb2.BidRequest) { for i := range request.Imp { if request.Imp[i].Banner != nil { banner := *request.Imp[i].Banner if (banner.W == nil || banner.H == nil || *banner.W == 0 || *banner.H == 0) && len(banner.Format) > 0 { firstFormat := banner.Format[0] - bannerCopy := *request.Imp[i].Banner - bannerCopy.W = &firstFormat.W - bannerCopy.H = &firstFormat.H - request.Imp[i].Banner = &bannerCopy + banner.W = &firstFormat.W + banner.H = &firstFormat.H + request.Imp[i].Banner = &banner } } } @@ -140,20 +134,22 @@ func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest for _, seatBid := range bidResp.SeatBid { for idx := range seatBid.Bid { - mediaType := getBidType(seatBid.Bid[idx].ImpID, internalRequest.Imp) bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ Bid: &seatBid.Bid[idx], - BidType: mediaType, + BidType: getMediaTypeForImp(seatBid.Bid[idx].ImpID, internalRequest.Imp), }) } } return bidResponse, nil } -// getBidType get Bid Type default: BannerType -func getBidType(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { +func getMediaTypeForImp(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { + mediaType := openrtb_ext.BidTypeBanner for _, imp := range imps { if imp.ID == impId { + if imp.Banner != nil { + return openrtb_ext.BidTypeBanner + } if imp.Native != nil { return openrtb_ext.BidTypeNative } @@ -162,5 +158,5 @@ func getBidType(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { } } } - return openrtb_ext.BidTypeBanner + return mediaType } diff --git a/adapters/algorix/algorixtest/supplemental/check_first_imp.json b/adapters/algorix/algorixtest/supplemental/check_first_imp.json new file mode 100644 index 00000000000..d776fbbc947 --- /dev/null +++ b/adapters/algorix/algorixtest/supplemental/check_first_imp.json @@ -0,0 +1,123 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}] + }, + "ext": { + "bidder": { + "sid": "testSid1", + "token": "testToken1" + } + } + }, + { + "id": "test-imp-id_2", + "banner": { + "format": [{"w": 300, "h": 250}] + }, + "ext": { + "bidder": "aaa" + } + } + ] + }, + + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://test.com?sid=testSid1&token=testToken1", + "body": { + "id": "test-request-id", + "imp": [ + { + "id":"test-imp-id", + "banner": { + "format": [{"w": 320, "h": 50}], + "w": 320, + "h": 50 + }, + "ext": { + "bidder": { + "sid": "testSid1", + "token": "testToken1" + } + } + }, + { + "id":"test-imp-id_2", + "banner": { + "format": [{"w": 300, "h": 250}], + "w": 300, + "h": 250 + }, + "ext": { + "bidder": "aaa" + } + } + ] + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "ttx", + "bid": [{ + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-ads", + "crid": "crid_testid" + }] + }, + { + "seat": "ttx", + "bid": [{ + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id_2", + "price": 0.5, + "adm": "some-ads", + "crid": "crid_testid" + }] + } + ], + "cur": "USD" + } + } + } + ], + + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id", + "price": 0.5, + "adm": "some-ads", + "crid": "crid_testid" + }, + "type": "banner" + }, + { + "bid": { + "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", + "impid": "test-imp-id_2", + "price": 0.5, + "adm": "some-ads", + "crid": "crid_testid" + }, + "type": "banner" + } + ] + } + ] +} From 4b0ae1806ff86af8e0690f758043adcf2ef10dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E4=BA=91=E6=B3=A2?= Date: Thu, 3 Jun 2021 11:34:18 +0800 Subject: [PATCH 7/9] change code and which the newest solution --- adapters/algorix/algorix.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adapters/algorix/algorix.go b/adapters/algorix/algorix.go index b355f74a8f4..b5c306ccf35 100644 --- a/adapters/algorix/algorix.go +++ b/adapters/algorix/algorix.go @@ -134,16 +134,17 @@ func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest for _, seatBid := range bidResp.SeatBid { for idx := range seatBid.Bid { + mediaType := getBidType(seatBid.Bid[idx].ImpID, internalRequest.Imp) bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ Bid: &seatBid.Bid[idx], - BidType: getMediaTypeForImp(seatBid.Bid[idx].ImpID, internalRequest.Imp), + BidType: mediaType, }) } } return bidResponse, nil } -func getMediaTypeForImp(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { +func getBidType(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { mediaType := openrtb_ext.BidTypeBanner for _, imp := range imps { if imp.ID == impId { From 7e135f8760de1421eb25813a39f3246a9d65b10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E4=BA=91=E6=B3=A2?= Date: Thu, 3 Jun 2021 19:26:24 +0800 Subject: [PATCH 8/9] fix code --- adapters/algorix/algorix.go | 11 +- .../supplemental/check_first_imp.json | 123 ------------------ 2 files changed, 7 insertions(+), 127 deletions(-) delete mode 100644 adapters/algorix/algorixtest/supplemental/check_first_imp.json diff --git a/adapters/algorix/algorix.go b/adapters/algorix/algorix.go index b5c306ccf35..deb55066d50 100644 --- a/adapters/algorix/algorix.go +++ b/adapters/algorix/algorix.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "net/url" "text/template" "github.com/mxmCherry/openrtb/v15/openrtb2" @@ -90,7 +91,10 @@ func getImpAlgoriXExt(imp *openrtb2.Imp) (*openrtb_ext.ExtImpAlgorix, error) { } func (a *adapter) getEndPoint(ext *openrtb_ext.ExtImpAlgorix) (string, error) { - endPointParams := macros.EndpointTemplateParams{SourceId: ext.Sid, AccountID: ext.Token} + endPointParams := macros.EndpointTemplateParams{ + SourceId: url.PathEscape(ext.Sid), + AccountID: url.PathEscape(ext.Token), + } return macros.ResolveMacros(a.EndpointTemplate, endPointParams) } @@ -145,11 +149,10 @@ func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest } func getBidType(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { - mediaType := openrtb_ext.BidTypeBanner for _, imp := range imps { if imp.ID == impId { if imp.Banner != nil { - return openrtb_ext.BidTypeBanner + break } if imp.Native != nil { return openrtb_ext.BidTypeNative @@ -159,5 +162,5 @@ func getBidType(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { } } } - return mediaType + return openrtb_ext.BidTypeBanner } diff --git a/adapters/algorix/algorixtest/supplemental/check_first_imp.json b/adapters/algorix/algorixtest/supplemental/check_first_imp.json deleted file mode 100644 index d776fbbc947..00000000000 --- a/adapters/algorix/algorixtest/supplemental/check_first_imp.json +++ /dev/null @@ -1,123 +0,0 @@ -{ - "mockBidRequest": { - "id": "test-request-id", - "imp": [ - { - "id": "test-imp-id", - "banner": { - "format": [{"w": 320, "h": 50}] - }, - "ext": { - "bidder": { - "sid": "testSid1", - "token": "testToken1" - } - } - }, - { - "id": "test-imp-id_2", - "banner": { - "format": [{"w": 300, "h": 250}] - }, - "ext": { - "bidder": "aaa" - } - } - ] - }, - - "httpCalls": [ - { - "expectedRequest": { - "uri": "https://test.com?sid=testSid1&token=testToken1", - "body": { - "id": "test-request-id", - "imp": [ - { - "id":"test-imp-id", - "banner": { - "format": [{"w": 320, "h": 50}], - "w": 320, - "h": 50 - }, - "ext": { - "bidder": { - "sid": "testSid1", - "token": "testToken1" - } - } - }, - { - "id":"test-imp-id_2", - "banner": { - "format": [{"w": 300, "h": 250}], - "w": 300, - "h": 250 - }, - "ext": { - "bidder": "aaa" - } - } - ] - } - }, - "mockResponse": { - "status": 200, - "body": { - "id": "test-request-id", - "seatbid": [ - { - "seat": "ttx", - "bid": [{ - "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", - "impid": "test-imp-id", - "price": 0.5, - "adm": "some-ads", - "crid": "crid_testid" - }] - }, - { - "seat": "ttx", - "bid": [{ - "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", - "impid": "test-imp-id_2", - "price": 0.5, - "adm": "some-ads", - "crid": "crid_testid" - }] - } - ], - "cur": "USD" - } - } - } - ], - - "expectedBidResponses": [ - { - "currency": "USD", - "bids": [ - { - "bid": { - "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", - "impid": "test-imp-id", - "price": 0.5, - "adm": "some-ads", - "crid": "crid_testid" - }, - "type": "banner" - }, - { - "bid": { - "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800", - "impid": "test-imp-id_2", - "price": 0.5, - "adm": "some-ads", - "crid": "crid_testid" - }, - "type": "banner" - } - ] - } - ] -} From 9126d9f9969c138851710c046983f58ed88aa7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E4=BA=91=E6=B3=A2?= Date: Fri, 4 Jun 2021 10:37:34 +0800 Subject: [PATCH 9/9] run gofmt and fix --- adapters/algorix/algorix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/algorix/algorix.go b/adapters/algorix/algorix.go index deb55066d50..7c0a6787c7b 100644 --- a/adapters/algorix/algorix.go +++ b/adapters/algorix/algorix.go @@ -92,7 +92,7 @@ func getImpAlgoriXExt(imp *openrtb2.Imp) (*openrtb_ext.ExtImpAlgorix, error) { func (a *adapter) getEndPoint(ext *openrtb_ext.ExtImpAlgorix) (string, error) { endPointParams := macros.EndpointTemplateParams{ - SourceId: url.PathEscape(ext.Sid), + SourceId: url.PathEscape(ext.Sid), AccountID: url.PathEscape(ext.Token), } return macros.ResolveMacros(a.EndpointTemplate, endPointParams)