-
Notifications
You must be signed in to change notification settings - Fork 870
New Adapter: Boldwin Rapid #4478
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
Changes from 8 commits
b08a06c
25e8722
01671a1
472ba65
950cccd
1536181
236d9f5
9960e04
20f1aa9
c559040
3fac16e
e4792b5
72e8afb
b9f1984
729e1c1
38a38c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| package boldwin_rapid | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "text/template" | ||
|
|
||
| "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/macros" | ||
| "github.com/prebid/prebid-server/v3/openrtb_ext" | ||
| "github.com/prebid/prebid-server/v3/util/jsonutil" | ||
| ) | ||
|
|
||
| type adapter struct { | ||
| //endpoint string | ||
| endpoint *template.Template | ||
| } | ||
|
|
||
| func Builder(_ openrtb_ext.BidderName, config config.Adapter, _ config.Server) (adapters.Bidder, error) { | ||
| endpointTemplate, err := template.New("endpointTemplate").Parse(config.Endpoint) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to parse endpoint template: %v", err) | ||
| } | ||
|
|
||
| bidder := &adapter{ | ||
| endpoint: endpointTemplate, | ||
| } | ||
|
|
||
| return bidder, nil | ||
| } | ||
|
|
||
| func (a adapter) buildEndpointURL(boldwinExt openrtb_ext.ImpExtBoldwinRapid) (string, error) { | ||
| endpointParams := macros.EndpointTemplateParams{ | ||
| PublisherID: boldwinExt.Pid, | ||
| PlacementID: boldwinExt.Tid, | ||
| } | ||
|
|
||
| return macros.ResolveMacros(a.endpoint, endpointParams) | ||
| } | ||
|
|
||
| func (a *adapter) MakeRequests(request *openrtb2.BidRequest, _ *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
| var adapterRequests []*adapters.RequestData | ||
|
|
||
| reqCopy := *request | ||
|
|
||
| for _, imp := range request.Imp { | ||
| // Create a new request with just this impression | ||
| reqCopy.Imp = []openrtb2.Imp{imp} | ||
BoldwinDev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| var bidderExt adapters.ExtImpBidder | ||
| var boldwinExt openrtb_ext.ImpExtBoldwinRapid | ||
|
|
||
| // Use the current impression's Ext | ||
| if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil { | ||
| return nil, []error{err} | ||
|
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. can you please add test coverage for these unmarshal errors
Contributor
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. Tests added |
||
| } | ||
|
|
||
| if err := jsonutil.Unmarshal(bidderExt.Bidder, &boldwinExt); err != nil { | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| endpoint, err := a.buildEndpointURL(boldwinExt) | ||
| if err != nil { | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| adapterReq, err := a.makeRequest(&reqCopy, endpoint) | ||
|
||
| if err != nil { | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| if adapterReq != nil { | ||
| adapterRequests = append(adapterRequests, adapterReq) | ||
| } | ||
| } | ||
|
|
||
| return adapterRequests, nil | ||
| } | ||
|
|
||
| func (a *adapter) getHeaders(request *openrtb2.BidRequest) http.Header { | ||
| headers := http.Header{} | ||
| headers.Add("Content-Type", "application/json;charset=utf-8") | ||
| headers.Add("Accept", "application/json") | ||
| headers.Add("x-openrtb-version", "2.5") | ||
|
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. if you support openrtb version 2.5, can you please declare openrtb version 2.5 in your .yaml file. Example here under bidder info: https://docs.prebid.org/prebid-server/developers/add-new-bidder-go.html
Contributor
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. Added version indication to the yaml file |
||
| headers.Add("Host", "rtb.beardfleet.com") // required header for the request | ||
BoldwinDev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if request.Device != nil { | ||
| if request.Device.UA != "" { | ||
| headers.Add("User-Agent", request.Device.UA) | ||
| } | ||
|
|
||
| if len(request.Device.IPv6) > 0 { | ||
| headers.Add("X-Forwarded-For", request.Device.IPv6) | ||
|
||
| } | ||
|
|
||
| if len(request.Device.IP) > 0 { | ||
| headers.Set("X-Forwarded-For", request.Device.IP) | ||
BoldwinDev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| headers.Add("IP", request.Device.IP) | ||
|
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. In the edge case where both
Contributor
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. Thanks for catching it, It's better for us to prioritize the |
||
| } | ||
| } | ||
|
|
||
| return headers | ||
| } | ||
|
|
||
| func (a *adapter) makeRequest(request *openrtb2.BidRequest, endpoint string) (*adapters.RequestData, error) { | ||
| reqJSON, err := json.Marshal(request) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| headers := a.getHeaders(request) | ||
|
|
||
| return &adapters.RequestData{ | ||
| Method: "POST", | ||
| Uri: endpoint, | ||
| Body: reqJSON, | ||
| Headers: headers, | ||
| ImpIDs: openrtb_ext.GetImpIDs(request.Imp), | ||
| }, nil | ||
| } | ||
|
|
||
| func (a *adapter) MakeBids(request *openrtb2.BidRequest, _ *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
| if adapters.IsResponseStatusCodeNoContent(responseData) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| err := adapters.CheckResponseStatusCodeForErrors(responseData) | ||
| if err != nil { | ||
| 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 | ||
|
||
|
|
||
| for _, seatBid := range response.SeatBid { | ||
| for i := range seatBid.Bid { | ||
| bidType, err := getBidMediaType(&seatBid.Bid[i]) | ||
| if err != nil { | ||
| return nil, []error{err} | ||
| } | ||
|
|
||
| b := &adapters.TypedBid{ | ||
| Bid: &seatBid.Bid[i], | ||
| BidType: bidType, | ||
| } | ||
| bidResponse.Bids = append(bidResponse.Bids, b) | ||
| } | ||
| } | ||
| return bidResponse, nil | ||
| } | ||
|
|
||
| func getBidMediaType(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 "", fmt.Errorf("Unable to fetch mediaType in multi-format: %s", bid.ImpID) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.