-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial commit * added notes file for temp use * jixie adapter development work * jixie adaptor development work: mainly the test json files but also the jixie usersync code * added a test case with accountid. and cosmetic line changes in the banner*json test file * updated the jixie user sync: the endpoint and some params stuf * tks and fixing per comments on pull request 1698 * responding to guscarreon's comments: -more checking in makerequest of the bidder params (added 2 more test jsons) -removed blank lines, lines commented out -test_params: a case with unit alone -BadInput error * responding to review. put condition on jixie unit string in the bidder-params/jixie.json file. removed checking in jixie.go that has become unnecssary. removed unnec test cases. updated params-test * added one failed params test * removed a function that I no longer call! * renamed JixieAdapter to adapter * removed bidfloor from jixie explicit ext params
- Loading branch information
1 parent
b74d7c0
commit fc4bb44
Showing
19 changed files
with
1,242 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,133 @@ | ||
package jixie | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/mxmCherry/openrtb" | ||
"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" | ||
) | ||
|
||
type adapter struct { | ||
endpoint string | ||
} | ||
|
||
// Builder builds a new instance of the Jixie adapter for the given bidder with the given config. | ||
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { | ||
bidder := &adapter{ | ||
endpoint: config.Endpoint, | ||
} | ||
return bidder, nil | ||
} | ||
|
||
// Adding header fields to request header | ||
func addHeaderIfNonEmpty(headers http.Header, headerName string, headerValue string) { | ||
if len(headerValue) > 0 { | ||
headers.Add(headerName, headerValue) | ||
} | ||
} | ||
|
||
func (a *adapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
var errs = make([]error, 0) | ||
|
||
data, err := json.Marshal(request) | ||
if err != nil { | ||
errs = append(errs, err) | ||
return nil, errs | ||
} | ||
|
||
headers := http.Header{} | ||
headers.Add("Content-Type", "application/json;charset=utf-8") | ||
headers.Add("Accept", "application/json") | ||
if request.Device != nil { | ||
addHeaderIfNonEmpty(headers, "User-Agent", request.Device.UA) | ||
addHeaderIfNonEmpty(headers, "X-Forwarded-For", request.Device.IP) | ||
} | ||
|
||
if request.Site != nil { | ||
addHeaderIfNonEmpty(headers, "Referer", request.Site.Page) | ||
} | ||
|
||
return []*adapters.RequestData{{ | ||
Method: "POST", | ||
Uri: a.endpoint, | ||
Body: data, | ||
Headers: headers, | ||
}}, errs | ||
} | ||
|
||
func containsAny(raw string, keys []string) bool { | ||
lowerCased := strings.ToLower(raw) | ||
for i := 0; i < len(keys); i++ { | ||
if strings.Contains(lowerCased, keys[i]) { | ||
return true | ||
} | ||
} | ||
return false | ||
|
||
} | ||
|
||
func getBidType(bidAdm string) openrtb_ext.BidType { | ||
if bidAdm != "" && containsAny(bidAdm, []string{"<?xml", "<vast"}) { | ||
return openrtb_ext.BidTypeVideo | ||
} | ||
return openrtb_ext.BidTypeBanner | ||
} | ||
|
||
// MakeBids make the bids for the bid response. | ||
func (a *adapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
|
||
if response.StatusCode == http.StatusNoContent { | ||
// no bid response | ||
return nil, nil | ||
} | ||
|
||
if response.StatusCode == http.StatusBadRequest { | ||
return nil, []error{&errortypes.BadInput{ | ||
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info", response.StatusCode), | ||
}} | ||
} | ||
|
||
if response.StatusCode != http.StatusOK { | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: fmt.Sprintf("Invalid Status Returned: %d. Run with request.debug = 1 for more info", response.StatusCode), | ||
}} | ||
} | ||
|
||
var bidResp openrtb.BidResponse | ||
|
||
if err := json.Unmarshal(response.Body, &bidResp); err != nil { | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: fmt.Sprintf("Unable to unpackage bid response. Error: %s", err.Error()), | ||
}} | ||
} | ||
|
||
var bids []*adapters.TypedBid | ||
|
||
for _, sb := range bidResp.SeatBid { | ||
for i := range sb.Bid { | ||
|
||
sb.Bid[i].ImpID = sb.Bid[i].ID | ||
|
||
bids = append(bids, &adapters.TypedBid{ | ||
Bid: &sb.Bid[i], | ||
BidType: getBidType(sb.Bid[i].AdM), | ||
}) | ||
} | ||
} | ||
adsResp := adapters.NewBidderResponseWithBidsCapacity(len(bids)) | ||
adsResp.Bids = bids | ||
if bidResp.Cur != "" { | ||
adsResp.Currency = bidResp.Cur | ||
} else { | ||
adsResp.Currency = "USD" | ||
} | ||
|
||
return adsResp, 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 jixie | ||
|
||
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.BidderJixie, config.Adapter{ | ||
Endpoint: "https://hb.jixie.io/v2/hbsvrpost"}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "jixietest", bidder) | ||
} |
230 changes: 230 additions & 0 deletions
230
adapters/jixie/jixietest/exemplary/banner-and-video-site.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,230 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "some_test_auction", | ||
"imp": [{ | ||
"id": "some_test_ad_id_1", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 100 | ||
}, { | ||
"w": 300, | ||
"h": 600 | ||
}], | ||
"w": 300, | ||
"h": 100 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"unit": "1000008-AbCdEf1234" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "some_test_ad_id_2", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 50 | ||
}], | ||
"w": 300, | ||
"h": 50 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"unit": "1000008-AbCdEf2345" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "some_test_ad_id_3", | ||
"video":{ | ||
"mimes": [ | ||
"video/mp4", | ||
"application/javascript" | ||
], | ||
"protocols":[ | ||
2, | ||
3, | ||
5, | ||
6 | ||
], | ||
"w":640, | ||
"h":480 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"unit": "1000008-AbCdEf3456" | ||
} | ||
} | ||
} | ||
], | ||
"device": { | ||
"ua": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36", | ||
"ip": "111.222.333.444" | ||
}, | ||
"site": { | ||
"domain": "www.publisher.com", | ||
"page": "http://www.publisher.com/today/site?param1=a¶m2=b" | ||
} | ||
}, | ||
|
||
"httpCalls": [{ | ||
"expectedRequest": { | ||
"uri": "https://hb.jixie.io/v2/hbsvrpost", | ||
"headers": { | ||
"Accept": [ | ||
"application/json" | ||
], | ||
"Content-Type": [ | ||
"application/json;charset=utf-8" | ||
], | ||
"X-Forwarded-For": [ | ||
"111.222.333.444" | ||
], | ||
"Referer": [ | ||
"http://www.publisher.com/today/site?param1=a¶m2=b" | ||
], | ||
"User-Agent": [ | ||
"Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36" | ||
] | ||
}, | ||
"body": { | ||
"id": "some_test_auction", | ||
"imp": [{ | ||
"id": "some_test_ad_id_1", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 100 | ||
},{ | ||
"w": 300, | ||
"h": 600 | ||
}], | ||
"w": 300, | ||
"h": 100 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"unit": "1000008-AbCdEf1234" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "some_test_ad_id_2", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 50 | ||
}], | ||
"w": 300, | ||
"h": 50 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"unit": "1000008-AbCdEf2345" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "some_test_ad_id_3", | ||
"video":{ | ||
"mimes": [ | ||
"video/mp4", | ||
"application/javascript" | ||
], | ||
"protocols":[ | ||
2, | ||
3, | ||
5, | ||
6 | ||
], | ||
"w":640, | ||
"h":480 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"unit": "1000008-AbCdEf3456" | ||
} | ||
} | ||
}], | ||
"site": { | ||
"domain": "www.publisher.com", | ||
"page": "http://www.publisher.com/today/site?param1=a¶m2=b" | ||
}, | ||
"device": { | ||
"ua": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36", | ||
"ip": "111.222.333.444" | ||
} | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "some_test_auction", | ||
"seatbid": [{ | ||
"seat": "12356", | ||
"bid": [{ | ||
"adm": "<div id=\"jxoutstream-dcc0ca9c6591\" style=\"width: 100%;\"> <script type=\"text/javascript\" src=\"https://creatives.b-cdn.net/js/hbrenderer.min.js\" defer=\"\"></script> <script> var p ={ responsive: 1, nested: 1, maxwidth: 640, container: \"jxoutstream-dcc0ca9c6591\", jsoncreativeobj64: \"eyJ0ZXN0dmFyIjoxMjN9\"}; function jxdefer(p) { if (window.jxhbuniversal) { window.jxhbuniversal.hbinit(p); } else { setTimeout(function() { jxdefer(p) }, 100); } } jxdefer(p); </script> </div>", | ||
"id": "some_test_ad_id_1", | ||
"impid": "some_test_ad_id_1", | ||
"ttl": 300, | ||
"crid": "94395500", | ||
"w": 300, | ||
"price": 2.942808, | ||
"adid": "94395500", | ||
"h": 250 | ||
}] | ||
}, | ||
{ | ||
"seat": "45678", | ||
"bid": [{ | ||
"adm": "<VAST xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"vast.xsd\" version=\"3.0\"><Ad id=\"JXAD953\"><InLine><AdSystem> JXADSERVER</AdSystem><AdTitle>DEMO</AdTitle><Description>in-stream</Description><Error><![CDATA[ https://tra.jixie.io/sync/ad?action=error ]]></Error><Impression><![CDATA[ https://tra.jixie.io/sync/ad?action=impression ]]></Impression><Creatives><Creative id=\"JXAD953\" sequence=\"1\"><Linear><Duration> 00:00:10</Duration><TrackingEvents><Tracking event=\"start\"><![CDATA[ https://tra.jixie.io/sync/ad?action=start ]]></Tracking><Tracking event=\"firstQuartil\"><![CDATA[ https://tra.jixie.io/sync/ad?action=firstQuartile ]]></Tracking><Tracking event=\"midpoint\"><![CDATA[ https://tra.jixie.io/sync/ad?action=midpoint ]]></Tracking><Tracking event=\"thirdQuartile\"><![CDATA[ https://tra.jixie.io/sync/ad?action=thirdQuartile ]]></Tracking><Tracking event=\"complete\"><![CDATA[ https://tra.jixie.io/sync/ad?action=complete ]]></Tracking></TrackingEvents><VideoClicks><ClickThrough><![CDATA[ https://tra.jixie.io/sync/ck?igr=1 ]]></ClickThrough><ClickTracking><![CDATA[ https://tra.jixie.io/sync/ad?action=click ]]></ClickTracking></VideoClicks><AdParameters><![CDATA[ {\"videos\": [{\"url\": \"https://creatives.b-cdn.net/80c8a13725c68736d9faf7e5858d51f1/230/798/motion_whitebanner _1_ _ Kislew Trily_240p.mp4\", \"width\": 426, \"height\": 240, \"bitrate\": 342, \"mimetype\": \"video/mp4\"}]}]]></AdParameters><MediaFiles><MediaFile apiFramework=\"VPAID\" type=\"application/javascript\"><![CDATA[ https://creatives.b-cdn.net/js/jxvpaid_1_0.min.js ]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>", | ||
"id": "some_test_ad_id_3", | ||
"impid": "some_test_ad_id_3", | ||
"ttl": 300, | ||
"crid": "9999999", | ||
"w": 640, | ||
"price": 1, | ||
"adid": "9999999", | ||
"h": 360 | ||
} | ||
] | ||
}], | ||
"cur": "USD" | ||
} | ||
} | ||
}], | ||
|
||
"expectedBidResponses": [{ | ||
"currency": "USD", | ||
"bids": [{ | ||
"bid": { | ||
"adm": "<div id=\"jxoutstream-dcc0ca9c6591\" style=\"width: 100%;\"> <script type=\"text/javascript\" src=\"https://creatives.b-cdn.net/js/hbrenderer.min.js\" defer=\"\"></script> <script> var p ={ responsive: 1, nested: 1, maxwidth: 640, container: \"jxoutstream-dcc0ca9c6591\", jsoncreativeobj64: \"eyJ0ZXN0dmFyIjoxMjN9\"}; function jxdefer(p) { if (window.jxhbuniversal) { window.jxhbuniversal.hbinit(p); } else { setTimeout(function() { jxdefer(p) }, 100); } } jxdefer(p); </script> </div>", | ||
"id": "some_test_ad_id_1", | ||
"impid": "some_test_ad_id_1", | ||
"crid": "94395500", | ||
"w": 300, | ||
"price": 2.942808, | ||
"adid": "94395500", | ||
"h": 250 | ||
}, | ||
"type": "banner" | ||
}, | ||
{ | ||
"bid": { | ||
"adm": "<VAST xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"vast.xsd\" version=\"3.0\"><Ad id=\"JXAD953\"><InLine><AdSystem> JXADSERVER</AdSystem><AdTitle>DEMO</AdTitle><Description>in-stream</Description><Error><![CDATA[ https://tra.jixie.io/sync/ad?action=error ]]></Error><Impression><![CDATA[ https://tra.jixie.io/sync/ad?action=impression ]]></Impression><Creatives><Creative id=\"JXAD953\" sequence=\"1\"><Linear><Duration> 00:00:10</Duration><TrackingEvents><Tracking event=\"start\"><![CDATA[ https://tra.jixie.io/sync/ad?action=start ]]></Tracking><Tracking event=\"firstQuartil\"><![CDATA[ https://tra.jixie.io/sync/ad?action=firstQuartile ]]></Tracking><Tracking event=\"midpoint\"><![CDATA[ https://tra.jixie.io/sync/ad?action=midpoint ]]></Tracking><Tracking event=\"thirdQuartile\"><![CDATA[ https://tra.jixie.io/sync/ad?action=thirdQuartile ]]></Tracking><Tracking event=\"complete\"><![CDATA[ https://tra.jixie.io/sync/ad?action=complete ]]></Tracking></TrackingEvents><VideoClicks><ClickThrough><![CDATA[ https://tra.jixie.io/sync/ck?igr=1 ]]></ClickThrough><ClickTracking><![CDATA[ https://tra.jixie.io/sync/ad?action=click ]]></ClickTracking></VideoClicks><AdParameters><![CDATA[ {\"videos\": [{\"url\": \"https://creatives.b-cdn.net/80c8a13725c68736d9faf7e5858d51f1/230/798/motion_whitebanner _1_ _ Kislew Trily_240p.mp4\", \"width\": 426, \"height\": 240, \"bitrate\": 342, \"mimetype\": \"video/mp4\"}]}]]></AdParameters><MediaFiles><MediaFile apiFramework=\"VPAID\" type=\"application/javascript\"><![CDATA[ https://creatives.b-cdn.net/js/jxvpaid_1_0.min.js ]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>", | ||
"id": "some_test_ad_id_3", | ||
"impid": "some_test_ad_id_3", | ||
"crid": "9999999", | ||
"w": 640, | ||
"price": 1, | ||
"adid": "9999999", | ||
"h": 360 | ||
}, | ||
"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,4 @@ | ||
{ | ||
"unit": "1000008-AbCdEf123400", | ||
"bidfloor": "0.02" | ||
} |
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,4 @@ | ||
{ | ||
"unit": "1000008-AbCdEf2345", | ||
"bidfloor": "0.03" | ||
} |
Oops, something went wrong.