Skip to content

Commit

Permalink
AIDEM: Added use to macros library (#3403)
Browse files Browse the repository at this point in the history
Co-authored-by: Giovanni Sollazzo <[email protected]>
Co-authored-by: AndreaC <[email protected]>
Co-authored-by: darkstar <[email protected]>
Co-authored-by: AndreaT <[email protected]>
  • Loading branch information
5 people authored Jan 23, 2024
1 parent 2ae62cf commit ae291f9
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 25 deletions.
50 changes: 45 additions & 5 deletions adapters/aidem/aidem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ 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/macros"
"github.com/prebid/prebid-server/v2/openrtb_ext"
)

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

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
Expand All @@ -23,12 +25,22 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
return nil, []error{err}
}

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

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

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

return []*adapters.RequestData{{
Method: "POST",
Uri: a.endpoint,
Uri: url,
Body: reqJson,
Headers: headers,
}}, nil
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 := &adapter{
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 *adapter) buildEndpointURL(params *openrtb_ext.ExtImpAidem) (string, error) {
endpointParams := macros.EndpointTemplateParams{PublisherID: params.PublisherId}
return macros.ResolveMacros(a.EndpointTemplate, endpointParams)
}
4 changes: 2 additions & 2 deletions adapters/aidem/aidem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

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
8 changes: 4 additions & 4 deletions openrtb_ext/imp_aidem.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package openrtb_ext

type ImpExtFoo struct {
SiteID string `json:"siteId"`
PublisherID string `json:"publisherId"`
PlacementID string `json:"placementId"`
type ExtImpAidem struct {
PlacementId string `json:"placementId"`
SiteId string `json:"siteId"`
PublisherId string `json:"publisherId"`
RateLimit string `json:"rateLimit"`
}
4 changes: 2 additions & 2 deletions static/bidder-info/aidem.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
endpoint: "https://zero.aidemsrv.com/ortb/v2.6/bid/request"
endpoint: "https://zero.aidemsrv.com/ortb/v2.6/bid/request?billing_id={{.PublisherID}}"
maintainer:
email: [email protected]
modifyingVastXmlAllowed: true
Expand All @@ -15,5 +15,5 @@ capabilities:
- native
userSync:
redirect:
url: https://gum.aidemsrv.com/prebid_sync?gdpr={{.GDPR}}&consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redirect={{.RedirectURL}}
url: https://gum.aidemsrv.com/prebid_sync?gdpr={{.GDPR}}&consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redirect={{.RedirectURL}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}
userMacro: "$UID"

0 comments on commit ae291f9

Please sign in to comment.