-
Notifications
You must be signed in to change notification settings - Fork 753
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: smartx #3109
Merged
Merged
New Adapter: smartx #3109
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8a87fea
new adapter smartx
bc6f73f
fix parameter tests
9bc44e2
fix typo in Builder
schubert-sc d15a8f6
review adjustments
schubert-sc 50d74b9
Update smartx.yaml
fkoch-sc 0616f85
Merge branch 'prebid:master' into master
schubert-sc 7cd6376
adjusted based on feedback
schubert-sc 1a66d09
Merge branch 'prebid:master' into master
schubert-sc 5763e95
feedback adjustments
schubert-sc 4fb973a
check no content before error
schubert-sc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,58 @@ | ||
package smartx | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
var validParams = []string{ | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A", "publisherId":"11986", "siteId":"22860"}`, | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A", "publisherId":"11986", "appId":"22860"}`, | ||
} | ||
|
||
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.BidderSmartx, json.RawMessage(validParam)); err != nil { | ||
t.Errorf("Schema rejected smartx params: %s", validParam) | ||
} | ||
} | ||
} | ||
|
||
var invalidParams = []string{ | ||
``, | ||
`null`, | ||
`true`, | ||
`5`, | ||
`[]`, | ||
`{}`, | ||
`{"anyparam": "anyvalue"}`, | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A"}`, | ||
`{"publisherId":"11986"}`, | ||
`{"siteId":"22860"}`, | ||
`{"appId":"22860"}`, | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A", "publisherId":"11986"}`, | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A", "siteId":"22860"}`, | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A", "appId":"22860"}`, | ||
`{"publisherId":"11986", "appId":"22860"}`, | ||
`{"publisherId":"11986", "appId":"22860"}`, | ||
} | ||
|
||
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.BidderSmartHub, json.RawMessage(invalidParam)); err == nil { | ||
t.Errorf("Schema allowed unexpected params: %s", invalidParam) | ||
} | ||
} | ||
} |
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,90 @@ | ||
package smartx | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/prebid/openrtb/v19/openrtb2" | ||
"github.com/prebid/prebid-server/adapters" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
type adapter struct { | ||
endpointURL string | ||
} | ||
|
||
func Builder(_ openrtb_ext.BidderName, config config.Adapter, _ config.Server) (adapters.Bidder, error) { | ||
return &adapter{ | ||
endpointURL: config.Endpoint, | ||
}, nil | ||
} | ||
|
||
func (a *adapter) MakeRequests(openRTBRequest *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) (requestsToBidder []*adapters.RequestData, errs []error) { | ||
openRTBRequestJSON, err := json.Marshal(openRTBRequest) | ||
if err != nil { | ||
errs = append(errs, fmt.Errorf("marshal bidRequest: %w", err)) | ||
return nil, errs | ||
} | ||
|
||
headers := http.Header{} | ||
headers.Add("Content-Type", "application/json;charset=utf-8") | ||
headers.Add("x-openrtb-version", "2.5") | ||
|
||
if openRTBRequest.Device != nil { | ||
if openRTBRequest.Device.UA != "" { | ||
headers.Set("User-Agent", openRTBRequest.Device.UA) | ||
} | ||
|
||
if openRTBRequest.Device.IP != "" { | ||
headers.Set("Forwarded", "for="+openRTBRequest.Device.IP) | ||
headers.Set("X-Forwarded-For", openRTBRequest.Device.IP) | ||
} | ||
} | ||
|
||
return append(requestsToBidder, &adapters.RequestData{ | ||
Method: http.MethodPost, | ||
Uri: a.endpointURL, | ||
Body: openRTBRequestJSON, | ||
Headers: headers, | ||
}), nil | ||
} | ||
|
||
func (a *adapter) MakeBids(request *openrtb2.BidRequest, _ *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
if adapters.IsResponseStatusCodeNoContent(responseData) { | ||
return nil, nil | ||
} | ||
|
||
var response openrtb2.BidResponse | ||
if err := json.Unmarshal(responseData.Body, &response); err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
if len(response.SeatBid) == 0 { | ||
return nil, []error{errors.New("no bidders found in JSON response")} | ||
} | ||
|
||
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) | ||
if response.Cur != "" { | ||
bidResponse.Currency = response.Cur | ||
} | ||
|
||
var errs []error | ||
|
||
for _, seatBid := range response.SeatBid { | ||
for i, _ := range seatBid.Bid { | ||
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | ||
Bid: &seatBid.Bid[i], | ||
BidType: openrtb_ext.BidTypeVideo, | ||
}) | ||
} | ||
} | ||
|
||
return bidResponse, errs | ||
} |
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,24 @@ | ||
package smartx | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/adapters/adapterstest" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
const testsDir = "smartxtest" | ||
const testsBidderEndpoint = "http://localhost/prebid_server" | ||
onkarvhanumante marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder( | ||
openrtb_ext.BidderRise, | ||
config.Adapter{Endpoint: testsBidderEndpoint}, | ||
config.Server{ExternalUrl: "http://hosturl.com", GvlID: 115, DataCenter: "2"}) | ||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, testsDir, bidder) | ||
} |
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,77 @@ | ||
{ | ||
"mockBidRequest":{ | ||
"id":"test-request-id-video", | ||
"imp":[ | ||
{ | ||
"id":"test-imp-id", | ||
"video":{ | ||
"mimes":[ | ||
"video/mp4" | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"httpCalls":[ | ||
{ | ||
"expectedRequest":{ | ||
"uri":"http://localhost/prebid_server", | ||
"body":{ | ||
"id":"test-request-id-video", | ||
"imp":[ | ||
{ | ||
"id":"test-imp-id", | ||
"video":{ | ||
"mimes":[ | ||
"video/mp4" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"mockResponse":{ | ||
"status":200, | ||
"body":{ | ||
"id":"test-request-id-video", | ||
"seatbid":[ | ||
{ | ||
"seat":"smartadserver", | ||
"bid":[ | ||
{ | ||
"id":"8ee514f1-b2b8-4abb-89fd-084437d1e800", | ||
"impid":"test-imp-id-video", | ||
"price":0.500000, | ||
"adm":"some-test-ad", | ||
"crid":"crid_10", | ||
"h":576, | ||
"w":1024, | ||
"mtype":2 | ||
} | ||
] | ||
} | ||
], | ||
"cur":"EUR" | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses":[ | ||
{ | ||
"bids":[{ | ||
"bid":{ | ||
"id":"8ee514f1-b2b8-4abb-89fd-084437d1e800", | ||
"impid":"test-imp-id-video", | ||
"price":0.500000, | ||
"adm":"some-test-ad", | ||
"crid":"crid_10", | ||
"h":576, | ||
"w":1024, | ||
"mtype":2 | ||
}, | ||
"currency":"EUR", | ||
"type": "video" | ||
}] | ||
} | ||
] | ||
} |
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,124 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"ext": { | ||
"prebid": { | ||
"bidder": { | ||
"smartx": { | ||
"publisherId": "11986", | ||
"tagId": "Nu68JuOWAvrbzoyrOR9a7A", | ||
"siteId": "22860" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"user": { | ||
"ext": { | ||
"consent": "COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw" | ||
} | ||
} | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "http://localhost/prebid_server", | ||
"body": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"ext": { | ||
"prebid": { | ||
"bidder": { | ||
"smartx": { | ||
"publisherId": "11986", | ||
"tagId": "Nu68JuOWAvrbzoyrOR9a7A", | ||
"siteId": "22860" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"user": { | ||
"ext": { | ||
"consent": "COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw" | ||
} | ||
} | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "test-request-id", | ||
"seatbid": [ | ||
{ | ||
"seat": "958", | ||
"bid": [ | ||
{ | ||
"id": "7706636740145184841", | ||
"impid": "test-imp-id", | ||
"price": 0.5, | ||
"adid": "29681110", | ||
"adm": "some-test-ad", | ||
"adomain": [ | ||
"https://advertiser.example.com" | ||
], | ||
"cid": "958", | ||
"crid": "29681110", | ||
"h": 250, | ||
"w": 300, | ||
"ext": { | ||
"ix": {} | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"bidid": "5778926625248726496", | ||
"cur": "USD" | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses": [ | ||
{ | ||
"currency": "USD", | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "7706636740145184841", | ||
"impid": "test-imp-id", | ||
"price": 0.5, | ||
"adm": "some-test-ad", | ||
"adid": "29681110", | ||
"adomain": [ | ||
"https://advertiser.example.com" | ||
], | ||
"cid": "958", | ||
"crid": "29681110", | ||
"w": 300, | ||
"h": 250, | ||
"ext": { | ||
"ix": {} | ||
} | ||
}, | ||
"type": "video" | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you might wanna reverse this. You should check for no content first before you check
CheckResponseStatusCodeForErrors
becauseCheckResponseStatusCodeForErrors
function will return an error even if response from bidder is204
which is StatusNoContent. So -