-
Notifications
You must be signed in to change notification settings - Fork 737
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
490 additions
and
0 deletions.
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,56 @@ | ||
package vox | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
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 _, p := range validParams { | ||
if err := validator.Validate(openrtb_ext.BidderVox, json.RawMessage(p)); err != nil { | ||
t.Errorf("Schema rejected valid params: %s", p) | ||
} | ||
} | ||
} | ||
|
||
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.BidderVox, json.RawMessage(p)); err == nil { | ||
t.Errorf("Schema allowed invalid params: %s", p) | ||
} | ||
} | ||
} | ||
|
||
var validParams = []string{ | ||
`{"placementId": "64be6fe6685a271d37e900d2"}`, | ||
`{"placementId": "Any String Basically"}`, | ||
`{"placementId":""}`, | ||
`{"placementId":"id", "imageUrl":"http://site.com/img1.png"}`, | ||
`{"placementId":"id", "imageUrl":"http://site.com/img1.png", "displaySizes":["123x90", "1x1", "987x1111"]}`, | ||
} | ||
|
||
var invalidParams = []string{ | ||
`{"placementId": 42}`, | ||
`{"placementId": null}`, | ||
`{"placementId": 3.1415}`, | ||
`{"placementId": true}`, | ||
`{"placementId": false}`, | ||
`{"placementId":"id", "imageUrl": null}`, | ||
`{"placementId":"id", "imageUrl": true}`, | ||
`{"placementId":"id", "imageUrl": []}`, | ||
`{"placementId":"id", "imageUrl": "http://some.url", "displaySizes": null}`, | ||
`{"placementId":"id", "imageUrl": "http://some.url", "displaySizes": {}}`, | ||
`{"placementId":"id", "imageUrl": "http://some.url", "displaySizes": "String"}`, | ||
} |
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,86 @@ | ||
package vox | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/prebid/openrtb/v19/openrtb2" | ||
"github.com/prebid/prebid-server/adapters" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
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 := json.Marshal(request) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
requestData := &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: a.endpoint, | ||
Body: requestJSON, | ||
} | ||
|
||
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} | ||
} | ||
|
||
var response openrtb2.BidResponse | ||
if err := json.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, bid := range seatBid.Bid { | ||
bidType, err := getMediaTypeForBid(bid) | ||
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 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 | ||
case openrtb2.MarkupAudio: | ||
return openrtb_ext.BidTypeAudio, nil | ||
case openrtb2.MarkupNative: | ||
return openrtb_ext.BidTypeNative, nil | ||
default: | ||
return "", fmt.Errorf("Unable to fetch mediaType in multi-format: %s", bid.ImpID) | ||
} | ||
} |
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,21 @@ | ||
package vox | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/adapters/adapterstest" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderVox, config.Adapter{ | ||
Endpoint: "http://somecoolurlfor.vox"}, | ||
config.Server{ExternalUrl: "http://somecoolurlfor.vox", GvlID: 1, DataCenter: "2"}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error: %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "voxtest", 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,82 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "cf4b0abb-7ccc-4057-9914-c85f467260c6", | ||
"site": { | ||
"page": "http://some.site/url/page?id=338" | ||
}, | ||
"cur": [ "USD" ], | ||
"imp": [{ | ||
"id": "8a7510f9-0ca1-44c4-a8c6-1ce639b5eef9", | ||
"banner": { "w": 100, "h": 100 }, | ||
"bidfloorcur": "USD", | ||
"ext": { | ||
"bidder": { | ||
"placementId":"64b939146d66df22ccae95c5" | ||
} | ||
} | ||
}] | ||
}, | ||
|
||
"httpCalls": [{ | ||
"expectedRequest": { | ||
"uri": "http://somecoolurlfor.vox", | ||
"headers": {}, | ||
"body": { | ||
"id": "cf4b0abb-7ccc-4057-9914-c85f467260c6", | ||
"site": { | ||
"page": "http://some.site/url/page?id=338" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "8a7510f9-0ca1-44c4-a8c6-1ce639b5eef9", | ||
"banner": { | ||
"w": 100, | ||
"h": 100 | ||
}, | ||
"bidfloorcur": "USD", | ||
"ext": { | ||
"bidder": { | ||
"placementId": "64b939146d66df22ccae95c5" | ||
} | ||
} | ||
} | ||
], | ||
"cur": [ "USD" ] | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"headers": {}, | ||
"body": { | ||
"id": "cf4b0abb-7ccc-4057-9914-c85f467260c6", | ||
"cur": "USD", | ||
"seatbid": [{ | ||
"bid": [{ | ||
"id": "e6a143f3-5176-4607-b09e-0e67e358b0b6", | ||
"impid": "8a7510f9-0ca1-44c4-a8c6-1ce639b5eef9", | ||
"price": 3.1415, | ||
"adm": "<html><h1>Hi, there</h1></html>", | ||
"w": 50, | ||
"h": 50, | ||
"mtype": 1 | ||
}] | ||
}] | ||
}} | ||
}], | ||
|
||
"expectedBidResponses": [{ | ||
"bids": [{ | ||
"currency": "USD", | ||
"bid": { | ||
"id": "e6a143f3-5176-4607-b09e-0e67e358b0b6", | ||
"impid": "8a7510f9-0ca1-44c4-a8c6-1ce639b5eef9", | ||
"price": 3.1415, | ||
"adm": "<html><h1>Hi, there</h1></html>", | ||
"w": 50, | ||
"h": 50, | ||
"mtype": 1 | ||
}, | ||
"type": "banner" | ||
}] | ||
}] | ||
} |
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,87 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "9a4bdb67-43ef-488f-937d-cd01e9dce43d", | ||
"site": { | ||
"page": "http://blog.com/article/1" | ||
}, | ||
"cur": ["PLN"], | ||
"imp": [{ | ||
"id": "d190d6f3-5264-4df5-91b2-8a9c72cbeb6a", | ||
"bidfloorcur": "PLN", | ||
"video": { | ||
"mimes": ["video/mp4"], | ||
"minduration": 5, | ||
"maxduration": 15, | ||
"w": 1280, | ||
"h": 720 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"placementId":"64b9486efecad2330718e233" | ||
} | ||
} | ||
}] | ||
}, | ||
|
||
"httpCalls": [{ | ||
"expectedRequest": { | ||
"uri": "http://somecoolurlfor.vox", | ||
"header": {}, | ||
"body": { | ||
"id": "9a4bdb67-43ef-488f-937d-cd01e9dce43d", | ||
"site": { | ||
"page": "http://blog.com/article/1" | ||
}, | ||
"cur": [ "PLN" ], | ||
"imp": [{ | ||
"id": "d190d6f3-5264-4df5-91b2-8a9c72cbeb6a", | ||
"bidfloorcur": "PLN", | ||
"video": { | ||
"mimes": ["video/mp4"], | ||
"minduration": 5, | ||
"maxduration": 15, | ||
"w": 1280, | ||
"h": 720 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"placementId":"64b9486efecad2330718e233" | ||
} | ||
} | ||
}] | ||
} | ||
}, | ||
|
||
"mockResponse": { | ||
"status": 200, | ||
"headers": {}, | ||
"body": { | ||
"id":"d64fdeae-cb1c-4322-8fb6-18f5ec49bb76", | ||
"cur": "PLN", | ||
"seatbid": [{ | ||
"bid": [{ | ||
"id": "05349123-29e2-4be0-b662-48914f75ebe1", | ||
"impid": "d190d6f3-5264-4df5-91b2-8a9c72cbeb6a", | ||
"price": 2.149, | ||
"adm": "<VAST>...</VAST>", | ||
"mtype": 2 | ||
}] | ||
}] | ||
} | ||
} | ||
}], | ||
|
||
"expectedBidResponses": [{ | ||
"bids": [{ | ||
"currency": "PLN", | ||
"bid": { | ||
"id": "05349123-29e2-4be0-b662-48914f75ebe1", | ||
"impid": "d190d6f3-5264-4df5-91b2-8a9c72cbeb6a", | ||
"price": 2.149, | ||
"adm": "<VAST>...</VAST>", | ||
"mtype": 2 | ||
}, | ||
"type": "video" | ||
}] | ||
}] | ||
} |
45 changes: 45 additions & 0 deletions
45
adapters/vox/voxtest/supplemental/response_204_to_nocontent.json
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,45 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "Some Id (445455)", | ||
"cur": ["AUD"], | ||
"imp": [{ | ||
"id": "Impression id #1", | ||
"banner": {}, | ||
"bidfloorcur": "AUD", | ||
"ext": { | ||
"bidder": { | ||
"placementId": "64b94ad4ed136806629dd51c" | ||
} | ||
} | ||
}] | ||
}, | ||
|
||
"httpCalls": [{ | ||
"expectedRequest": { | ||
"uri": "http://somecoolurlfor.vox", | ||
"headers": {}, | ||
"body": { | ||
"id": "Some Id (445455)", | ||
"cur": ["AUD"], | ||
"imp": [{ | ||
"id": "Impression id #1", | ||
"banner": {}, | ||
"bidfloorcur": "AUD", | ||
"ext": { | ||
"bidder": { | ||
"placementId": "64b94ad4ed136806629dd51c" | ||
} | ||
} | ||
}] | ||
} | ||
}, | ||
|
||
"mockResponse": { | ||
"status": 204, | ||
"headers": {}, | ||
"body": {} | ||
} | ||
}], | ||
|
||
"expectedBidResponses": [] | ||
} |
Oops, something went wrong.