Skip to content
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

VIS.X: fix bid.ID, bid.CrID and set default currency value #1296

Merged
merged 3 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions adapters/visx/visx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,38 @@ type VisxAdapter struct {
endpoint string
}

type visxBid struct {
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved
ImpID string `json:"impid"`
Price float64 `json:"price"`
UID int `json:"auid"`
AdM string `json:"adm,omitempty"`
ADomain []string `json:"adomain,omitempty"`
DealID string `json:"dealid,omitempty"`
W uint64 `json:"w,omitempty"`
H uint64 `json:"h,omitempty"`
}

type visxSeatBid struct {
Bid []visxBid `json:"bid"`
Seat string `json:"seat,omitempty"`
}

type visxResponse struct {
SeatBid []visxSeatBid `json:"seatbid,omitempty"`
}

// MakeRequests makes the HTTP requests which should be made to fetch bids.
func (a *VisxAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errors = make([]error, 0)

reqJSON, err := json.Marshal(request)
// copy the request, because we are going to mutate it
requestCopy := *request
if len(requestCopy.Cur) == 0 {
requestCopy.Cur = make([]string, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine. An alternative way of writing this is the one liner: requestCopy.Cur = []string{"USD"}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

requestCopy.Cur[0] = "USD"
}

reqJSON, err := json.Marshal(requestCopy)
if err != nil {
errors = append(errors, err)
return nil, errors
Expand Down Expand Up @@ -53,7 +80,7 @@ func (a *VisxAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequ
}}
}

var bidResp openrtb.BidResponse
var bidResp visxResponse
if err := json.Unmarshal(response.Body, &bidResp); err != nil {
return nil, []error{err}
}
Expand All @@ -62,8 +89,19 @@ func (a *VisxAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequ

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
bid := openrtb.Bid{}
bid.ID = internalRequest.ID
bid.CrID = fmt.Sprint(sb.Bid[i].UID)
bid.ImpID = sb.Bid[i].ImpID
bid.Price = sb.Bid[i].Price
bid.AdM = sb.Bid[i].AdM
bid.W = sb.Bid[i].W
bid.H = sb.Bid[i].H
bid.ADomain = sb.Bid[i].ADomain
bid.DealID = sb.Bid[i].DealID
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
Bid: &bid,
BidType: "banner",
})
}
Expand Down
13 changes: 7 additions & 6 deletions adapters/visx/visxtest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"amp": 0
}
},
"cur": ["USD"],
"imp": [{
"id": "test-imp-id",
"banner": {
Expand Down Expand Up @@ -132,20 +133,19 @@
"status": 200,
"body": {
"id": "1519967420713_259406708_583019428",
"cur": ["USD"],
"seatbid": [
{
"bid": [
{
"price": 0.500000,
"adm": "some-test-ad",
"impid": "1",
"impid": "test-imp-id",
"auid": 46,
"id": "1",
"h": 250,
"adomain": [
"goodadvertiser.com"
],
"crid": "11_222222",
"w": 300
}
],
Expand All @@ -157,17 +157,18 @@
}],

"expectedBidResponses": [{
"currency": "USD",
"bids": [{
"bid": {
"price": 0.5,
"adm": "some-test-ad",
"impid": "1",
"id": "1",
"impid": "test-imp-id",
"id": "test-request-id",
"h": 250,
"adomain": [
"goodadvertiser.com"
],
"crid": "11_222222",
"crid": "46",
"w": 300
},
"type": "banner"
Expand Down
94 changes: 94 additions & 0 deletions adapters/visx/visxtest/exemplary/with_currency.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"mockBidRequest": {
"id": "test-request-id",
"site": {
"page": "https://good.site/url"
},
"cur": ["EUR"],
"imp": [{
"id": "test-imp-id",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {
"uid": 7
}
}
}]
},

"httpCalls": [{
"expectedRequest": {
"uri": "http://localhost/prebid",
"body": {
"id": "test-request-id",
"site": {
"page": "https://good.site/url"
},
"cur": ["EUR"],
"imp": [{
"id": "test-imp-id",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {
"uid": 7
}
}
}]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"cur": ["EUR"],
"seatbid": [
{
"bid": [
{
"price": 0.500000,
"adm": "some-test-ad",
"impid": "test-imp-id",
"auid": 46,
"h": 250,
"adomain": [
"goodadvertiser.com"
],
"w": 300
}
],
"seat": "51"
}
]
}
}
}],

"expectedBidResponses": [{
"currency": "EUR",
"bids": [{
"bid": {
"price": 0.5,
"adm": "some-test-ad",
"impid": "test-imp-id",
"id": "test-request-id",
"h": 250,
"adomain": [
"goodadvertiser.com"
],
"crid": "46",
"w": 300
},
"type": "banner"
}]
}]
}
3 changes: 2 additions & 1 deletion adapters/visx/visxtest/supplemental/bad_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"uri": "http://localhost/prebid",
"body": {
"id": "test-request-id",
"cur": ["USD"],
"imp": [
{
"id": "test-imp-id",
Expand Down Expand Up @@ -54,7 +55,7 @@

"expectedMakeBidsErrors": [
{
"value": "json: cannot unmarshal string into Go value of type openrtb.BidResponse",
"value": "json: cannot unmarshal string into Go value of type visx.visxResponse",
"comparison": "literal"
}
]
Expand Down
1 change: 1 addition & 0 deletions adapters/visx/visxtest/supplemental/status_204.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"uri": "http://localhost/prebid",
"body": {
"id": "test-request-id",
"cur": ["USD"],
"imp": [
{
"id": "test-imp-id",
Expand Down
1 change: 1 addition & 0 deletions adapters/visx/visxtest/supplemental/status_400.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"uri": "http://localhost/prebid",
"body": {
"id": "test-request-id",
"cur": ["USD"],
"imp": [
{
"id": "test-imp-id",
Expand Down
1 change: 1 addition & 0 deletions adapters/visx/visxtest/supplemental/status_418.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"uri": "http://localhost/prebid",
"body": {
"id": "test-request-id",
"cur": ["USD"],
"imp": [
{
"id": "test-imp-id",
Expand Down