forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'prebid:master' into master
- Loading branch information
Showing
403 changed files
with
5,112 additions
and
819 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
29 changes: 29 additions & 0 deletions
29
adapters/33across/33acrosstest/supplemental/video-validation-fail-size-null.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,29 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"video": { | ||
"protocols": [2], | ||
"playbackmethod": [2], | ||
"mimes": ["foo", "bar"] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"siteId": "fake-site-id", | ||
"productId": "siab" | ||
} | ||
} | ||
} | ||
], | ||
"site": {} | ||
}, | ||
|
||
"expectedMakeRequestsErrors": [ | ||
{ | ||
"value": "One or more invalid or missing video field(s) w, h, protocols, mimes, playbackmethod", | ||
"comparison": "literal" | ||
} | ||
] | ||
} |
30 changes: 30 additions & 0 deletions
30
adapters/33across/33acrosstest/supplemental/video-validation-fail-size-partial.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,30 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"video": { | ||
"h": 100, | ||
"protocols": [2], | ||
"playbackmethod": [2], | ||
"mimes": ["foo", "bar"] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"siteId": "fake-site-id", | ||
"productId": "siab" | ||
} | ||
} | ||
} | ||
], | ||
"site": {} | ||
}, | ||
|
||
"expectedMakeRequestsErrors": [ | ||
{ | ||
"value": "One or more invalid or missing video field(s) w, h, protocols, mimes, playbackmethod", | ||
"comparison": "literal" | ||
} | ||
] | ||
} |
31 changes: 31 additions & 0 deletions
31
adapters/33across/33acrosstest/supplemental/video-validation-fail-size-zero.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,31 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"video": { | ||
"w": 0, | ||
"h": 0, | ||
"protocols": [2], | ||
"playbackmethod": [2], | ||
"mimes": ["foo", "bar"] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"siteId": "fake-site-id", | ||
"productId": "siab" | ||
} | ||
} | ||
} | ||
], | ||
"site": {} | ||
}, | ||
|
||
"expectedMakeRequestsErrors": [ | ||
{ | ||
"value": "One or more invalid or missing video field(s) w, h, protocols, mimes, playbackmethod", | ||
"comparison": "literal" | ||
} | ||
] | ||
} |
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
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
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
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
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
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,139 @@ | ||
package adelement | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"text/template" | ||
|
||
"github.com/prebid/openrtb/v20/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/macros" | ||
"github.com/prebid/prebid-server/v2/openrtb_ext" | ||
) | ||
|
||
type adapter struct { | ||
endpoint *template.Template | ||
} | ||
|
||
// Builder builds a new instance of the Adelement adapter for the given bidder with the given config. | ||
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) { | ||
template, err := template.New("endpointTemplate").Parse(config.Endpoint) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse endpoint url template: %v", err) | ||
} | ||
|
||
bidder := &adapter{ | ||
endpoint: template, | ||
} | ||
return bidder, nil | ||
} | ||
|
||
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
adelementExt, err := getImpressionExt(&request.Imp[0]) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
url, err := a.buildEndpointURL(adelementExt) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
requestJSON, err := json.Marshal(request) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
requestData := &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: url, | ||
Body: requestJSON, | ||
} | ||
|
||
return []*adapters.RequestData{requestData}, nil | ||
} | ||
|
||
func getImpressionExt(imp *openrtb2.Imp) (*openrtb_ext.ExtAdelement, error) { | ||
var bidderExt adapters.ExtImpBidder | ||
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { | ||
return nil, &errortypes.BadInput{ | ||
Message: "ext.bidder not provided", | ||
} | ||
} | ||
var adelementExt openrtb_ext.ExtAdelement | ||
if err := json.Unmarshal(bidderExt.Bidder, &adelementExt); err != nil { | ||
return nil, &errortypes.BadInput{ | ||
Message: "ext.bidder not provided", | ||
} | ||
} | ||
imp.Ext = nil | ||
return &adelementExt, nil | ||
} | ||
|
||
func (a *adapter) buildEndpointURL(params *openrtb_ext.ExtAdelement) (string, error) { | ||
endpointParams := macros.EndpointTemplateParams{SupplyId: params.SupplyId} | ||
return macros.ResolveMacros(a.endpoint, endpointParams) | ||
} | ||
|
||
func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
if adapters.IsResponseStatusCodeNoContent(responseData) { | ||
return nil, nil | ||
} | ||
|
||
if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
var response openrtb2.BidResponse | ||
if err := json.Unmarshal(responseData.Body, &response); err != nil { | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: "Bad Server Response", | ||
}} | ||
} | ||
|
||
if len(response.SeatBid) == 0 { | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: "Empty SeatBid array", | ||
}} | ||
} | ||
|
||
var bidErrs []error | ||
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) | ||
bidResponse.Currency = response.Cur | ||
for _, seatBid := range response.SeatBid { | ||
for i := range seatBid.Bid { | ||
bid := seatBid.Bid[i] | ||
bidType, err := getBidType(bid) | ||
if err != nil { | ||
// could not determinate media type, append an error and continue with the next bid. | ||
bidErrs = append(bidErrs, err) | ||
continue | ||
} | ||
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | ||
Bid: &bid, | ||
BidType: bidType, | ||
}) | ||
} | ||
} | ||
return bidResponse, bidErrs | ||
} | ||
|
||
func getBidType(bid openrtb2.Bid) (openrtb_ext.BidType, error) { | ||
// determinate media type by bid response field mtype | ||
switch bid.MType { | ||
case openrtb2.MarkupBanner: | ||
return openrtb_ext.BidTypeBanner, nil | ||
case openrtb2.MarkupVideo: | ||
return openrtb_ext.BidTypeVideo, nil | ||
case openrtb2.MarkupAudio: | ||
return openrtb_ext.BidTypeAudio, nil | ||
case openrtb2.MarkupNative: | ||
return openrtb_ext.BidTypeNative, nil | ||
} | ||
|
||
return "", &errortypes.BadInput{ | ||
Message: fmt.Sprintf("Could not define media type for impression: %s", bid.ImpID), | ||
} | ||
} |
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 adelement | ||
|
||
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" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderAdelement, config.Adapter{ | ||
Endpoint: "http://test.adelement.com/openrtb2/auction?supply_id={{.SupplyId}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 196}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "adelementtest", bidder) | ||
} | ||
|
||
func TestEndpointTemplateMalformed(t *testing.T) { | ||
_, buildErr := Builder(openrtb_ext.BidderAdelement, config.Adapter{ | ||
Endpoint: "{{Malformed}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 196}) | ||
|
||
assert.Error(t, buildErr) | ||
} |
Oops, something went wrong.