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

New Adapter: Admatic #3654

Merged
merged 46 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d7218f0
admatic s2s
bakicam May 2, 2024
594a808
Merge branch 'prebid:master' into master
bakicam May 2, 2024
546cda3
Update admatic.go
bakicam May 2, 2024
435b598
formatted jsons
bakicam May 2, 2024
dbec2de
fmt
bakicam May 2, 2024
c05d833
Merge branch 'prebid:master' into master
farukcam May 13, 2024
094bd52
Update admatic.go
bakicam May 14, 2024
87dd911
Merge branch 'master' of https://github.com/Admatic-Sofware/prebid-se…
bakicam May 14, 2024
49b9c49
Merge branch 'prebid:master' into master
farukcam May 22, 2024
bc0468f
impIDs
bakicam May 23, 2024
f6caf06
Merge branch 'master' of https://github.com/Admatic-Sofware/prebid-se…
bakicam May 23, 2024
801a99c
Merge branch 'prebid:master' into master
farukcam May 23, 2024
60a434c
Update admatic.json
bakicam May 23, 2024
331f4f0
Merge branch 'master' of https://github.com/Admatic-Sofware/prebid-se…
bakicam May 23, 2024
4fb522c
Merge branch 'prebid:master' into master
farukcam May 23, 2024
ac61d1c
Update admatic.go
bakicam May 24, 2024
f978cf0
Update admatic.go
bakicam May 24, 2024
f025b87
Update admatic.yaml
bakicam May 24, 2024
b02724b
Update admatic.go
bakicam May 24, 2024
63387d3
Update admatic.go
bakicam May 24, 2024
6754f16
Merge branch 'prebid:master' into master
farukcam May 27, 2024
c5a8a1e
Merge branch 'prebid:master' into master
farukcam May 30, 2024
61369b4
Merge branch 'prebid:master' into master
farukcam May 31, 2024
41258e8
Merge branch 'prebid:master' into master
farukcam Jun 2, 2024
6d11972
Merge branch 'prebid:master' into master
farukcam Jun 4, 2024
fbb1c27
Merge branch 'prebid:master' into master
farukcam Jun 5, 2024
186ce42
Merge branch 'prebid:master' into master
farukcam Jun 5, 2024
a3c2dd9
Merge branch 'prebid:master' into master
farukcam Jun 7, 2024
ac73568
Merge branch 'prebid:master' into master
farukcam Jun 11, 2024
6577bc0
Merge branch 'prebid:master' into master
farukcam Jun 17, 2024
af62418
Merge branch 'prebid:master' into master
farukcam Jun 24, 2024
81e7c20
Merge branch 'prebid:master' into master
farukcam Jun 24, 2024
4d10b47
Merge branch 'prebid:master' into master
farukcam Jun 25, 2024
d1dfaef
Update admatic.go
bakicam Jun 26, 2024
83b23a1
Merge branch 'prebid:master' into master
farukcam Jun 28, 2024
6198a7b
Merge branch 'prebid:master' into master
farukcam Jun 28, 2024
6558291
solved problems
bakicam Jun 29, 2024
9fe986d
Update server-error.json
bakicam Jun 29, 2024
3dced1b
update server error
bakicam Jun 29, 2024
fa1bbba
Create bad-request.json
bakicam Jun 29, 2024
c2655e5
Merge branch 'prebid:master' into master
farukcam Jul 2, 2024
5fc719d
solved problems
bakicam Jul 2, 2024
06a91e3
Create multiple-imps-with-error.json
bakicam Jul 2, 2024
9d10bdd
Update multiple-imps-with-error.json
bakicam Jul 2, 2024
1df070a
Create multiple-imps.json
bakicam Jul 2, 2024
d20bbb8
Update multiple-imps.json
bakicam Jul 2, 2024
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
89 changes: 35 additions & 54 deletions adapters/admatic/admatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"text/template"

"github.com/prebid/openrtb/v20/openrtb2"
Expand Down Expand Up @@ -32,85 +31,67 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co
}

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

host := ""

requestCopy := *request
for _, imp := range request.Imp {
bakicam marked this conversation as resolved.
Show resolved Hide resolved
admaticExt, err := getImpressionExt(imp)
requestCopy.Imp = []openrtb2.Imp{imp}

endpoint, err := a.buildEndpointFromRequest(&imp)
if err != nil {
return nil, []error{err}
errs = append(errs, err)
continue
}

if host == "" {
host = admaticExt.Host
} else if host != admaticExt.Host {
return nil, []error{&errortypes.BadInput{
Message: "There must be only one Host",
}}
requestJSON, err := json.Marshal(requestCopy)
if err != nil {
errs = append(errs, err)
continue
}
}

resolvedUrl, err := a.resolveUrl(host)

if err != nil {
return nil, []error{err}
}

requestJSON, err := json.Marshal(request)
if err != nil {
return nil, []error{err}
}
request := &adapters.RequestData{
Method: http.MethodPost,
Body: requestJSON,
Uri: endpoint,
ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp),
}

requestData := &adapters.RequestData{
Method: "POST",
Uri: resolvedUrl,
Body: requestJSON,
ImpIDs: openrtb_ext.GetImpIDs(request.Imp),
requests = append(requests, request)
}

return []*adapters.RequestData{requestData}, nil
return requests, errs
}

func getImpressionExt(imp openrtb2.Imp) (*openrtb_ext.ImpExtAdmatic, error) {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, &errortypes.BadInput{
Message: "Bidder extension not provided or can't be unmarshalled",
func (a *adapter) buildEndpointFromRequest(imp *openrtb2.Imp) (string, error) {
var impExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &impExt); err != nil {
return "", &errortypes.BadInput{
Message: fmt.Sprintf("Failed to deserialize bidder impression extension: %v", err),
}
}

var admaticExt openrtb_ext.ImpExtAdmatic
if err := json.Unmarshal(bidderExt.Bidder, &admaticExt); err != nil {
return nil, &errortypes.BadInput{
Message: "Error while unmarshaling bidder extension",
if err := json.Unmarshal(impExt.Bidder, &admaticExt); err != nil {
return "", &errortypes.BadInput{
Message: fmt.Sprintf("Failed to deserialize AdMatic extension: %v", err),
}
}

return &admaticExt, nil
}

// resolveUrl "un-templates" the endpoint by replacing macroses and adding the required query parameters
func (a *adapter) resolveUrl(host string) (string, error) {
params := macros.EndpointTemplateParams{Host: host}

endpointStr, err := macros.ResolveMacros(a.endpoint, params)
if err != nil {
return "", err
endpointParams := macros.EndpointTemplateParams{
Host: admaticExt.Host,
}

parsedUrl, err := url.Parse(endpointStr)
if err != nil {
return "", err
}

return parsedUrl.String(), nil
return macros.ResolveMacros(a.endpoint, endpointParams)
}

func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if responseData.StatusCode == http.StatusNoContent {
if adapters.IsResponseStatusCodeNoContent(responseData) {
return nil, nil
}

if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil {
return nil, []error{err}
}
var response openrtb2.BidResponse
if err := json.Unmarshal(responseData.Body, &response); err != nil {
return nil, []error{err}
Expand Down
8 changes: 8 additions & 0 deletions adapters/admatic/admatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"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/stretchr/testify/assert"
)

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

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

func TestEndpointTemplateMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderAso, config.Adapter{
bakicam marked this conversation as resolved.
Show resolved Hide resolved
Endpoint: "host={{Host}}"}, config.Server{ExternalUrl: "http://hosturl.com"})

assert.Error(t, buildErr)
}
8 changes: 5 additions & 3 deletions adapters/admatic/admatictest/exemplary/banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr"
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
Expand All @@ -23,7 +24,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs.admatic.com.tr?host=admatic.rtb.admatic.com.tr",
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id-banner",
"imp": [
Expand All @@ -39,7 +40,8 @@
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr"
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions adapters/admatic/admatictest/exemplary/native.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr"
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
Expand All @@ -18,7 +19,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs.admatic.com.tr?host=admatic.rtb.admatic.com.tr",
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id-native",
"imp": [
Expand All @@ -29,7 +30,8 @@
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr"
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions adapters/admatic/admatictest/exemplary/optional-params.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr",
"host": "layer.serve.admatic.com.tr",
"networkId": 12345,
"bidFloor": 0.1,
"isTest": false
}
Expand All @@ -25,7 +26,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs.admatic.com.tr?host=admatic.rtb.admatic.com.tr",
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id-banner",
"imp": [
Expand All @@ -41,7 +42,8 @@
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr",
"host": "layer.serve.admatic.com.tr",
"networkId": 12345,
"bidFloor": 0.1,
"isTest": false
}
Expand Down
8 changes: 5 additions & 3 deletions adapters/admatic/admatictest/exemplary/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr"
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
Expand All @@ -20,7 +21,7 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs.admatic.com.tr?host=admatic.rtb.admatic.com.tr",
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id",
"imp": [
Expand All @@ -33,7 +34,8 @@
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr"
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
{
"id": "test-imp-id",
"banner": {
"format": [{"w": 728, "h": 90}]
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr"
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
Expand All @@ -19,18 +25,24 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs.admatic.com.tr?host=admatic.rtb.admatic.com.tr",
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [{"w": 728, "h": 90}]
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr"
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
Expand Down
22 changes: 17 additions & 5 deletions adapters/admatic/admatictest/supplemental/response-204.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
{
"id": "test-imp-id",
"banner": {
"format": [{"w": 728, "h": 90}]
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr"
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
Expand All @@ -19,18 +25,24 @@
"httpCalls": [
{
"expectedRequest": {
"uri": "http://pbs.admatic.com.tr?host=admatic.rtb.admatic.com.tr",
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [{"w": 728, "h": 90}]
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"host": "admatic.rtb.admatic.com.tr"
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
Expand Down
Loading
Loading