Skip to content

Commit

Permalink
Merge branch 'prebid:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SylviaF authored Jun 3, 2024
2 parents 687cbbe + 2b8e8cd commit b682e0b
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 18 deletions.
46 changes: 28 additions & 18 deletions adapters/yieldmo/yieldmo.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/openrtb2"
"github.com/prebid/prebid-server/v2/adapters"
Expand Down Expand Up @@ -35,16 +36,11 @@ type ExtBid struct {
}

func (a *YieldmoAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
reqData, errors := a.makeRequest(request)
return []*adapters.RequestData{reqData}, errors
}

func (a *YieldmoAdapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestData, []error) {
var errs []error

if err := preprocess(request); err != nil {
errs = append(errs, err)
}
preprocessErrors := preprocess(request, reqInfo)

errs = append(errs, preprocessErrors...)

// Last Step
reqJSON, err := json.Marshal(request)
Expand All @@ -56,33 +52,47 @@ func (a *YieldmoAdapter) makeRequest(request *openrtb2.BidRequest) (*adapters.Re
headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")

return &adapters.RequestData{
return []*adapters.RequestData{{
Method: "POST",
Uri: a.endpoint,
Body: reqJSON,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(request.Imp),
}, errs
}}, errs
}

// Mutate the request to get it ready to send to yieldmo.
func preprocess(request *openrtb2.BidRequest) error {
func preprocess(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) []error {
var errs []error

for i := 0; i < len(request.Imp); i++ {
var imp = request.Imp[i]
var bidderExt ExtImpBidderYieldmo

if imp.BidFloor > 0 && imp.BidFloorCur != "" && strings.ToUpper(imp.BidFloorCur) != "USD" {
floor, err := reqInfo.ConvertCurrency(imp.BidFloor, imp.BidFloorCur, "USD")
if err != nil {
errs = append(errs, &errortypes.BadInput{
Message: fmt.Sprintf("Unable to convert provided bid floor currency from %s to USD", imp.BidFloorCur),
})
} else {
request.Imp[i].BidFloorCur = "USD"
request.Imp[i].BidFloor = floor
}
}

if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return &errortypes.BadInput{
errs = append(errs, &errortypes.BadInput{
Message: err.Error(),
}
})
}

var yieldmoExt openrtb_ext.ExtImpYieldmo

if err := json.Unmarshal(bidderExt.Bidder, &yieldmoExt); err != nil {
return &errortypes.BadInput{
errs = append(errs, &errortypes.BadInput{
Message: err.Error(),
}
})
}

var impExt Ext
Expand All @@ -96,15 +106,15 @@ func preprocess(request *openrtb2.BidRequest) error {

impExtJSON, err := json.Marshal(impExt)
if err != nil {
return &errortypes.BadInput{
errs = append(errs, &errortypes.BadInput{
Message: err.Error(),
}
})
}

request.Imp[i].Ext = impExtJSON
}

return nil
return errs
}

// MakeBids make the bids for the bid response.
Expand Down
150 changes: 150 additions & 0 deletions adapters/yieldmo/yieldmotest/exemplary/valid_currency_conversion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"bidfloor": 1.0,
"bidfloorcur": "EUR",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"placementId": "123"
}
}
}
],
"site": {
"id": "fake-site-id"
},
"regs": {
"coppa": 1,
"ext": {
"gdpr": 1,
"us_privacy": "uspConsentString",
"gpp": "gppString",
"gpp_sid": [6]
}
},
"ext": {
"prebid": {
"currency": {
"rates": {
"EUR": {
"USD": 1.1
}
}
}
}
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://ads.yieldmo.com/openrtb2",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"bidfloor": 1.1,
"bidfloorcur": "USD",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"placement_id": "123"
}
}
],
"site": {
"id": "fake-site-id"
},
"regs": {
"coppa": 1,
"ext": {
"gdpr": 1,
"us_privacy": "uspConsentString",
"gpp": "gppString",
"gpp_sid": [6]
}
},
"ext": {
"prebid": {
"currency": {
"rates": {
"EUR": {
"USD": 1.1
}
}
}
}
}
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "yieldmo",
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 1.500000,
"adm": "some-test-ad",
"crid": "crid_10",
"h": 250,
"w": 300,
"ext":
{
"mediatype": "banner"
}
}
]
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 1.5,
"adm": "some-test-ad",
"crid": "crid_10",
"w": 300,
"h": 250,
"ext":
{
"mediatype": "banner"
}
},
"type": "banner"
}
]
}
]
}
109 changes: 109 additions & 0 deletions adapters/yieldmo/yieldmotest/supplemental/unsupported_currency.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"bidfloor": 1.0,
"bidfloorcur": "EUR",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"placementId": "123"
}
}
}
],
"site": {
"id": "fake-site-id"
},
"regs": {
"coppa": 1,
"ext": {
"gdpr": 1,
"us_privacy": "uspConsentString",
"gpp": "gppString",
"gpp_sid": [6]
}
},
"ext": {
"prebid": {
"currency": {
"rates": {
"EUR": {
"GBP": 0.85
}
}
}
}
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://ads.yieldmo.com/openrtb2",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"bidfloor": 1.0,
"bidfloorcur": "EUR",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"placement_id": "123"
}
}
],
"site": {
"id": "fake-site-id"
},
"regs": {
"coppa": 1,
"ext": {
"gdpr": 1,
"us_privacy": "uspConsentString",
"gpp": "gppString",
"gpp_sid": [6]
}
},
"ext": {
"prebid": {
"currency": {
"rates": {
"EUR": {
"GBP": 0.85
}
}
}
}
}
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 204
}
}
],
"expectedMakeRequestsErrors": [
{
"value": "Unable to convert provided bid floor currency from EUR to USD",
"comparison": "literal"
}
]
}
5 changes: 5 additions & 0 deletions static/bidder-info/tredio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
endpoint: "http://tredio-prebid.smart-hub.io/pbserver/?seat={{.AccountID}}&token={{.SourceId}}"
aliasOf: "smarthub"
userSync:
supports:
- redirect

0 comments on commit b682e0b

Please sign in to comment.