forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FW-113142 modify code according review (prebid#2) FW-113142 1.503-bid-resposne. 2.Add server to builder (prebid#3) * modify code according review * FW-113142 1.503-bid-resposne. 2.Add server to builder
- Loading branch information
1 parent
21b2bd6
commit 39fd190
Showing
11 changed files
with
534 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,110 @@ | ||
package freewheelssp | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/mxmCherry/openrtb/v16/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 RequestImpExt struct { | ||
ZoneId int `json:"zoneId"` | ||
} | ||
|
||
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()), | ||
}} | ||
} | ||
requestImpExt := RequestImpExt{ | ||
ZoneId: impExt.ZoneId, | ||
} | ||
|
||
var err error | ||
if imp.Ext, err = json.Marshal(requestImpExt); 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) | ||
} | ||
} | ||
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.