-
Notifications
You must be signed in to change notification settings - Fork 897
New Adapter: Oprx #4432
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
Ivan-Z-Oprx
wants to merge
15
commits into
prebid:master
Choose a base branch
from
Ivan-Z-Oprx:adding-adapter-oprx
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: Oprx #4432
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
46c7dab
initial oprx adapter files
Ivan-Z-Oprx 1ff192e
registering oprx adapter
Ivan-Z-Oprx 835c115
started work on tests
Ivan-Z-Oprx 8bec429
fixed types in imp_oprx
Ivan-Z-Oprx 96af088
fixed params and banner test now works
Ivan-Z-Oprx bd13367
added params tests
Ivan-Z-Oprx bc443bf
endpoint changed from testing one (localhost)
Ivan-Z-Oprx 6ca1843
cleanup
Ivan-Z-Oprx 832fbbe
removed comments
Ivan-Z-Oprx 5870c1f
moved getMediaTypeForBid to the end of file
Ivan-Z-Oprx b855061
added some new test cases
Ivan-Z-Oprx b639119
fixed formatting
Ivan-Z-Oprx 6c94fb9
comments addressed
Ivan-Z-Oprx 96321f8
tests aligned
Ivan-Z-Oprx f3d84e9
typo
Ivan-Z-Oprx 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,94 @@ | ||
| package oprx | ||
|
|
||
| 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" | ||
| ) | ||
|
|
||
| type adapter struct { | ||
| endpoint string | ||
| } | ||
|
|
||
| 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: "POST", | ||
| 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} | ||
| } | ||
|
|
||
| if responseData.StatusCode != http.StatusOK { | ||
| err := &errortypes.BadServerResponse{ | ||
| Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", responseData.StatusCode), | ||
| } | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| var response openrtb2.BidResponse | ||
| if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil { | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) | ||
| bidResponse.Currency = response.Cur | ||
| var errors []error | ||
| for _, seatBid := range response.SeatBid { | ||
| for i, bid := range seatBid.Bid { | ||
| bidType, err := getMediaTypeForBid(bid) | ||
| if err != nil { | ||
| errors = append(errors, err) | ||
| continue | ||
| } | ||
| bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | ||
| Bid: &seatBid.Bid[i], | ||
| BidType: bidType, | ||
| }) | ||
| } | ||
| } | ||
| return bidResponse, nil | ||
| } | ||
|
|
||
| func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) { | ||
| if bid.Ext != nil { | ||
| var bidExt openrtb_ext.ExtBid | ||
| err := jsonutil.Unmarshal(bid.Ext, &bidExt) | ||
| if err == nil && bidExt.Prebid != nil { | ||
| return openrtb_ext.ParseBidType(string(bidExt.Prebid.Type)) | ||
| } | ||
| } | ||
|
|
||
| return "", &errortypes.BadServerResponse{ | ||
| Message: fmt.Sprintf("Failed to parse impression \"%s\" mediatype", bid.ImpID), | ||
| } | ||
| } | ||
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 oprx | ||
|
|
||
| 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.BidderOprx, config.Adapter{ | ||
| Endpoint: "http://localhost:8080"}, | ||
| config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) | ||
|
|
||
| if buildErr != nil { | ||
| t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
| } | ||
|
|
||
| adapterstest.RunJSONBidderTest(t, "oprxtest", bidder) | ||
| } |
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,121 @@ | ||
| { | ||
|
Ivan-Z-Oprx marked this conversation as resolved.
|
||
| "mockBidRequest": { | ||
| "id": "request-id", | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "key": "p123", | ||
| "placement_id": "my-placement-id", | ||
| "bid-floor": 0.5, | ||
| "npi": "my-npi", | ||
| "ndc": "my-ndc" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "httpCalls": [{ | ||
| "expectedRequest": { | ||
| "uri": "http://localhost:8080", | ||
| "body": { | ||
| "id": "request-id", | ||
| "imp": [ | ||
| { | ||
| "id": "imp-id", | ||
| "banner": { | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ] | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "key": "p123", | ||
| "placement_id": "my-placement-id", | ||
| "bid-floor": 0.5, | ||
| "npi": "my-npi", | ||
| "ndc": "my-ndc" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "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", | ||
| "ext": { | ||
| "prebid": { | ||
| "type": "banner" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "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", | ||
| "h": 250, | ||
| "w": 300, | ||
| "dealid": "test deal", | ||
| "ext": { | ||
| "prebid": { | ||
| "type": "banner" | ||
| } | ||
| } | ||
| }, | ||
| "type": "banner" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider this as a suggestion. Prebid server expects the media type to be explicitly set in the adapter response. Therefore, recommends implementing a pattern where the adapter server sets the MType field in the response to accurately determine the media type for the impression.