Skip to content
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

TripleLift Prebid S2S Adapter #954

Merged
merged 77 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
d2b2e19
ignore swp files
Kevin-P-Kerr Jun 13, 2019
d210145
start small
Kevin-P-Kerr Jun 13, 2019
3acedbe
start really small
Kevin-P-Kerr Jun 13, 2019
04a6137
add a user sync
Kevin-P-Kerr Jun 13, 2019
5babcb1
justify
Kevin-P-Kerr Jun 13, 2019
a55a9c1
triplelift adapter
Kevin-P-Kerr Jun 13, 2019
3c4ccbc
add our endpoint
Kevin-P-Kerr Jun 13, 2019
44f921b
fix syntax
Kevin-P-Kerr Jun 13, 2019
f9d30c4
config stuff
Kevin-P-Kerr Jun 13, 2019
9f299fe
compiler fixes
Kevin-P-Kerr Jun 13, 2019
bc3b636
more config
Kevin-P-Kerr Jun 14, 2019
408c011
add params
Kevin-P-Kerr Jun 14, 2019
e7cb43d
making progress
Kevin-P-Kerr Jun 14, 2019
cf6bbe8
make our ext more exty
Kevin-P-Kerr Jun 14, 2019
61f72b3
start making responses
Kevin-P-Kerr Jun 14, 2019
d9b8c59
more logic
Kevin-P-Kerr Jun 15, 2019
c6e5f55
fix compilation errors
Kevin-P-Kerr Jun 15, 2019
a57cfde
can we just nil this out?
Kevin-P-Kerr Jun 15, 2019
1707d8a
augment our json
Kevin-P-Kerr Jun 17, 2019
6d3a72e
radically simplify our json
Kevin-P-Kerr Jun 17, 2019
e1efc38
fix errs
Kevin-P-Kerr Jun 17, 2019
0a25607
infer the bid type
Kevin-P-Kerr Jun 17, 2019
856f3ab
fix syntax
Kevin-P-Kerr Jun 17, 2019
c46c510
fix comilation errors
Kevin-P-Kerr Jun 17, 2019
f49c552
rename
Kevin-P-Kerr Jun 17, 2019
7bd8bb0
fix compilation error
Kevin-P-Kerr Jun 17, 2019
2a6c2be
config stuff
Kevin-P-Kerr Jun 17, 2019
dae5782
simplify params
Kevin-P-Kerr Jun 17, 2019
b1aa20d
more config stuff
Kevin-P-Kerr Jun 17, 2019
796ab7a
fixes
Kevin-P-Kerr Jun 17, 2019
d2d8a8a
revert this
Kevin-P-Kerr Jun 17, 2019
02f1073
fix up the extension
Kevin-P-Kerr Jun 17, 2019
7d9df4d
getting closer
Kevin-P-Kerr Jun 17, 2019
a835c6c
add a test
Kevin-P-Kerr Jun 17, 2019
eabff67
update config
Kevin-P-Kerr Jun 18, 2019
645879d
update bidder params
Kevin-P-Kerr Jun 18, 2019
68abbf9
add the floor here, too
Kevin-P-Kerr Jun 18, 2019
3de38ec
add a usersync test
Kevin-P-Kerr Jun 18, 2019
248a2b8
validation, ws, and a test
Kevin-P-Kerr Jun 18, 2019
22acdce
update tests
Kevin-P-Kerr Jun 18, 2019
951dcf4
fix test
Kevin-P-Kerr Jun 18, 2019
9c75da6
update email
Kevin-P-Kerr Jun 18, 2019
3d8635a
why not
Kevin-P-Kerr Jun 18, 2019
1160d94
change email
Kevin-P-Kerr Jun 19, 2019
0b59aa4
preprocess requests
Kevin-P-Kerr Jun 26, 2019
d14a353
do some parsing
Kevin-P-Kerr Jun 26, 2019
67f241c
take care of some errors
Kevin-P-Kerr Jun 26, 2019
863a2c5
floor is optional
Kevin-P-Kerr Jun 26, 2019
0955972
ws
Kevin-P-Kerr Jul 2, 2019
7a1d044
remove native
Kevin-P-Kerr Jul 2, 2019
f763064
everything is either banner or video
Kevin-P-Kerr Jul 2, 2019
1e7b6ab
Merge pull request #1 from triplelift/triplelift-dev-work
Kevin-P-Kerr Jul 8, 2019
10b2a2d
Merge branch 'master' of github.com:prebid/prebid-server
Kevin-P-Kerr Jul 8, 2019
f6183ff
this should be a float
Kevin-P-Kerr Jul 10, 2019
8b2706b
floor to floor
Kevin-P-Kerr Jul 11, 2019
df5fbc8
fix compilation errors
Kevin-P-Kerr Jul 11, 2019
21d9526
add some tests
Kevin-P-Kerr Jul 11, 2019
edda36e
more tests
Kevin-P-Kerr Jul 11, 2019
d63b2fd
more tests
Kevin-P-Kerr Jul 11, 2019
121efee
simplify
Kevin-P-Kerr Jul 11, 2019
0212e67
more progress
Kevin-P-Kerr Jul 16, 2019
04063ae
format
Kevin-P-Kerr Jul 16, 2019
3a35776
ws
Kevin-P-Kerr Jul 16, 2019
4d47460
rm
Kevin-P-Kerr Jul 16, 2019
b1219c3
don't need this
Kevin-P-Kerr Jul 16, 2019
da4664b
fix test
Kevin-P-Kerr Jul 16, 2019
8d64ae3
fix test
Kevin-P-Kerr Jul 16, 2019
8a0a65b
Merge pull request #2 from triplelift/add-tests-tl
Kevin-P-Kerr Jul 16, 2019
6e5024f
don't ignore swap
Kevin-P-Kerr Jul 17, 2019
9256e07
Merge branch 'add-tests-tl'
Kevin-P-Kerr Jul 17, 2019
329cbc1
Merge remote-tracking branch 'origin/master' into HEAD
Kevin-P-Kerr Jul 17, 2019
88e4261
change line back
Kevin-P-Kerr Jul 23, 2019
7898b4e
report an error if there are no valid impressions for triplelift
Kevin-P-Kerr Jul 23, 2019
f83bdab
check for either a Banner or Video object on the impression
Kevin-P-Kerr Jul 23, 2019
45f6749
more tests
Kevin-P-Kerr Aug 2, 2019
7feeb75
mv
Kevin-P-Kerr Aug 2, 2019
f21041d
more tests
Kevin-P-Kerr Aug 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions adapters/triplelift/triplelift.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package triplelift

import (
"encoding/json"
"fmt"
"net/http"

"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
)

type TripleliftAdapter struct {
endpoint string
}

type TripleliftInnerExt struct {
Format int `json:"format"`
}

type TripleliftRespExt struct {
Triplelift TripleliftInnerExt `json:"triplelift_pb"`
}

func getBidType(ext TripleliftRespExt) openrtb_ext.BidType {
t := ext.Triplelift.Format
if t == 11 {
return openrtb_ext.BidTypeVideo
}
return openrtb_ext.BidTypeBanner
}

func processImp(imp *openrtb.Imp) error {
// get the triplelift extension
var ext adapters.ExtImpBidder
var tlext openrtb_ext.ExtImpTriplelift
if err := json.Unmarshal(imp.Ext, &ext); err != nil {
return err
}
if err := json.Unmarshal(ext.Bidder, &tlext); err != nil {
return err
}
if imp.Banner == nil && imp.Video == nil {
return fmt.Errorf("neither Banner nor Video object specified")
}
guscarreon marked this conversation as resolved.
Show resolved Hide resolved
imp.TagID = tlext.InvCode
guscarreon marked this conversation as resolved.
Show resolved Hide resolved
// floor is optional
if tlext.Floor == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just have if tlext.Floor != nil { imp.BidFloor = *tlext.Floor } as you return nil in either case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good point, that's a bit more parsimonious. but it seems this is already merged. if I have to patch later I'll take this idea and apply it though.

return nil
} else {
imp.BidFloor = *tlext.Floor
}
// no error
return nil
}

func (a *TripleliftAdapter) MakeRequests(request *openrtb.BidRequest, extra *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
errs := make([]error, 0, len(request.Imp)+1)
reqs := make([]*adapters.RequestData, 0, 1)
// copy the request, because we are going to mutate it
tlRequest := *request
// this will contain all the valid impressions
var validImps []openrtb.Imp
// pre-process the imps
for _, imp := range tlRequest.Imp {
guscarreon marked this conversation as resolved.
Show resolved Hide resolved
if err := processImp(&imp); err == nil {
validImps = append(validImps, imp)
} else {
errs = append(errs, err)
}
}
if len(validImps) == 0 {
err := fmt.Errorf("No valid impressions for triplelift")
errs = append(errs, err)
return nil, errs
}
tlRequest.Imp = validImps
reqJSON, err := json.Marshal(tlRequest)
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")
ad := a.endpoint
reqs = append(reqs, &adapters.RequestData{
Method: "POST",
Uri: ad,
Body: reqJSON,
Headers: headers})
return reqs, errs
}

func getBidCount(bidResponse openrtb.BidResponse) int {
c := 0
for _, sb := range bidResponse.SeatBid {
c = c + len(sb.Bid)
}
return c
}

func (a *TripleliftAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if response.StatusCode == http.StatusNoContent {
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{fmt.Errorf("Unexpected status code: %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{err}
}
var errs []error
count := getBidCount(bidResp)
bidResponse := adapters.NewBidderResponseWithBidsCapacity(count)

for _, sb := range bidResp.SeatBid {
for i := 0; i < len(sb.Bid); i++ {
bid := sb.Bid[i]
var bidExt TripleliftRespExt
if err := json.Unmarshal(bid.Ext, &bidExt); err != nil {
errs = append(errs, err)
} else {
bidType := getBidType(bidExt)
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
})
}
}
}
return bidResponse, errs
}

func NewTripleliftBidder(client *http.Client, endpoint string) *TripleliftAdapter {
return &TripleliftAdapter{
endpoint: endpoint}
}
10 changes: 10 additions & 0 deletions adapters/triplelift/triplelift_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package triplelift

import (
"github.com/prebid/prebid-server/adapters/adapterstest"
"testing"
)

func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "triplelifttest", NewTripleliftBidder(nil, "http://tlx.3lift.net/s2s/auction?supplier_id=19"))
}
66 changes: 66 additions & 0 deletions adapters/triplelift/triplelifttest/exemplary/optional-params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"inventoryCode": "foo",
"floor" : 20
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://tlx.3lift.net/s2s/auction?supplier_id=19",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"tagid": "foo",
"bidfloor": 20,
"ext": {
"bidder": {
"inventoryCode": "foo",
"floor" : 20
}
}
}
]
}
},
"mockResponse": {
"status": 204
}
}
]
}
125 changes: 125 additions & 0 deletions adapters/triplelift/triplelifttest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"inventoryCode": "aa"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://tlx.3lift.net/s2s/auction?supplier_id=19",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"tagid" : "aa",
"ext": {
"bidder": {
"inventoryCode": "aa"
}
}
}
]
}
},
"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": [
"triplelift.com"
],
"iurl": "http://nym1-ib.adnxs.com/cr?id=29681110",
"cid": "958",
"crid": "29681110",
"h": 250,
"w": 300,
"ext": {
"triplelift_pb": {
"format" : 2
}
}
}
]
}
],
"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": [
"triplelift.com"
],
"iurl": "http://nym1-ib.adnxs.com/cr?id=29681110",
"cid": "958",
"crid": "29681110",
"w": 300,
"h": 250,
"ext": {
"triplelift_pb": {
"format" : 2
}
}
},
"type": "banner"
}
]
}
]
}
Loading