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

[Synacormedia] Add tagId bidder parameter #1165

Merged
merged 9 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions adapters/synacormedia/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func TestInvalidParams(t *testing.T) {
}

var validParams = []string{
`{"seatId": "123"}`,
`{"seatId": "123", "tagId":"234"}`,
}

var invalidParams = []string{
`{"seatId": 123}`,
`{"seatId": 123, "tagId":234}`,
}
19 changes: 15 additions & 4 deletions adapters/synacormedia/synacormedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type SynacorMediaAdapter struct {

type SyncEndpointTemplateParams struct {
SeatId string
TagId string
}

type ReqExt struct {
Expand Down Expand Up @@ -55,14 +56,23 @@ func (a *SynacorMediaAdapter) makeRequest(request *openrtb.BidRequest) (*adapter
var firstExtImp *openrtb_ext.ExtImpSynacormedia = nil

for _, imp := range request.Imp {
validImp, err := getExtImpObj(&imp)
validExtImpObj, err := getExtImpObj(&imp) // getExtImpObj returns {seatId:"", tagId:""}
if err != nil {
errs = append(errs, err)
continue
}
// if the bid request is missing seatId or TagId then ignore it
if validExtImpObj.SeatId == "" || validExtImpObj.TagId == "" {
errs = append(errs, &errortypes.BadServerResponse{
Message: fmt.Sprintf("Invalid Impression"),
})
continue
}
// right here is where we need to take out the tagId and then add it to imp
imp.TagID = validExtImpObj.TagId
validImps = append(validImps, imp)
if firstExtImp == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a possibility that the first element of the Imp array coming with a non-nil validExtImpObj has an empty seatId="" or tagId="" values and subsequent elements inside Imp come with non-empty seatId and/or tagIds. Are we sure we want to discard the entire request and return error in line 78 below?

 52 func (a *SynacorMediaAdapter) makeRequest(request *openrtb.BidRequest) (*adapters.RequestData, []error) {
 53     var errs []error
 54 +--  4 lines: var validImps []openrtb.Imp-------------------------------------------------------------
 58     for _, imp := range request.Imp {
 59         validExtImpObj, err := getExtImpObj(&imp) // getExtImpObj returns {seatId:"", tagId:""}
 60         if err != nil {
 61             errs = append(errs, err)
 62             continue
 63         }
 64         // right here is where we need to take out the tagId and then add it to imp
 65         imp.TagID = validExtImpObj.TagId
 66         validImps = append(validImps, imp)
 67         if firstExtImp == nil {
 68             firstExtImp = validExtImpObj
 69         }
 70     }
 71
 72     if len(validImps) == 0 {
 73         return nil, errs
 74     }
 75
 76     var err error
 77
 78     if firstExtImp == nil || firstExtImp.SeatId == "" || firstExtImp.TagId == "" {
 79         return nil, append(errs, &errortypes.BadServerResponse{
 80             Message: fmt.Sprintf("Invalid Impression"),
 81         })
 82     }
 83     // this is where the empty seatId is filled
 84     re = &ReqExt{SeatId: firstExtImp.SeatId}
 85 +-- 24 lines: create JSON Request Body-------------------------------------------------------------------
109     return &adapters.RequestData{
110         Method:  http.MethodPost,
111         Uri:     reqUri,
112         Body:    reqJSON,
113         Headers: headers,
114     }, errs
115 }
adapters/synacormedia/synacormedia.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the code to note any empty tagId or seatID values, then skip over them. There is a unit test for this now.

firstExtImp = validImp
firstExtImp = validExtImpObj
}
}

Expand All @@ -72,11 +82,12 @@ func (a *SynacorMediaAdapter) makeRequest(request *openrtb.BidRequest) (*adapter

var err error

if firstExtImp == nil || firstExtImp.SeatId == "" {
if firstExtImp == nil || firstExtImp.SeatId == "" || firstExtImp.TagId == "" {
return nil, append(errs, &errortypes.BadServerResponse{
Message: fmt.Sprintf("Impression missing seat id"),
Message: fmt.Sprintf("Invalid Impression"),
})
}
// this is where the empty seatId is filled
re = &ReqExt{SeatId: firstExtImp.SeatId}
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't TagId also meant to be copied into the ReqExt object? I realize ReqExt isn't even defined with a TagId field, I'm just wondering if we don't want that value in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TagId is a part of the Imp object, so for each Imp in request.Imp we get the TagId out of the Ext object and add it to the root of the Imp object and then add all those Imps to validImps. Those become the new request.Imp that gets sent out.

Copy link
Contributor

Choose a reason for hiding this comment

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

You may wish to consider using a different error message here and on line 67 so the unique error message may assist in debugging.


// create JSON Request Body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"ext": {
"bidder": {
"seatId": "1927"
"seatId": "prebid",
"tagId": "demo1"
}
}
}
Expand All @@ -24,23 +25,25 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://1927.technoratimedia.com/openrtb/bids/1927",
"uri": "http://prebid.technoratimedia.com/openrtb/bids/prebid",
"body": {
"id": "test-request-id",
"ext": {
"seatId": "1927"
"seatId": "prebid"
},
"imp": [
{
"id":"test-imp-id",
"tagid": "demo1",
"banner": {
"format": [
{"w":300,"h":250}
]
},
"ext": {
"bidder": {
"seatId": "1927"
"seatId": "prebid",
"tagId": "demo1"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"imp": [
{
"id": "i3",
"tagid": "3020",
"video": {
"w": 300,
"h": 250,
Expand All @@ -21,8 +20,9 @@
},
"metric": [],
"ext": {
"bidder":{
"seatId":"1927"
"bidder": {
"seatId":"prebid",
"tagId": "demo1"
}
}
}
Expand All @@ -31,7 +31,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://1927.technoratimedia.com/openrtb/bids/1927",
"uri": "http://prebid.technoratimedia.com/openrtb/bids/prebid",
"body": {
"id": "1",
"site": {
Expand All @@ -40,12 +40,12 @@
"publisher": {}
},
"ext": {
"seatId": "1927"
"seatId": "prebid"
},
"imp": [
{
"id": "i3",
"tagid": "3020",
"tagid": "demo1",
"video": {
"w": 300,
"h": 250,
Expand All @@ -56,7 +56,8 @@
},
"ext": {
"bidder":{
"seatId":"1927"
"seatId":"prebid",
"tagId": "demo1"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion adapters/synacormedia/synacormediatest/params/banner.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"seatId": "123"
"seatId": "123",
"tagId": "234"
}
3 changes: 2 additions & 1 deletion adapters/synacormedia/synacormediatest/params/video.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"seatId": "123"
"seatId": "123",
"tagId": "234"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"ext": {
"bidder": {
"seatId": "1927"
"seatId": "prebid",
"tagId": "demo1"
}
}
}
Expand All @@ -19,21 +20,23 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://1927.technoratimedia.com/openrtb/bids/1927",
"uri": "http://prebid.technoratimedia.com/openrtb/bids/prebid",
"body": {
"id": "test-request-id",
"ext": {
"seatId": "1927"
"seatId": "prebid"
},
"imp": [
{
"id":"test-imp-id",
"tagid": "demo1",
"audio": {
"mimes": ["video/mp4"]
},
"ext": {
"bidder": {
"seatId": "1927"
"seatId": "prebid",
"tagId": "demo1"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
},
"ext": {
"bidder": {
"seatId": "1927"
"seatId": "prebid",
"tagId": "demo1"
}
}
}
Expand All @@ -28,15 +29,16 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://1927.technoratimedia.com/openrtb/bids/1927",
"uri": "http://prebid.technoratimedia.com/openrtb/bids/prebid",
"body": {
"id": "test-request-id",
"ext": {
"seatId": "1927"
"seatId": "prebid"
},
"imp": [
{
"id":"test-imp-id",
"tagid": "demo1",
"banner": {
"format": [
{"w":300,"h":250},
Expand All @@ -45,7 +47,8 @@
},
"ext": {
"bidder": {
"seatId": "1927"
"seatId": "prebid",
"tagId": "demo1"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"ext": {
"bidder": {
"seatId": 1927
"seatId": 1927,
"tagId": "demo1"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"ext": {
"bidder": {
"tagId": "demo1"
}
}
}
Expand All @@ -22,7 +23,7 @@

"expectedMakeRequestsErrors": [
{
"value": "Impression missing seat id",
"value": "Invalid Impression",
"comparison": "literal"
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"seatId": "prebid"
}
}
}
]
},

"expectedMakeRequestsErrors": [
{
"value": "Invalid Impression",
"comparison": "literal"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"ext": {
"bidder": {
"seatId": "1927"
"seatId": "prebid",
"tagId": "demo1"
}
}
}
Expand All @@ -19,21 +20,23 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://1927.technoratimedia.com/openrtb/bids/1927",
"uri": "http://prebid.technoratimedia.com/openrtb/bids/prebid",
"body": {
"id": "test-request-id",
"ext": {
"seatId": "1927"
"seatId": "prebid"
},
"imp": [
{
"id":"test-imp-id",
"tagid": "demo1",
"native": {
"request": ""
},
"ext": {
"bidder": {
"seatId": "1927"
"seatId": "prebid",
"tagId": "demo1"
}
}
}
Expand Down
Loading