Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
VIS.X: fix bid.ID, bid.CrID and set default currency value (prebid#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
mk0x9 authored May 21, 2020
1 parent d9323d8 commit d21a154
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 11 deletions.
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 {
ImpID string `json:"impid"`
Price float64 `json:"price"`
UID int `json:"auid"`
CrID string `json:"crid,omitempty"`
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 = []string{"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 = sb.Bid[i].CrID
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

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
Bid: &bid,
BidType: "banner",
})
}
Expand Down
17 changes: 10 additions & 7 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 @@ -131,21 +132,21 @@
"mockResponse": {
"status": 200,
"body": {
"id": "1519967420713_259406708_583019428",
"cur": ["USD"],
"seatbid": [
{
"bid": [
{
"crid": "2_260",
"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",
"dealid": "test_deal_id",
"w": 300
}
],
Expand All @@ -157,17 +158,19 @@
}],

"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",
"dealid": "test_deal_id",
"crid": "2_260",
"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": {
"cur": ["EUR"],
"seatbid": [
{
"bid": [
{
"crid": "2_261",
"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": "2_261",
"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

0 comments on commit d21a154

Please sign in to comment.