Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Allow app requests for Conversant (prebid#868)
Browse files Browse the repository at this point in the history
* Allow app requests for Conversant

* Update conversant.yaml to add app media types for Conversant
  • Loading branch information
johnwier authored and hhhjort committed Apr 22, 2019
1 parent 014b416 commit 9bc3c7e
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 14 deletions.
20 changes: 9 additions & 11 deletions adapters/conversant/conversant.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ func (a *ConversantAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidde
return nil, err
}

// Without this, the code crashes with a nil-pointer dereference below, on
// cnvrReq.Site.ID = params.SiteID
if cnvrReq.Site == nil {
return nil, &errortypes.BadInput{
Message: "Conversant doesn't support App requests",
}
}

// Create a map of impression objects for both request creation
// and response parsing.

Expand Down Expand Up @@ -87,11 +79,11 @@ func (a *ConversantAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidde

// Fill in additional Site info

if params.SiteID != "" {
if params.SiteID != "" && !(cnvrReq.Site == nil) {
cnvrReq.Site.ID = params.SiteID
}

if params.Mobile != nil {
if params.Mobile != nil && !(cnvrReq.Site == nil) {
cnvrReq.Site.Mobile = *params.Mobile
}

Expand Down Expand Up @@ -149,12 +141,18 @@ func (a *ConversantAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidde

// Do a quick check on required parameters

if cnvrReq.Site.ID == "" {
if cnvrReq.Site != nil && cnvrReq.Site.ID == "" {
return nil, &errortypes.BadInput{
Message: "Missing site id",
}
}

if cnvrReq.App != nil && cnvrReq.App.ID == "" {
return nil, &errortypes.BadInput{
Message: "Missing app id",
}
}

// Start capturing debug info

debug := &pbs.BidderDebug{
Expand Down
91 changes: 88 additions & 3 deletions adapters/conversant/conversant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,80 @@ func TestConversantRequestDefault(t *testing.T) {
assertEqual(t, int(*imp.Banner.H), 250, "Request height")
}

// Verify inapp video request
func TestConversantInappVideoRequest(t *testing.T) {
server, lastReq := CreateServer()
if server == nil {
t.Fatal("server not created")
}

defer server.Close()

conf := *adapters.DefaultHTTPAdapterConfig
an := NewConversantAdapter(&conf, server.URL)

requestParam := `{"secure": 1}`
appParam := `{ "Id": "12345" }`
videoParam := `{ "mimes": ["video/x-ms-wmv"],
"protocols": [1, 2],
"maxduration": 90 }`

ctx := context.TODO()
pbReq := CreateRequest(requestParam)
pbReq, err := ConvertToVideoRequest(pbReq, videoParam)
if err != nil {
t.Fatal("failed to parse request")
}
pbReq, err = ConvertToAppRequest(pbReq, appParam)
if err != nil {
t.Fatal("failed to parse request")
}
pbReq, err = ParseRequest(pbReq)
if err != nil {
t.Fatal("failed to parse request")
}

_, err = an.Call(ctx, pbReq, pbReq.Bidders[0])

imp := &lastReq.Imp[0]
assertEqual(t, int(imp.Video.W), 300, "Request width")
assertEqual(t, int(imp.Video.H), 250, "Request height")
assertEqual(t, lastReq.App.ID, "12345", "App Id")
}

// Verify inapp video request
func TestConversantInappBannerRequest(t *testing.T) {
server, lastReq := CreateServer()
if server == nil {
t.Fatal("server not created")
}

defer server.Close()

conf := *adapters.DefaultHTTPAdapterConfig
an := NewConversantAdapter(&conf, server.URL)

param := `{ "secure": 1,
"tag_id": "top",
"position": 2,
"bidfloor": 1.01 }`
appParam := `{ "Id": "12345" }`

ctx := context.TODO()
pbReq, _ := CreateBannerRequest(param)
pbReq, err := ConvertToAppRequest(pbReq, appParam)
if err != nil {
t.Fatal("failed to parse request")
}

_, err = an.Call(ctx, pbReq, pbReq.Bidders[0])

imp := &lastReq.Imp[0]
assertEqual(t, lastReq.App.ID, "12345", "App Id")
assertEqual(t, int(*imp.Banner.W), 300, "Request width")
assertEqual(t, int(*imp.Banner.H), 250, "Request height")
}

// Verify an outgoing openrtp request with additional conversant parameters is
// processed correctly

Expand Down Expand Up @@ -595,18 +669,29 @@ func ConvertToVideoRequest(req *pbs.PBSRequest, videoParams ...string) (*pbs.PBS
return req, nil
}

// Convert a request to an app request by adding required properties
func ConvertToAppRequest(req *pbs.PBSRequest, appParams string) (*pbs.PBSRequest, error) {
app := new(openrtb.App)
err := json.Unmarshal([]byte(appParams), &app)
if err == nil {
req.App = app
}

return req, nil
}

// Feed the request thru the prebid parser so user id and
// other private properties are defined

func ParseRequest(req *pbs.PBSRequest) (*pbs.PBSRequest, error) {
body := new(bytes.Buffer)
json.NewEncoder(body).Encode(req)
_ = json.NewEncoder(body).Encode(req)

// Need to pass the conversant user id thru uid cookie

httpReq := httptest.NewRequest("POST", "/foo", body)
cookie := usersync.NewPBSCookie()
cookie.TrySync("conversant", ExpectedBuyerUID)
_ = cookie.TrySync("conversant", ExpectedBuyerUID)
httpReq.Header.Set("Cookie", cookie.ToHTTPCookie(90*24*time.Hour).String())
httpReq.Header.Add("Referer", "http://example.com")
cache, _ := dummycache.New()
Expand Down Expand Up @@ -712,7 +797,7 @@ func CreateServer(prices ...float64) (*httptest.Server, *openrtb.BidRequest) {
})

w.Header().Set("Content-Type", "application/json")
w.Write(js)
_, _ = w.Write(js)
}
}),
)
Expand Down
4 changes: 4 additions & 0 deletions static/bidder-info/conversant.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
maintainer:
email: "mediapsr@conversantmedia.com"
capabilities:
app:
mediaTypes:
- banner
- video
site:
mediaTypes:
- banner
Expand Down

0 comments on commit 9bc3c7e

Please sign in to comment.