-
Notifications
You must be signed in to change notification settings - Fork 750
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
New Adapter: bigoad #3711
Merged
Merged
New Adapter: bigoad #3711
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a40121d
New Adapter: bigoad
74967e9
update bigoad adapter
fccd9b7
fix bigoad updater
2baaaa3
fix bigoad updater
08d1bf8
fix bigoad updater
12aa766
Merge branch 'master' into bigoad-adapter
BIGOAds 1d5f4a3
Merge remote-tracking branch 'origin/master' into bigoad-adapter
9c26cc8
Merge remote-tracking branch 'origin/bigoad-adapter' into bigoad-adapter
6ebe3cc
update bigoad adapter bigoad.yaml
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 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,156 @@ | ||
package bigoad | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"text/template" | ||
|
||
"github.com/prebid/openrtb/v20/openrtb2" | ||
"github.com/prebid/prebid-server/v2/adapters" | ||
"github.com/prebid/prebid-server/v2/config" | ||
"github.com/prebid/prebid-server/v2/errortypes" | ||
"github.com/prebid/prebid-server/v2/macros" | ||
"github.com/prebid/prebid-server/v2/openrtb_ext" | ||
) | ||
|
||
type adapter struct { | ||
endpoint *template.Template | ||
} | ||
|
||
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) { | ||
template, err := template.New("endpointTemplate").Parse(config.Endpoint) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse endpoint url template: %v", err) | ||
} | ||
|
||
bidder := &adapter{ | ||
endpoint: template, | ||
} | ||
|
||
return bidder, nil | ||
} | ||
|
||
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
bigoadExt, err := getImpExt(&request.Imp[0]) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
resolvedUrl, err := a.buildEndpointURL(bigoadExt) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
requestJSON, err := json.Marshal(request) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
requestData := &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: resolvedUrl, | ||
Body: requestJSON, | ||
Headers: getHeaders(request), | ||
ImpIDs: openrtb_ext.GetImpIDs(request.Imp), | ||
} | ||
|
||
return []*adapters.RequestData{requestData}, nil | ||
} | ||
|
||
func getHeaders(request *openrtb2.BidRequest) http.Header { | ||
headers := http.Header{} | ||
addNonEmptyHeaders(&headers, map[string]string{ | ||
"Content-Type": "application/json;charset=utf-8", | ||
"Accept": "application/json", | ||
"x-openrtb-version": "2.5", | ||
}) | ||
return headers | ||
} | ||
|
||
func addNonEmptyHeaders(headers *http.Header, headerValues map[string]string) { | ||
for key, value := range headerValues { | ||
if len(value) > 0 { | ||
headers.Add(key, value) | ||
} | ||
} | ||
} | ||
|
||
func getImpExt(imp *openrtb2.Imp) (*openrtb_ext.ExtImpBigoAd, error) { | ||
var bidderExt adapters.ExtImpBidder | ||
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { | ||
return nil, &errortypes.BadInput{ | ||
Message: fmt.Sprintf("imp %s: unable to unmarshal ext", imp.ID), | ||
} | ||
} | ||
var bigoadExt openrtb_ext.ExtImpBigoAd | ||
if err := json.Unmarshal(bidderExt.Bidder, &bigoadExt); err != nil { | ||
return nil, &errortypes.BadInput{ | ||
Message: fmt.Sprintf("imp %s: unable to unmarshal ext.bidder: %v", imp.ID, err), | ||
} | ||
} | ||
imp.Ext = bidderExt.Bidder | ||
return &bigoadExt, nil | ||
} | ||
|
||
func (a *adapter) buildEndpointURL(params *openrtb_ext.ExtImpBigoAd) (string, error) { | ||
endpointParams := macros.EndpointTemplateParams{Host: params.Host, SspId: params.SspId} | ||
return macros.ResolveMacros(a.endpoint, endpointParams) | ||
BIGOAds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func (a *adapter) MakeBids(request *openrtb2.BidRequest, _ *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 bidResponse openrtb2.BidResponse | ||
if err := json.Unmarshal(responseData.Body, &bidResponse); err != nil { | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: fmt.Sprintf("Bad server response: %d", err), | ||
}} | ||
} | ||
|
||
if len(bidResponse.SeatBid) == 0 { | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: "Empty SeatBid array", | ||
}} | ||
} | ||
BIGOAds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
bidResponseWithCapacity := adapters.NewBidderResponseWithBidsCapacity(len(bidResponse.SeatBid[0].Bid)) | ||
|
||
var errors []error | ||
seatBid := bidResponse.SeatBid[0] | ||
for i := range seatBid.Bid { | ||
bid := seatBid.Bid[i] | ||
bidType, err := getBidType(request.Imp[0], bid) | ||
if err != nil { | ||
errors = append(errors, err) | ||
continue | ||
} | ||
bidResponseWithCapacity.Bids = append(bidResponseWithCapacity.Bids, &adapters.TypedBid{ | ||
Bid: &bid, | ||
BIGOAds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
BidType: bidType, | ||
}) | ||
} | ||
|
||
return bidResponseWithCapacity, errors | ||
} | ||
|
||
func getBidType(imp openrtb2.Imp, bid openrtb2.Bid) (openrtb_ext.BidType, error) { | ||
switch bid.MType { | ||
case openrtb2.MarkupBanner: | ||
return openrtb_ext.BidTypeBanner, nil | ||
case openrtb2.MarkupNative: | ||
return openrtb_ext.BidTypeNative, nil | ||
case openrtb2.MarkupVideo: | ||
return openrtb_ext.BidTypeVideo, nil | ||
} | ||
|
||
return "", &errortypes.BadInput{ | ||
Message: fmt.Sprintf("unrecognized bid type in response from bigoad %s", imp.ID), | ||
} | ||
} | ||
BIGOAds marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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,29 @@ | ||
package bigoad | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/v2/adapters/adapterstest" | ||
"github.com/prebid/prebid-server/v2/config" | ||
"github.com/prebid/prebid-server/v2/openrtb_ext" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderBigoAd, | ||
config.Adapter{Endpoint: "https://api.imotech.tech/Ad/GetAdOut?sspid={{.SspId}}"}, | ||
config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "bigoadtest", bidder) | ||
} | ||
|
||
func TestEndpointTemplateMalformed(t *testing.T) { | ||
_, buildErr := Builder(openrtb_ext.BidderBigoAd, config.Adapter{ | ||
Endpoint: "{{Malformed}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) | ||
|
||
assert.Error(t, buildErr) | ||
} |
This file contains 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,186 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"app": { | ||
"id": "123456789", | ||
"bundle": "com.prebid", | ||
"domain": "prebid.com", | ||
"ver": "3.3.2", | ||
"publisher": { | ||
"id": "123456789" | ||
}, | ||
"cat": [ | ||
"IAB22-1" | ||
] | ||
}, | ||
"device": { | ||
"ifa": "87857b31-8942-4646-ae80-ab9c95bf3fab", | ||
"ua": "test-user-agent", | ||
"ip": "123.123.123.123", | ||
"language": "en", | ||
"geo": { | ||
"lon": 16.0, | ||
"country": "KWT", | ||
"city": "deli" | ||
} | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"tagid": "tagid", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 250 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"sspid": "sspid" | ||
} | ||
} | ||
} | ||
], | ||
"tmax": 1000 | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "https://api.imotech.tech/Ad/GetAdOut?sspid=sspid", | ||
"headers": { | ||
"Content-Type": [ | ||
"application/json;charset=utf-8" | ||
], | ||
"Accept": [ | ||
"application/json" | ||
], | ||
"X-Openrtb-Version": [ | ||
"2.5" | ||
] | ||
}, | ||
"body": { | ||
"id": "test-request-id", | ||
"app": { | ||
"id": "123456789", | ||
"bundle": "com.prebid", | ||
"domain": "prebid.com", | ||
"ver": "3.3.2", | ||
"publisher": { | ||
"id": "123456789" | ||
}, | ||
"cat": [ | ||
"IAB22-1" | ||
] | ||
}, | ||
"device": { | ||
"ifa": "87857b31-8942-4646-ae80-ab9c95bf3fab", | ||
"ua": "test-user-agent", | ||
"ip": "123.123.123.123", | ||
"language": "en", | ||
"geo": { | ||
"lon": 16.0, | ||
"country": "KWT", | ||
"city": "deli" | ||
} | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"tagid": "tagid", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 250 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"sspid": "sspid" | ||
} | ||
} | ||
], | ||
"tmax": 1000 | ||
}, | ||
"impIDs": [ | ||
"test-imp-id" | ||
] | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "test-request-id", | ||
"seatbid": [ | ||
{ | ||
"seat": "bigoad", | ||
"type": "banner", | ||
"bid": [ | ||
{ | ||
"id": "test-imp-id", | ||
"impid": "test-imp-id", | ||
"adid": "11110126", | ||
"mtype": 1, | ||
"price": 0.42632559, | ||
"adm": "some-test-ad", | ||
"adomain": [ | ||
"www.lazada.com" | ||
], | ||
"crid": "test-crid", | ||
"cat": [ | ||
"IAB22", | ||
"IAB8-5" | ||
], | ||
"attr": [ | ||
4 | ||
], | ||
"h": 250, | ||
"w": 300, | ||
"ext": { | ||
"dsp": "bigo" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"cur": "USD" | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses": [ | ||
{ | ||
"currency": "USD", | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "test-imp-id", | ||
"impid": "test-imp-id", | ||
"adid": "11110126", | ||
"price": 0.42632559, | ||
"adm": "some-test-ad", | ||
"mtype": 1, | ||
"adomain": [ | ||
"www.lazada.com" | ||
], | ||
"crid": "test-crid", | ||
"cat": [ | ||
"IAB22", | ||
"IAB8-5" | ||
], | ||
"attr": [ | ||
4 | ||
], | ||
"h": 250, | ||
"w": 300, | ||
"ext": { | ||
"dsp": "bigo" | ||
} | ||
}, | ||
"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.
Based on line 35 -
bigoadExt, err := getImpExt(&request.Imp[0])
looks likeBigoad
expects all imps to use same values forImp.Ext
@BIGOAds please confirm above behaviour. If all imps should have same values for
Imp.Ext
then create/update bidder docs PR to mention this expected behaviourThere 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.
How to mention this in bidder docs PR
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.
Create doc PR in https://github.com/prebid/prebid.github.io repo and link doc PR in this PR's description.
Refer prebid/prebid.github.io#5395 as example
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.
prebid/prebid.github.io#5349
This is my doc PR