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 all 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
77 changes: 67 additions & 10 deletions adapters/gamma/gamma.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ 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 == "" {
return &errortypes.BadInput{
Expand Down Expand Up @@ -180,6 +201,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 = 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,24 +240,38 @@ 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 len(gammaResp.SeatBid) == 0 {
return nil, nil
gammassp marked this conversation as resolved.
Show resolved Hide resolved
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(gammaResp.SeatBid[0].Bid))
errs := make([]error, 0, 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 {
err := &errortypes.BadServerResponse{
Message: fmt.Sprintf("Missing Ad Markup. Run with request.debug = 1 for more info"),
}
errs = append(errs, err)
}
}
}
return bidResponse, nil
return bidResponse, errs
}

//Adding header fields to request header
Expand Down
15 changes: 10 additions & 5 deletions adapters/gamma/gammatest/exemplary/banner-and-video-and-audio.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"id": "test-imp-video-id",
"cur": "USD",
"seatbid": [
{
Expand All @@ -89,7 +89,10 @@
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-video-id",
"price": 0.500000,
"adm": "some-test-ad",
"adm": "",
"adomain": ["sample.com"],
"vastXml": "some-test-ad",
"vastUrl": "some-test-url",
"crid": "29484110",
"w": 640,
"h": 480
Expand Down Expand Up @@ -122,13 +125,15 @@
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-video-id",
"price": 0.5,
"adm": "some-test-ad",
"adm": "",
"vastXml": "some-test-ad",
"vastUrl": "some-test-url",
"adid": "29484110",
"adomain": ["sample.com"],
"cid": "958",
"crid": "29484110",
"w": 1024,
"h": 576
"w": 640,
"h": 480
},
"type": "video"
}
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
56 changes: 56 additions & 0 deletions adapters/gamma/gammatest/supplemental/nobid-signaling.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app":{
"id":"test-app-id",
"name":"test-app-name",
"bundle":"test-app-bundle"
},

"device":{
"ua":"test-device-ua",
"ip":"test-device-ip",
"ifa":"test-device-ifa",
"model":"test-device-model",
"os":"test-device-os",
"dnt":1
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 50
}
]
},
"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-id&hb=pbmobile&device_ip=test-device-ip&device_model=test-device-model&device_os=test-device-os&device_ua=test-device-ua&device_ifa=test-device-ifa&app_id=test-app-id&app_bundle=test-app-bundle&app_name=test-app-name"
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
]
}
}
}
],
"expectedMakeBidsErrors": []
}
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