Skip to content
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

Update gamma adapter #1447

Merged
merged 36 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ebfddaf
Gamma SSP Adapter
gammassp Jun 21, 2019
48a4ae8
increase coverage
gammassp Jun 21, 2019
19a323d
Merge branch 'master' into master
gammassp Jun 25, 2019
6a49d48
Fix conflict with base master
gammassp Jun 25, 2019
1ecf5cf
Add check MediaType for Imp
gammassp Jun 26, 2019
1f482af
Implement Multi Imps request
gammassp Jul 11, 2019
72c5102
Merge branch 'master' into master
gammassp Jul 11, 2019
a64d2f2
Changes requested
gammassp Jul 16, 2019
3cd5d28
remove bad-request
gammassp Jul 19, 2019
004932b
increase coverage
gammassp Aug 8, 2019
69f75cf
Remove duplicate test file
gammassp Aug 8, 2019
258033f
Update gamma.go
gammassp Aug 8, 2019
8e30e21
Update gamma.go
gammassp Aug 19, 2019
1007985
Update gamma.go
gammassp Aug 30, 2019
74aa93d
Merge remote-tracking branch 'upstream/master'
gammassp Sep 23, 2019
8f78d35
Update config.go
gammassp Sep 27, 2019
e63270f
Gamma SSP Adapter
gammassp Jun 21, 2019
35d2b79
increase coverage
gammassp Jun 21, 2019
9ed3772
Fix conflict with base master
gammassp Jun 25, 2019
fb325ce
Add check MediaType for Imp
gammassp Jun 26, 2019
cfdae81
Implement Multi Imps request
gammassp Jul 11, 2019
787dd29
Changes requested
gammassp Jul 16, 2019
7b4a844
remove bad-request
gammassp Jul 19, 2019
aada526
increase coverage
gammassp Aug 8, 2019
8a6504b
Remove duplicate test file
gammassp Aug 8, 2019
9c968d5
Update gamma.go
gammassp Aug 19, 2019
792c979
Update gamma.go
gammassp Aug 30, 2019
bea96a9
Merge branch 'master' of https://github.com/gammassp/prebid-server
gammassp Aug 10, 2020
af59031
update gamma adapter
gammassp Aug 19, 2020
4a9ab00
return nil when have No-Bid Signaling
gammassp Aug 19, 2020
6657dc4
add missing-adm.json
gammassp Aug 20, 2020
4fa8705
discard the bid that's missing adm
ezlifega Aug 25, 2020
436030e
discard the bid that's missing adm
gammassp Aug 25, 2020
68f174e
Merge branch 'master' of https://github.com/gammassp/prebid-server
gammassp Aug 25, 2020
bd8d4f8
escape vast instead of encoded it
gammassp Aug 25, 2020
d2ce9a6
expand test coverage
gammassp Aug 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 63 additions & 9 deletions adapters/gamma/gamma.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ import (
type GammaAdapter struct {
URI string
}
type gammaBid struct {
gammassp marked this conversation as resolved.
Show resolved Hide resolved
openrtb.Bid //base
VastXML string `json:"vastXml,omitempty"`
VastURL string `json:"vastUrl,omitempty"`
}

type gammaSeatBid struct {
Bid []gammaBid `json:"bid"`
Group int8 `json:"group,omitempty"`
Ext json.RawMessage `json:"ext,omitempty"`
}
type gammaBidResponse struct {
ID string `json:"id"`
SeatBid []gammaSeatBid `json:"seatbid,omitempty"`
BidID string `json:"bidid,omitempty"`
Cur string `json:"cur,omitempty"`
CustomData string `json:"customdata,omitempty"`
NBR *openrtb.NoBidReasonCode `json:"nbr,omitempty"`
Ext json.RawMessage `json:"ext,omitempty"`
}

func checkParams(gammaExt openrtb_ext.ExtImpGamma) error {
if gammaExt.PartnerID == "" {
Expand Down Expand Up @@ -180,6 +200,28 @@ func (a *GammaAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapte
return adapterRequests, errs
}

func convertBid(gBid gammaBid, mediaType openrtb_ext.BidType) *openrtb.Bid {
var bid openrtb.Bid
bid = gBid.Bid

if mediaType == openrtb_ext.BidTypeVideo {
//Return inline VAST XML Document (Section 6.4.2)
gammassp marked this conversation as resolved.
Show resolved Hide resolved
if len(gBid.VastXML) > 0 {
if len(gBid.VastURL) > 0 {
bid.NURL = gBid.VastURL
}
bid.AdM = url.QueryEscape(gBid.VastXML)
} else {
return nil
}
} else {
if len(gBid.Bid.AdM) == 0 {
return nil
}
}
return &bid
}

func (a *GammaAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if response.StatusCode == http.StatusNoContent {
return nil, nil
Expand All @@ -197,21 +239,33 @@ func (a *GammaAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalReq
}}
}

var bidResp openrtb.BidResponse
if err := json.Unmarshal(response.Body, &bidResp); err != nil {
var gammaResp gammaBidResponse
if err := json.Unmarshal(response.Body, &gammaResp); err != nil {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("bad server response: %d. ", err),
}}
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(bidResp.SeatBid[0].Bid))
for _, sb := range bidResp.SeatBid {
//(Section 7.1 No-Bid Signaling)
if gammaResp.SeatBid == nil || len(gammaResp.SeatBid) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Go, len(nil) = 0, so you could omit the first check here if you want to.

return nil, nil
gammassp marked this conversation as resolved.
Show resolved Hide resolved
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(gammaResp.SeatBid[0].Bid))
for _, sb := range gammaResp.SeatBid {
for i := range sb.Bid {
bid := sb.Bid[i]
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: getMediaTypeForImp(bidResp.ID, internalRequest.Imp),
})
mediaType := getMediaTypeForImp(gammaResp.ID, internalRequest.Imp)
bid := convertBid(sb.Bid[i], mediaType)
if bid != nil {
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: bid,
BidType: mediaType,
})
} else {
return nil, []error{&errortypes.BadServerResponse{
gammassp marked this conversation as resolved.
Show resolved Hide resolved
Message: fmt.Sprintf("Missing Ad Markup. Run with request.debug = 1 for more info"),
}}
}
}
}
return bidResponse, nil
Expand Down
2 changes: 1 addition & 1 deletion adapters/gamma/gammatest/exemplary/valid-full-params.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"mockBidRequest": {
"id": "test-request-id",
"app":{
"id":"test-app-id",
"id":"test-app-id",
"name":"test-app-name",
"bundle":"test-app-bundle"
},
Expand Down
2 changes: 1 addition & 1 deletion adapters/gamma/gammatest/supplemental/bad-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"mockBidRequest": {
"id": "test-request-id",
"app":{
"id":"test-app-id",
"id":"test-app-id",
"name":"test-app-name",
"bundle":"test-app-bundle"
},
Expand Down
76 changes: 76 additions & 0 deletions adapters/gamma/gammatest/supplemental/missing-adm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-video-id",
"video": {
"mimes": [
"video/mp4"
],
"protocols": [
2,
5
],
"w": 640,
"h": 480
},
"ext": {
"bidder": {
"id": "sample-id",
"zid": "sample-zone-id",
"wid": "sample-web-id"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://hb.gammaplatform.com/adx/request/?id=sample-id&zid=sample-zone-id&wid=sample-web-id&bidid=test-imp-video-id&hb=pbmobile"
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"cur": "USD",
"seatbid": [
{
"seat": "gamma",
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-video-id",
"price": 0.500000,
"crid": "29484110",
"w": 640,
"h": 360
}
]
}
]
}
}
}
],
"expectedBids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-video-id",
"price": 0.500000,
"crid": "29484110",
"w": 640,
"h": 360
},
"type": "video"
}
],
"expectedMakeBidsErrors": [
{
"value": "Missing Ad Markup. Run with request.debug = 1 for more info",
"comparison": "literal"
}
]
}
2 changes: 1 addition & 1 deletion adapters/gamma/gammatest/supplemental/missing-param.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"bidder": {
"zid": "sample-zone-id",
"wid": "sample-web-id"

}
}

Expand Down
2 changes: 1 addition & 1 deletion adapters/gamma/gammatest/supplemental/missing-zone.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"bidder": {
"id": "sample-id",
"wid": "sample-web-id"

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"mockBidRequest": {
"id": "test-request-id",
"app":{
"id":"test-app-id",
"id":"test-app-id",
"name":"test-app-name",
"bundle":"test-app-bundle"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"mockBidRequest": {
"id": "test-request-id",
"app":{
"id":"test-app-id",
"id":"test-app-id",
"name":"test-app-name",
"bundle":"test-app-bundle"
},
Expand Down