Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/prebid/prebid-server into…
Browse files Browse the repository at this point in the history
… sharethrough_master

# Conflicts:
#	exchange/adapter_map.go
#	openrtb_ext/bidders.go
  • Loading branch information
Mathieu Pheulpin committed May 15, 2019
2 parents a17beca + 993f2f7 commit 0b73d0e
Show file tree
Hide file tree
Showing 114 changed files with 6,926 additions and 1,347 deletions.
25 changes: 23 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@
[[constraint]]
branch = "master"
name = "github.com/asaskevich/govalidator"

[[constraint]]
name = "github.com/gofrs/uuid"
version = "^3.2.0"
2 changes: 1 addition & 1 deletion adapters/33across/usersync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
)

func New33AcrossSyncer(temp *template.Template) usersync.Usersyncer {
return adapters.NewSyncer("ttx", 58, temp, adapters.SyncTypeRedirect)
return adapters.NewSyncer("33across", 58, temp, adapters.SyncTypeIframe)
}
6 changes: 3 additions & 3 deletions adapters/33across/usersync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
)

func Test33AcrossSyncer(t *testing.T) {
temp := template.Must(template.New("sync-template").Parse("https://ssc-cms.33across.com/ps/?ri=123&ru=localhost%2Fsetuid%3Fbidder%3Dttx%26uid%3D33XUSERID33X"))
temp := template.Must(template.New("sync-template").Parse("https://ic.tynt.com/r/d?m=xch&rt=html&ri=123&ru=%2Fsetuid%3Fbidder%3D33across%26uid%3D33XUSERID33X&id=zzz000000000002zzz"))
syncer := New33AcrossSyncer(temp)
syncInfo, err := syncer.GetUsersyncInfo("", "")
assert.NoError(t, err)
assert.Equal(t, "https://ssc-cms.33across.com/ps/?ri=123&ru=localhost%2Fsetuid%3Fbidder%3Dttx%26uid%3D33XUSERID33X", syncInfo.URL)
assert.Equal(t, "redirect", syncInfo.Type)
assert.Equal(t, "https://ic.tynt.com/r/d?m=xch&rt=html&ri=123&ru=%2Fsetuid%3Fbidder%3D33across%26uid%3D33XUSERID33X&id=zzz000000000002zzz", syncInfo.URL)
assert.Equal(t, "iframe", syncInfo.Type)
assert.EqualValues(t, 58, syncer.GDPRVendorID())
assert.False(t, syncInfo.SupportCORS)
}
1 change: 1 addition & 0 deletions adapters/adform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please contact <[email protected]> if you would like to build and deploy Prebid server and use it with Adform.
32 changes: 17 additions & 15 deletions adapters/adform/adform.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type adformRequest struct {
gdprApplies string
consent string
digitrust *adformDigitrust
cur string
currency string
}

type adformDigitrust struct {
Expand Down Expand Up @@ -75,6 +75,7 @@ type adformBid struct {

const priceTypeGross = "gross"
const priceTypeNet = "net"
const defaultCurrency = "USD"

func isPriceTypeValid(priceType string) (string, bool) {
pt := strings.ToLower(priceType)
Expand Down Expand Up @@ -224,7 +225,7 @@ func pbsRequestToAdformRequest(a *AdformAdapter, request *pbs.PBSRequest, bidder
gdprApplies: gdprApplies,
consent: consent,
digitrust: digitrust,
cur: "USD",
currency: defaultCurrency,
}, nil
}

Expand Down Expand Up @@ -286,7 +287,7 @@ func (r *adformRequest) buildAdformUrl(a *AdformAdapter) string {

adUnitsParams := make([]string, 0, len(r.adUnits))
for _, adUnit := range r.adUnits {
str := fmt.Sprintf("mid=%s&rcur=%s", adUnit.MasterTagId, r.cur)
str := fmt.Sprintf("mid=%s&rcur=%s", adUnit.MasterTagId, r.currency)
adUnitsParams = append(adUnitsParams, base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString([]byte(str)))
}

Expand Down Expand Up @@ -366,7 +367,7 @@ func NewAdformBidder(client *http.Client, endpointURL string) *AdformAdapter {
return &AdformAdapter{
http: a,
URL: uriObj,
version: "0.1.2",
version: "0.1.3",
}
}

Expand Down Expand Up @@ -475,20 +476,17 @@ func openRtbToAdformRequest(request *openrtb.BidRequest) (*adformRequest, []erro
}
}

cur := "USD"
if request.Cur != nil && len(request.Cur) > 0 {
/* If USD is one of the supported currencies, then we should send that to the adserver */
usdSupported := false
requestCurrency := defaultCurrency
if len(request.Cur) != 0 {
hasDefaultCurrency := false
for _, c := range request.Cur {
if c == "USD" {
usdSupported = true
if defaultCurrency == c {
hasDefaultCurrency = true
break
}
}

/* If USD is not a supported currency, then we'll just choose the top level currency */
if usdSupported == false {
cur = request.Cur[0]
if !hasDefaultCurrency {
requestCurrency = request.Cur[0]
}
}

Expand All @@ -504,7 +502,7 @@ func openRtbToAdformRequest(request *openrtb.BidRequest) (*adformRequest, []erro
gdprApplies: gdprApplies,
consent: consent,
digitrust: digitrust,
cur: cur,
currency: requestCurrency,
}, errors
}

Expand Down Expand Up @@ -565,6 +563,7 @@ func (a *AdformAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRe

func toOpenRtbBidResponse(adformBids []*adformBid, r *openrtb.BidRequest) *adapters.BidderResponse {
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(adformBids))
currency := bidResponse.Currency

if len(adformBids) > 0 {
bidResponse.Currency = adformBids[0].Currency
Expand All @@ -586,7 +585,10 @@ func toOpenRtbBidResponse(adformBids []*adformBid, r *openrtb.BidRequest) *adapt
}

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{Bid: &openRtbBid, BidType: openrtb_ext.BidTypeBanner})
currency = bid.Currency
}

bidResponse.Currency = currency

return bidResponse
}
27 changes: 20 additions & 7 deletions adapters/adform/adform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type aBidInfo struct {
tid string
buyerUID string
secure bool
currency string
delay time.Duration
}

Expand All @@ -57,7 +58,7 @@ var adformTestData aBidInfo
// Legacy auction tests

func DummyAdformServer(w http.ResponseWriter, r *http.Request) {
errorString := assertAdformServerRequest(adformTestData, r)
errorString := assertAdformServerRequest(adformTestData, r, false)
if errorString != nil {
http.Error(w, *errorString, http.StatusInternalServerError)
return
Expand All @@ -82,7 +83,7 @@ func createAdformServerResponse(testData aBidInfo) ([]byte, error) {
ResponseType: "banner",
Banner: testData.tags[0].content,
Price: testData.tags[0].price,
Currency: "USD",
Currency: "EUR",
Width: testData.width,
Height: testData.height,
DealId: testData.tags[0].dealId,
Expand All @@ -93,7 +94,7 @@ func createAdformServerResponse(testData aBidInfo) ([]byte, error) {
ResponseType: "banner",
Banner: testData.tags[2].content,
Price: testData.tags[2].price,
Currency: "USD",
Currency: "EUR",
Width: testData.width,
Height: testData.height,
DealId: testData.tags[2].dealId,
Expand Down Expand Up @@ -171,6 +172,7 @@ func initTestData(server *httptest.Server, t *testing.T) (*AdformAdapter, contex
tid: "transaction-id",
buyerUID: "user-id",
secure: false,
currency: "EUR",
}
adformTestData.tags[0] = aTagInfo{mid: 32344, priceType: "gross", code: "code1", price: 1.23, content: "banner-content1", dealId: "dealId1", creativeId: "creativeId1"}
adformTestData.tags[1] = aTagInfo{mid: 32345, priceType: "net", code: "code2"} // no bid for ad unit
Expand Down Expand Up @@ -289,7 +291,7 @@ func TestOpenRTBRequest(t *testing.T) {
}
r.Header = httpRequests[0].Headers

errorString := assertAdformServerRequest(*testData, r)
errorString := assertAdformServerRequest(*testData, r, true)
if errorString != nil {
t.Errorf("Request error: %s", *errorString)
}
Expand Down Expand Up @@ -332,7 +334,8 @@ func createTestData() *aBidInfo {
{mid: 32345, priceType: "net", code: "code2"}, // no bid for ad unit
{mid: 32346, code: "code3", price: 1.24, content: "banner-content2", dealId: "dealId2"},
},
secure: true,
secure: true,
currency: "EUR",
}
return testData
}
Expand Down Expand Up @@ -374,6 +377,9 @@ func createOpenRtbRequest(testData *aBidInfo) *openrtb.BidRequest {
bidRequest.Regs = &regs
bidRequest.User.Ext = getUserExt()

bidRequest.Cur = make([]string, 1)
bidRequest.Cur[0] = testData.currency

return bidRequest
}

Expand Down Expand Up @@ -504,7 +510,7 @@ func getPriceTypeString(priceType string) string {
return ""
}

func assertAdformServerRequest(testData aBidInfo, r *http.Request) *string {
func assertAdformServerRequest(testData aBidInfo, r *http.Request, isOpenRtb bool) *string {
if ok, err := equal("GET", r.Method, "HTTP method"); !ok {
return err
}
Expand All @@ -514,7 +520,14 @@ func assertAdformServerRequest(testData aBidInfo, r *http.Request) *string {
}
}

if ok, err := equal("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&bWlkPTMyMzQ0JnJjdXI9VVNE&bWlkPTMyMzQ1JnJjdXI9VVNE&bWlkPTMyMzQ2JnJjdXI9VVNE", r.URL.RawQuery, "Query string"); !ok {
var midsWithCurrency = ""
if isOpenRtb {
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9RVVS&bWlkPTMyMzQ1JnJjdXI9RVVS&bWlkPTMyMzQ2JnJjdXI9RVVS"
} else {
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9VVNE&bWlkPTMyMzQ1JnJjdXI9VVNE&bWlkPTMyMzQ2JnJjdXI9VVNE" // no way to pass currency in legacy adapter
}

if ok, err := equal("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, r.URL.RawQuery, "Query string"); !ok {
return err
}
if ok, err := equal("application/json;charset=utf-8", r.Header.Get("Content-Type"), "Content type"); !ok {
Expand Down
Loading

0 comments on commit 0b73d0e

Please sign in to comment.