Skip to content

Commit

Permalink
[Sharethrough] Adapter fixes (#1082)
Browse files Browse the repository at this point in the history
* Get bidfloor value from ExtImp instead of Imp

[#168939771]

* Bump adapter version to 7

* Remove gzip encoding handling (not working)
  • Loading branch information
Mathieu Pheulpin authored and guscarreon committed Oct 24, 2019
1 parent ec6bd93 commit 3ad99dd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
7 changes: 3 additions & 4 deletions adapters/sharethrough/butler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (s StrOpenRTBTranslator) requestFromOpenRTB(imp openrtb.Imp, request *openr
headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
headers.Add("Accept-Encoding", "gzip")
headers.Add("Origin", domain)
headers.Add("Referer", request.Site.Page)
headers.Add("X-Forwarded-For", request.Device.IP)
Expand All @@ -90,7 +89,7 @@ func (s StrOpenRTBTranslator) requestFromOpenRTB(imp openrtb.Imp, request *openr
userInfo := s.Util.parseUserInfo(request.User)
height, width := s.Util.getPlacementSize(imp, strImpParams)

jsonBody, err := (StrBodyHelper{Clock: s.Util.getClock()}).buildBody(request, imp)
jsonBody, err := (StrBodyHelper{Clock: s.Util.getClock()}).buildBody(request, strImpParams)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -163,7 +162,7 @@ func (s StrOpenRTBTranslator) responseToOpenRTB(strRawResp []byte, btlrReq *adap
return bidResponse, errs
}

func (h StrBodyHelper) buildBody(request *openrtb.BidRequest, imp openrtb.Imp) (body []byte, err error) {
func (h StrBodyHelper) buildBody(request *openrtb.BidRequest, strImpParams openrtb_ext.ExtImpSharethrough) (body []byte, err error) {
timeout := request.TMax
if timeout == 0 {
timeout = defaultTmax
Expand All @@ -173,7 +172,7 @@ func (h StrBodyHelper) buildBody(request *openrtb.BidRequest, imp openrtb.Imp) (
BlockedAdvDomains: request.BAdv,
MaxTimeout: timeout,
Deadline: h.Clock.now().Add(time.Duration(timeout) * time.Millisecond).Format(time.RFC3339Nano),
BidFloor: imp.BidFloor,
BidFloor: strImpParams.BidFloor,
})

return
Expand Down
15 changes: 6 additions & 9 deletions adapters/sharethrough/butler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ func TestSuccessRequestFromOpenRTB(t *testing.T) {
"Generates the correct AdServer request from Imp (no user provided)": {
inputImp: openrtb.Imp{
ID: "abc",
Ext: []byte(`{ "bidder": {"pkey": "pkey", "iframe": true, "iframeSize": [10, 20]} }`),
Ext: []byte(`{ "bidder": {"pkey": "pkey", "iframe": true, "iframeSize": [10, 20], "bidfloor": 1.0} }`),
Banner: &openrtb.Banner{
Format: []openrtb.Format{{H: 30, W: 40}},
},
BidFloor: 1.0,
},
inputReq: &openrtb.BidRequest{
App: &openrtb.App{Ext: []byte(`{}`)},
Expand All @@ -106,7 +105,6 @@ func TestSuccessRequestFromOpenRTB(t *testing.T) {
Headers: http.Header{
"Content-Type": []string{"application/json;charset=utf-8"},
"Accept": []string{"application/json"},
"Accept-Encoding": []string{"gzip"},
"Origin": []string{"http://a.domain.com"},
"Referer": []string{"http://a.domain.com/page"},
"User-Agent": []string{"Android Chome/60"},
Expand Down Expand Up @@ -140,7 +138,6 @@ func TestSuccessRequestFromOpenRTB(t *testing.T) {
Headers: http.Header{
"Content-Type": []string{"application/json;charset=utf-8"},
"Accept": []string{"application/json"},
"Accept-Encoding": []string{"gzip"},
"Origin": []string{"http://a.domain.com"},
"Referer": []string{"http://a.domain.com/page"},
"User-Agent": []string{"Android Chome/60"},
Expand Down Expand Up @@ -379,35 +376,35 @@ func TestFailResponseToOpenRTB(t *testing.T) {
func TestBuildBody(t *testing.T) {
tests := map[string]struct {
inputRequest *openrtb.BidRequest
inputImp openrtb.Imp
inputImp openrtb_ext.ExtImpSharethrough
expectedJson []byte
expectedError error
}{
"Empty input: skips badomains, tmax default to 10 sec and sets deadline accordingly": {
inputRequest: &openrtb.BidRequest{},
inputImp: openrtb.Imp{},
inputImp: openrtb_ext.ExtImpSharethrough{},
expectedJson: []byte(`{"tmax":10000, "deadline":"2019-09-12T11:29:10.000123456Z"}`),
expectedError: nil,
},
"Sets badv as list of domains according to Badv (tmax default to 10 sec and sets deadline accordingly)": {
inputRequest: &openrtb.BidRequest{
BAdv: []string{"dom1.com", "dom2.com"},
},
inputImp: openrtb.Imp{},
inputImp: openrtb_ext.ExtImpSharethrough{},
expectedJson: []byte(`{"badv": ["dom1.com", "dom2.com"], "tmax":10000, "deadline":"2019-09-12T11:29:10.000123456Z"}`),
expectedError: nil,
},
"Sets tmax and deadline according to Tmax": {
inputRequest: &openrtb.BidRequest{
TMax: 500,
},
inputImp: openrtb.Imp{},
inputImp: openrtb_ext.ExtImpSharethrough{},
expectedJson: []byte(`{"tmax": 500, "deadline":"2019-09-12T11:29:00.500123456Z"}`),
expectedError: nil,
},
"Sets bidfloor according to the Imp object": {
inputRequest: &openrtb.BidRequest{},
inputImp: openrtb.Imp{
inputImp: openrtb_ext.ExtImpSharethrough{
BidFloor: 1.23,
},
expectedJson: []byte(`{"tmax":10000, "deadline":"2019-09-12T11:29:10.000123456Z", "bidfloor":1.23}`),
Expand Down
2 changes: 1 addition & 1 deletion adapters/sharethrough/sharethrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const supplyId = "FGMrCMMc"
const strVersion = 6
const strVersion = 7

func NewSharethroughBidder(endpoint string) *SharethroughAdapter {
return &SharethroughAdapter{
Expand Down
7 changes: 4 additions & 3 deletions openrtb_ext/imp_sharethrough.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package openrtb_ext

type ExtImpSharethrough struct {
Pkey string `json:"pkey"`
Iframe bool `json:"iframe"`
IframeSize []int `json:"iframeSize"`
Pkey string `json:"pkey"`
Iframe bool `json:"iframe"`
IframeSize []int `json:"iframeSize"`
BidFloor float64 `json:"bidfloor"`
}

// ExtImpSharethrough defines the contract for bidrequest.imp[i].ext.sharethrough
Expand Down
4 changes: 4 additions & 0 deletions static/bidder-params/sharethrough.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
},
"description": "iframe dimensions",
"default": [0, 0]
},
"bidfloor": {
"type": "number",
"description": "The floor price, or minimum amount, a publisher will accept for an impression, given in CPM in USD"
}
},
"required": ["pkey"]
Expand Down

0 comments on commit 3ad99dd

Please sign in to comment.