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.
Co-authored-by: Tomasz Mielcarz <[email protected]>
- Loading branch information
1 parent
968974e
commit 207e624
Showing
12 changed files
with
458 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,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 | ||
} |
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,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) | ||
} |
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,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
115
adapters/adrino/adrinotest/exemplary/single-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,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" | ||
} | ||
] | ||
} | ||
] | ||
} |
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,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": [] | ||
} |
Oops, something went wrong.