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

Conversant: Make requests in USD #3611

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 21 additions & 2 deletions adapters/conversant/conversant.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"

"github.com/prebid/openrtb/v20/adcom1"
"github.com/prebid/openrtb/v20/openrtb2"
Expand All @@ -18,6 +19,10 @@ type ConversantAdapter struct {
}

func (c *ConversantAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
//Backend needs USD or it will reject the request
if len(request.Cur) > 0 && request.Cur[0] != "USD" {
request.Cur = []string{"USD"}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the json test cases for this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added this to one of the test cases

for i := 0; i < len(request.Imp); i++ {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(request.Imp[i].Ext, &bidderExt); err != nil {
Expand Down Expand Up @@ -50,7 +55,10 @@ func (c *ConversantAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *
request.App.ID = cnvrExt.SiteID
}
}
parseCnvrParams(&request.Imp[i], cnvrExt)
err := parseCnvrParams(&request.Imp[i], cnvrExt, reqInfo)
if err != nil {
return nil, err
}
}

//create the request body
Expand All @@ -72,7 +80,7 @@ func (c *ConversantAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *
}}, nil
}

func parseCnvrParams(imp *openrtb2.Imp, cnvrExt openrtb_ext.ExtImpConversant) {
func parseCnvrParams(imp *openrtb2.Imp, cnvrExt openrtb_ext.ExtImpConversant, reqInfo *adapters.ExtraRequestInfo) []error {
imp.DisplayManager = "prebid-s2s"
imp.DisplayManagerVer = "2.0.0"

Expand Down Expand Up @@ -130,6 +138,17 @@ func parseCnvrParams(imp *openrtb2.Imp, cnvrExt openrtb_ext.ExtImpConversant) {
imp.Video.MaxDuration = *cnvrExt.MaxDuration
}
}
if imp.BidFloor > 0 && imp.BidFloorCur != "" && strings.ToUpper(imp.BidFloorCur) != "USD" {
floor, err := reqInfo.ConvertCurrency(imp.BidFloor, imp.BidFloorCur, "USD")
if err != nil {
return []error{&errortypes.BadInput{
Message: fmt.Sprintf("Unable to convert provided bid floor currency from %s to USD", imp.BidFloorCur),
}}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would the floor not be greater than 0 after a currency conversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking I didn't want a negative floor, but now I think better to pass it through than mysteriously dropping it. fixed

imp.BidFloorCur = "USD"
imp.BidFloor = floor
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the json test case for this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added this to one of the test cases

return nil
}

func (c *ConversantAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
Expand Down
27 changes: 24 additions & 3 deletions adapters/conversant/conversanttest/exemplary/video.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"mockBidRequest": {
"id": "testauction",
"cur": ["EUR"],
"imp": [
{
"id": "1",
"video": {
"w": 300,
"h": 250
},
"bidfloor": 2.00,
"bidfloorcur": "EUR",
"ext": {
"bidder": {
"site_id": "108060",
"bidfloor": 0.01,
"tag_id": "mytag",
"secure": 1,
"mimes": ["video/mp4", "video/x-flv"],
Expand All @@ -31,6 +33,15 @@
},
"site": {
"domain": "www.mypage.com"
},
"ext": {
"prebid": {
"currency": {
"rates": {
"USD": {"EUR": 0.08}
}
}
}
}
},
"httpCalls": [
Expand All @@ -39,6 +50,7 @@
"uri": "",
"body": {
"id": "testauction",
"cur": ["USD"],
"site": {
"id": "108060",
"domain": "www.mypage.com"
Expand All @@ -48,7 +60,8 @@
"id": "1",
"tagid": "mytag",
"secure": 1,
"bidfloor": 0.01,
"bidfloor": 25.0,
"bidfloorcur": "USD",
"displaymanager": "prebid-s2s",
"displaymanagerver": "2.0.0",
"video": {
Expand All @@ -66,7 +79,6 @@
"ext": {
"bidder": {
"site_id": "108060",
"bidfloor": 0.01,
"tag_id": "mytag",
"secure": 1,
"mimes": [
Expand All @@ -86,6 +98,15 @@
"ua": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36",
"ip": "192.168.1.1",
"dnt": 1
},
"ext": {
"prebid": {
"currency": {
"rates": {
"USD": {"EUR": 0.08}
}
}
}
}
}
},
Expand Down
Loading