forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add BidsCube adapter * add BidsCube adapter * add BidsCube adapter * add BidsCube adapter * add BidsCube adapter * add BidsCube adapter Co-authored-by: vlad <vlaktionov@decenterads.com>
- Loading branch information
1 parent
b8ee01a
commit a29608c
Showing
25 changed files
with
1,267 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package bidscube | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/buger/jsonparser" | ||
"github.com/mxmCherry/openrtb/v15/openrtb2" | ||
"github.com/prebid/prebid-server/adapters" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/errortypes" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
type adapter struct { | ||
endpoint string | ||
} | ||
|
||
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, _ *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
headers := http.Header{} | ||
headers.Add("Content-Type", "application/json;charset=utf-8") | ||
headers.Add("Accept", "application/json") | ||
impressions := request.Imp | ||
result := make([]*adapters.RequestData, 0, len(impressions)) | ||
var errs []error | ||
|
||
for _, impression := range impressions { | ||
var impExt map[string]json.RawMessage | ||
if err := json.Unmarshal(impression.Ext, &impExt); err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
|
||
bidderExt, bidderExtExists := impExt["bidder"] | ||
if !bidderExtExists || len(bidderExt) == 0 { | ||
errs = append(errs, errors.New("bidder parameters required")) | ||
continue | ||
} | ||
|
||
impression.Ext = bidderExt | ||
request.Imp = []openrtb2.Imp{impression} | ||
body, err := json.Marshal(request) | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
result = append(result, &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: a.endpoint, | ||
Body: body, | ||
Headers: headers, | ||
}) | ||
} | ||
|
||
request.Imp = impressions | ||
return result, errs | ||
} | ||
|
||
func (a *adapter) MakeBids(request *openrtb2.BidRequest, _ *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
var errs []error | ||
|
||
switch responseData.StatusCode { | ||
case http.StatusNoContent: | ||
return nil, nil | ||
case http.StatusBadRequest: | ||
return nil, []error{&errortypes.BadInput{ | ||
Message: "unexpected status code: " + strconv.Itoa(responseData.StatusCode), | ||
}} | ||
case http.StatusOK: | ||
break | ||
default: | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: "unexpected status code: " + strconv.Itoa(responseData.StatusCode), | ||
}} | ||
} | ||
|
||
var bidResponse openrtb2.BidResponse | ||
err := json.Unmarshal(responseData.Body, &bidResponse) | ||
if err != nil { | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: err.Error(), | ||
}} | ||
} | ||
|
||
response := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) | ||
|
||
for _, seatBid := range bidResponse.SeatBid { | ||
for i := range seatBid.Bid { | ||
bidType, err := jsonparser.GetString(seatBid.Bid[i].Ext, "prebid", "type") | ||
if err != nil { | ||
errs = append(errs, fmt.Errorf("unable to read bid.ext.prebid.type: %v", err)) | ||
continue | ||
} | ||
response.Bids = append(response.Bids, &adapters.TypedBid{ | ||
Bid: &seatBid.Bid[i], | ||
BidType: getMediaTypeForImp(bidType), | ||
}) | ||
} | ||
} | ||
|
||
return response, errs | ||
} | ||
|
||
func getMediaTypeForImp(bidType string) openrtb_ext.BidType { | ||
switch bidType { | ||
case "banner": | ||
return openrtb_ext.BidTypeBanner | ||
case "video": | ||
return openrtb_ext.BidTypeVideo | ||
case "native": | ||
return openrtb_ext.BidTypeNative | ||
} | ||
return openrtb_ext.BidTypeBanner | ||
} | ||
|
||
// Builder builds a new instance of the BidsCube adapter for the given bidder with the given config. | ||
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { | ||
bidder := &adapter{ | ||
endpoint: config.Endpoint, | ||
} | ||
return bidder, 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,18 @@ | ||
package bidscube | ||
|
||
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.BidderBidsCube, config.Adapter{ | ||
Endpoint: "http://example.com/?c=o&m=ortb"}) | ||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
adapterstest.RunJSONBidderTest(t, "bidscubetest", bidder) | ||
} |
128 changes: 128 additions & 0 deletions
128
adapters/bidscube/bidscubetest/exemplary/simple-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,128 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
{ | ||
"w": 300, | ||
"h": 600 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"placementId": "3" | ||
} | ||
} | ||
} | ||
], | ||
"app": { | ||
"id": "1", | ||
"bundle": "com.wls.testwlsapplication" | ||
}, | ||
"device": { | ||
"ip": "123.123.123.123", | ||
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx" | ||
} | ||
}, | ||
|
||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "http://example.com/?c=o&m=ortb", | ||
"body": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
{ | ||
"w": 300, | ||
"h": 600 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"placementId": "3" | ||
} | ||
} | ||
], | ||
"app": { | ||
"id": "1", | ||
"bundle": "com.wls.testwlsapplication" | ||
}, | ||
"device": { | ||
"ip": "123.123.123.123", | ||
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx" | ||
} | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "test-request-id", | ||
"seatbid": [ | ||
{ | ||
"bid": [ | ||
{ | ||
"id": "test_bid_id", | ||
"impid": "test-imp-id", | ||
"price": 0.27543, | ||
"adm": "<iframe id=\"adm-banner-16\" width=\"300\" height=\"250\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" style=\"{overflow:hidden}\" src=\"http://supply.bidscube.com/?c=o&m=adm&k=882b2510ed6d6c94fa69c99aa522a708\"></iframe>", | ||
"cid": "test_cid", | ||
"crid": "test_crid", | ||
"dealid": "test_dealid", | ||
"w": 300, | ||
"h": 250, | ||
"ext": { | ||
"prebid": { | ||
"type": "banner" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
|
||
"expectedBidResponses": [ | ||
{ | ||
"bids":[ | ||
{ | ||
"bid": { | ||
"id": "test_bid_id", | ||
"impid": "test-imp-id", | ||
"price": 0.27543, | ||
"adm": "<iframe id=\"adm-banner-16\" width=\"300\" height=\"250\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" style=\"{overflow:hidden}\" src=\"http://supply.bidscube.com/?c=o&m=adm&k=882b2510ed6d6c94fa69c99aa522a708\"></iframe>", | ||
"cid": "test_cid", | ||
"crid": "test_crid", | ||
"dealid": "test_dealid", | ||
"w": 300, | ||
"h": 250, | ||
"ext": { | ||
"prebid": { | ||
"type": "banner" | ||
} | ||
} | ||
}, | ||
"type": "banner" | ||
} | ||
] | ||
} | ||
] | ||
} |
112 changes: 112 additions & 0 deletions
112
adapters/bidscube/bidscubetest/exemplary/simple-native.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,112 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"native": { | ||
"ver":"1.1", | ||
"request":"{\"adunit\":2,\"assets\":[{\"id\":3,\"img\":{\"h\":120,\"hmin\":0,\"type\":3,\"w\":180,\"wmin\":0},\"required\":1},{\"id\":0,\"required\":1,\"title\":{\"len\":25}},{\"data\":{\"len\":25,\"type\":1},\"id\":4,\"required\":1},{\"data\":{\"len\":140,\"type\":2},\"id\":6,\"required\":1}],\"context\":1,\"layout\":1,\"contextsubtype\":11,\"plcmtcnt\":1,\"plcmttype\":2,\"ver\":\"1.1\",\"ext\":{\"banner\":{\"w\":320,\"h\":50}}}" | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"placementId": "5" | ||
} | ||
} | ||
} | ||
], | ||
"app": { | ||
"id": "1", | ||
"bundle": "com.wls.testwlsapplication" | ||
}, | ||
"device": { | ||
"ip": "123.123.123.123", | ||
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx" | ||
} | ||
}, | ||
|
||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "http://example.com/?c=o&m=ortb", | ||
"body": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"native": { | ||
"ver":"1.1", | ||
"request":"{\"adunit\":2,\"assets\":[{\"id\":3,\"img\":{\"h\":120,\"hmin\":0,\"type\":3,\"w\":180,\"wmin\":0},\"required\":1},{\"id\":0,\"required\":1,\"title\":{\"len\":25}},{\"data\":{\"len\":25,\"type\":1},\"id\":4,\"required\":1},{\"data\":{\"len\":140,\"type\":2},\"id\":6,\"required\":1}],\"context\":1,\"layout\":1,\"contextsubtype\":11,\"plcmtcnt\":1,\"plcmttype\":2,\"ver\":\"1.1\",\"ext\":{\"banner\":{\"w\":320,\"h\":50}}}" | ||
}, | ||
"ext": { | ||
"placementId": "5" | ||
} | ||
} | ||
], | ||
"app": { | ||
"id": "1", | ||
"bundle": "com.wls.testwlsapplication" | ||
}, | ||
"device": { | ||
"ip": "123.123.123.123", | ||
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx" | ||
} | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "test-request-id", | ||
"seatbid": [ | ||
{ | ||
"bid": [ | ||
{ | ||
"id": "test_bid_id", | ||
"impid": "test-imp-id", | ||
"price": 0.97642, | ||
"adm": "awesome", | ||
"cid": "test_cid", | ||
"crid": "test_crid", | ||
"dealid": "test_dealid", | ||
"w": 300, | ||
"h": 250, | ||
"ext": { | ||
"prebid": { | ||
"type": "native" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
|
||
"expectedBidResponses": [ | ||
{ | ||
"bids":[ | ||
{ | ||
"bid": { | ||
"id": "test_bid_id", | ||
"impid": "test-imp-id", | ||
"price": 0.97642, | ||
"adm": "awesome", | ||
"cid": "test_cid", | ||
"crid": "test_crid", | ||
"dealid": "test_dealid", | ||
"w": 300, | ||
"h": 250, | ||
"ext": { | ||
"prebid": { | ||
"type": "native" | ||
} | ||
} | ||
}, | ||
"type": "native" | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.