Skip to content
Open
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
38 changes: 36 additions & 2 deletions adapters/amx/amx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"strings"

"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v4/adapters"
Expand All @@ -15,7 +16,8 @@ import (
)

const nbrHeaderName = "x-nbr"
const adapterVersion = "pbs1.2"
const adapterVersion = "pbs1.3"
const bidderCurrency = "USD"

// AMXAdapter is the AMX bid adapter
type AMXAdapter struct {
Expand Down Expand Up @@ -57,12 +59,36 @@ func ensurePublisherWithID(pub *openrtb2.Publisher, publisherID string) openrtb2
return pubCopy
}

func resolveBidFloor(imp *openrtb2.Imp, reqInfo *adapters.ExtraRequestInfo) error {
if reqInfo == nil || imp.BidFloor <= 0 || imp.BidFloorCur == "" || strings.EqualFold(imp.BidFloorCur, bidderCurrency) {
return nil
}

convertedValue, err := reqInfo.ConvertCurrency(imp.BidFloor, imp.BidFloorCur, bidderCurrency)
if err != nil {
return err
}

imp.BidFloor = convertedValue
imp.BidFloorCur = bidderCurrency
return nil
}

// MakeRequests creates AMX adapter requests
func (adapter *AMXAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapters.ExtraRequestInfo) (reqsBidder []*adapters.RequestData, errs []error) {
reqCopy := *request

var publisherID string
hasBidFloor := false
for idx, imp := range reqCopy.Imp {
if err := resolveBidFloor(&imp, req); err != nil {
errs = append(errs, err)
return nil, errs
}
if imp.BidFloor > 0 {
hasBidFloor = true
}

var params amxExt
if err := jsonutil.Unmarshal(imp.Ext, &params); err == nil {
if params.Bidder.TagID != "" {
Expand All @@ -72,9 +98,14 @@ func (adapter *AMXAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
// if it has an adUnitId, set as the tagid
if params.Bidder.AdUnitID != "" {
imp.TagID = params.Bidder.AdUnitID
reqCopy.Imp[idx] = imp
}
}

reqCopy.Imp[idx] = imp
}

if hasBidFloor && len(reqCopy.Cur) > 0 {
reqCopy.Cur = []string{bidderCurrency}
}

if publisherID != "" {
Expand Down Expand Up @@ -147,6 +178,9 @@ func (adapter *AMXAdapter) MakeBids(request *openrtb2.BidRequest, externalReques
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(5)
if bidResp.Cur != "" {
bidResponse.Currency = bidResp.Cur
}

for _, sb := range bidResp.SeatBid {
for _, bid := range sb.Bid {
Expand Down
2 changes: 1 addition & 1 deletion adapters/amx/amxtest/exemplary/app-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.2",
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.3",
"body": {
"app": {
"bundle": "639881495",
Expand Down
4 changes: 2 additions & 2 deletions adapters/amx/amxtest/exemplary/display-multiple.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
"httpCalls": [{
"expectedRequest": {
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.2",
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.3",
"body": {
"device": {
"dnt": 0,
Expand Down Expand Up @@ -294,4 +294,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion adapters/amx/amxtest/exemplary/simple-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"httpcalls": [
{
"expectedRequest": {
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.2",
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.3",
"body": {
"id": "req_id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/amx/amxtest/exemplary/video-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.2",
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.3",
"body": {
"device": {
"dnt": 0,
Expand Down
4 changes: 2 additions & 2 deletions adapters/amx/amxtest/exemplary/web-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
"httpCalls": [{
"expectedRequest": {
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.2",
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.3",
"body": {
"device": {
"dnt": 0,
Expand Down Expand Up @@ -244,4 +244,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion adapters/amx/amxtest/supplemental/204-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.2",
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.3",
"body": {
"device": {
"dnt": 0,
Expand Down
2 changes: 1 addition & 1 deletion adapters/amx/amxtest/supplemental/400-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.2",
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.3",
"body": {
"device": {
"dnt": 0,
Expand Down
2 changes: 1 addition & 1 deletion adapters/amx/amxtest/supplemental/500-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"httpCalls": [{
"expectedRequest": {
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.2",
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.3",
"body": {
"device": {
"dnt": 0,
Expand Down
155 changes: 155 additions & 0 deletions adapters/amx/amxtest/supplemental/currency-conversion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"mockBidRequest": {
"id": "currency-request-id",
"cur": [
"EUR"
],
"imp": [
{
"id": "1",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
],
"w": 300,
"h": 250
},
"bidfloor": 1,
"bidfloorcur": "GBP",
"ext": {
"bidder": {
"tagId": "cHJlYmlkLm9yZw"
}
}
}
],
"site": {
"domain": "www.example.com",
"publisher": {
"id": "unused_publisher_id"
}
},
"ext": {
"prebid": {
"currency": {
"rates": {
"GBP": {
"USD": 2
}
},
"usepbsrates": false
}
}
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs-dev.amxrtb.com/auction/openrtb?v=pbs1.3",
"body": {
"id": "currency-request-id",
"cur": [
"USD"
],
"imp": [
{
"id": "1",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
],
"w": 300,
"h": 250
},
"bidfloor": 2,
"bidfloorcur": "USD",
"ext": {
"bidder": {
"tagId": "cHJlYmlkLm9yZw"
}
}
}
],
"site": {
"domain": "www.example.com",
"publisher": {
"id": "cHJlYmlkLm9yZw"
}
},
"ext": {
"prebid": {
"currency": {
"rates": {
"GBP": {
"USD": 2
}
},
"usepbsrates": false
}
}
}
},
"impIDs": [
"1"
]
},
"mockResponse": {
"status": 200,
"body": {
"id": "currency-response-id",
"cur": "USD",
"seatbid": [
{
"bid": [
{
"id": "TEST",
"impid": "1",
"price": 10,
"adid": "1",
"adm": "<script src=\"https://assets.a-mo.net/tmode.v1.js\"></script>",
"adomain": [
"amxrtb.com"
],
"cid": "1",
"crid": "1",
"h": 250,
"w": 300
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "TEST",
"impid": "1",
"price": 10,
"adid": "1",
"adm": "<script src=\"https://assets.a-mo.net/tmode.v1.js\"></script>",
"adomain": [
"amxrtb.com"
],
"cid": "1",
"crid": "1",
"h": 250,
"w": 300
},
"type": "banner"
}
]
}
]
}
Loading