-
Notifications
You must be signed in to change notification settings - Fork 867
New adapter: BeOp #4660
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
jeans11
wants to merge
18
commits into
prebid:master
Choose a base branch
from
BeOpinion: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: BeOp #4660
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0c56b14
feat: add beop.json bidder params
jeans11 3b044f2
feat: add beop.yaml bidder info
jeans11 db6bc4e
feat: add imp_beop.go
jeans11 b0b4833
feat: add beop.go adapter
jeans11 70e7896
feat: register beop adapter
jeans11 68f08c5
feat: add beop adapter test
jeans11 d49baa1
Merge pull request #1 from BeOpinion/adapter
jeans11 64e60bf
refacto: update bid reference
jeans11 77c9c14
refacto: use mtype field
jeans11 49abbe9
refacto: tests
jeans11 7908799
Merge branch 'prebid:master' into master
jeans11 d8f8a75
review: remove extra cases
jeans11 acb9c44
review: remove extra validation
jeans11 d8643a6
review: remove url parse error check
jeans11 42bba13
review: add missing bidder params test
jeans11 a5cb34d
review: add invalid bid type test
jeans11 ae27191
review: add params_test
jeans11 963f154
review: add status code no content test
jeans11 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,172 @@ | ||
| package beop | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
| "net/url" | ||
|
|
||
| "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) getRequestExtImpBeop(imp *openrtb2.Imp) (*openrtb_ext.ExtImpBeop, error) { | ||
| var bidderExt adapters.ExtImpBidder | ||
| if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil { | ||
| return nil, &errortypes.BadInput{ | ||
| Message: "ext.bidder not provided", | ||
| } | ||
| } | ||
| var beopExt openrtb_ext.ExtImpBeop | ||
| if err := jsonutil.Unmarshal(bidderExt.Bidder, &beopExt); err != nil { | ||
| return nil, &errortypes.BadInput{ | ||
| Message: "ext.bidder not provided", | ||
| } | ||
| } | ||
| return &beopExt, nil | ||
| } | ||
|
|
||
| func (a *adapter) buildEndpointURL(params *openrtb_ext.ExtImpBeop) (string, error) { | ||
| url, _ := url.Parse(a.endpoint) | ||
| query := url.Query() | ||
| if pid := params.BeopPublisherID; len(pid) != 0 { | ||
| query.Set("pid", pid) | ||
| } | ||
| if nid := params.BeopNetworkID; len(nid) != 0 { | ||
| query.Set("nid", nid) | ||
| } | ||
| if nptnid := params.BeopNetworkPartnerID; len(nptnid) != 0 { | ||
| query.Set("nptnid", nptnid) | ||
| } | ||
| url.RawQuery = query.Encode() | ||
| return url.String(), nil | ||
| } | ||
|
|
||
| func (a *adapter) MakeRequests( | ||
| request *openrtb2.BidRequest, | ||
| requestInfo *adapters.ExtraRequestInfo) ( | ||
| []*adapters.RequestData, []error, | ||
| ) { | ||
| var beopExt *openrtb_ext.ExtImpBeop | ||
| var err error | ||
|
|
||
| beopExt, err = a.getRequestExtImpBeop(&request.Imp[0]) | ||
| if err != nil { | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| requestJSON, err := json.Marshal(request) | ||
| if err != nil { | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| headers := http.Header{} | ||
| headers.Add("Content-Type", "application/json;charset=utf-8") | ||
| headers.Add("Accept", "application/json") | ||
|
|
||
| url, err := a.buildEndpointURL(beopExt) | ||
| if err != nil { | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| requestData := &adapters.RequestData{ | ||
| Method: "POST", | ||
| Uri: url, | ||
| Body: requestJSON, | ||
| Headers: headers, | ||
| ImpIDs: openrtb_ext.GetImpIDs(request.Imp), | ||
| } | ||
|
|
||
| return []*adapters.RequestData{requestData}, nil | ||
| } | ||
|
|
||
| func getMediaTypeForBid(bid *openrtb2.Bid) (openrtb_ext.BidType, error) { | ||
| mType := bid.MType | ||
| var bidType openrtb_ext.BidType | ||
| switch mType { | ||
| case openrtb2.MarkupBanner: | ||
| bidType = openrtb_ext.BidTypeBanner | ||
| case openrtb2.MarkupVideo: | ||
| bidType = openrtb_ext.BidTypeVideo | ||
| default: | ||
| return bidType, fmt.Errorf("Failed to parse bid mType for impression \"%s\"", bid.ImpID) | ||
| } | ||
| return bidType, nil | ||
| } | ||
|
|
||
| func (a *adapter) MakeBids( | ||
| request *openrtb2.BidRequest, | ||
| requestData *adapters.RequestData, | ||
| responseData *adapters.ResponseData) ( | ||
| *adapters.BidderResponse, []error, | ||
| ) { | ||
| if responseData.StatusCode == http.StatusNoContent { | ||
|
Contributor
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. Missing test case
Author
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. |
||
| return nil, nil | ||
| } | ||
|
|
||
| if responseData.StatusCode == http.StatusServiceUnavailable { | ||
| return nil, []error{&errortypes.BadInput{ | ||
| Message: fmt.Sprintf("Service Unavailable. Status Code: [ %d ] ", responseData.StatusCode), | ||
| }} | ||
| } | ||
|
|
||
| if responseData.StatusCode == http.StatusBadRequest { | ||
| 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 responseBody openrtb2.BidResponse | ||
| if err := jsonutil.Unmarshal(responseData.Body, &responseBody); err != nil { | ||
| return nil, []error{&errortypes.BadServerResponse{ | ||
| Message: "Bad Server Response", | ||
| }} | ||
| } | ||
|
|
||
| if len(responseBody.SeatBid) == 0 { | ||
| return nil, []error{&errortypes.BadServerResponse{ | ||
| Message: "Empty SeatBid array", | ||
| }} | ||
| } | ||
|
|
||
| bidResponseFinal := adapters.NewBidderResponseWithBidsCapacity(len(responseBody.SeatBid[0].Bid)) | ||
| seatBid := responseBody.SeatBid[0] | ||
| var errors []error | ||
| for i := range seatBid.Bid { | ||
| bid := &seatBid.Bid[i] | ||
| bidType, err := getMediaTypeForBid(bid) | ||
| if err != nil { | ||
| errors = append(errors, err) | ||
karwaankit32 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| continue | ||
| } | ||
| bidResponseFinal.Bids = append(bidResponseFinal.Bids, &adapters.TypedBid{ | ||
| Bid: bid, | ||
| BidType: bidType, | ||
| }) | ||
| } | ||
| if len(bidResponseFinal.Bids) == 0 { | ||
| return nil, errors | ||
| } | ||
| return bidResponseFinal, errors | ||
| } | ||
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 beop | ||
|
|
||
| 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.BidderBeop, config.Adapter{ | ||
| Endpoint: "http://hb-test.collectiveaudience.co/rtb/bid"}, | ||
| config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) | ||
|
|
||
| if buildErr != nil { | ||
| t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
| } | ||
|
|
||
| adapterstest.RunJSONBidderTest(t, "beoptest", bidder) | ||
| } |
155 changes: 155 additions & 0 deletions
155
adapters/beop/beoptest/exemplary/banner-web-with-nid.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,155 @@ | ||
| { | ||
| "mockBidRequest": { | ||
| "id": "request-id", | ||
| "site": { | ||
| "page": "test.com/page", | ||
| "domain": "test.com", | ||
| "cat": [ | ||
| "IAB9-1" | ||
| ], | ||
| "publisher": { | ||
| "id": "123456789" | ||
| } | ||
| }, | ||
| "device": { | ||
| "ua": "useragent", | ||
| "ip": "100.100.100.100", | ||
| "language": "en" | ||
| }, | ||
| "tmax": 1000, | ||
| "user": { | ||
| "id": "some-user" | ||
| }, | ||
| "imp": [ | ||
| { | ||
| "id": "impression-id", | ||
| "tagid": "tid", | ||
| "banner": { | ||
| "w": 320, | ||
| "h": 50 | ||
| }, | ||
| "ext": { | ||
| "bidder": { | ||
| "nid": "aaaaaaaaaaaaaaaaaaaaaaaa", | ||
| "nptnid": "1234" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "httpCalls": [ | ||
| { | ||
| "expectedRequest": { | ||
| "method": "POST", | ||
| "uri": "http://hb-test.collectiveaudience.co/rtb/bid?nid=aaaaaaaaaaaaaaaaaaaaaaaa&nptnid=1234", | ||
| "headers": { | ||
| "Content-Type": [ | ||
| "application/json;charset=utf-8" | ||
| ], | ||
| "Accept": [ | ||
| "application/json" | ||
| ] | ||
| }, | ||
| "body": { | ||
| "id": "request-id", | ||
| "device": { | ||
| "ua": "useragent", | ||
| "ip": "100.100.100.100", | ||
| "language": "en" | ||
| }, | ||
| "imp": [ | ||
| { | ||
| "id": "impression-id", | ||
| "banner": { | ||
| "w": 320, | ||
| "h": 50 | ||
| }, | ||
| "tagid": "tid", | ||
| "ext": { | ||
| "bidder": { | ||
| "nid": "aaaaaaaaaaaaaaaaaaaaaaaa", | ||
| "nptnid": "1234" | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "site": { | ||
| "page": "test.com/page", | ||
| "domain": "test.com", | ||
| "cat": [ | ||
| "IAB9-1" | ||
| ], | ||
| "publisher": { | ||
| "id": "123456789" | ||
| } | ||
| }, | ||
| "user": { | ||
| "id": "some-user" | ||
| }, | ||
| "tmax": 1000 | ||
| }, | ||
| "impIDs": [ | ||
| "impression-id" | ||
| ] | ||
| }, | ||
| "mockResponse": { | ||
| "status": 200, | ||
| "body": { | ||
| "id": "resp-id", | ||
| "seatbid": [ | ||
| { | ||
| "bid": [ | ||
| { | ||
| "id": "123456789", | ||
| "impid": "impression-id", | ||
| "price": 2, | ||
| "adm": "adm code", | ||
| "adomain": [ | ||
| "testdomain.com" | ||
| ], | ||
| "crid": "100", | ||
| "w": 320, | ||
| "h": 50, | ||
| "mtype": 1, | ||
| "ext": { | ||
| "prebid": { | ||
| "type": "banner" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "cur": "USD" | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "expectedBidResponses": [ | ||
| { | ||
| "bids": [ | ||
| { | ||
| "bid": { | ||
| "id": "123456789", | ||
| "impid": "impression-id", | ||
| "price": 2, | ||
| "adm": "adm code", | ||
| "adomain": [ | ||
| "testdomain.com" | ||
| ], | ||
| "crid": "100", | ||
| "w": 320, | ||
| "h": 50, | ||
| "mtype": 1, | ||
| "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.
I think we can add coverage for unmarshalling errors in this code path