-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New Axonix adapter * Changed endpoint * Rename adapter type * Leave in examplary only the basic test fixtures * PR comments
- Loading branch information
Showing
22 changed files
with
1,137 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,116 @@ | ||
package axonix | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"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 { | ||
URI string | ||
} | ||
|
||
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { | ||
bidder := &adapter{ | ||
URI: config.Endpoint, | ||
} | ||
return bidder, nil | ||
} | ||
|
||
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
var errors []error | ||
|
||
var bidderExt adapters.ExtImpBidder | ||
if err := json.Unmarshal(request.Imp[0].Ext, &bidderExt); err != nil { | ||
errors = append(errors, &errortypes.BadInput{ | ||
Message: err.Error(), | ||
}) | ||
|
||
return nil, errors | ||
} | ||
|
||
var axonixExt openrtb_ext.ExtImpAxonix | ||
if err := json.Unmarshal(bidderExt.Bidder, &axonixExt); err != nil { | ||
errors = append(errors, &errortypes.BadInput{ | ||
Message: err.Error(), | ||
}) | ||
|
||
return nil, errors | ||
} | ||
|
||
thisURI := a.URI | ||
if len(thisURI) == 0 { | ||
thisURI = "https://openrtb-us-east-1.axonix.com/supply/prebid-server/" + axonixExt.SupplyId | ||
} | ||
|
||
requestJSON, err := json.Marshal(request) | ||
if err != nil { | ||
errors = append(errors, err) | ||
return nil, errors | ||
} | ||
|
||
headers := http.Header{} | ||
headers.Add("Content-Type", "application/json") | ||
|
||
requestData := &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: thisURI, | ||
Body: requestJSON, | ||
Headers: headers, | ||
} | ||
|
||
return []*adapters.RequestData{requestData}, nil | ||
} | ||
|
||
func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
if responseData.StatusCode == http.StatusNoContent { | ||
return nil, nil | ||
} | ||
|
||
if responseData.StatusCode != http.StatusOK { | ||
err := &errortypes.BadServerResponse{ | ||
Message: fmt.Sprintf("Unexpected status code: %d.", responseData.StatusCode), | ||
} | ||
return nil, []error{err} | ||
} | ||
|
||
var response openrtb2.BidResponse | ||
if err := json.Unmarshal(responseData.Body, &response); err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) | ||
bidResponse.Currency = response.Cur | ||
for _, seatBid := range response.SeatBid { | ||
for _, bid := range seatBid.Bid { | ||
bid := bid | ||
b := &adapters.TypedBid{ | ||
Bid: &bid, | ||
BidType: getMediaType(bid.ImpID, request.Imp), | ||
} | ||
bidResponse.Bids = append(bidResponse.Bids, b) | ||
} | ||
} | ||
|
||
return bidResponse, nil | ||
} | ||
|
||
func getMediaType(impId string, imps []openrtb2.Imp) openrtb_ext.BidType { | ||
for _, imp := range imps { | ||
if imp.ID == impId { | ||
if imp.Native != nil { | ||
return openrtb_ext.BidTypeNative | ||
} else if imp.Video != nil { | ||
return openrtb_ext.BidTypeVideo | ||
} | ||
return openrtb_ext.BidTypeBanner | ||
} | ||
} | ||
return openrtb_ext.BidTypeBanner | ||
} |
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,30 @@ | ||
package axonix | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/adapters/adapterstest" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
func TestJsonSamplesWithConfiguredURI(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderAxonix, config.Adapter{ | ||
Endpoint: "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8"}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "axonixtest", bidder) | ||
} | ||
|
||
func TestJsonSamplesWithHardcodedURI(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderAxonix, config.Adapter{}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "axonixtest", bidder) | ||
} |
133 changes: 133 additions & 0 deletions
133
adapters/axonix/axonixtest/exemplary/banner-and-video.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,133 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
{ | ||
"w": 300, | ||
"h": 600 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "test-imp-video-id", | ||
"video": { | ||
"mimes": ["video/mp4"], | ||
"protocols": [2, 5], | ||
"w": 1024, | ||
"h": 576 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8", | ||
"body": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
{ | ||
"w": 300, | ||
"h": 600 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "test-imp-video-id", | ||
"video": { | ||
"mimes": ["video/mp4"], | ||
"protocols": [2, 5], | ||
"w": 1024, | ||
"h": 576 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "test-request-id", | ||
"seatbid": [ | ||
{ | ||
"seat": "958", | ||
"bid": [{ | ||
"id": "7706636740145184841", | ||
"impid": "test-imp-video-id", | ||
"price": 0.500000, | ||
"adid": "29681110", | ||
"adm": "some-test-ad", | ||
"adomain": ["axonix.com"], | ||
"cid": "958", | ||
"crid": "29681110", | ||
"h": 576, | ||
"w": 1024 | ||
}] | ||
} | ||
], | ||
"bidid": "5778926625248726496", | ||
"cur": "USD" | ||
} | ||
} | ||
} | ||
], | ||
|
||
"expectedBidResponses": [ | ||
{ | ||
"bids": [{ | ||
"bid": { | ||
"id": "7706636740145184841", | ||
"impid": "test-imp-video-id", | ||
"price": 0.5, | ||
"adm": "some-test-ad", | ||
"adid": "29681110", | ||
"adomain": ["axonix.com"], | ||
"cid": "958", | ||
"crid": "29681110", | ||
"w": 1024, | ||
"h": 576 | ||
}, | ||
"type": "video" | ||
}] | ||
} | ||
] | ||
|
||
} |
Oops, something went wrong.