-
Notifications
You must be signed in to change notification settings - Fork 769
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/prebid/openrtb/v20/adcom1" | ||
"github.com/prebid/openrtb/v20/openrtb2" | ||
|
@@ -18,6 +19,11 @@ type ConversantAdapter struct { | |
} | ||
|
||
func (c *ConversantAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
cnvrRequest := *request | ||
//Backend needs USD or it will reject the request | ||
if cnvrRequest.Cur != nil && len(cnvrRequest.Cur) > 0 && cnvrRequest.Cur[0] != "USD" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: There is no need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's easy enough I'll fix that |
||
cnvrRequest.Cur = []string{"USD"} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the json test cases for this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
@@ -42,19 +48,22 @@ func (c *ConversantAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo * | |
if i == 0 { | ||
if request.Site != nil { | ||
tmpSite := *request.Site | ||
request.Site = &tmpSite | ||
request.Site.ID = cnvrExt.SiteID | ||
cnvrRequest.Site = &tmpSite | ||
cnvrRequest.Site.ID = cnvrExt.SiteID | ||
} else if request.App != nil { | ||
tmpApp := *request.App | ||
request.App = &tmpApp | ||
request.App.ID = cnvrExt.SiteID | ||
cnvrRequest.App = &tmpApp | ||
cnvrRequest.App.ID = cnvrExt.SiteID | ||
} | ||
} | ||
parseCnvrParams(&request.Imp[i], cnvrExt) | ||
err := parseCnvrParams(&cnvrRequest.Imp[i], cnvrExt, reqInfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
//create the request body | ||
data, err := json.Marshal(request) | ||
data, err := json.Marshal(cnvrRequest) | ||
if err != nil { | ||
return nil, []error{&errortypes.BadInput{ | ||
Message: "Error in packaging request to JSON", | ||
|
@@ -72,7 +81,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" | ||
|
||
|
@@ -130,6 +139,18 @@ 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), | ||
}} | ||
} else if floor > 0 { | ||
imp.BidFloorCur = "USD" | ||
imp.BidFloor = floor | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the json test case for this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
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 are making a shallow copy of the request?
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.
I didn't want to affect any of the other adapters when I changed the top level currency field for my request
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.
At this point in code, the request is already exclusive for ConversantAdapter. You will not be affecting any other adapters.
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.
ok, I removed the shallow copy
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.
Just checking in. Are there any further changes needed?