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

AIDEM: Added use to macros library #3403

Merged
merged 20 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
64 changes: 52 additions & 12 deletions adapters/aidem/aidem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,49 @@ import (
"encoding/json"
"fmt"
"net/http"
"text/template"

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

type adapter struct {
endpoint string
type AIDEMAdapter struct {
EndpointTemplate *template.Template
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
func (a *AIDEMAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {

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

impExt, err := getImpressionExt(&request.Imp[0])
if err != nil {
return nil, []error{err}
}

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

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

return []*adapters.RequestData{{
Method: "POST",
Uri: a.endpoint,
Uri: url,
Body: reqJson,
Headers: headers,
}}, nil
}

func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
func (a *AIDEMAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
var errs []error

if adapters.IsResponseStatusCodeNoContent(response) {
Expand Down Expand Up @@ -81,9 +93,15 @@ func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest

// Builder builds a new instance of the AIDEM adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
return &adapter{
endpoint: config.Endpoint,
}, nil
urlTemplate, err := template.New("endpointTemplate").Parse(config.Endpoint)
if err != nil {
return nil, fmt.Errorf("unable to parse endpoint url template: %v", err)
}

bidder := &AIDEMAdapter{
EndpointTemplate: urlTemplate,
}
return bidder, nil
}

func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
Expand All @@ -100,3 +118,25 @@ func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
return "", fmt.Errorf("Unable to fetch mediaType in multi-format: %s", bid.ImpID)
}
}

func getImpressionExt(imp *openrtb2.Imp) (*openrtb_ext.ExtImpAIDEM, error) {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, &errortypes.BadInput{
Message: err.Error(),
}
}
var AIDEMExt openrtb_ext.ExtImpAIDEM
if err := json.Unmarshal(bidderExt.Bidder, &AIDEMExt); err != nil {
return nil, &errortypes.BadInput{
Message: err.Error(),
}
}
return &AIDEMExt, nil
}

// Builds enpoint url based on adapter-specific pub settings from imp.ext
func (a *AIDEMAdapter) buildEndpointURL(params *openrtb_ext.ExtImpAIDEM) (string, error) {
endpointParams := macros.EndpointTemplateParams{PublisherID: params.PublisherId}
return macros.ResolveMacros(a.EndpointTemplate, endpointParams)
}
10 changes: 5 additions & 5 deletions adapters/aidem/aidem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (

"github.com/stretchr/testify/assert"

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

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderAidem, config.Adapter{
Endpoint: "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
Endpoint: "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id={{.PublisherID}}",
}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
Expand All @@ -26,5 +26,5 @@ func TestEndpointTemplateMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderAidem, config.Adapter{
Endpoint: "{{Malformed}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

assert.Nil(t, buildErr)
assert.Error(t, buildErr)
}
2 changes: 1 addition & 1 deletion adapters/aidem/aidemtest/exemplary/multi-format.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/aidem/aidemtest/exemplary/no-bid.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/aidem/aidemtest/exemplary/optional-params.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/aidem/aidemtest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
2 changes: 1 addition & 1 deletion adapters/aidem/aidemtest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "some-request-id",
"imp": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "some-request-id",
"imp": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"id": "test-request-id",
"imp": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request",
"uri": "https://fakezero.aidemsrv.com/ortb/v2.6/bid/request?billing_id=1234",
"body": {
"app": {
"bundle": "com.example.app"
Expand Down
2 changes: 1 addition & 1 deletion adapters/aidem/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

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

// This file actually intends to test static/bidder-params/aidem.json TODO: MUST BE CREATED
Expand Down
Loading
Loading