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.
New Adapter: Interactive Offers (prebid#1835)
- Loading branch information
1 parent
e16b746
commit 6c5d09e
Showing
17 changed files
with
878 additions
and
241 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,79 @@ | ||
package interactiveoffers | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/mxmCherry/openrtb/v15/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" | ||
) | ||
|
||
type adapter struct { | ||
endpoint string | ||
} | ||
|
||
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
requestJSON, err := json.Marshal(request) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
requestData := &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: a.endpoint, | ||
Body: requestJSON, | ||
} | ||
|
||
return []*adapters.RequestData{requestData}, nil | ||
} | ||
|
||
func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
if responseData.StatusCode == http.StatusNoContent { | ||
return nil, nil | ||
} | ||
|
||
if responseData.StatusCode == http.StatusBadRequest { | ||
err := &errortypes.BadInput{ | ||
Message: "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.", | ||
} | ||
return nil, []error{err} | ||
} | ||
|
||
if responseData.StatusCode != http.StatusOK { | ||
err := &errortypes.BadServerResponse{ | ||
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", responseData.StatusCode), | ||
} | ||
return nil, []error{err} | ||
} | ||
|
||
var response openrtb2.BidResponse | ||
if err := json.Unmarshal(responseData.Body, &response); err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) | ||
bidResponse.Currency = response.Cur | ||
for _, seatBid := range response.SeatBid { | ||
for _, bid := range seatBid.Bid { | ||
bid := bid // pin https://github.com/kyoh86/scopelint#whats-this | ||
b := &adapters.TypedBid{ | ||
Bid: &bid, | ||
BidType: openrtb_ext.BidTypeBanner, | ||
} | ||
bidResponse.Bids = append(bidResponse.Bids, b) | ||
} | ||
} | ||
return bidResponse, nil | ||
} | ||
|
||
// Builder builds a new instance of the Interactiveoffers 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 | ||
} |
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,20 @@ | ||
package interactiveoffers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/adapters/adapterstest" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderInteractiveoffers, config.Adapter{ | ||
Endpoint: "https://rtb.ioadx.com/bidRequest/?partnerId=d9e56d418c4825d466ee96c7a31bf1da6b62fa04"}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "interactiveofferstest", bidder) | ||
} |
136 changes: 136 additions & 0 deletions
136
adapters/interactiveoffers/interactiveofferstest/exemplary/goodmultiplebidrequest.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,136 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"site": { | ||
"page": "https://good.site/url" | ||
}, | ||
"imp": [{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 250 | ||
}] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"pubid": 35 | ||
} | ||
} | ||
},{ | ||
"id": "test-imp-id-2", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 250 | ||
}] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"pubid": 35 | ||
} | ||
} | ||
}] | ||
}, | ||
|
||
"httpCalls": [{ | ||
"expectedRequest": { | ||
"uri": "https://rtb.ioadx.com/bidRequest/?partnerId=d9e56d418c4825d466ee96c7a31bf1da6b62fa04", | ||
"body": { | ||
"id": "test-request-id", | ||
"site": { | ||
"page": "https://good.site/url" | ||
}, | ||
"imp": [{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 250 | ||
}] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"pubid": 35 | ||
} | ||
} | ||
},{ | ||
"id": "test-imp-id-2", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 250 | ||
}] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"pubid": 35 | ||
} | ||
} | ||
}] | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "test-request-id", | ||
"seatbid": [{ | ||
"seat": "interactiveoffers", | ||
"bid": [{ | ||
"id": "randomid", | ||
"impid": "test-imp-id", | ||
"price": 0.500000, | ||
"adid": "12345678", | ||
"adm": "some-test-ad", | ||
"cid": "987", | ||
"crid": "12345678", | ||
"h": 250, | ||
"w": 300 | ||
},{ | ||
"id": "randomid2", | ||
"impid": "test-imp-id-2", | ||
"price": 0.500000, | ||
"adid": "12345678", | ||
"adm": "some-test-ad", | ||
"cid": "987", | ||
"crid": "12345678", | ||
"h": 250, | ||
"w": 300 | ||
}] | ||
}], | ||
"cur": "USD" | ||
} | ||
} | ||
}], | ||
|
||
"expectedBidResponses": [{ | ||
"currency": "USD", | ||
"bids": [{ | ||
"bid": { | ||
"id": "randomid", | ||
"impid": "test-imp-id", | ||
"price": 0.5, | ||
"adm": "some-test-ad", | ||
"adid": "12345678", | ||
"cid": "987", | ||
"crid": "12345678", | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"type": "banner" | ||
},{ | ||
"bid": { | ||
"id": "randomid2", | ||
"impid": "test-imp-id-2", | ||
"price": 0.5, | ||
"adm": "some-test-ad", | ||
"adid": "12345678", | ||
"cid": "987", | ||
"crid": "12345678", | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"type": "banner" | ||
}] | ||
}] | ||
} |
87 changes: 87 additions & 0 deletions
87
adapters/interactiveoffers/interactiveofferstest/exemplary/goodsinglebidrequest.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,87 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"site": { | ||
"page": "https://good.site/url" | ||
}, | ||
"imp": [{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 250 | ||
}] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"pubid": 35 | ||
} | ||
} | ||
}] | ||
}, | ||
|
||
"httpCalls": [{ | ||
"expectedRequest": { | ||
"uri": "https://rtb.ioadx.com/bidRequest/?partnerId=d9e56d418c4825d466ee96c7a31bf1da6b62fa04", | ||
"body": { | ||
"id": "test-request-id", | ||
"site": { | ||
"page": "https://good.site/url" | ||
}, | ||
"imp": [{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 250 | ||
}] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"pubid": 35 | ||
} | ||
} | ||
}] | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "test-request-id", | ||
"seatbid": [{ | ||
"seat": "interactiveoffers", | ||
"bid": [{ | ||
"id": "randomid", | ||
"impid": "test-imp-id", | ||
"price": 0.500000, | ||
"adid": "12345678", | ||
"adm": "some-test-ad", | ||
"cid": "987", | ||
"crid": "12345678", | ||
"h": 250, | ||
"w": 300 | ||
}] | ||
}], | ||
"cur": "USD" | ||
} | ||
} | ||
}], | ||
|
||
"expectedBidResponses": [{ | ||
"currency": "USD", | ||
"bids": [{ | ||
"bid": { | ||
"id": "randomid", | ||
"impid": "test-imp-id", | ||
"price": 0.5, | ||
"adm": "some-test-ad", | ||
"adid": "12345678", | ||
"cid": "987", | ||
"crid": "12345678", | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"type": "banner" | ||
}] | ||
}] | ||
} |
3 changes: 3 additions & 0 deletions
3
adapters/interactiveoffers/interactiveofferstest/params/race/banner.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,3 @@ | ||
{ | ||
"pubid": 35 | ||
} |
55 changes: 55 additions & 0 deletions
55
adapters/interactiveoffers/interactiveofferstest/supplemental/204.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,55 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"site": { | ||
"page": "https://good.site/url" | ||
}, | ||
"imp": [{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 250 | ||
}] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"pubid": 35 | ||
} | ||
} | ||
}] | ||
}, | ||
|
||
"httpCalls": [{ | ||
"expectedRequest": { | ||
"uri": "https://rtb.ioadx.com/bidRequest/?partnerId=d9e56d418c4825d466ee96c7a31bf1da6b62fa04", | ||
"body": { | ||
"id": "test-request-id", | ||
"site": { | ||
"page": "https://good.site/url" | ||
}, | ||
"imp": [{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [{ | ||
"w": 300, | ||
"h": 250 | ||
}] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"pubid": 35 | ||
} | ||
} | ||
}] | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 204, | ||
"body": {} | ||
} | ||
}], | ||
|
||
"expectedBidResponses": [], | ||
"expectedMakeBidsErrors": [] | ||
} |
Oops, something went wrong.