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

New Adapter: Nativo #3790

Merged
merged 29 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0f1af65
New Adapter: Nativo
rafataveira Jul 3, 2024
7f56ab1
Merge branch 'master' of https://github.com/NativoPlatform/prebid-server
rafataveira Jul 3, 2024
59e57cb
Nativo: fix tests
rafataveira Jul 3, 2024
8c798c9
Nativo: fix tests
rafataveira Jul 3, 2024
46e7869
Merge branch 'prebid:master' into master
rafataveira Aug 15, 2024
3e8a7db
Merge branch 'prebid:master' into master
rafataveira Aug 27, 2024
ec70552
Nativo: Addressed code review issues
rafataveira Aug 28, 2024
100db19
fix tests
rafataveira Aug 28, 2024
c449bc8
fix tests
rafataveira Aug 28, 2024
130f025
fix tests
rafataveira Aug 28, 2024
a7bb341
fix tests
rafataveira Aug 28, 2024
b7d5576
Fix tests
rafataveira Aug 28, 2024
e568b98
fix tests
rafataveira Aug 28, 2024
f98e664
fix unit tests
rafataveira Sep 9, 2024
5d3c8bb
Merge branch 'prebid:master' into master
rafataveira Sep 13, 2024
fec9463
Nativo: fix macro
rafataveira Oct 1, 2024
6d45678
resolve conflicts
aparekh-nativo Nov 1, 2024
82320de
Merge branch 'master' into master
aparekh-nativo Nov 1, 2024
96b26e9
Update to v3
rafataveira Nov 4, 2024
e35a49e
fix merge issues
rafataveira Nov 4, 2024
bb1d602
Merge branch 'prebid:master' into master
rafataveira Nov 8, 2024
02d8219
Improvements after code review suggestions
rafataveira Nov 8, 2024
8d2dd15
fix unit tests
rafataveira Nov 8, 2024
d9720a3
fix unit tests
rafataveira Nov 8, 2024
e3ba313
fix unit tests
rafataveira Nov 8, 2024
f6e8b77
fix unit tests
rafataveira Nov 8, 2024
cb3e1ff
fix unit tests
rafataveira Nov 8, 2024
05b8c95
fix unit tests
rafataveira Nov 8, 2024
116abc4
fix unit tests
rafataveira Nov 8, 2024
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
96 changes: 96 additions & 0 deletions adapters/nativo/nativo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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"
)

type adapter struct {
endpoint string
}

// Builder builds a new instance of the Nativo adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
bidder := &adapter{
endpoint: config.Endpoint,
}
return bidder, nil
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, _ *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
requestJSON, err := json.Marshal(request)
if err != nil {
return nil, []error{err}
}

headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")

requestData := &adapters.RequestData{
Method: "POST",
Uri: a.endpoint,
Body: requestJSON,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(request.Imp),
}

return []*adapters.RequestData{requestData}, nil
}

func (a *adapter) MakeBids(request *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if adapters.IsResponseStatusCodeNoContent(response) {
return nil, nil
}

if err := adapters.CheckResponseStatusCodeForErrors(response); err != nil {
return nil, []error{err}
}

var bidResp openrtb2.BidResponse

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

bidResponse := adapters.NewBidderResponse()

var errs []error
for _, seatBid := range bidResp.SeatBid {
for i := range seatBid.Bid {
bidType, err := getMediaTypeForImp(seatBid.Bid[i].ImpID, request.Imp)
if err != nil {
errs = append(errs, err)
continue
}

b := &adapters.TypedBid{
Bid: &seatBid.Bid[i],
BidType: bidType,
}

bidResponse.Bids = append(bidResponse.Bids, b)
}
}
return bidResponse, errs
}

func getMediaTypeForImp(impID string, imps []openrtb2.Imp) (openrtb_ext.BidType, error) {
for _, imp := range imps {
if imp.ID == impID {
if imp.Native != nil {
return openrtb_ext.BidTypeNative, nil
} else if imp.Video != nil {
return openrtb_ext.BidTypeVideo, nil
} else if imp.Banner != nil {
onkarvhanumante marked this conversation as resolved.
Show resolved Hide resolved
return openrtb_ext.BidTypeBanner, nil
}
}
}
return "", fmt.Errorf("Unrecognized impression type in response from nativo: %s", impID)
}
21 changes: 21 additions & 0 deletions adapters/nativo/nativo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package nativo

import (
"testing"

"github.com/prebid/prebid-server/v3/adapters/adapterstest"
"github.com/prebid/prebid-server/v3/config"
"github.com/prebid/prebid-server/v3/openrtb_ext"
)

func TestBidderNativo(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderNativo, config.Adapter{
Endpoint: "https://foo.io/?src=prebid"},
config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}

adapterstest.RunJSONBidderTest(t, "nativotest", bidder)
}
133 changes: 133 additions & 0 deletions adapters/nativo/nativotest/exemplary/banner-app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"mockBidRequest": {
"id": "some-request-id",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"tmax": 1000,
"user": {
"buyeruid": "awesome-user"
},
"app": {
"publisher": {
"id": "123456789"
},
"cat": [
"IAB22-1"
],
"bundle": "com.app.awesome",
"name": "Awesome App",
"domain": "awesomeapp.com",
"id": "123456789"
},
"imp": [
{
"id": "some-impression-id",
"tagid": "ogTAGID",
"banner": {
"w": 320,
"h": 50
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://foo.io/?src=prebid",
"body": {
"id": "some-request-id",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "some-impression-id",
"banner": {
"w": 320,
"h": 50
},
"tagid": "ogTAGID"
}
],
"app": {
"id": "123456789",
"name": "Awesome App",
"bundle": "com.app.awesome",
"domain": "awesomeapp.com",
"cat": [
"IAB22-1"
],
"publisher": {
"id": "123456789"
}
},
"user": {
"buyeruid": "awesome-user"
},
"tmax": 1000
},
"impIDs":["some-impression-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "awesome-resp-id",
"seatbid": [
{
"bid": [
{
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
],
"crid": "20",
"w": 320,
"h": 50
}
],
"seat": "nativo"
}
],
"cur": "USD",
"ext": {
"responsetimemillis": {
"nativo": 154
},
"tmaxrequest": 1000
}
}
}
}
],
"expectedBidResponses": [
{
"bids": [
{
"bid": {
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
],
"crid": "20",
"w": 320,
"h": 50
},
"type": "banner"
}
]
}
]
}
121 changes: 121 additions & 0 deletions adapters/nativo/nativotest/exemplary/banner-web.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"mockBidRequest": {
"id": "some-request-id",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"tmax": 1000,
"user": {
"buyeruid": "awesome-user"
},
"site": {
"page": "test.com",
"publisher": {
"id": "123456789"
}
},
"imp": [
{
"id": "some-impression-id",
"tagid": "ogTAGID",
"banner": {
"w":320,
"h":50
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://foo.io/?src=prebid",
"body": {
"id": "some-request-id",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "some-impression-id",
"tagid": "ogTAGID",
"banner": {
"w":320,
"h":50
}
}
],
"site": {
"page": "test.com",
"publisher": {
"id": "123456789"
}
},
"user": {
"buyeruid": "awesome-user"
},
"tmax": 1000
},
"impIDs":["some-impression-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "awesome-resp-id",
"seatbid": [
{
"bid": [
{
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
],
"crid": "20",
"w": 320,
"h": 50
}
],
"seat": "nativo"
}
],
"cur": "USD",
"ext": {
"responsetimemillis": {
"nativo": 154
},
"tmaxrequest": 1000
}
}
}
}
],
"expectedBidResponses": [
{
"bids":[
{
"bid": {
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"adm": "awesome-markup",
"crid": "20",
"adomain": [
"awesome.com"
],
"w": 320,
"h": 50
},
"type": "banner"
}
]
}
]
}
Loading
Loading