Skip to content

Commit

Permalink
Axonix: enabled by default (prebid#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarfd authored Jul 30, 2021
1 parent bab487e commit be6c749
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 55 deletions.
27 changes: 21 additions & 6 deletions adapters/axonix/axonix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,39 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"text/template"

"github.com/mxmCherry/openrtb/v15/openrtb2"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/macros"
"github.com/prebid/prebid-server/openrtb_ext"
)

type adapter struct {
URI string
EndpointTemplate template.Template
}

func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) {
endpoint, err := template.New("endpointTemplate").Parse(config.Endpoint)
if err != nil {
return nil, fmt.Errorf("unable to parse endpoint url template: %v", err)
}
bidder := &adapter{
URI: config.Endpoint,
EndpointTemplate: *endpoint,
}
return bidder, nil
}

func (a *adapter) getEndpoint(ext *openrtb_ext.ExtImpAxonix) (string, error) {
endpointParams := macros.EndpointTemplateParams{
AccountID: url.PathEscape(ext.SupplyId),
}
return macros.ResolveMacros(a.EndpointTemplate, endpointParams)
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errors []error

Expand All @@ -44,9 +58,10 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
return nil, errors
}

thisURI := a.URI
if len(thisURI) == 0 {
thisURI = "https://openrtb-us-east-1.axonix.com/supply/prebid-server/" + axonixExt.SupplyId
endpoint, err := a.getEndpoint(&axonixExt)
if err != nil {
errors = append(errors, err)
return nil, errors
}

requestJSON, err := json.Marshal(request)
Expand All @@ -60,7 +75,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte

requestData := &adapters.RequestData{
Method: "POST",
Uri: thisURI,
Uri: endpoint,
Body: requestJSON,
Headers: headers,
}
Expand Down
16 changes: 7 additions & 9 deletions adapters/axonix/axonix_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package axonix

import (
"github.com/stretchr/testify/assert"
"testing"

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

func TestJsonSamplesWithConfiguredURI(t *testing.T) {
func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderAxonix, config.Adapter{
Endpoint: "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8"})
Endpoint: "https://axonix.com/supply/prebid-server/{{.AccountID}}",
})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
Expand All @@ -19,12 +21,8 @@ func TestJsonSamplesWithConfiguredURI(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "axonixtest", bidder)
}

func TestJsonSamplesWithHardcodedURI(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderAxonix, config.Adapter{})
func TestEndpointTemplateMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderAxonix, config.Adapter{Endpoint: "{{Malformed}}"})

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

adapterstest.RunJSONBidderTest(t, "axonixtest", bidder)
assert.Error(t, buildErr)
}
10 changes: 5 additions & 5 deletions adapters/axonix/axonixtest/exemplary/banner-and-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
},
Expand All @@ -32,7 +32,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand All @@ -41,7 +41,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8",
"uri": "https://axonix.com/supply/prebid-server/supply-test",
"body": {
"id": "test-request-id",
"imp": [
Expand All @@ -61,7 +61,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
},
Expand All @@ -75,7 +75,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions adapters/axonix/axonixtest/exemplary/banner-video-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
},
Expand All @@ -30,7 +30,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
},
Expand All @@ -44,7 +44,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand All @@ -53,7 +53,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8",
"uri": "https://axonix.com/supply/prebid-server/supply-test",
"body": {
"id": "test-request-id",
"imp": [
Expand All @@ -73,7 +73,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
},
Expand All @@ -85,7 +85,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
},
Expand All @@ -99,7 +99,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions adapters/axonix/axonixtest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand All @@ -28,7 +28,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8",
"uri": "https://axonix.com/supply/prebid-server/supply-test",
"body": {
"id": "test-request-id",
"imp": [
Expand All @@ -48,7 +48,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions adapters/axonix/axonixtest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"ext":{
"bidder":{
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand All @@ -22,7 +22,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8",
"uri": "https://axonix.com/supply/prebid-server/supply-test",
"body": {
"id": "test-request-id",
"imp": [
Expand All @@ -36,7 +36,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/axonix/axonixtest/params/race/banner.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
2 changes: 1 addition & 1 deletion adapters/axonix/axonixtest/params/race/video.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"ext":{
"bidder":{
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand All @@ -22,7 +22,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8",
"uri": "https://axonix.com/supply/prebid-server/supply-test",
"body": {
"id": "test-request-id",
"imp": [
Expand All @@ -36,7 +36,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"ext":{
"bidder":{
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand All @@ -22,7 +22,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8",
"uri": "https://axonix.com/supply/prebid-server/supply-test",
"body": {
"id": "test-request-id",
"imp": [
Expand All @@ -36,7 +36,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"ext":{
"bidder":{
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand All @@ -22,7 +22,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8",
"uri": "https://axonix.com/supply/prebid-server/supply-test",
"body": {
"id": "test-request-id",
"imp": [
Expand All @@ -36,7 +36,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"ext":{
"bidder":{
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand All @@ -22,7 +22,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://openrtb-us-east-1.axonix.com/supply/prebid-server/24cc9034-f861-47b8-a6a8-b7e0968c00b8",
"uri": "https://axonix.com/supply/prebid-server/supply-test",
"body": {
"id": "test-request-id",
"imp": [
Expand All @@ -36,7 +36,7 @@
},
"ext": {
"bidder": {
"supplyId": "24cc9034-f861-47b8-a6a8-b7e0968c00b8"
"supplyId": "supply-test"
}
}
}
Expand Down
Loading

0 comments on commit be6c749

Please sign in to comment.