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: Generic #3743

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
115 changes: 115 additions & 0 deletions adapters/generic/generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package generic

import (
"encoding/json"
"fmt"
"net/http"

"github.com/prebid/openrtb/v20/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"
)

type adapter struct {
endpoint string
}

type genericBidExt struct {
VideoCreativeInfo *genericBidExtVideo `json:"video,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do bidders return these fields today in PBS-Java?

}

type genericBidExtVideo struct {
Duration *int `json:"duration,omitempty"`
}

func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
bidder := &adapter{
endpoint: config.Endpoint,
}
return bidder, nil
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
requestJSON, err := json.Marshal(request)
if err != nil {
return nil, []error{err}
}

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

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

func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if response.StatusCode == http.StatusNoContent {
return nil, nil
}
if response.StatusCode == http.StatusBadRequest {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Unexpected status code: %d.", response.StatusCode),
}}
}
if response.StatusCode != http.StatusOK {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Unexpected status code: %d.", response.StatusCode),
}}
}
var bidResp openrtb2.BidResponse
if err := json.Unmarshal(response.Body, &bidResp); err != nil {
return nil, []error{err}
}
bidResponse := adapters.NewBidderResponseWithBidsCapacity(1)
for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
var mediaType = getBidType(sb.Bid[i].ImpID, internalRequest.Imp)
bid := sb.Bid[i]
typedBid := &adapters.TypedBid{
Bid: &bid,
BidType: mediaType,
BidVideo: &openrtb_ext.ExtBidPrebidVideo{},
}
if bid.Ext != nil {
var bidExt *genericBidExt
err := json.Unmarshal(bid.Ext, &bidExt)
if err != nil {
return nil, []error{fmt.Errorf("bid.ext json unmarshal error")}
} else if bidExt != nil {
if bidExt.VideoCreativeInfo != nil && bidExt.VideoCreativeInfo.Duration != nil {
typedBid.BidVideo.Duration = *bidExt.VideoCreativeInfo.Duration
}
}
}
bidResponse.Bids = append(bidResponse.Bids, typedBid)
}
}
return bidResponse, nil

}

func getBidType(impId string, imps []openrtb2.Imp) openrtb_ext.BidType {
bidType := openrtb_ext.BidTypeBanner
for _, imp := range imps {
if imp.ID == impId {
if imp.Banner != nil {
break
}
if imp.Video != nil {
bidType = openrtb_ext.BidTypeVideo
break
}
if imp.Native != nil {
bidType = openrtb_ext.BidTypeNative
break
}

}
}
return bidType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the approach used by PBS-Java? It's an antipattern which is all too common in adapters. IMHO we should prefer MType, then perhaps the prebid metadata extension, and maybe finally fall back to this approach,, in which case audio needs to be supported here too.

}
5 changes: 5 additions & 0 deletions openrtb_ext/imp_generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openrtb_ext

type ExtImpGeneric struct {
ExampleProperty string `json:"example"`
}
154 changes: 154 additions & 0 deletions static/bidder-info/generic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
endpoint: https://
aliases:
genericAlias:
enabled: false
adrino:
enabled: false
endpoint: https://prd-prebid-bidder.adrino.io/openrtb/bid
meta-info:
maintainer-email: [email protected]
app-media-types:
site-media-types:
- native
supported-vendors:
vendor-id: 1072
ccx:
enabled: false
endpoint: https://delivery.clickonometrics.pl/ortb/prebid/bid
meta-info:
maintainer-email: [email protected]
site-media-types:
- banner
- video
vendor-id: 773
usersync:
enabled: true
cookie-family-name: ccx
redirect:
url: https://sync.clickonometrics.pl/prebid/set-cookie?gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&cb={{redirect_url}}
support-cors: false
uid-macro: '${USER_ID}'
infytv:
enabled: false
endpoint: https://nxs.infy.tv/pbs/openrtb
meta-info:
maintainer-email: [email protected]
app-media-types:
- video
site-media-types:
- video
supported-vendors:
vendor-id: 0
loopme:
enabled: false
endpoint: http://prebid-eu.loopmertb.com
meta-info:
maintainer-email: [email protected]
app-media-types:
- banner
- video
- native
site-media-types:
- banner
- video
- native
supported-vendors:
vendor-id: 109
zeta_global_ssp:
enabled: false
endpoint: https://ssp.disqus.com/bid/prebid-server?sid=GET_SID_FROM_ZETA
endpoint-compression: gzip
meta-info:
maintainer-email: [email protected]
app-media-types:
- banner
- video
site-media-types:
- banner
- video
supported-vendors:
vendor-id: 833
usersync:
enabled: true
cookie-family-name: zeta_global_ssp
redirect:
url: https://ssp.disqus.com/redirectuser?sid=GET_SID_FROM_ZETA&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&r={{redirect_url}}
uid-macro: 'BUYERUID'
support-cors: false
blue:
enabled: false
endpoint: https://prebid-us-east-1.getblue.io/?src=prebid
meta-info:
maintainer-email: [email protected]
site-media-types:
- banner
app-media-types:
- banner
supported-vendors:
vendor-id: 620
cwire:
enabled: false
endpoint: https://ortb.cwi.re/v1/bid
modifying-vast-xml-allowed: false
endpoint-compression: gzip
meta-info:
maintainer-email: [email protected]
app-media-types:
site-media-types:
- banner
supported-vendors:
vendor-id: 1081
adsinteractive:
enabled: false
endpoint: http://bid.adsinteractive.com/prebid
modifying-vast-xml-allowed: false
meta-info:
maintainer-email: [email protected]
app-media-types:
- banner
site-media-types:
- banner
supported-vendors:
vendor-id: 1212
usersync:
cookie-family-name: adsinteractive
redirect:
url: https://sync.adsinteractive.com/getuid?{{redirect_url}}&gpp={{gpp}}&gpp_sid={{gpp_sid}}
support-cors: false
uid-macro: '$AUID'
nativo:
enabled: false
endpoint: https://exchange.postrelease.com/esi?ntv_epid=7
pbs-enforces-ccpa: false
meta-info:
maintainer-email: [email protected]
app-media-types:
- banner
- video
- native
site-media-types:
- banner
- video
- native
supported-vendors:
vendor-id: 263
usersync:
cookie-family-name: nativo
redirect:
url: http://jadserve.postrelease.com/suid/101787?gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&ntv_gpp_consent={{gpp}}&ntv_r={{redirect_url}}
support-cors: false
uid-macro: 'NTV_USER_ID'
meta-info:
maintainer-email: [email protected]
app-media-types:
- banner
- video
- native
- audio
site-media-types:
- banner
- video
- native
- audio
supported-vendors:
vendor-id: 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PBS-Java config is not valid for PBS-Go. This should break out into one file per alias of the generic adapter.

IMHO the root generic adapter is a special case which should not have a generic.yaml file, which likely requires extra logic.

13 changes: 13 additions & 0 deletions static/bidder-params/generic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Generic Adapter Params",
"description": "A schema which validates params accepted by the Generic adapter",
"type": "object",
"properties": {
"exampleProperty": {
"type": "string",
"description": "Example property",
"minLength": 1
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's invalid in PBS-Go for aliases to specify a different json schema. Does PBS-Java allow generic aliases to specify their own schema?

Loading