-
Notifications
You must be signed in to change notification settings - Fork 750
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: FeedAd #4104
Open
andwun
wants to merge
4
commits into
prebid:master
Choose a base branch
from
andwun:feedad-pbs-adapter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New Adapter: FeedAd #4104
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0b0bf7b
Import initial version of FeedAd PBS adapter
andwun 67f84c8
static.bidder-info: feedad.yaml: Added GPP macros to user sync URL
andwun 29a94e9
adapters.feedad.feedadtest.exemplary: s/banner-web.json/banner-site.j…
andwun 842aee5
adapters.feedad: params_test.go: Updated tests to match Prebid template
andwun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,105 @@ | ||
package feedad | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/prebid/openrtb/v20/openrtb2" | ||
"github.com/prebid/prebid-server/v3/adapters" | ||
"github.com/prebid/prebid-server/v3/config" | ||
"github.com/prebid/prebid-server/v3/errortypes" | ||
"github.com/prebid/prebid-server/v3/openrtb_ext" | ||
"github.com/prebid/prebid-server/v3/util/jsonutil" | ||
) | ||
|
||
const feedAdAdapterVersion = "1.0.0" | ||
|
||
func getHeaders(request *openrtb2.BidRequest) http.Header { | ||
headers := http.Header{} | ||
headers.Add("Accept", "application/json") | ||
headers.Add("Content-Type", "application/json;charset=utf-8") | ||
headers.Add("X-FA-PBS-Adapter-Version", feedAdAdapterVersion) | ||
headers.Add("X-Openrtb-Version", "2.5") | ||
|
||
if request.Device != nil { | ||
if len(request.Device.IPv6) > 0 { | ||
headers.Add("X-Forwarded-For", request.Device.IPv6) | ||
} | ||
|
||
if len(request.Device.IP) > 0 { | ||
headers.Add("X-Forwarded-For", request.Device.IP) | ||
} | ||
} | ||
|
||
return headers | ||
} | ||
|
||
type adapter struct { | ||
endpoint string | ||
} | ||
|
||
func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *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 | ||
err := jsonutil.Unmarshal(responseData.Body, &response) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(internalRequest.Imp)) | ||
bidResponse.Currency = response.Cur | ||
|
||
for _, seatBid := range response.SeatBid { | ||
for i := range seatBid.Bid { | ||
bidResponse.Bids = append( | ||
bidResponse.Bids, | ||
&adapters.TypedBid{ | ||
Bid: &seatBid.Bid[i], | ||
BidType: openrtb_ext.BidTypeBanner, | ||
}, | ||
) | ||
} | ||
} | ||
|
||
return bidResponse, nil | ||
} | ||
|
||
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
requestBody, err := jsonutil.Marshal(request) | ||
if err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
requestData := &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: a.endpoint, | ||
Body: requestBody, | ||
Headers: getHeaders(request), | ||
ImpIDs: openrtb_ext.GetImpIDs(request.Imp), | ||
} | ||
return []*adapters.RequestData{requestData}, nil | ||
} | ||
|
||
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (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,25 @@ | ||
package feedad | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/v3/adapters/adapterstest" | ||
"github.com/prebid/prebid-server/v3/config" | ||
"github.com/prebid/prebid-server/v3/openrtb_ext" | ||
) | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder( | ||
openrtb_ext.BidderFeedAd, | ||
config.Adapter{ | ||
Endpoint: "https://ortb.feedad.com/1/prebid/requests", | ||
}, | ||
config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}, | ||
) | ||
|
||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error: %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, "feedadtest", bidder) | ||
} |
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,161 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "some-request-id", | ||
"device": { | ||
"ua": "test-user-agent", | ||
"ip": "123.123.123.123", | ||
"language": "en", | ||
"dnt": 0 | ||
}, | ||
"tmax": 1000, | ||
"user": { | ||
"buyeruid": "awesome-user" | ||
}, | ||
"app": { | ||
"publisher": { | ||
"id": "123456789" | ||
}, | ||
"cat": [ | ||
"IAB22-1" | ||
], | ||
"bundle": "com.app.awesome", | ||
"name": "Awesome App", | ||
"domain": "awesomeapp.com", | ||
"id": "123456789" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "1", | ||
"tagid": "ogTAGID", | ||
"banner": { | ||
"w": 320, | ||
"h": 50 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"clientToken": "some-client-token", | ||
"placementId": "some-placement-id" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"headers": { | ||
"Accept": [ | ||
"application/json" | ||
], | ||
"Content-Type": [ | ||
"application/json;charset=utf-8" | ||
], | ||
"X-Fa-Pbs-Adapter-Version": [ | ||
"1.0.0" | ||
], | ||
"X-Forwarded-For": [ | ||
"123.123.123.123" | ||
], | ||
"X-Openrtb-Version": [ | ||
"2.5" | ||
] | ||
}, | ||
"uri": "https://ortb.feedad.com/1/prebid/requests", | ||
"body": { | ||
"id": "some-request-id", | ||
"device": { | ||
"ua": "test-user-agent", | ||
"ip": "123.123.123.123", | ||
"language": "en", | ||
"dnt": 0 | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "1", | ||
"banner": { | ||
"w": 320, | ||
"h": 50 | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"clientToken": "some-client-token", | ||
"placementId": "some-placement-id" | ||
} | ||
}, | ||
"tagid": "ogTAGID" | ||
} | ||
], | ||
"app": { | ||
"id": "123456789", | ||
"name": "Awesome App", | ||
"bundle": "com.app.awesome", | ||
"domain": "awesomeapp.com", | ||
"cat": [ | ||
"IAB22-1" | ||
], | ||
"publisher": { | ||
"id": "123456789" | ||
} | ||
}, | ||
"user": { | ||
"buyeruid": "awesome-user" | ||
}, | ||
"tmax": 1000 | ||
}, | ||
"impIDs": [ | ||
"1" | ||
] | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "awesome-resp-id", | ||
"seatbid": [ | ||
{ | ||
"bid": [ | ||
{ | ||
"id": "a3ae1b4e2fc24a4fb45540082e98e161", | ||
"impid": "1", | ||
"price": 3.5, | ||
"adm": "awesome-markup", | ||
"adomain": [ | ||
"awesome.com" | ||
], | ||
"crid": "20", | ||
"w": 320, | ||
"h": 50, | ||
"mtype": 1 | ||
} | ||
], | ||
"type": "banner", | ||
"seat": "escalax" | ||
} | ||
], | ||
"cur": "USD" | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses": [ | ||
{ | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "a3ae1b4e2fc24a4fb45540082e98e161", | ||
"impid": "1", | ||
"price": 3.5, | ||
"adm": "awesome-markup", | ||
"adomain": [ | ||
"awesome.com" | ||
], | ||
"crid": "20", | ||
"w": 320, | ||
"h": 50, | ||
"mtype": 1 | ||
}, | ||
"type": "banner" | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are you able to support OpenRTB 2.6 instead?
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.
I’m afraid, we don’t have support for oRTB 2.6, yet, but it’s on our roadmap for next year.
Can we please start with oRTB 2.5 for now?