-
Notifications
You must be signed in to change notification settings - Fork 719
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: Vidazoo #3698
Merged
Merged
New Adapter: Vidazoo #3698
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
903684b
Add Vidazoo bidder adapter
saar120 2031cd5
Added tests to vidazoo adapter
saar120 61f9b0b
Vidazoo prebid server adapter
saar120 074bc86
update vidazoo cId
saar120 ad2b2ce
update vidazoo cId
saar120 7d64a63
Change adapter to support imp splitting and added tests.
saar120 0bd805b
Updated userMacro value
saar120 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,41 @@ | ||
package vidazoo | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/prebid/prebid-server/v2/openrtb_ext" | ||
"testing" | ||
) | ||
|
||
func TestValidParams(t *testing.T) { | ||
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") | ||
if err != nil { | ||
t.Fatalf("Failed to fetch the json schema. %v", err) | ||
} | ||
|
||
for _, validParam := range validParams { | ||
if err := validator.Validate(openrtb_ext.BidderVidazoo, json.RawMessage(validParam)); err != nil { | ||
t.Errorf("Schema rejected valid params: %s", validParam) | ||
} | ||
} | ||
} | ||
|
||
func TestInvalidParams(t *testing.T) { | ||
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") | ||
if err != nil { | ||
t.Fatalf("Failed to fetch the json schema. %v", err) | ||
} | ||
|
||
for _, p := range invalidParams { | ||
if err := validator.Validate(openrtb_ext.BidderVidazoo, json.RawMessage(p)); err == nil { | ||
t.Errorf("Schema allowed invalid params: %s", p) | ||
} | ||
} | ||
} | ||
|
||
var validParams = []string{ | ||
`{"cId": "provided_cid_123"}`, | ||
} | ||
|
||
var invalidParams = []string{ | ||
`{"cId": 3898334}`, | ||
} |
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,133 @@ | ||
package vidazoo | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
|
||
"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/openrtb_ext" | ||
) | ||
|
||
type adapter struct { | ||
endpoint string | ||
} | ||
|
||
// Builder builds a new instance of the Vidazoo for the given bidder with the given config. | ||
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) { | ||
var requests []*adapters.RequestData | ||
var errors []error | ||
|
||
requestCopy := *request | ||
|
||
for _, imp := range request.Imp { | ||
requestCopy.Imp = []openrtb2.Imp{imp} | ||
|
||
requestJSON, err := json.Marshal(&requestCopy) | ||
if err != nil { | ||
errors = append(errors, fmt.Errorf("marshal bidRequest: %w", err)) | ||
continue | ||
} | ||
|
||
cId, err := extractCid(&imp) | ||
if err != nil { | ||
errors = append(errors, fmt.Errorf("extract cId: %w", err)) | ||
continue | ||
} | ||
|
||
headers := http.Header{} | ||
headers.Add("Content-Type", "application/json;charset=utf-8") | ||
|
||
requestData := &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: fmt.Sprintf("%s%s", a.endpoint, url.QueryEscape(cId)), | ||
Body: requestJSON, | ||
Headers: headers, | ||
ImpIDs: []string{imp.ID}, | ||
} | ||
|
||
requests = append(requests, requestData) | ||
} | ||
|
||
return requests, errors | ||
} | ||
|
||
func getMediaTypeForBid(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 | ||
} | ||
return "", &errortypes.BadInput{ | ||
Message: fmt.Sprintf("Could not define bid type for imp: %s", bid.ImpID), | ||
} | ||
} | ||
|
||
func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
var errs []error | ||
|
||
if adapters.IsResponseStatusCodeNoContent(responseData) { | ||
return nil, nil | ||
} | ||
|
||
if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil { | ||
return nil, []error{&errortypes.BadInput{ | ||
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info", responseData.StatusCode), | ||
}} | ||
} | ||
|
||
var response openrtb2.BidResponse | ||
if err := json.Unmarshal(responseData.Body, &response); err != nil { | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: fmt.Sprintf("bad server response: %d. ", err), | ||
}} | ||
} | ||
|
||
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(response.SeatBid)) | ||
|
||
if response.Cur != "" { | ||
bidResponse.Currency = response.Cur | ||
} | ||
|
||
for _, seatBid := range response.SeatBid { | ||
for i, bid := range seatBid.Bid { | ||
bidType, err := getMediaTypeForBid(bid) | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | ||
Bid: &seatBid.Bid[i], | ||
BidType: bidType, | ||
}) | ||
} | ||
} | ||
|
||
return bidResponse, errs | ||
} | ||
|
||
func extractCid(imp *openrtb2.Imp) (string, error) { | ||
var bidderExt adapters.ExtImpBidder | ||
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { | ||
return "", fmt.Errorf("unmarshal bidderExt: %w", err) | ||
} | ||
|
||
var impExt openrtb_ext.ImpExtVidazoo | ||
if err := json.Unmarshal(bidderExt.Bidder, &impExt); err != nil { | ||
return "", fmt.Errorf("unmarshal ImpExtVidazoo: %w", err) | ||
} | ||
return strings.TrimSpace(impExt.ConnectionId), nil | ||
} |
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,24 @@ | ||
package vidazoo | ||
|
||
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" | ||
) | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderVidazoo, config.Adapter{ | ||
Endpoint: "http://prebid-server.cootlogix.com/openrtb/", | ||
}, | ||
config.Server{ | ||
ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2", | ||
}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "vidazootest", bidder) | ||
} |
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,127 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "some-request-id", | ||
"site": { | ||
"page": "prebid.org" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "some-impression-id", | ||
"banner": { | ||
"w": 240, | ||
"h": 400 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"cId": "test_cid_123" | ||
} | ||
} | ||
} | ||
], | ||
"tmax": 5000 | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "http://prebid-server.cootlogix.com/openrtb/test_cid_123", | ||
"body": { | ||
"id": "some-request-id", | ||
"site": { | ||
"page": "prebid.org" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "some-impression-id", | ||
"banner": { | ||
"w": 240, | ||
"h": 400 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"cId": "test_cid_123" | ||
} | ||
} | ||
} | ||
], | ||
"tmax": 5000 | ||
}, | ||
"impIDs": [ | ||
"some-impression-id" | ||
] | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "some-request-id", | ||
"cur": "", | ||
"bidid": "some-bid-id", | ||
"seatbid": [ | ||
{ | ||
"bid": [ | ||
{ | ||
"exp": 60, | ||
"adm": "<div>Some creative</div>", | ||
"burl": "", | ||
"iurl": "http://prebid-server.cootlogix.com/creative.jpg", | ||
"lurl": "", | ||
"nurl": "", | ||
"id": "some-bid-id", | ||
"impid": "some-impression-id", | ||
"h": 400, | ||
"w": 240, | ||
"price": 1, | ||
"dealid": "deal123", | ||
"adomain": [ | ||
"test.com" | ||
], | ||
"adid": "some-ad-id", | ||
"cid": "test", | ||
"attr": [], | ||
"cat": [], | ||
"crid": "some-creative-id", | ||
"ext": {}, | ||
"hratio": 0, | ||
"language": "", | ||
"protocol": 0, | ||
"qagmediarating": 0, | ||
"tactic": "", | ||
"wratio": 0, | ||
"mtype": 1 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses": [ | ||
{ | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "some-bid-id", | ||
"impid": "some-impression-id", | ||
"price": 1, | ||
"adm": "<div>Some creative</div>", | ||
"adid": "some-ad-id", | ||
"cid": "test", | ||
"iurl": "http://prebid-server.cootlogix.com/creative.jpg", | ||
"crid": "some-creative-id", | ||
"adomain": [ | ||
"test.com" | ||
], | ||
"dealid": "deal123", | ||
"w": 240, | ||
"h": 400, | ||
"exp": 60, | ||
"ext": {}, | ||
"mtype": 1 | ||
}, | ||
"type": "banner" | ||
} | ||
] | ||
} | ||
], | ||
"expectedMakeBidsErrors": [] | ||
} |
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.
Why does this effectively use the cid from the first impression only?
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.
Updated to use imp splitting as suggested in the docs