-
Notifications
You must be signed in to change notification settings - Fork 766
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
New Adapter: Aax #2219
New Adapter: Aax #2219
Changes from 1 commit
57f2265
325b7b6
d4bc060
6a06759
05828be
a54803e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,121 @@ | ||||
package aax | ||||
|
||||
import ( | ||||
"encoding/json" | ||||
"fmt" | ||||
"net/http" | ||||
"net/url" | ||||
|
||||
"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, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||||
var errs []error | ||||
|
||||
reqJson, 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") | ||||
|
||||
return []*adapters.RequestData{{ | ||||
Method: "POST", | ||||
Uri: a.endpoint, | ||||
Body: reqJson, | ||||
Headers: headers, | ||||
}}, errs | ||||
} | ||||
|
||||
func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||||
var errs []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{&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} | ||||
} | ||||
|
||||
bidResponse := adapters.NewBidderResponse() | ||||
|
||||
for _, sb := range bidResp.SeatBid { | ||||
for i := range sb.Bid { | ||||
bidType, err := getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp) | ||||
if err != nil { | ||||
errs = append(errs, err) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test case for this error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added, Thanks. |
||||
} else { | ||||
b := &adapters.TypedBid{ | ||||
Bid: &sb.Bid[i], | ||||
BidType: bidType, | ||||
} | ||||
bidResponse.Bids = append(bidResponse.Bids, b) | ||||
} | ||||
} | ||||
} | ||||
return bidResponse, errs | ||||
} | ||||
|
||||
// Builder builds a new instance of the Aax adapter for the given bidder with the given config. | ||||
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { | ||||
url := buildEndpoint(config.Endpoint, config.ExtraAdapterInfo) | ||||
return &adapter{ | ||||
endpoint: url, | ||||
}, nil | ||||
} | ||||
|
||||
func getMediaTypeForImp(impID string, imps []openrtb2.Imp) (openrtb_ext.BidType, error) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed this PR with a team. There is one thing for you to consider. I case if imp has multi format this function may return incorrect bid type. We recommend to extract mediaType from response. Here is the example for reference: prebid-server/adapters/algorix/algorix.go Line 190 in 74d2199
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other than this this PR loos good to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Want to second what @VeronikaSolovei9 stated above. This PR also looks good to me, but just want to bring up this update. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, Thanks ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not really what is needed. You need to pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted, Let me fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused, did you change it? I'm looking for something like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No No, Have not pushed anything yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I have pushed the changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, it looks good now, thank you for the update! |
||||
mediaType := openrtb_ext.BidTypeBanner | ||||
for _, imp := range imps { | ||||
if imp.ID == impID { | ||||
if imp.Banner == nil && imp.Video != nil { | ||||
mediaType = openrtb_ext.BidTypeVideo | ||||
} | ||||
return mediaType, nil | ||||
} | ||||
} | ||||
|
||||
return "", &errortypes.BadInput{ | ||||
Message: fmt.Sprintf("Failed to find impression \"%s\" ", impID), | ||||
} | ||||
} | ||||
|
||||
func buildEndpoint(aaxUrl, hostUrl string) string { | ||||
|
||||
if len(hostUrl) == 0 { | ||||
return aaxUrl | ||||
} | ||||
urlObject, err := url.Parse(aaxUrl) | ||||
if err != nil { | ||||
return aaxUrl | ||||
} | ||||
values := urlObject.Query() | ||||
values.Add("src", hostUrl) | ||||
urlObject.RawQuery = values.Encode() | ||||
return urlObject.String() | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package aax | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"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.BidderAax, config.Adapter{ | ||
Endpoint: "https://example.aax.media/rtb/prebid", | ||
ExtraAdapterInfo: "http://localhost:8080/extrnal_url", | ||
}) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "aaxtest", bidder) | ||
} | ||
|
||
func TestEndpointTemplateMalformed(t *testing.T) { | ||
_, buildErr := Builder(openrtb_ext.BidderAax, config.Adapter{ | ||
Endpoint: "{{Malformed}}"}) | ||
|
||
assert.Nil(t, buildErr) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "1", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 320, | ||
"h": 50 | ||
} | ||
] | ||
}, | ||
"video": { | ||
"mimes": [ | ||
"video/mp4" | ||
], | ||
"protocols": [ | ||
2, | ||
5 | ||
], | ||
"w": 320, | ||
"h": 480 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"cid": "TCID", | ||
"crid": "1234" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "https://example.aax.media/rtb/prebid?src=http%3A%2F%2Flocalhost%3A8080%2Fextrnal_url", | ||
"body": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "1", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 320, | ||
"h": 50 | ||
} | ||
] | ||
}, | ||
"video": { | ||
"mimes": [ | ||
"video/mp4" | ||
], | ||
"protocols": [ | ||
2, | ||
5 | ||
], | ||
"w": 320, | ||
"h": 480 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"cid": "TCID", | ||
"crid": "1234" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 204, | ||
"body": "" | ||
} | ||
} | ||
], | ||
"expectedBidResponses": [] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "1", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 320, | ||
"h": 50 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"cid": "TCID", | ||
"crid": "1234" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "2", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 50 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"cid": "TCID", | ||
"crid": "1234" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "https://example.aax.media/rtb/prebid?src=http%3A%2F%2Flocalhost%3A8080%2Fextrnal_url", | ||
"body": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "1", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 320, | ||
"h": 50 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"cid": "TCID", | ||
"crid": "1234" | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "2", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 50 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"cid": "TCID", | ||
"crid": "1234" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "test-request-id", | ||
"seatbid": [ | ||
{ | ||
"seat": "aax", | ||
"bid": [ | ||
{ | ||
"id": "test-bid-id", | ||
"impid": "1", | ||
"price": 1.50, | ||
"adm": "some-test-ad", | ||
"crid": "test-crid", | ||
"h": 50, | ||
"w": 320 | ||
} | ||
] | ||
} | ||
], | ||
"cur": "USD" | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses": [ | ||
{ | ||
"currency": "USD", | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "test-bid-id", | ||
"impid": "1", | ||
"price": 1.50, | ||
"adm": "some-test-ad", | ||
"crid": "test-crid", | ||
"w": 320, | ||
"h": 50 | ||
}, | ||
"type": "banner" | ||
} | ||
] | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: could you rename
sb
to beseatBid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.