Skip to content

Commit

Permalink
Axis adapter: updated url (#3002)
Browse files Browse the repository at this point in the history
Co-authored-by: Maksym Pavliv <makspavliv@MacBook-Air-Maksym.local>
  • Loading branch information
PyjamaWarrior and Maksym Pavliv authored Aug 4, 2023
1 parent dda9230 commit 19d4dae
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 36 deletions.
31 changes: 5 additions & 26 deletions adapters/axis/axis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,25 @@ import (
"encoding/json"
"fmt"
"net/http"
"text/template"

"github.com/prebid/openrtb/v19/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 {
endpoint *template.Template
endpoint string
}

type reqBodyExt struct {
AxisBidderExt openrtb_ext.ImpExtAxis `json:"bidder"`
}

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)
}

bidder := &adapter{
endpoint: template,
endpoint: config.Endpoint,
}

return bidder, nil
Expand All @@ -49,19 +42,14 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
continue
}

url, err := a.buildEndpointURL(&bidderExt)
if err != nil {
return nil, []error{err}
}

extJson, err := json.Marshal(bidderExt)
if err != nil {
return nil, []error{err}
}

request.Imp[0].Ext = extJson

adapterReq, err := buildRequest(request, url)
adapterReq, err := a.buildRequest(request)
if err != nil {
return nil, []error{err}
}
Expand All @@ -74,16 +62,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
return adapterRequests, nil
}

func (a *adapter) buildEndpointURL(bidderExt *reqBodyExt) (string, error) {
endpointParams := macros.EndpointTemplateParams{
AccountID: bidderExt.AxisBidderExt.Integration,
SourceId: bidderExt.AxisBidderExt.Token,
}

return macros.ResolveMacros(a.endpoint, endpointParams)
}

func buildRequest(request *openrtb2.BidRequest, url string) (*adapters.RequestData, error) {
func (a *adapter) buildRequest(request *openrtb2.BidRequest) (*adapters.RequestData, error) {
reqJSON, err := json.Marshal(request)
if err != nil {
return nil, err
Expand All @@ -95,7 +74,7 @@ func buildRequest(request *openrtb2.BidRequest, url string) (*adapters.RequestDa

return &adapters.RequestData{
Method: "POST",
Uri: url,
Uri: a.endpoint,
Body: reqJSON,
Headers: headers,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion adapters/axis/axis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderAxis, config.Adapter{
Endpoint: "http://prebid.axis-marketplace.com/{{.AccountID}}?token={{.SourceId}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
Endpoint: "http://prebid.axis-marketplace.com/pbserver"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
Expand Down
2 changes: 1 addition & 1 deletion adapters/axis/axistest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://prebid.axis-marketplace.com/000000?token=000000",
"uri": "http://prebid.axis-marketplace.com/pbserver",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/axis/axistest/exemplary/simple-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://prebid.axis-marketplace.com/000000?token=000000",
"uri": "http://prebid.axis-marketplace.com/pbserver",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/axis/axistest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://prebid.axis-marketplace.com/000000?token=000000",
"uri": "http://prebid.axis-marketplace.com/pbserver",
"body": {
"id": "test-request-id",
"device": {
Expand Down
2 changes: 1 addition & 1 deletion adapters/axis/axistest/exemplary/simple-web-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://prebid.axis-marketplace.com/000000?token=000000",
"uri": "http://prebid.axis-marketplace.com/pbserver",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/axis/axistest/supplemental/bad_media_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"httpCalls": [{
"expectedRequest": {
"uri": "http://prebid.axis-marketplace.com/000000?token=000000",
"uri": "http://prebid.axis-marketplace.com/pbserver",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/axis/axistest/supplemental/bad_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"httpCalls": [{
"expectedRequest": {
"uri": "http://prebid.axis-marketplace.com/000000?token=000000",
"uri": "http://prebid.axis-marketplace.com/pbserver",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/axis/axistest/supplemental/status-204.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"httpCalls": [{
"expectedRequest": {
"uri": "http://prebid.axis-marketplace.com/000000?token=000000",
"uri": "http://prebid.axis-marketplace.com/pbserver",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/axis/axistest/supplemental/status-not-200.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"httpCalls": [{
"expectedRequest": {
"uri": "http://prebid.axis-marketplace.com/000000?token=000000",
"uri": "http://prebid.axis-marketplace.com/pbserver",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion static/bidder-info/axis.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
endpoint: "http://prebid.axis-marketplace.com/{{.AccountID}}?token={{.SourceId}}"
endpoint: "http://prebid.axis-marketplace.com/pbserver"
maintainer:
email: "help@axis-marketplace.com"
capabilities:
Expand Down

0 comments on commit 19d4dae

Please sign in to comment.