-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into bidderRequestPayload_RequestWrapper
- Loading branch information
Showing
90 changed files
with
4,871 additions
and
701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
110
adapters/mabidder/mabiddertest/exemplary/simple-app-banner.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
Oops, something went wrong.