-
Notifications
You must be signed in to change notification settings - Fork 752
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: yfcr <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,252 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,80 @@ | ||
package oms | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/prebid/openrtb/v19/openrtb2" | ||
"github.com/prebid/prebid-server/v2/adapters" | ||
"github.com/prebid/prebid-server/v2/config" | ||
"github.com/prebid/prebid-server/v2/errortypes" | ||
"github.com/prebid/prebid-server/v2/openrtb_ext" | ||
"net/http" | ||
) | ||
|
||
type adapter struct { | ||
endpoint string | ||
} | ||
|
||
// Builder builds a new instance of the OMS 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 responseData.StatusCode == http.StatusNoContent { | ||
return nil, nil | ||
} | ||
|
||
if responseData.StatusCode == http.StatusBadRequest { | ||
err := &errortypes.BadInput{ | ||
Message: "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", | ||
} | ||
return nil, []error{err} | ||
} | ||
|
||
if responseData.StatusCode != http.StatusOK { | ||
err := &errortypes.BadServerResponse{ | ||
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", 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)) | ||
if len(response.Cur) == 0 { | ||
bidResponse.Currency = response.Cur | ||
} | ||
for _, seatBid := range response.SeatBid { | ||
for i := range seatBid.Bid { | ||
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | ||
Bid: &seatBid.Bid[i], | ||
BidType: openrtb_ext.BidTypeBanner, | ||
}) | ||
} | ||
} | ||
|
||
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,20 @@ | ||
package oms | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/v2/adapters/adapterstest" | ||
"github.com/prebid/prebid-server/v2/config" | ||
"github.com/prebid/prebid-server/v2/openrtb_ext" | ||
) | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderOms, config.Adapter{ | ||
Endpoint: "http://rt.marphezis.com/pbs"}, config.Server{ExternalUrl: "http://hosturl.com"}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "omstest", bidder) | ||
} |
128 changes: 128 additions & 0 deletions
128
adapters/oms/omstest/exemplary/simple-banner-cookie-uid.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", | ||
"site": { | ||
"id": "site-id", | ||
"page": "oms.com" | ||
}, | ||
"device": { | ||
"os": "android", | ||
"ip": "91.199.242.236", | ||
"ua": "random user agent" | ||
}, | ||
"user": { | ||
"buyeruid": "oms-user-id" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 250 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"pid": "12345" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "http://rt.marphezis.com/pbs", | ||
"headers": {}, | ||
"body": { | ||
"id": "test-request-id", | ||
"site": { | ||
"id": "site-id", | ||
"page": "oms.com" | ||
}, | ||
"device": { | ||
"os": "android", | ||
"ip": "91.199.242.236", | ||
"ua": "random user agent" | ||
}, | ||
"user": { | ||
"buyeruid": "oms-user-id" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 250 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"pid": "12345" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "test-request-id", | ||
"currency": "USD", | ||
"seatbid": [ | ||
{ | ||
"bid": [ | ||
{ | ||
"id": "test-slot-id", | ||
"impid": "test-imp-id", | ||
"price": 0.1, | ||
"crid": "creative-123", | ||
"adm": "<iframe id='789abc' name='789abc' src='http://creative-url.oms.com'></iframe>", | ||
"w": 300, | ||
"h": 250, | ||
"ext": { | ||
"prebid": { | ||
"type": "banner" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses": [ | ||
{ | ||
"currency": "USD", | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "test-slot-id", | ||
"impid": "test-imp-id", | ||
"price": 0.1, | ||
"crid": "creative-123", | ||
"adm": "<iframe id='789abc' name='789abc' src='http://creative-url.oms.com'></iframe>", | ||
"w": 300, | ||
"h": 250, | ||
"ext": { | ||
"prebid": { | ||
"type": "banner" | ||
} | ||
} | ||
}, | ||
"type": "banner" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
Oops, something went wrong.