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

New Adapter mabidder #3080

Merged
merged 27 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5eb0681
add bidder configuration
ecdrsvc Apr 24, 2023
29d8eeb
add bidder parameter schema
ecdrsvc Apr 24, 2023
a71055c
add bidder params struct implementation
ecdrsvc Apr 24, 2023
e6bdbef
add mabidder adapter
ecdrsvc May 3, 2023
338d050
update bidders.go with mabidder
ecdrsvc May 3, 2023
69d6d94
update adapter_builders with mabidder
ecdrsvc May 3, 2023
49ee6dc
simplify range
ecdrsvc May 9, 2023
e6608ae
update package
ecdrsvc May 9, 2023
e318987
add mabidder_test.go
ecdrsvc May 10, 2023
741fef3
add server response types and implement MakeBids method
ecdrsvc May 26, 2023
f06e767
update endpoint
ecdrsvc Jun 6, 2023
d27411e
validate impression currency and process ext
ecdrsvc Jun 7, 2023
5737976
read bid/media type and ad domain from response
ecdrsvc Jul 14, 2023
5616e13
remove unnecessary validation
ecdrsvc Jul 17, 2023
e1d7d4c
fix bug with setting bidResponse currency in MakeBids method
ecdrsvc Jul 20, 2023
a48b8f5
update fake test endpoint
ecdrsvc Jul 20, 2023
42c6663
params test
ecdrsvc Jul 20, 2023
0200948
don't hardcode status code in message
ecdrsvc Jul 21, 2023
49f0177
unit tests
ecdrsvc Jul 21, 2023
d1a34ab
simplify error return in MakeReqeuests
ecdrsvc Jul 24, 2023
d39ffe9
fix simple banner test case
ecdrsvc Jul 24, 2023
b4ba52f
add supplemental test cases
ecdrsvc Jul 24, 2023
183345e
merge, add BidderMabidder
ecdrsvc Sep 7, 2023
be743b9
update uri in tests
ecdrsvc Sep 8, 2023
06a1267
use util function for status error check
ecdrsvc Sep 8, 2023
9d7c529
rename internal structs used by mabidder
ecdrsvc Sep 8, 2023
f12bd30
fix setting currency
ecdrsvc Sep 8, 2023
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
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
Loading