Skip to content
Open
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
6 changes: 3 additions & 3 deletions adapters/nativo/nativo.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package nativo

import (
"encoding/json"
"fmt"
"net/http"

"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v3/adapters"
"github.com/prebid/prebid-server/v3/config"
"github.com/prebid/prebid-server/v3/openrtb_ext"
"github.com/prebid/prebid-server/v3/util/jsonutil"
)

type adapter struct {
Expand All @@ -24,7 +24,7 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, _ *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
requestJSON, err := json.Marshal(request)
requestJSON, err := jsonutil.Marshal(request)
if err != nil {
return nil, []error{err}
}
Expand Down Expand Up @@ -54,7 +54,7 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, externalRequest *adapte

var bidResp openrtb2.BidResponse

if err := json.Unmarshal(response.Body, &bidResp); err != nil {
if err := jsonutil.Unmarshal(response.Body, &bidResp); err != nil {
return nil, []error{err}
}

Expand Down
12 changes: 11 additions & 1 deletion adapters/nativo/nativotest/exemplary/banner-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"banner": {
"w": 320,
"h": 50
},
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
]
Expand All @@ -53,7 +58,12 @@
"w": 320,
"h": 50
},
"tagid": "ogTAGID"
"tagid": "ogTAGID",
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
],
"app": {
Expand Down
10 changes: 10 additions & 0 deletions adapters/nativo/nativotest/exemplary/banner-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"banner": {
"w":320,
"h":50
},
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
]
Expand All @@ -47,6 +52,11 @@
"banner": {
"w":320,
"h":50
},
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
],
Expand Down
12 changes: 11 additions & 1 deletion adapters/nativo/nativotest/exemplary/native-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"native": {
"ver":"1.1",
"request":"{\"adunit\":2,\"assets\":[{\"id\":3,\"img\":{\"h\":120,\"hmin\":0,\"type\":3,\"w\":180,\"wmin\":0},\"required\":1},{\"id\":0,\"required\":1,\"title\":{\"len\":25}},{\"data\":{\"len\":25,\"type\":1},\"id\":4,\"required\":1},{\"data\":{\"len\":140,\"type\":2},\"id\":6,\"required\":1}],\"context\":1,\"layout\":1,\"contextsubtype\":11,\"plcmtcnt\":1,\"plcmttype\":2,\"ver\":\"1.1\",\"ext\":{\"banner\":{\"w\":320,\"h\":50}}}"
},
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
]
Expand All @@ -53,7 +58,12 @@
"ver":"1.1",
"request":"{\"adunit\":2,\"assets\":[{\"id\":3,\"img\":{\"h\":120,\"hmin\":0,\"type\":3,\"w\":180,\"wmin\":0},\"required\":1},{\"id\":0,\"required\":1,\"title\":{\"len\":25}},{\"data\":{\"len\":25,\"type\":1},\"id\":4,\"required\":1},{\"data\":{\"len\":140,\"type\":2},\"id\":6,\"required\":1}],\"context\":1,\"layout\":1,\"contextsubtype\":11,\"plcmtcnt\":1,\"plcmttype\":2,\"ver\":\"1.1\",\"ext\":{\"banner\":{\"w\":320,\"h\":50}}}"
},
"tagid": "ogTAGID"
"tagid": "ogTAGID",
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
],
"app": {
Expand Down
10 changes: 10 additions & 0 deletions adapters/nativo/nativotest/exemplary/native-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"native": {
"ver":"1.1",
"request":"{\"adunit\":2,\"assets\":[{\"id\":3,\"img\":{\"h\":120,\"hmin\":0,\"type\":3,\"w\":180,\"wmin\":0},\"required\":1},{\"id\":0,\"required\":1,\"title\":{\"len\":25}},{\"data\":{\"len\":25,\"type\":1},\"id\":4,\"required\":1},{\"data\":{\"len\":140,\"type\":2},\"id\":6,\"required\":1}],\"context\":1,\"layout\":1,\"contextsubtype\":11,\"plcmtcnt\":1,\"plcmttype\":2,\"ver\":\"1.1\",\"ext\":{\"banner\":{\"w\":320,\"h\":50}}}"
},
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
]
Expand All @@ -47,6 +52,11 @@
"native": {
"ver":"1.1",
"request":"{\"adunit\":2,\"assets\":[{\"id\":3,\"img\":{\"h\":120,\"hmin\":0,\"type\":3,\"w\":180,\"wmin\":0},\"required\":1},{\"id\":0,\"required\":1,\"title\":{\"len\":25}},{\"data\":{\"len\":25,\"type\":1},\"id\":4,\"required\":1},{\"data\":{\"len\":140,\"type\":2},\"id\":6,\"required\":1}],\"context\":1,\"layout\":1,\"contextsubtype\":11,\"plcmtcnt\":1,\"plcmttype\":2,\"ver\":\"1.1\",\"ext\":{\"banner\":{\"w\":320,\"h\":50}}}"
},
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
],
Expand Down
12 changes: 11 additions & 1 deletion adapters/nativo/nativotest/exemplary/video-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"h": 480,
"minduration": 120,
"maxduration": 150
},
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
]
Expand Down Expand Up @@ -63,7 +68,12 @@
"w": 640,
"h": 480
},
"tagid": "ogTAGID"
"tagid": "ogTAGID",
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
],
"app": {
Expand Down
10 changes: 10 additions & 0 deletions adapters/nativo/nativotest/exemplary/video-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"h": 480,
"minduration": 120,
"maxduration": 150
},
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
]
Expand Down Expand Up @@ -57,6 +62,11 @@
"maxduration": 150,
"w": 640,
"h": 480
},
"ext": {
"bidder": {
"placementId": 12345678
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"placementId": "12345678"
}
}
}
]
Expand All @@ -36,7 +38,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"placementId": "12345678"
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"placementId": 12345678
}
}
}
]
Expand All @@ -36,7 +38,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"placementId": 12345678
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"placementId": 12345678
}
}
}
]
Expand All @@ -36,7 +38,9 @@
]
},
"ext": {
"bidder": {}
"bidder": {
"placementId": 12345678
}
}
}
]
Expand Down
44 changes: 44 additions & 0 deletions adapters/nativo/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package nativo

import (
"encoding/json"
"testing"

"github.com/prebid/prebid-server/v3/openrtb_ext"
)

func TestValidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json-schemas. %v", err)
}

for _, validParam := range validParams {
if err := validator.Validate(openrtb_ext.BidderNativo, json.RawMessage(validParam)); err != nil {
t.Errorf("Schema rejected valid params: %s", validParam)
}
}
}

func TestInvalidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json-schemas. %v", err)
}

for _, invalidParam := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderNativo, json.RawMessage(invalidParam)); err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
}
}
}

var validParams = []string{
`{"placementId": "12345678"}`,
`{"placementId": 12345678}`,
`{}`,
}

var invalidParams = []string{
`{"placementId": false}`,
}
7 changes: 7 additions & 0 deletions openrtb_ext/imp_nativo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package openrtb_ext

import "github.com/prebid/prebid-server/v3/util/jsonutil"

type ImpExtNativo struct {
PlacementID jsonutil.StringInt `json:"placementId"`
}
7 changes: 6 additions & 1 deletion static/bidder-params/nativo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"title": "Nativo Adapter Params",
"description": "A schema which validates params accepted by the Nativo adapter",
"type": "object",
"properties": {}
"properties": {
"placementId": {
"type": ["integer", "string"],
"description": "Placement ID"
}
}
}
Loading