Skip to content

Commit

Permalink
New Adapter: Adrino (prebid#2329)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomasz Mielcarz <[email protected]>
  • Loading branch information
2 people authored and pm-aadit-patil committed Sep 22, 2022
1 parent 3f49b84 commit 0073e45
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 0 deletions.
85 changes: 85 additions & 0 deletions adapters/adrino/adrino.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package adrino

import (
"encoding/json"
"fmt"
"net/http"

"github.com/mxmCherry/openrtb/v16/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, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error

reqJson, err := json.Marshal(request)
if err != nil {
errs = append(errs, err)
return nil, errs
}

headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")

return []*adapters.RequestData{{
Method: "POST",
Uri: a.endpoint,
Body: reqJson,
Headers: headers,
}}, errs
}

func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
var errs []error

if response.StatusCode == http.StatusNoContent {
return nil, nil
}

if response.StatusCode == http.StatusBadRequest {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info", response.StatusCode),
}}
}

if response.StatusCode != http.StatusOK {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info", response.StatusCode),
}}
}

var bidResp openrtb2.BidResponse

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

bidResponse := adapters.NewBidderResponse()
bidResponse.Currency = bidResp.Cur

for _, seatBid := range bidResp.SeatBid {
for i := range seatBid.Bid {
bidType := openrtb_ext.BidTypeNative // our adserver supports only native ads
b := &adapters.TypedBid{
Bid: &seatBid.Bid[i],
BidType: bidType,
}
bidResponse.Bids = append(bidResponse.Bids, b)
}
}
return bidResponse, errs
}

func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) {
bidder := &adapter{
endpoint: config.Endpoint,
}
return bidder, nil
}
28 changes: 28 additions & 0 deletions adapters/adrino/adrino_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package adrino

import (
"github.com/stretchr/testify/assert"
"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.BidderAdrino, config.Adapter{
Endpoint: "https://prd-prebid-bidder.adrino.io/openrtb/bid"})

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

adapterstest.RunJSONBidderTest(t, "adrinotest", bidder)
}

func TestEndpointTemplateMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderAdrino, config.Adapter{
Endpoint: "{{Malformed}}"})

assert.Nil(t, buildErr)
}
73 changes: 73 additions & 0 deletions adapters/adrino/adrinotest/exemplary/no-bid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"ext": {
"bidder": {
"hash": "123456"
}
},
"native": {
"request": "{json string}",
"ver": "1.2"
}
}
],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://prd-prebid-bidder.adrino.io/openrtb/bid",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
]
},
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"ext": {
"bidder": {
"hash": "123456"
}
},
"native": {
"request": "{json string}",
"ver": "1.2"
}
}
],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
}
},
"mockResponse": {
"status": 204,
"body": {}
}
}
],
"expectedBidResponses": []
}
115 changes: 115 additions & 0 deletions adapters/adrino/adrinotest/exemplary/single-native.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"ext": {
"bidder": {
"hash": "123456"
}
},
"native": {
"request": "{json string}",
"ver": "1.2"
}
}
],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://prd-prebid-bidder.adrino.io/openrtb/bid",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
]
},
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"ext": {
"bidder": {
"hash": "123456"
}
},
"native": {
"request": "{json string}",
"ver": "1.2"
}
}
],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"bid": [
{
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{json response string}",
"crid": "test-creative-id",
"ext": {
"prebid": {
"type": "native"
}
}
}
]
}
],
"cur": "PLN"
}
}
}
],
"expectedBidResponses": [
{
"currency": "PLN",
"bids": [
{
"bid": {
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{json response string}",
"crid": "test-creative-id",
"ext": {
"prebid": {
"type": "native"
}
}
},
"type": "native"
}
]
}
]
}
73 changes: 73 additions & 0 deletions adapters/adrino/adrinotest/supplemental/unknown-hash.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"ext": {
"bidder": {
"hash": "some-unknown-hash"
}
},
"native": {
"request": "{json string}",
"ver": "1.2"
}
}
],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://prd-prebid-bidder.adrino.io/openrtb/bid",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
]
},
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"ext": {
"bidder": {
"hash": "some-unknown-hash"
}
},
"native": {
"request": "{json string}",
"ver": "1.2"
}
}
],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
}
},
"mockResponse": {
"status": 204,
"body": {}
}
}
],
"expectedBidResponses": []
}
Loading

0 comments on commit 0073e45

Please sign in to comment.