-
Notifications
You must be signed in to change notification settings - Fork 765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Adapter: Zentotem #4053
base: master
Are you sure you want to change the base?
New Adapter: Zentotem #4053
Changes from all commits
9aef1ae
6fdcc11
3edd765
9ec095a
a7d9462
36a4b0f
9c6b5e3
b3caeaa
153ebf5
f075a67
6f3f47c
536f118
b5cb591
573c59e
f8ee4ed
4bee7d9
5cb43d2
b6bc533
39567ab
93e3969
bd22820
2b0b9b1
7a2144a
d4290d3
764f48a
dc73050
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package zentotem | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/prebid/prebid-server/v3/openrtb_ext" | ||
"testing" | ||
) | ||
|
||
//Zentotem doesn't currently require any custom fields. This file is included for conformity only | ||
//We do include an unused, non-required custom param in static/bidder-params/zentotem.json, but only to hinder the prebid server from crashing by looking for at least 1 custom param | ||
|
||
// This file actually intends to test static/bidder-params/zentotem.json | ||
// | ||
// These also validate the format of the external API: request.imp[i].ext.prebid.bidder.zentotem | ||
// TestValidParams makes sure that the Zentotem schema accepts all imp.ext fields which we intend to support. | ||
func TestValidParams(t *testing.T) { | ||
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") | ||
if err != nil { | ||
t.Fatalf("Failed to fetch the json-schemas. %v", err) | ||
} | ||
|
||
for _, validParam := range validParams { | ||
if err := validator.Validate(openrtb_ext.BidderZentotem, json.RawMessage(validParam)); err != nil { | ||
t.Errorf("Schema rejected Zentotem params: %s", validParam) | ||
} | ||
} | ||
} | ||
|
||
// TestInvalidParams makes sure that the Zentotem schema rejects all the imp.ext fields we don't support. | ||
func TestInvalidParams(t *testing.T) { | ||
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") | ||
if err != nil { | ||
t.Fatalf("Failed to fetch the json-schemas. %v", err) | ||
} | ||
|
||
for _, invalidParam := range invalidParams { | ||
if err := validator.Validate(openrtb_ext.BidderZentotem, json.RawMessage(invalidParam)); err == nil { | ||
t.Errorf("Schema allowed unexpected params: %s", invalidParam) | ||
} | ||
} | ||
} | ||
|
||
var validParams = []string{} | ||
|
||
var invalidParams = []string{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package zentotem | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/prebid/openrtb/v20/openrtb2" | ||
"github.com/prebid/prebid-server/v3/adapters" | ||
"github.com/prebid/prebid-server/v3/config" | ||
"github.com/prebid/prebid-server/v3/openrtb_ext" | ||
) | ||
|
||
type adapter struct { | ||
endpoint string | ||
} | ||
|
||
// Builder builds a new instance of the {bidder} adapter for the given bidder with the given config. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: |
||
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) { | ||
requests := make([]*adapters.RequestData, 0, len(request.Imp)) | ||
var errors []error | ||
|
||
requestCopy := *request | ||
for _, imp := range request.Imp { | ||
requestCopy.Imp = []openrtb2.Imp{imp} | ||
|
||
requestJSON, err := json.Marshal(request) | ||
if err != nil { | ||
errors = append(errors, err) | ||
continue | ||
} | ||
|
||
requestData := &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: a.endpoint, | ||
Body: requestJSON, | ||
ImpIDs: []string{imp.ID}, | ||
} | ||
requests = append(requests, requestData) | ||
} | ||
return requests, errors | ||
} | ||
|
||
func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) { | ||
switch bid.MType { | ||
case openrtb2.MarkupBanner: | ||
return openrtb_ext.BidTypeBanner, nil | ||
case openrtb2.MarkupVideo: | ||
return openrtb_ext.BidTypeVideo, nil | ||
case openrtb2.MarkupNative: | ||
return openrtb_ext.BidTypeNative, nil | ||
} | ||
|
||
return "", fmt.Errorf("could not define media type for impression: %s", bid.ImpID) | ||
} | ||
|
||
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{err} | ||
} | ||
|
||
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) | ||
bidResponse.Currency = response.Cur | ||
var errors []error | ||
for _, seatBid := range response.SeatBid { | ||
for i := range seatBid.Bid { | ||
bidType, err := getMediaTypeForBid(seatBid.Bid[i]) | ||
if err != nil { | ||
errors = append(errors, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: you're collecting errors, then not returning the errors below. Can you update to return the errors, or remove this |
||
continue | ||
} | ||
|
||
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | ||
Bid: &seatBid.Bid[i], | ||
BidType: bidType, | ||
}) | ||
} | ||
} | ||
return bidResponse, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package zentotem | ||
|
||
import ( | ||
"github.com/prebid/openrtb/v20/openrtb2" | ||
"github.com/prebid/prebid-server/v3/adapters/adapterstest" | ||
"github.com/prebid/prebid-server/v3/config" | ||
"github.com/prebid/prebid-server/v3/openrtb_ext" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderZentotem, config.Adapter{ | ||
Endpoint: "https://rtb.zentotem.net/bid?sspuid=cqlnvfk00bhs0b6rci6g"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest using fake urls for your tests for maintenance reasons. |
||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "zentotemtest", bidder) | ||
} | ||
|
||
func TestGetMediaTypeForBid(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
bid openrtb2.Bid | ||
wantType openrtb_ext.BidType | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "get bid native type", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: |
||
bid: openrtb2.Bid{ | ||
MType: 4, | ||
}, | ||
wantType: openrtb_ext.BidTypeNative, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "get bid banner type", | ||
bid: openrtb2.Bid{ | ||
MType: 1, | ||
}, | ||
wantType: openrtb_ext.BidTypeBanner, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "get bid video type", | ||
bid: openrtb2.Bid{ | ||
MType: 2, | ||
}, | ||
wantType: openrtb_ext.BidTypeVideo, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "fail", | ||
wantType: "", | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
bType, err := getMediaTypeForBid(tt.bid) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("getMediaTypeForBid error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
|
||
assert.Equal(t, bType, tt.wantType) | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this was copied from another adapter, vrtcal, which was created six years ago. Is a custom param still needed to keep prebid server from crashing? I suspect not; I will investigate.