forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Kargo #1
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
Open
ssadman22
wants to merge
23
commits into
master
Choose a base branch
from
kargo
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
Kargo #1
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b969f22
Old boilerplate code
ssadman22 4899a30
Added media types
ssadman22 19ae9e8
added endpoint
ssadman22 e5b3939
unit test template
ssadman22 b4f8545
banner and native jsons
ssadman22 dd96629
tests passing
ssadman22 7575018
yaml fix
ssadman22 ee7d8f5
Update kargo.yaml
ssadman22 9445edc
Update kargo.json
ssadman22 1c7ea9e
spaces
ssadman22 e383063
Merge branch 'kargo' of github.com:KargoGlobal/prebid-server into kargo
ssadman22 2b81c30
replaced placementId with tagid
ssadman22 185ab4b
un-export KargoAdapter to adapter
ssadman22 0bc2b80
Added supplemental tests
ssadman22 cfcc8e5
Add native, remove some fields from test
ssadman22 e9222c9
local is buggy, test in dev
ssadman22 17e5b93
remove redundant return
ssadman22 60f97d6
adSlotId instead of tagId, get mediaType from ext
ssadman22 8a01530
update imp_ext
ssadman22 80de643
lowercase
ssadman22 e841a91
code review
ssadman22 9e371f8
removed some ext
ssadman22 13a9b11
fix json test
ssadman22 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 hidden or 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,89 @@ | ||
| package kargo | ||
|
|
||
| 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 { | ||
| URI string | ||
| } | ||
| type kargoExt struct { | ||
| MediaType string `json:"mediaType"` | ||
| } | ||
|
|
||
| // Builder builds a new instance of the Kargo adapter for the given bidder with the given config. | ||
| func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { | ||
| bidder := &adapter{ | ||
| URI: config.Endpoint, // base url of bidding server | ||
| } | ||
| return bidder, nil | ||
| } | ||
|
|
||
| // MakeRequests creates outgoing requests to the Kargo bidding server. | ||
| 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.URI, | ||
| Body: requestJSON, | ||
| } | ||
|
|
||
| return []*adapters.RequestData{requestData}, nil | ||
| } | ||
|
|
||
| // MakeBids receives a bid response from the Kargo bidding server and creates bids for the publishers auction. | ||
| 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.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 i, bid := range seatBid.Bid { | ||
| b := &adapters.TypedBid{ | ||
| Bid: &seatBid.Bid[i], | ||
| BidType: getMediaTypeForBid(bid.Ext), | ||
| } | ||
| bidResponse.Bids = append(bidResponse.Bids, b) | ||
| } | ||
| } | ||
| return bidResponse, nil | ||
| } | ||
|
|
||
| func getMediaTypeForBid(ext json.RawMessage) openrtb_ext.BidType { | ||
| var impExt kargoExt | ||
| if err := json.Unmarshal(ext, &impExt); err == nil { | ||
| switch impExt.MediaType { | ||
| case string(openrtb_ext.BidTypeVideo): | ||
| return openrtb_ext.BidTypeVideo | ||
| case string(openrtb_ext.BidTypeNative): | ||
| return openrtb_ext.BidTypeNative | ||
| } | ||
| } | ||
| return openrtb_ext.BidTypeBanner | ||
| } |
This file contains hidden or 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 kargo | ||
|
|
||
| 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.BidderKargo, config.Adapter{ | ||
| Endpoint: "http://example.com/bid"}) | ||
|
|
||
| if buildErr != nil { | ||
| t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
| } | ||
|
|
||
| adapterstest.RunJSONBidderTest(t, "kargotest", bidder) | ||
| } |
This file contains hidden or 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,207 @@ | ||
| { | ||
| "mockBidRequest": { | ||
| "id": "5f4d1e01", | ||
| "at": 1, | ||
| "imp": [ | ||
| { | ||
| "id": "8b1bdcca", | ||
| "banner": { | ||
| "w": 300, | ||
| "h": 300, | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ], | ||
| "pos": 0, | ||
| "expdir": [1, 2, 3, 4, 5] | ||
| }, | ||
| "tagid": "73", | ||
| "secure": 1, | ||
| "iframebuster": ["ALL"], | ||
| "ext": { | ||
| "adSlotID": "11523" | ||
| } | ||
| } | ||
| ], | ||
| "site": { | ||
| "id": "123", | ||
| "domain": "www.dailymail.co.uk", | ||
| "cat": ["IAB7"], | ||
| "page": "https://www.dailymail.co.uk/", | ||
| "ref": "https://www.dailymail.co.uk/", | ||
| "mobile": 1, | ||
| "publisher": { | ||
| "id": "1" | ||
| } | ||
| }, | ||
| "device": { | ||
| "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.1 Safari/537", | ||
| "geo": { | ||
| "ipservice": 4, | ||
| "country": "US", | ||
| "region": "CO", | ||
| "metro": "751", | ||
| "city": "SomeCityInCo", | ||
| "zip": "11223" | ||
| }, | ||
| "ip": "127.0.0.1", | ||
| "devicetype": 2, | ||
| "make": "Apple", | ||
| "model": "iPhone", | ||
| "os": "Windows", | ||
| "osv": "10.0", | ||
| "carrier": "none", | ||
| "language": "en", | ||
| "connectiontype": 2, | ||
| "dnt": 0 | ||
| }, | ||
| "user": { | ||
| "id": "07fb48ed", | ||
| "ext": { | ||
| }, | ||
| "buyeruid": "345" | ||
| }, | ||
| "regs": { | ||
| "ext": { | ||
| "us_privacy": "1" | ||
| } | ||
| }, | ||
| "tmax": 200, | ||
| "ext": { | ||
| } | ||
| }, | ||
| "httpCalls": [ | ||
| { | ||
| "expectedRequest": { | ||
| "uri": "http://example.com/bid", | ||
| "body": { | ||
| "id": "5f4d1e01", | ||
| "at": 1, | ||
| "imp": [ | ||
| { | ||
| "id": "8b1bdcca", | ||
| "banner": { | ||
| "w": 300, | ||
| "h": 300, | ||
| "format": [ | ||
| { | ||
| "w": 300, | ||
| "h": 250 | ||
| } | ||
| ], | ||
| "pos": 0, | ||
| "expdir": [1, 2, 3, 4, 5] | ||
| }, | ||
| "tagid": "73", | ||
| "secure": 1, | ||
| "iframebuster": ["ALL"], | ||
| "ext": { | ||
| "adSlotID": "11523" | ||
| } | ||
| } | ||
| ], | ||
| "site": { | ||
| "id": "123", | ||
| "domain": "www.dailymail.co.uk", | ||
| "cat": ["IAB7"], | ||
| "page": "https://www.dailymail.co.uk/", | ||
| "ref": "https://www.dailymail.co.uk/", | ||
| "mobile": 1, | ||
| "publisher": { | ||
| "id": "1" | ||
| } | ||
| }, | ||
| "device": { | ||
| "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.1 Safari/537", | ||
| "geo": { | ||
| "ipservice": 4, | ||
| "country": "US", | ||
| "region": "CO", | ||
| "metro": "751", | ||
| "city": "SomeCityInCo", | ||
| "zip": "11223" | ||
| }, | ||
| "ip": "127.0.0.1", | ||
| "devicetype": 2, | ||
| "make": "Apple", | ||
| "model": "iPhone", | ||
| "os": "Windows", | ||
| "osv": "10.0", | ||
| "carrier": "none", | ||
| "language": "en", | ||
| "connectiontype": 2, | ||
| "dnt": 0 | ||
| }, | ||
| "user": { | ||
| "id": "07fb48ed", | ||
| "ext": { | ||
| }, | ||
| "buyeruid": "345" | ||
| }, | ||
| "regs": { | ||
| "ext": { | ||
| "us_privacy": "1" | ||
| } | ||
| }, | ||
| "tmax": 200, | ||
| "ext": { | ||
| } | ||
| } | ||
| }, | ||
| "mockResponse": { | ||
| "status": 200, | ||
| "body": { | ||
| "id": "5f4d1e01", | ||
| "seatbid": [ | ||
| { | ||
| "bid": [ | ||
| { | ||
| "id": "67sadsac", | ||
| "impid": "8b1bdcca", | ||
| "price": 10, | ||
| "nurl": "http://example.com/win/10", | ||
| "adm": "<div>ad</div>", | ||
| "adomain": ["example.com"], | ||
| "cid": "test-cid", | ||
| "crid": "test-crid", | ||
| "cat": ["IAB13"], | ||
| "w": 300, | ||
| "h": 300, | ||
| "ext": {"mediaType": "banner"} | ||
|
Author
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 will now be sending the |
||
| } | ||
| ], | ||
| "seat": "_b345" | ||
| } | ||
| ], | ||
| "bidid": "67sadsac", | ||
| "cur": "USD" | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "expectedBidResponses": [ | ||
| { | ||
| "bids": [ | ||
| { | ||
| "bid": { | ||
| "id": "67sadsac", | ||
| "impid": "8b1bdcca", | ||
| "price": 10, | ||
| "nurl": "http://example.com/win/10", | ||
| "adm": "<div>ad</div>", | ||
| "adomain": ["example.com"], | ||
| "cid": "test-cid", | ||
| "crid": "test-crid", | ||
| "cat": ["IAB13"], | ||
| "w": 300, | ||
| "h": 300, | ||
| "ext": {"mediaType": "banner"} | ||
| }, | ||
| "type": "banner" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Each impression will have an
Imp.Ext.adSlotIDand aImp.tagid. Since theadSlotIDis now required by Prebid S2S, Kraken can check this instead of appending"siteID" + . + "tagId"as shown here for Prebid requests: