Skip to content

Commit

Permalink
New Adapter mabidder (#3080)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecdrsvc authored Sep 15, 2023
1 parent 23342ee commit e8632b0
Show file tree
Hide file tree
Showing 13 changed files with 604 additions and 0 deletions.
99 changes: 99 additions & 0 deletions adapters/mabidder/mabidder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package mabidder

import (
"encoding/json"

"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
)

type serverResponse struct {
Responses []bidResponse
PrivateIdStatus string `json:"-"`
}

type bidResponse struct {
RequestID string `json:"requestId"`
Currency string `json:"currency"`
Width int32 `json:"width"`
Height int32 `json:"height"`
PlacementId string `json:"creativeId"`
Deal string `json:"dealId,omitempty"`
NetRevenue bool `json:"netRevenue"`
TimeToLiveSeconds int32 `json:"ttl"`
AdTag string `json:"ad"`
MediaType string `json:"mediaType"`
Meta meta `json:"meta"`
CPM float32 `json:"cpm"`
}

type meta struct {
AdDomain []string `json:"advertiserDomains"`
}

type adapter struct {
endpoint string
}

// Builder builds a new instance of the Mabidder adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
bidder := &adapter{
endpoint: config.Endpoint,
}
return bidder, nil
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
requestJSON, err := json.Marshal(request)
if err != nil {
return nil, []error{err}
}

requestData := &adapters.RequestData{
Method: "POST",
Uri: a.endpoint,
Body: requestJSON,
}

return []*adapters.RequestData{requestData}, nil
}

func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if adapters.IsResponseStatusCodeNoContent(responseData) {
return nil, nil
}

if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil {
return nil, []error{err}
}

var response serverResponse
if err := json.Unmarshal(responseData.Body, &response); err != nil {
return nil, []error{err}
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp))
for _, maBidResp := range response.Responses {
b := &adapters.TypedBid{
Bid: &openrtb2.Bid{
ID: maBidResp.RequestID,
ImpID: maBidResp.RequestID,
Price: float64(maBidResp.CPM),
AdM: maBidResp.AdTag,
W: int64(maBidResp.Width),
H: int64(maBidResp.Height),
CrID: maBidResp.PlacementId,
DealID: maBidResp.Deal,
ADomain: maBidResp.Meta.AdDomain,
},
BidType: openrtb_ext.BidType(maBidResp.MediaType),
}
bidResponse.Bids = append(bidResponse.Bids, b)
if maBidResp.Currency != "" {
bidResponse.Currency = maBidResp.Currency
}
}
return bidResponse, nil
}
21 changes: 21 additions & 0 deletions adapters/mabidder/mabidder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mabidder

import (
"testing"

"github.com/prebid/prebid-server/adapters/adapterstest"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
)

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderMabidder, config.Adapter{
Endpoint: "https://prebid.ecdrsvc.com/pbs"},
config.Server{ExternalUrl: "https://prebid.ecdrsvc.com/pbs", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}

adapterstest.RunJSONBidderTest(t, "mabiddertest", bidder)
}
110 changes: 110 additions & 0 deletions adapters/mabidder/mabiddertest/exemplary/simple-app-banner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa":"87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"ppid": "ppidtest"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://prebid.ecdrsvc.com/pbs",
"body": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa":"87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"ppid": "ppidtest"
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"Responses": [
{
"requestId": "1",
"currency": "CAD",
"width": 300,
"height": 250,
"creativeId": "6002677",
"dealId": "testdeal",
"netRevenue": false,
"ttl": 5,
"ad": "<script type='text/javascript' src='https://adsvr.ecdrsvc.com/js?6002677'></script>",
"meta": {
"advertiserDomains": [
"https://www.loblaws.ca/"
]
},
"cpm": 3.5764000415802
}
]
}
}
}
],
"expectedBidResponses": [
{
"id": "test-request-id",
"bids": [
{
"bid": {
"id": "1",
"impid": "1",
"price":3.5764000415802,
"adm": "<script type='text/javascript' src='https://adsvr.ecdrsvc.com/js?6002677'></script>",
"adomain": [
"https://www.loblaws.ca/"
],
"crid": "6002677",
"dealid": "testdeal",
"w": 300,
"h": 250
}
}
],
"cur": "USD"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa":"87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"ppid": "mabidder-test"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://prebid.ecdrsvc.com/pbs",
"body": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa":"87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"ppid": "mabidder-test"
}
}
}
]
}
},
"mockResponse": {
"status": 400,
"body": {
}
}
}
],
"expectedMakeBidsErrors": [
{
"value": "Unexpected status code: 400. Run with request.debug = 1 for more info",
"comparison": "literal"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa":"87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"ppid": "mabidder-test"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://prebid.ecdrsvc.com/pbs",
"body": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa":"87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"ppid": "mabidder-test"
}
}
}
]
}
},
"mockResponse": {
"status": 200
}
}
],
"expectedMakeBidsErrors": [
{
"value": "unexpected end of JSON input",
"comparison": "literal"
}
]
}
Loading

0 comments on commit e8632b0

Please sign in to comment.