Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/smaato-adap…
Browse files Browse the repository at this point in the history
…ter-video

* origin/master: (26 commits)
  Fix bid dedup (prebid#1456)
  moving docs to website repo (prebid#1443)
  Fixing comment for usage of deal priority field (prebid#1451)
  Fix minor error message spelling mistake "vastml" -> "vastxml" (prebid#1455)
  Adform adapter: additional targeting params added (prebid#1424)
  Added adpod_id to request extension (prebid#1444)
  Fixes bug (prebid#1448)
  Validate External Cache Host  (prebid#1422)
  Enable geo activation of GDPR flag (prebid#1427)
  Update the fallback GVL to last version (prebid#1440)
  Fix no bid debug log (prebid#1375)
  Eplanning adapter: Get domain from page (prebid#1434)
  Fix TCF1 Fetcher Fallback (prebid#1438)
  Refactor rate converter separating scheduler from converter logic to improve testability (prebid#1394)
  [WIP] Bid deduplication enhancement (prebid#1430)
  Video endpoint bid selection enhancements (prebid#1419)
  update to the latest go-gdpr release (prebid#1436)
  Default TCF1 GVL in anticipation of IAB no longer hosting the v1 GVL (prebid#1433)
  Tcf2 id support (prebid#1420)
  Remove redundad struct (prebid#1432)
  ...
  • Loading branch information
sbrosinski committed Aug 27, 2020
2 parents ead6890 + ceaf883 commit d011944
Show file tree
Hide file tree
Showing 142 changed files with 5,664 additions and 3,031 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ It is managed by [Prebid.org](http://prebid.org/overview/what-is-prebid-org.html
and upholds the principles from the [Prebid Code of Conduct](http://prebid.org/wrapper_code_of_conduct.html).

This project does not support the same set of Bidders as Prebid.js, although there is overlap.
The current set can be found in the [adapters](./adapters) package. If you don't see the one you want, feel free to [contribute it](docs/developers/add-new-bidder.md).
The current set can be found in the [adapters](./adapters) package. If you don't see the one you want, feel free to [contribute it](https://docs.prebid.org/prebid-server/developers/add-new-bidder-go.html).

For more information, see:

- [What is Prebid?](http://prebid.org/overview/intro.html)
- [Getting started with Prebid Server](http://prebid.org/dev-docs/get-started-with-prebid-server.html)
- [Current Bidders](http://prebid.org/dev-docs/prebid-server-bidders.html)
- [What is Prebid?](https://prebid.org/overview/intro.html)
- [Prebid Server Overview](https://docs.prebid.org/prebid-server/overview/prebid-server-overview.html)
- [Current Bidders](http://prebid.org/dev-docs/pbs-bidders.html)

## Installation

Expand Down Expand Up @@ -45,14 +45,12 @@ go build .
```

Load the landing page in your browser at `http://localhost:8000/`.
For the full API reference, see [docs/endpoints](docs/endpoints)
For the full API reference, see [the endpoint documentation](https://docs.prebid.org/prebid-server/endpoints/pbs-endpoint-overview.html)


## Contributing

Want to [add an adapter](docs/developers/add-new-bidder.md)? Found a bug? Great!
This project is in its infancy, and many things can be improved.

Want to [add an adapter](https://docs.prebid.org/prebid-server/developers/add-new-bidder-go.html)? Found a bug? Great!

Report bugs, request features, and suggest improvements [on Github](https://github.com/prebid/prebid-server/issues).

Expand Down
21 changes: 21 additions & 0 deletions adapters/adform/adform.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type adformRequest struct {
digitrust *adformDigitrust
currency string
eids string
url string
}

type adformDigitrust struct {
Expand All @@ -61,6 +62,9 @@ type adformAdUnit struct {
PriceType string `json:"priceType,omitempty"`
KeyValues string `json:"mkv,omitempty"`
KeyWords string `json:"mkw,omitempty"`
CDims string `json:"cdims,omitempty"`
MinPrice float64 `json:"minp,omitempty"`
Url string `json:"url,omitempty"`

bidId string
adUnitCode string
Expand Down Expand Up @@ -284,6 +288,10 @@ func (r *adformRequest) buildAdformUrl(a *AdformAdapter) string {
parameters.Add("eids", r.eids)
}

if r.url != "" {
parameters.Add("url", r.url)
}

URL := *a.URL
URL.RawQuery = parameters.Encode()

Expand All @@ -302,6 +310,12 @@ func (r *adformRequest) buildAdformUrl(a *AdformAdapter) string {
if adUnit.KeyWords != "" {
buffer.WriteString(fmt.Sprintf("&mkw=%s", adUnit.KeyWords))
}
if adUnit.CDims != "" {
buffer.WriteString(fmt.Sprintf("&cdims=%s", adUnit.CDims))
}
if adUnit.MinPrice > 0 {
buffer.WriteString(fmt.Sprintf("&minp=%.2f", adUnit.MinPrice))
}
adUnitsParams = append(adUnitsParams, base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(buffer.Bytes()))
}

Expand Down Expand Up @@ -407,6 +421,8 @@ func openRtbToAdformRequest(request *openrtb.BidRequest) (*adformRequest, []erro
adUnits := make([]*adformAdUnit, 0, len(request.Imp))
errors := make([]error, 0, len(request.Imp))
secure := false
url := ""

for _, imp := range request.Imp {
params, _, _, err := jsonparser.Get(imp.Ext, "bidder")
if err != nil {
Expand Down Expand Up @@ -441,6 +457,10 @@ func openRtbToAdformRequest(request *openrtb.BidRequest) (*adformRequest, []erro
secure = true
}

if url == "" {
url = adformAdUnit.Url
}

adformAdUnit.bidId = imp.ID
adformAdUnit.adUnitCode = imp.ID
adUnits = append(adUnits, &adformAdUnit)
Expand Down Expand Up @@ -520,6 +540,7 @@ func openRtbToAdformRequest(request *openrtb.BidRequest) (*adformRequest, []erro
digitrust: digitrust,
currency: requestCurrency,
eids: eids,
url: url,
}, errors
}

Expand Down
30 changes: 22 additions & 8 deletions adapters/adform/adform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type aTagInfo struct {
keyValues string
keyWords string
code string
cdims string
url string
minp float64

price float64
content string
Expand Down Expand Up @@ -320,9 +323,9 @@ func createTestData(secure bool) aBidInfo {
tid: "transaction-id",
buyerUID: "user-id",
tags: []aTagInfo{
{mid: 32344, keyValues: "color:red,age:30-40", keyWords: "red,blue", priceType: "gross", code: "code1", price: 1.23, content: "banner-content1", dealId: "dealId1", creativeId: "creativeId1"},
{mid: 32345, priceType: "net", code: "code2"}, // no bid for ad unit
{mid: 32346, code: "code3", price: 1.24, content: "banner-content2", dealId: "dealId2"},
{mid: 32344, keyValues: "color:red,age:30-40", keyWords: "red,blue", cdims: "300x300,400x200", priceType: "gross", code: "code1", price: 1.23, content: "banner-content1", dealId: "dealId1", creativeId: "creativeId1"},
{mid: 32345, priceType: "net", code: "code2", minp: 23.1, cdims: "300x200"}, // no bid for ad unit
{mid: 32346, code: "code3", price: 1.24, content: "banner-content2", dealId: "dealId2", url: "https://adform.com?a=b"},
},
secure: secure,
currency: "EUR",
Expand Down Expand Up @@ -519,11 +522,22 @@ func getUserExt() []byte {
}

func formatAdUnitJson(tag aTagInfo) string {
return fmt.Sprintf("{ \"mid\": %d%s%s%s}",
return fmt.Sprintf("{ \"mid\": %d%s%s%s%s%s%s}",
tag.mid,
formatAdUnitParam("priceType", tag.priceType),
formatAdUnitParam("mkv", tag.keyValues),
formatAdUnitParam("mkw", tag.keyWords))
formatAdUnitParam("mkw", tag.keyWords),
formatAdUnitParam("cdims", tag.cdims),
formatAdUnitParam("url", tag.url),
formatDemicalAdUnitParam("minp", tag.minp))
}

func formatDemicalAdUnitParam(fieldName string, fieldValue float64) string {
if fieldValue > 0 {
return fmt.Sprintf(", \"%s\": %.2f", fieldName, fieldValue)
}

return ""
}

func formatAdUnitParam(fieldName string, fieldValue string) string {
Expand All @@ -547,10 +561,10 @@ func assertAdformServerRequest(testData aBidInfo, r *http.Request, isOpenRtb boo
var midsWithCurrency = ""
var queryString = ""
if isOpenRtb {
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9RVVSJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZQ&bWlkPTMyMzQ1JnJjdXI9RVVS&bWlkPTMyMzQ2JnJjdXI9RVVS"
queryString = "CC=1&adid=6D92078A-8246-4BA4-AE5B-76104861E7DC&eids=eyJ0ZXN0LmNvbSI6eyJvdGhlcl91c2VyX2lkIjpbMF0sInNvbWVfdXNlcl9pZCI6WzFdfSwidGVzdDIub3JnIjp7Im90aGVyX3VzZXJfaWQiOlsyXX19&fd=1&gdpr=1&gdpr_consent=abc&ip=111.111.111.111&pt=gross&rp=4&stid=transaction-id&" + midsWithCurrency
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9RVVSJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZSZjZGltcz0zMDB4MzAwLDQwMHgyMDA&bWlkPTMyMzQ1JnJjdXI9RVVSJmNkaW1zPTMwMHgyMDAmbWlucD0yMy4xMA&bWlkPTMyMzQ2JnJjdXI9RVVS"
queryString = "CC=1&adid=6D92078A-8246-4BA4-AE5B-76104861E7DC&eids=eyJ0ZXN0LmNvbSI6eyJvdGhlcl91c2VyX2lkIjpbMF0sInNvbWVfdXNlcl9pZCI6WzFdfSwidGVzdDIub3JnIjp7Im90aGVyX3VzZXJfaWQiOlsyXX19&fd=1&gdpr=1&gdpr_consent=abc&ip=111.111.111.111&pt=gross&rp=4&stid=transaction-id&url=https%3A%2F%2Fadform.com%3Fa%3Db&" + midsWithCurrency
} else {
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9VVNEJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZQ&bWlkPTMyMzQ1JnJjdXI9VVNE&bWlkPTMyMzQ2JnJjdXI9VVNE" // no way to pass currency in legacy adapter
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9VVNEJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZSZjZGltcz0zMDB4MzAwLDQwMHgyMDA&bWlkPTMyMzQ1JnJjdXI9VVNEJmNkaW1zPTMwMHgyMDAmbWlucD0yMy4xMA&bWlkPTMyMzQ2JnJjdXI9VVNE" // no way to pass currency in legacy adapter
queryString = "CC=1&adid=6D92078A-8246-4BA4-AE5B-76104861E7DC&fd=1&gdpr=1&gdpr_consent=abc&ip=111.111.111.111&pt=gross&rp=4&stid=transaction-id&" + midsWithCurrency
}

Expand Down
8 changes: 8 additions & 0 deletions adapters/adform/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ var validParams = []string{
`{"mid":"123","mkv":"color:"}`,
`{"mid":"123","mkw":"green,male"}`,
`{"mid":"123","mkv":" ","mkw":" "}`,
`{"mid":"123","cdims":"500x300,400x200","mkw":" "}`,
`{"mid":"123","cdims":"500x300","mkv":" ","mkw":" "}`,
`{"mid":"123","minp":2.1}`,
`{"mid":"123","url":"https://adform.com/page"}`,
}

var invalidParams = []string{
Expand All @@ -66,4 +70,8 @@ var invalidParams = []string{
`{"mid":"123","mkv":"color:blue,l&ngth:350"}`,
`{"mid":"123","mkv":"color::blue"}`,
`{"mid":"123","mkw":"fem&le"}`,
`{"mid":"123","minp":"2.1"}`,
`{"mid":"123","cdims":"500x300:400:200","mkw":" "}`,
`{"mid":"123","cdims":"500x300,400:200","mkv":" ","mkw":" "}`,
`{"mid":"123","url":10}`,
}
138 changes: 138 additions & 0 deletions adapters/adprime/adprime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package adprime

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

"github.com/buger/jsonparser"
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/openrtb_ext"
)

// AdprimeAdapter struct
type AdprimeAdapter struct {
URI string
}

// NewAdprimeBidder Initializes the Bidder
func NewAdprimeBidder(endpoint string) *AdprimeAdapter {
return &AdprimeAdapter{
URI: endpoint,
}
}

// MakeRequests create bid request for adprime demand
func (a *AdprimeAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error
var err error
var tagID string

var adapterRequests []*adapters.RequestData

reqCopy := *request
for _, imp := range request.Imp {
reqCopy.Imp = []openrtb.Imp{imp}

tagID, err = jsonparser.GetString(reqCopy.Imp[0].Ext, "bidder", "TagID")
if err != nil {
errs = append(errs, err)
continue
}

reqCopy.Imp[0].TagID = tagID

adapterReq, errors := a.makeRequest(&reqCopy)
if adapterReq != nil {
adapterRequests = append(adapterRequests, adapterReq)
}
errs = append(errs, errors...)
}
return adapterRequests, errs
}

func (a *AdprimeAdapter) makeRequest(request *openrtb.BidRequest) (*adapters.RequestData, []error) {

var errs []error

reqJSON, err := json.Marshal(request)

if err != nil {
errs = append(errs, err)
return nil, errs
}

headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
return &adapters.RequestData{
Method: "POST",
Uri: a.URI,
Body: reqJSON,
Headers: headers,
}, errs
}

// MakeBids makes the bids
func (a *AdprimeAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
var errs []error

if response.StatusCode == http.StatusNoContent {
return nil, nil
}

if response.StatusCode == http.StatusNotFound {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Page not found: %d. Run with request.debug = 1 for more info", response.StatusCode),
}}
}

if response.StatusCode != http.StatusOK {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info", response.StatusCode),
}}
}

var bidResp openrtb.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 {
bidType, err := getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp)
if err != nil {
errs = append(errs, err)
} else {
b := &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: bidType,
}
bidResponse.Bids = append(bidResponse.Bids, b)
}
}
}
return bidResponse, errs
}

func getMediaTypeForImp(impID string, imps []openrtb.Imp) (openrtb_ext.BidType, error) {
mediaType := openrtb_ext.BidTypeBanner
for _, imp := range imps {
if imp.ID == impID {
if imp.Banner == nil && imp.Video != nil {
mediaType = openrtb_ext.BidTypeVideo
}
return mediaType, nil
}
}

// This shouldnt happen. Lets handle it just incase by returning an error.
return "", &errortypes.BadInput{
Message: fmt.Sprintf("Failed to find impression \"%s\" ", impID),
}
}
12 changes: 12 additions & 0 deletions adapters/adprime/adprime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package adprime

import (
"testing"

"github.com/prebid/prebid-server/adapters/adapterstest"
)

func TestJsonSamples(t *testing.T) {
adprimeAdapter := NewAdprimeBidder("http://delta.adprime.com/?c=o&m=ortb")
adapterstest.RunJSONBidderTest(t, "adprimetest", adprimeAdapter)
}
Loading

0 comments on commit d011944

Please sign in to comment.