-
Notifications
You must be signed in to change notification settings - Fork 867
New Adapter: RevX #4335
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
Open
nikithacode
wants to merge
13
commits into
prebid:master
Choose a base branch
from
nikithacode:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New Adapter: RevX #4335
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5645a81
Integration of RevX
nikithacode 690b4dc
fixing bug
nikithacode 92ee93d
Update imp_revx.go
nikithacode 59595e3
updated suggested changes
nikithacode 55b484e
build fix
nikithacode a0caa1a
revised review
nikithacode 7fcf91d
RevX Adapter: Handle 400 BadRequest properly in MakeBids
nikithacode b297134
Added required changes
asifarahiman 168eabd
Added requested suppliumental test files
asifarahiman 50c5392
Added review comments
asifarahiman cfa88b3
Added review comments
asifarahiman 5e42423
Added name of aggregator and removed required param check
asifarahiman a684190
Updated as per review comments
asifarahiman 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
Some comments aren't visible on the classic Files Changed page.
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,115 @@ | ||
| package revx | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "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" | ||
| ) | ||
|
|
||
| // RevXAdapter struct | ||
| type adapter struct { | ||
| endPoint string | ||
| } | ||
|
|
||
| // Builder builds a new instance of the RevX adapter. | ||
| func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) { | ||
| return &adapter{ | ||
| endPoint: config.Endpoint, // Default endpoint | ||
| }, nil | ||
| } | ||
|
|
||
| // MakeRequests handles the OpenRTB bid request and returns адаптер.RequestData | ||
| func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
| var errors []error | ||
|
|
||
| // Build headers | ||
| headers := http.Header{} | ||
| headers.Add("Content-Type", "application/json;charset=utf-8") | ||
| headers.Add("Accept", "application/json") | ||
|
|
||
| // Marshal request | ||
| reqJson, err := jsonutil.Marshal(request) | ||
| if err != nil { | ||
| return nil, []error{&errortypes.BadInput{Message: fmt.Sprintf("Failed to marshal request: %s", err)}} // skip append | ||
| } | ||
|
|
||
| requestData := &adapters.RequestData{ | ||
| Method: http.MethodPost, | ||
| Uri: a.endPoint, | ||
| Body: reqJson, | ||
| Headers: headers, | ||
| ImpIDs: openrtb_ext.GetImpIDs(request.Imp), | ||
| } | ||
|
|
||
| return []*adapters.RequestData{requestData}, errors | ||
| } | ||
|
|
||
| // MakeBids handles the OpenRTB bid response. | ||
| func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
| if externalRequest == nil { | ||
| return nil, nil | ||
| } | ||
|
|
||
| // Handle specific status codes first | ||
| if adapters.IsResponseStatusCodeNoContent(response) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| // For all other status codes | ||
| if err := adapters.CheckResponseStatusCodeForErrors(response); err != nil { | ||
| return nil, []error{err} | ||
ccorbo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Proceed with normal parsing | ||
| var serverBidResponse openrtb2.BidResponse | ||
| if err := jsonutil.Unmarshal(response.Body, &serverBidResponse); err != nil { | ||
| return nil, []error{err} | ||
ccorbo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| var typedBids []*adapters.TypedBid | ||
| var errs []error | ||
| for _, sb := range serverBidResponse.SeatBid { | ||
| for i := range sb.Bid { | ||
| mediaType, err := getMediaTypeForImp(sb.Bid[i]) | ||
| if err != nil { | ||
pm-jaydeep-mohite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| errs = append(errs, err) | ||
| continue | ||
| } | ||
| typedBids = append(typedBids, &adapters.TypedBid{ | ||
| Bid: &sb.Bid[i], | ||
| BidType: mediaType, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| if len(typedBids) == 0 { | ||
| return nil, errs | ||
| } | ||
|
|
||
| bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(typedBids)) | ||
| bidResponse.Bids = typedBids | ||
| bidResponse.Currency = serverBidResponse.Cur | ||
|
|
||
| return bidResponse, errs | ||
| } | ||
|
|
||
| func getMediaTypeForImp(bid openrtb2.Bid) (openrtb_ext.BidType, error) { | ||
| switch bid.MType { | ||
| case openrtb2.MarkupBanner: | ||
| return openrtb_ext.BidTypeBanner, nil | ||
| case openrtb2.MarkupVideo: | ||
| return openrtb_ext.BidTypeVideo, nil | ||
| case openrtb2.MarkupNative: | ||
| return openrtb_ext.BidTypeNative, nil | ||
| default: | ||
| return "", &errortypes.BadServerResponse{ | ||
| Message: fmt.Sprintf("Unsupported mtype %d for bid %s", bid.MType, bid.ID), | ||
| } | ||
| } | ||
| } | ||
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,35 @@ | ||
| package revx_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/prebid/openrtb/v20/openrtb2" | ||
| "github.com/prebid/prebid-server/v3/adapters" | ||
| "github.com/prebid/prebid-server/v3/adapters/revx" | ||
| "github.com/prebid/prebid-server/v3/config" | ||
| "github.com/prebid/prebid-server/v3/openrtb_ext" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestMakeBids_NilExternalRequest(t *testing.T) { | ||
| // Arrange | ||
| bidder, buildErr := revx.Builder(openrtb_ext.BidderRevX, config.Adapter{ | ||
| Endpoint: "prebid-use.atomex.net/ag=PUB123", | ||
| }, config.Server{ | ||
| ExternalUrl: "http://hosturl.com", | ||
| GvlID: 375, | ||
| DataCenter: "2", | ||
| }) | ||
|
|
||
| var internalReq *openrtb2.BidRequest | ||
| var response *adapters.ResponseData | ||
| if buildErr != nil { | ||
| t.Logf("RevX Builder created successfully: %+v", bidder) | ||
| } | ||
| // Act | ||
| bidderResponse, errs := bidder.MakeBids(internalReq, nil, response) | ||
|
|
||
| // Assert | ||
| assert.Nil(t, bidderResponse, "Expected bidderResponse to be nil when externalRequest is nil") | ||
| assert.Nil(t, errs, "Expected errors to be nil when externalRequest is 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,27 @@ | ||
| package revx_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/prebid/prebid-server/v3/adapters/adapterstest" | ||
| "github.com/prebid/prebid-server/v3/adapters/revx" | ||
| "github.com/prebid/prebid-server/v3/config" | ||
| "github.com/prebid/prebid-server/v3/openrtb_ext" | ||
| ) | ||
|
|
||
| func TestJsonSamples(t *testing.T) { | ||
| bidder, buildErr := revx.Builder(openrtb_ext.BidderRevX, config.Adapter{ | ||
| Endpoint: "prebid-use.atomex.net/ag=PUB123", | ||
| }, config.Server{ | ||
| ExternalUrl: "http://hosturl.com", | ||
| GvlID: 375, | ||
| DataCenter: "2", | ||
| }) | ||
|
|
||
| if buildErr != nil { | ||
|
|
||
| t.Logf("RevX Builder created successfully: %+v", bidder) | ||
| } | ||
|
|
||
| adapterstest.RunJSONBidderTest(t, "revxtest", bidder) | ||
| } |
109 changes: 109 additions & 0 deletions
109
adapters/revx/revxtest/exemplary/simple-app-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,109 @@ | ||
| { | ||
| "mockBidRequest": { | ||
| "id": "test-request-id", | ||
| "site": { | ||
| "page": "https://good.site/url" | ||
| }, | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 111, | ||
| "h": 111 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "pubname": "PUB123" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "httpCalls": [ | ||
| { | ||
| "expectedRequest": { | ||
| "uri": "prebid-use.atomex.net/ag=PUB123", | ||
|
|
||
| "body": { | ||
| "id": "test-request-id", | ||
| "site": { | ||
| "page": "https://good.site/url" | ||
| }, | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 111, | ||
| "h": 111 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "pubname": "PUB123" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "impIDs": [ | ||
| "imp-id" | ||
| ] | ||
| }, | ||
| "mockResponse": { | ||
| "status": 200, | ||
| "body": { | ||
| "id": "test-request-id", | ||
| "seatbid": [ | ||
| { | ||
| "seat": "interactiveoffers", | ||
| "bid": [ | ||
| { | ||
| "id": "randomid", | ||
| "impid": "imp-id", | ||
| "price": 0.5, | ||
| "adid": "12345678", | ||
| "adm": "some-test-ad", | ||
| "cid": "987", | ||
| "crid": "12345678", | ||
| "h": 111, | ||
| "w": 111, | ||
| "mtype": 1 | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "cur": "USD" | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "expectedBidResponses": [ | ||
| { | ||
| "currency": "USD", | ||
| "bids": [ | ||
| { | ||
| "bid": { | ||
| "id": "randomid", | ||
| "impid": "imp-id", | ||
| "price": 0.5, | ||
| "adm": "some-test-ad", | ||
| "adid": "12345678", | ||
| "cid": "987", | ||
| "crid": "12345678", | ||
| "w": 111, | ||
| "h": 111, | ||
| "mtype": 1 | ||
| }, | ||
| "type": "banner" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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,99 @@ | ||
| { | ||
| "mockBidRequest": { | ||
| "id": "test-request-id", | ||
| "app": { | ||
| "publisher": { | ||
| "name": "PUB123" | ||
| } | ||
| }, | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "native": { | ||
| "request": "{\"native\":{\"ver\":\"1.2\",\"api\":[1],\"battr\":[1,3,9],\"assets\":[{\"id\":0,\"required\":1,\"title\":{\"len\":25}},{\"id\":1,\"required\":1,\"img\":{\"type\":3,\"wmin\":100,\"hmin\":50}},{\"id\":2,\"required\":0,\"data\":{\"type\":2,\"len\":200}},{\"id\":3,\"required\":0,\"data\":{\"type\":12}},{\"id\":4,\"required\":0,\"data\":{\"type\":1}}]}}" | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "pubname": "PUB123" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "httpCalls": [ | ||
| { | ||
| "expectedRequest": { | ||
| "uri": "prebid-use.atomex.net/ag=PUB123", | ||
| "body": { | ||
| "id": "test-request-id", | ||
| "app": { | ||
| "publisher": { | ||
| "name": "PUB123" | ||
| } | ||
| }, | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "native": { | ||
| "request": "{\"native\":{\"ver\":\"1.2\",\"api\":[1],\"battr\":[1,3,9],\"assets\":[{\"id\":0,\"required\":1,\"title\":{\"len\":25}},{\"id\":1,\"required\":1,\"img\":{\"type\":3,\"wmin\":100,\"hmin\":50}},{\"id\":2,\"required\":0,\"data\":{\"type\":2,\"len\":200}},{\"id\":3,\"required\":0,\"data\":{\"type\":12}},{\"id\":4,\"required\":0,\"data\":{\"type\":1}}]}}" | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "pubname": "PUB123" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "impIDs": [ | ||
| "imp-id" | ||
| ] | ||
| }, | ||
| "mockResponse": { | ||
| "status": 200, | ||
| "body": { | ||
| "id": "test-request-id", | ||
| "seatbid": [ | ||
| { | ||
| "seat": "interactiveoffers", | ||
| "bid": [ | ||
| { | ||
| "id": "randomid", | ||
| "impid": "imp-id", | ||
| "price": 0.5, | ||
| "adid": "12345678", | ||
| "adm": "{\"native\":{\"ver\":\"1.2\",\"assets\":[{\"id\":0,\"title\":{\"text\":\"Test Title\"}},{\"id\":1,\"img\":{\"url\":\"http://some.image.url\",\"w\":100,\"h\":50}},{\"id\":2,\"data\":{\"type\":2,\"value\":\"Test Body\"}},{\"id\":3,\"data\":{\"type\":12,\"value\":\"Test Sponsored\"}},{\"id\":4,\"data\":{\"type\":1,\"value\":\"Test Display URL\"}}],\"link\":{\"url\":\"http://click.url\"},\"imptrackers\":[\"http://impression.url\"]}}", | ||
| "cid": "987", | ||
| "crid": "12345678", | ||
| "mtype": 4 | ||
|
|
||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "cur": "USD" | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "expectedBidResponses": [ | ||
| { | ||
| "currency": "USD", | ||
| "bids": [ | ||
| { | ||
| "bid": { | ||
| "id": "randomid", | ||
| "impid": "imp-id", | ||
| "price": 0.5, | ||
| "adm": "{\"native\":{\"ver\":\"1.2\",\"assets\":[{\"id\":0,\"title\":{\"text\":\"Test Title\"}},{\"id\":1,\"img\":{\"url\":\"http://some.image.url\",\"w\":100,\"h\":50}},{\"id\":2,\"data\":{\"type\":2,\"value\":\"Test Body\"}},{\"id\":3,\"data\":{\"type\":12,\"value\":\"Test Sponsored\"}},{\"id\":4,\"data\":{\"type\":1,\"value\":\"Test Display URL\"}}],\"link\":{\"url\":\"http://click.url\"},\"imptrackers\":[\"http://impression.url\"]}}", | ||
| "adid": "12345678", | ||
| "cid": "987", | ||
| "crid": "12345678", | ||
| "mtype": 4 | ||
| }, | ||
| "type": "native" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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.