-
Notifications
You must be signed in to change notification settings - Fork 749
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: freewheelssp #2392
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
39fd190
update endpoint to static yaml
e8357ff
update import package
mwang-sticky c52533e
Update adapter_builders.go
mwang-sticky 4779284
Update bidders.go
mwang-sticky ef07818
add old biddercode support
mwang-sticky 2514b7c
add freewheelssp old data
mwang-sticky 9b5e3a1
use the freewheel-ssp code
mwang-sticky 7f749ad
Delete freewheelsspold.yaml
mwang-sticky 2ead09c
skip freewheelold bidder check
mwang-sticky 679e695
Merge branch 'prebid:master' into freewheel-go-adapter
mwang-sticky b667a7b
Merge branch 'prebid:master' into freewheel-go-adapter
mwang-sticky f229580
remove useless struct
mwang-sticky 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,103 @@ | ||
package freewheelssp | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/prebid/openrtb/v17/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" | ||
"net/http" | ||
) | ||
|
||
type adapter struct { | ||
endpoint string | ||
} | ||
|
||
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
for i := 0; i < len(request.Imp); i++ { | ||
imp := &request.Imp[i] | ||
var bidderExt adapters.ExtImpBidder | ||
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { | ||
return nil, []error{&errortypes.BadInput{ | ||
Message: fmt.Sprintf("Invalid imp.ext for impression index %d. Error Infomation: %s", i, err.Error()), | ||
}} | ||
} | ||
|
||
var impExt openrtb_ext.ImpExtFreewheelSSP | ||
if err := json.Unmarshal(bidderExt.Bidder, &impExt); err != nil { | ||
return nil, []error{&errortypes.BadInput{ | ||
Message: fmt.Sprintf("Invalid imp.ext for impression index %d. Error Infomation: %s", i, err.Error()), | ||
}} | ||
} | ||
|
||
var err error | ||
if imp.Ext, err = json.Marshal(impExt); err != nil { | ||
return nil, []error{&errortypes.BadInput{ | ||
Message: fmt.Sprintf("Unable to transfer requestImpExt to Json fomat, %s", err.Error()), | ||
}} | ||
} | ||
} | ||
|
||
requestJSON, err := json.Marshal(request) | ||
if err != nil { | ||
return nil, []error{&errortypes.BadInput{ | ||
Message: fmt.Sprintf("Unable to transfer request to Json fomat, %s", err.Error()), | ||
}} | ||
} | ||
|
||
headers := http.Header{} | ||
headers.Add("Componentid", "prebid-go") | ||
|
||
requestData := &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: a.endpoint, | ||
Body: requestJSON, | ||
Headers: headers, | ||
} | ||
return []*adapters.RequestData{requestData}, nil | ||
} | ||
|
||
func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
if response.StatusCode == http.StatusNoContent { | ||
return nil, nil | ||
} | ||
|
||
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} | ||
} | ||
|
||
cur := bidResp.Cur | ||
bidResponse := &adapters.BidderResponse{ | ||
Currency: cur, | ||
Bids: []*adapters.TypedBid{}, | ||
} | ||
|
||
bidType := openrtb_ext.BidTypeVideo | ||
|
||
for _, seatBid := range bidResp.SeatBid { | ||
for i := range seatBid.Bid { | ||
b := &adapters.TypedBid{ | ||
Bid: &seatBid.Bid[i], | ||
BidType: bidType, | ||
} | ||
bidResponse.Bids = append(bidResponse.Bids, b) | ||
} | ||
} | ||
SyntaxNode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return bidResponse, nil | ||
} | ||
|
||
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) { | ||
bidder := &adapter{ | ||
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,19 @@ | ||
package freewheelssp | ||
|
||
import ( | ||
"github.com/prebid/prebid-server/adapters/adapterstest" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
"testing" | ||
) | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderFreewheelSSP, config.Adapter{ | ||
Endpoint: "https://testjsonsample.com"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "freewheelssptest", bidder) | ||
} |
144 changes: 144 additions & 0 deletions
144
adapters/freewheelssp/freewheelssptest/exemplary/multi-imp.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,144 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "freewheelssp-test", | ||
"site": { | ||
"page": "prebid.org" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "imp-1", | ||
"video": { | ||
"mimes": ["video/mp4"], | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"zoneId": 12345 | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "imp-2", | ||
"video": { | ||
"mimes": ["video/mp4"], | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"zoneId": 12346 | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
|
||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "https://testjsonsample.com", | ||
"body":{ | ||
"id": "freewheelssp-test", | ||
"site": { | ||
"page": "prebid.org" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "imp-1", | ||
"video": { | ||
"mimes": ["video/mp4"], | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"ext": { | ||
"zoneId": 12345 | ||
} | ||
}, | ||
{ | ||
"id": "imp-2", | ||
"video": { | ||
"mimes": ["video/mp4"], | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"ext": { | ||
"zoneId": 12346 | ||
} | ||
} | ||
] | ||
}, | ||
"headers": { | ||
"Componentid": [ | ||
"prebid-go" | ||
] | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "freewheelssp-test", | ||
"seatbid": [ | ||
{ | ||
"bid": [ | ||
{ | ||
"id": "12345_freewheelssp-test_1", | ||
"impid": "imp-1", | ||
"price": 1.0, | ||
"adid": "7857", | ||
"adm": "<?xml version='1.0' encoding='UTF-8'?><VAST version='2.0'></VAST>", | ||
"cid": "4001", | ||
"crid": "7857" | ||
}, | ||
{ | ||
"id": "12346_freewheelssp-test_2", | ||
"impid": "imp-2", | ||
"price": 1.0, | ||
"adid": "7933", | ||
"adm": "<?xml version='1.0' encoding='UTF-8'?><VAST version='2.0'></VAST>", | ||
"cid": "3476", | ||
"crid": "7933" | ||
} | ||
], | ||
"seat": "freewheelsspTv" | ||
} | ||
], | ||
"bidid": "freewheelssp-test", | ||
"cur": "EUR" | ||
} | ||
} | ||
} | ||
], | ||
|
||
"expectedBidResponses": [ | ||
{ | ||
"currency": "CUR", | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "12345_freewheelssp-test_1", | ||
"impid": "imp-1", | ||
"price": 1.0, | ||
"adid": "7857", | ||
"adm": "<?xml version='1.0' encoding='UTF-8'?><VAST version='2.0'></VAST>", | ||
"cid": "4001", | ||
"crid": "7857" | ||
}, | ||
"type": "video" | ||
}, | ||
{ | ||
"bid": { | ||
"id": "12346_freewheelssp-test_2", | ||
"impid": "imp-2", | ||
"price": 1.0, | ||
"adid": "7933", | ||
"adm": "<?xml version='1.0' encoding='UTF-8'?><VAST version='2.0'></VAST>", | ||
"cid": "3476", | ||
"crid": "7933" | ||
}, | ||
"type": "video" | ||
} | ||
] | ||
} | ||
] | ||
} |
97 changes: 97 additions & 0 deletions
97
adapters/freewheelssp/freewheelssptest/exemplary/single-imp.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,97 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "freewheelssp-test", | ||
"site": { | ||
"page": "prebid.org" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "imp-1", | ||
"video": { | ||
"mimes": ["video/mp4"], | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"zoneId": 12345 | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
|
||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "https://testjsonsample.com", | ||
"body":{ | ||
"id": "freewheelssp-test", | ||
"site": { | ||
"page": "prebid.org" | ||
}, | ||
"imp": [{ | ||
"id": "imp-1", | ||
"video": { | ||
"mimes": ["video/mp4"], | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"ext": { | ||
"zoneId": 12345 | ||
} | ||
}] | ||
}, | ||
"headers": { | ||
"Componentid": [ | ||
"prebid-go" | ||
] | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "freewheelssp-test", | ||
"seatbid": [ | ||
{ | ||
"bid": [ | ||
{ | ||
"id": "12345_freewheelssp-test_1", | ||
"impid": "imp-1", | ||
"price": 1.0, | ||
"adid": "7857", | ||
"adm": "<?xml version='1.0' encoding='UTF-8'?><VAST version='2.0'></VAST>", | ||
"cid": "4001", | ||
"crid": "7857" | ||
} | ||
], | ||
"seat": "freewheelsspTv" | ||
} | ||
], | ||
"bidid": "freewheelssp-test", | ||
"cur": "EUR" | ||
} | ||
} | ||
} | ||
], | ||
|
||
"expectedBidResponses": [ | ||
{ | ||
"currency": "CUR", | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "12345_freewheelssp-test_1", | ||
"impid": "imp-1", | ||
"price": 1.0, | ||
"adid": "7857", | ||
"adm": "<?xml version='1.0' encoding='UTF-8'?><VAST version='2.0'></VAST>", | ||
"cid": "4001", | ||
"crid": "7857" | ||
}, | ||
"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.
Is there a way to cover this error case with tests?