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
62 changes: 51 additions & 11 deletions adapters/intenze/intenze.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"text/template"

"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v4/adapters"
"github.com/prebid/prebid-server/v4/config"
"github.com/prebid/prebid-server/v4/errortypes"
"github.com/prebid/prebid-server/v4/macros"

"github.com/prebid/prebid-server/v4/openrtb_ext"
"github.com/prebid/prebid-server/v4/util/jsonutil"
)
Expand All @@ -19,15 +20,19 @@ type adapter struct {
endpoint *template.Template
}

func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
template, err := template.New("endpointTemplate").Parse(config.Endpoint)
if err != nil {
return nil, fmt.Errorf("unable to parse endpoint url template: %v", err)
}
var exchangeSubdomainsRegions = map[string]string{
"us-east": "lb-east",
"eu": "n2",
"apac": "lb-apac",
}
var sspSubdomainsRegions = map[string]string{
"us-east": "us-east-ssp",
"eu": "eu-ssp",
"apac": "apac-ssp",
}

bidder := &adapter{
endpoint: template,
}
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
bidder := &adapter{}
return bidder, nil
}

Expand Down Expand Up @@ -55,6 +60,7 @@ func getHeaders(request *openrtb2.BidRequest) http.Header {
}

func (a *adapter) MakeRequests(openRTBRequest *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) (requestsToBidder []*adapters.RequestData, errs []error) {

impExt, err := getImpressionExt(&openRTBRequest.Imp[0])
if err != nil {
return nil, []error{err}
Expand Down Expand Up @@ -99,8 +105,42 @@ func getImpressionExt(imp *openrtb2.Imp) (*openrtb_ext.ExtIntenze, error) {
}

func (a *adapter) buildEndpointURL(params *openrtb_ext.ExtIntenze) (string, error) {
Comment thread
devops473 marked this conversation as resolved.
endpointParams := macros.EndpointTemplateParams{AccountID: params.AccountID}
return macros.ResolveMacros(a.endpoint, endpointParams)
if params.AccountID == nil && params.PlacementID == nil {
return "", &errortypes.BadInput{
Message: "either accountId or placementId expected",
}
}

var route = ""
var subdomain, queryKey, queryValue string
var regionMap map[string]string

if params.AccountID != nil {
subdomain = "lb-east"
queryKey = "pass"
queryValue = *params.AccountID
regionMap = exchangeSubdomainsRegions
} else {
subdomain = "us-east-ssp"
queryKey = "placementId"
route = "pbs-serve"
queryValue = *params.PlacementID
regionMap = sspSubdomainsRegions
}

if params.Region != nil {
var exists bool
subdomain, exists = regionMap[*params.Region]
if !exists {
return "", &errortypes.BadInput{
Message: fmt.Sprintf("invalid region: %s. Expected us-east, eu or apac", *params.Region),
}
}
}

endpoint := fmt.Sprintf("https://%s.intenze.co/%s?%s=%s", subdomain, route, queryKey, url.QueryEscape(queryValue))

return endpoint, nil
}

func checkResponseStatusCodes(response *adapters.ResponseData) error {
Expand Down
8 changes: 0 additions & 8 deletions adapters/intenze/intenze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/prebid/prebid-server/v4/adapters/adapterstest"
"github.com/prebid/prebid-server/v4/config"
"github.com/prebid/prebid-server/v4/openrtb_ext"
"github.com/stretchr/testify/assert"
)

func TestJsonSamples(t *testing.T) {
Expand All @@ -19,10 +18,3 @@ func TestJsonSamples(t *testing.T) {

adapterstest.RunJSONBidderTest(t, "intenzetest", bidder)
}

func TestEndpointTemplateMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderIntenze, config.Adapter{
Endpoint: "{{Malformed}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

assert.Error(t, buildErr)
}
2 changes: 1 addition & 1 deletion adapters/intenze/intenzetest/exemplary/banner-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"123.123.123.123"
]
},
"uri": "http://lb-east.intenze.co/?pass=accountId",
"uri": "https://lb-east.intenze.co/?pass=accountId",
"body": {
"id": "some-request-id",
"device": {
Expand Down
2 changes: 1 addition & 1 deletion adapters/intenze/intenzetest/exemplary/banner-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"123.123.123.123"
]
},
"uri": "http://lb-east.intenze.co/?pass=accountId",
"uri": "https://lb-east.intenze.co/?pass=accountId",
"body": {
"id": "some-request-id",
"device": {
Expand Down
2 changes: 1 addition & 1 deletion adapters/intenze/intenzetest/exemplary/native-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"123.123.123.123"
]
},
"uri": "http://lb-east.intenze.co/?pass=accountId",
"uri": "https://lb-east.intenze.co/?pass=accountId",
"body": {
"id": "some-request-id",
"device": {
Expand Down
2 changes: 1 addition & 1 deletion adapters/intenze/intenzetest/exemplary/native-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"2607:fb90:f27:4512:d800:cb23:a603:e245"
]
},
"uri": "http://lb-east.intenze.co/?pass=accountId",
"uri": "https://lb-east.intenze.co/?pass=accountId",
"body": {
"id": "some-request-id",
"device": {
Expand Down
155 changes: 155 additions & 0 deletions adapters/intenze/intenzetest/exemplary/simple-account-apac.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"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": "1",
"tagid": "ogTAGID",
"banner": {
"w": 320,
"h": 50
},
"ext": {
"bidder": {
"region": "apac",
"accountId": "accountId"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
],
"X-Openrtb-Version": [
"2.5"
],
"User-Agent": [
"test-user-agent"
],
"X-Forwarded-For": [
"123.123.123.123"
]
},
"uri": "https://lb-apac.intenze.co/?pass=accountId",
"body": {
"id": "some-request-id",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "1",
"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": [
"1"
]
},
"mockResponse": {
"status": 200,
"body": {
"id": "awesome-resp-id",
"seatbid": [
{
"bid": [
{
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "1",
"price": 3.5,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
],
"crid": "20",
"w": 320,
"h": 50,
"mtype": 1
}
],
"type": "banner",
"seat": "intenze"
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"bids": [
{
"bid": {
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "1",
"price": 3.5,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
],
"crid": "20",
"w": 320,
"h": 50,
"mtype": 1
},
"type": "banner"
}
]
}
]
}
Loading
Loading