Skip to content

Commit

Permalink
ImproveDigital adapter: (#887)
Browse files Browse the repository at this point in the history
- Add support for video
 - Add support for mobile/app
 - Add support for multibid responses
 - Extend optional parameters
  • Loading branch information
improve-prebid-dev authored and hhhjort committed May 29, 2019
1 parent c022572 commit f8261a6
Show file tree
Hide file tree
Showing 19 changed files with 774 additions and 12 deletions.
59 changes: 52 additions & 7 deletions adapters/improvedigital/improvedigital.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
)

type ImprovedigitalAdapter struct {
Expand Down Expand Up @@ -58,15 +59,36 @@ func (a *ImprovedigitalAdapter) MakeBids(internalRequest *openrtb.BidRequest, ex
return nil, []error{err}
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(1)
if len(bidResp.SeatBid) == 0 {
return nil, nil
}

if len(bidResp.SeatBid) > 1 {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Unexpected SeatBid! Must be only one but have: %d", len(bidResp.SeatBid)),
}}
}

seatBid := bidResp.SeatBid[0]

if len(seatBid.Bid) == 0 {
return nil, nil
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(seatBid.Bid))

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: "banner",
})
for i := range seatBid.Bid {
bid := seatBid.Bid[i]

bidType, err := getMediaTypeForImp(bid.ImpID, internalRequest.Imp)
if err != nil {
return nil, []error{err}
}

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
})
}
return bidResponse, nil

Expand All @@ -78,3 +100,26 @@ func NewImprovedigitalBidder(endpoint string) *ImprovedigitalAdapter {
endpoint: endpoint,
}
}

func getMediaTypeForImp(impID string, imps []openrtb.Imp) (openrtb_ext.BidType, error) {
for _, imp := range imps {
if imp.ID == impID {
if imp.Banner != nil {
return openrtb_ext.BidTypeBanner, nil
}

if imp.Video != nil {
return openrtb_ext.BidTypeVideo, nil
}

return "", &errortypes.BadServerResponse{
Message: fmt.Sprintf("Unknown impression type for ID: \"%s\"", impID),
}
}
}

// This shouldnt happen. Lets handle it just incase by returning an error.
return "", &errortypes.BadServerResponse{
Message: fmt.Sprintf("Failed to find impression for ID: \"%s\"", impID),
}
}
152 changes: 152 additions & 0 deletions adapters/improvedigital/improvedigitaltest/exemplary/app-multi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"id": "appID",
"publisher": {
"id": "uniq_pub_id"
}
},
"device":{
"ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
},
"imp": [{
"id": "test-imp-id-banner",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {
"placementId": 13245
}
}
},
{
"id": "test-imp-id-video",
"video": {
"mimes": ["video/mp4"],
"protocols": [2, 5],
"w": 1920,
"h": 1080
},
"ext": {
"bidder": {
"placementId": 13244
}
}
}
]
},

"httpCalls": [{
"expectedRequest": {
"uri": "http://localhost/pbs",
"body": {
"id": "test-request-id",
"app": {
"id": "appID",
"publisher": {
"id": "uniq_pub_id"
}
},
"device":{
"ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
},
"imp": [{
"id": "test-imp-id-banner",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {
"placementId": 13245
}
}
},
{
"id": "test-imp-id-video",
"video": {
"mimes": ["video/mp4"],
"protocols": [2, 5],
"w": 1920,
"h": 1080
},
"ext": {
"bidder": {
"placementId": 13244
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"seat": "improvedigital",
"bid": [{
"id": "randomid1",
"impid": "test-imp-id-banner",
"price": 0.500000,
"adid": "12345678",
"adm": "some-test-ad-html",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300
},
{
"id": "randomid2",
"impid": "test-imp-id-video",
"price": 0.500000,
"adm": "some-test-ad-vast",
"crid": "1234567",
"w": 1920,
"h": 1080
}
]
}],
"cur": "USD"
}
}
}],

"expectedBidResponses": [{
"currency": "USD",
"bids": [{
"bid": {
"id": "randomid1",
"impid": "test-imp-id-banner",
"price": 0.5,
"adm": "some-test-ad-html",
"adid": "12345678",
"cid": "987",
"crid": "12345678",
"w": 300,
"h": 250
},
"type": "banner"
},
{
"bid": {
"id": "randomid2",
"impid": "test-imp-id-video",
"price": 0.5,
"adm": "some-test-ad-vast",
"crid": "1234567",
"w": 1920,
"h": 1080
},
"type": "video"
}
]
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
},
"imp": [{
"id": "test-imp-id",
"pid": 123,
"banner": {
"format": [{
"w": 300,
Expand Down
156 changes: 156 additions & 0 deletions adapters/improvedigital/improvedigitaltest/exemplary/site-multi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"mockBidRequest": {
"id": "test-request-id",
"site": {
"page": "https://good.site/url",
"domain": "good.site",
"publisher": {
"id": "uniq_pub_id"
},
"keywords": "omgword",
"ext": {
"amp": 0
}
},
"imp": [{
"id": "test-imp-id-banner",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {
"placementId": 13245
}
}
},
{
"id": "test-imp-id-video",
"video": {
"mimes": ["video/mp4"],
"protocols": [2, 5],
"w": 1920,
"h": 1080
},
"ext": {
"bidder": {
"placementId": 13244
}
}
}
]
},

"httpCalls": [{
"expectedRequest": {
"uri": "http://localhost/pbs",
"body": {
"id": "test-request-id",
"site": {
"page": "https://good.site/url",
"domain": "good.site",
"publisher": {
"id": "uniq_pub_id"
},
"keywords": "omgword",
"ext": {
"amp": 0
}
},
"imp": [{
"id": "test-imp-id-banner",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {
"placementId": 13245
}
}
},
{
"id": "test-imp-id-video",
"video": {
"mimes": ["video/mp4"],
"protocols": [2, 5],
"w": 1920,
"h": 1080
},
"ext": {
"bidder": {
"placementId": 13244
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"seat": "improvedigital",
"bid": [{
"id": "randomid1",
"impid": "test-imp-id-banner",
"price": 0.500000,
"adid": "12345678",
"adm": "some-test-ad-html",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300
},
{
"id": "randomid2",
"impid": "test-imp-id-video",
"price": 0.500000,
"adm": "some-test-ad-vast",
"crid": "1234567",
"w": 1920,
"h": 1080
}
]
}],
"cur": "USD"
}
}
}],

"expectedBidResponses": [{
"currency": "USD",
"bids": [{
"bid": {
"id": "randomid1",
"impid": "test-imp-id-banner",
"price": 0.5,
"adm": "some-test-ad-html",
"adid": "12345678",
"cid": "987",
"crid": "12345678",
"w": 300,
"h": 250
},
"type": "banner"
},
{
"bid": {
"id": "randomid2",
"impid": "test-imp-id-video",
"price": 0.5,
"adm": "some-test-ad-vast",
"crid": "1234567",
"w": 1920,
"h": 1080
},
"type": "video"
}
]
}]
}
Loading

0 comments on commit f8261a6

Please sign in to comment.