-
Notifications
You must be signed in to change notification settings - Fork 897
New Adapter: Optidigital #4287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Adapter: Optidigital #4287
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2d621eb
optidigital adapter
3975027
add `divId` parameter as optional
90b249d
protect strings in yaml just-in-case
67d0194
remove un-used errors slide
46598d0
validate params
5f66589
[skip ci] fix comment
c27f8bd
Merge pull request #2 from optidigital-prebid/adapter/optidigital
optidigital-prebid cee3787
normalize checks
05463ca
add bad_response test case
8b269ed
Merge pull request #3 from optidigital-prebid/adapter/optidigital
optidigital-prebid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package optidigital | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/prebid/openrtb/v20/openrtb2" | ||
| "github.com/prebid/prebid-server/v3/adapters" | ||
| "github.com/prebid/prebid-server/v3/config" | ||
| "github.com/prebid/prebid-server/v3/errortypes" | ||
| "github.com/prebid/prebid-server/v3/openrtb_ext" | ||
| "github.com/prebid/prebid-server/v3/util/jsonutil" | ||
| ) | ||
|
|
||
| type adapter struct { | ||
| endpoint string | ||
| } | ||
|
|
||
| // Builder builds a new instance of the optidigital adapter for the given bidder with the given config. | ||
| func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) { | ||
| bidder := &adapter{ | ||
| endpoint: config.Endpoint, | ||
| } | ||
| return bidder, nil | ||
| } | ||
|
|
||
| func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
| requestJSON, err := jsonutil.Marshal(request) | ||
| if err != nil { | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| requestData := &adapters.RequestData{ | ||
| Method: http.MethodPost, | ||
| Uri: a.endpoint, | ||
| Body: requestJSON, | ||
| ImpIDs: openrtb_ext.GetImpIDs(request.Imp), | ||
| } | ||
|
|
||
| return []*adapters.RequestData{requestData}, nil | ||
| } | ||
|
|
||
| func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
|
|
||
| if adapters.IsResponseStatusCodeNoContent(responseData) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil { | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| var response openrtb2.BidResponse | ||
| if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil { | ||
| return nil, []error{&errortypes.BadServerResponse{ | ||
| Message: "Bad Server Response", | ||
| }} | ||
| } | ||
|
|
||
| bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) | ||
| bidResponse.Currency = response.Cur | ||
|
|
||
| for _, seatBid := range response.SeatBid { | ||
| for i := range seatBid.Bid { | ||
| bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | ||
| Bid: &seatBid.Bid[i], | ||
| BidType: openrtb_ext.BidTypeBanner, | ||
| }) | ||
| } | ||
| } | ||
|
Comment on lines
+62
to
+69
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, it's better to add code like this: I know that right now you're only using "banner", but in the future You might want to change something, and this approach will make it easier. |
||
| return bidResponse, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package optidigital | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/prebid/prebid-server/v3/adapters/adapterstest" | ||
| "github.com/prebid/prebid-server/v3/config" | ||
| "github.com/prebid/prebid-server/v3/openrtb_ext" | ||
| ) | ||
|
|
||
| func TestJsonSamples(t *testing.T) { | ||
| bidder, buildErr := Builder(openrtb_ext.BidderOptidigital, config.Adapter{ | ||
| Endpoint: "https://pbs.optidigital.com/bidder/openrtb2", | ||
| }, config.Server{}) | ||
|
|
||
| if buildErr != nil { | ||
| t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
| } | ||
|
|
||
| adapterstest.RunJSONBidderTest(t, "optidigitaltest", bidder) | ||
| } |
107 changes: 107 additions & 0 deletions
107
adapters/optidigital/optidigitaltest/exemplary/banner.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| { | ||
| "mockBidRequest": { | ||
| "id": "request-id", | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "publisherId": "p123", | ||
| "placementId": "my-placement-id" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "httpCalls": [ | ||
| { | ||
| "expectedRequest": { | ||
| "uri": "https://pbs.optidigital.com/bidder/openrtb2", | ||
| "body": { | ||
| "id": "request-id", | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "publisherId": "p123", | ||
| "placementId": "my-placement-id" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "impIDs": ["imp-id"] | ||
| }, | ||
| "mockResponse": { | ||
| "status": 200, | ||
| "body": { | ||
| "id": "request-id", | ||
| "seatbid": [ | ||
| { | ||
| "seat": "958", | ||
| "bid": [ | ||
| { | ||
| "id": "bid-id", | ||
| "impid": "imp-id", | ||
| "price": 0.5, | ||
| "adid": "29681110", | ||
| "adm": "some-test-ad", | ||
| "adomain": [ | ||
| "foo.com" | ||
| ], | ||
| "crid": "29681110", | ||
| "h": 250, | ||
| "w": 300, | ||
| "dealid": "test deal" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "bidid": "request-id", | ||
| "cur": "USD" | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "expectedBidResponses": [ | ||
| { | ||
| "currency": "USD", | ||
| "bids": [ | ||
| { | ||
| "bid": { | ||
| "id": "bid-id", | ||
| "impid": "imp-id", | ||
| "price": 0.5, | ||
| "adid": "29681110", | ||
| "adm": "some-test-ad", | ||
| "adomain": [ | ||
| "foo.com" | ||
| ], | ||
| "crid": "29681110", | ||
| "w": 300, | ||
| "h": 250, | ||
| "dealid": "test deal" | ||
| }, | ||
| "type": "banner" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
63 changes: 63 additions & 0 deletions
63
adapters/optidigital/optidigitaltest/supplemental/bad_request.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| { | ||
| "mockBidRequest": { | ||
| "id": "request-id", | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "publisherId": "p123", | ||
| "placementId": "my-placement-id" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "httpCalls": [ | ||
| { | ||
| "expectedRequest": { | ||
| "uri": "https://pbs.optidigital.com/bidder/openrtb2", | ||
| "body": { | ||
| "id": "request-id", | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "publisherId": "p123", | ||
| "placementId": "my-placement-id" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "impIDs": ["imp-id"] | ||
| }, | ||
| "mockResponse": { | ||
| "status": 400 | ||
| } | ||
| } | ||
| ], | ||
| "expectedMakeBidsErrors": [ | ||
| { | ||
| "value": "Unexpected status code: 400", | ||
| "comparison": "startswith" | ||
| } | ||
| ] | ||
| } |
65 changes: 65 additions & 0 deletions
65
adapters/optidigital/optidigitaltest/supplemental/bad_response.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| { | ||
| "mockBidRequest": { | ||
| "id": "request-id", | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "publisherId": "p123", | ||
| "placementId": "my-placement-id" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "httpCalls": [ | ||
| { | ||
| "expectedRequest": { | ||
| "uri": "https://pbs.optidigital.com/bidder/openrtb2", | ||
| "body": { | ||
| "id": "request-id", | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "publisherId": "p123", | ||
| "placementId": "my-placement-id" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "impIDs": ["imp-id"] | ||
| }, | ||
| "mockResponse": { | ||
| "status": 200, | ||
| "body": "invalid response" | ||
| } | ||
| } | ||
| ], | ||
|
|
||
| "expectedMakeBidsErrors": [ | ||
| { | ||
| "value": "Bad Server Response", | ||
| "comparison": "literal" | ||
| } | ||
| ] | ||
| } |
57 changes: 57 additions & 0 deletions
57
adapters/optidigital/optidigitaltest/supplemental/no_response.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| { | ||
| "mockBidRequest": { | ||
| "id": "request-id", | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "publisherId": "p123", | ||
| "placementId": "my-placement-id" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "httpCalls": [ | ||
| { | ||
| "expectedRequest": { | ||
| "uri": "https://pbs.optidigital.com/bidder/openrtb2", | ||
| "body": { | ||
| "id": "request-id", | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "publisherId": "p123", | ||
| "placementId": "my-placement-id" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "impIDs": ["imp-id"] | ||
| }, | ||
| "mockResponse": { | ||
| "status": 204 | ||
| } | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.