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
Changes from 1 commit
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
35 changes: 28 additions & 7 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,11 @@ type ConversantAdapter struct {
}

func (c *ConversantAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
cnvrRequest := *request
Copy link
Contributor

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?

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 didn't want to affect any of the other adapters when I changed the top level currency field for my request

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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?

//Backend needs USD or it will reject the request
if cnvrRequest.Cur != nil && len(cnvrRequest.Cur) > 0 && cnvrRequest.Cur[0] != "USD" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: There is no need for cnvrRequest.Cur != nil since that check is implicit with len(cnvrRequest.Cur) > 0. In Go, it's ok to take the length of a nil slice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's easy enough I'll fix that

cnvrRequest.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 All @@ -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",
Expand All @@ -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"

Expand Down Expand Up @@ -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
}
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

}
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
Loading