-
Notifications
You must be signed in to change notification settings - Fork 752
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
Missena: Update params #4057
base: master
Are you sure you want to change the base?
Missena: Update params #4057
Changes from 2 commits
9144aec
091ffa9
9398c8a
75e77ba
7c92744
dd7c2c1
8f5c3f5
5b606eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,40 +12,60 @@ import ( | |
"github.com/prebid/prebid-server/v3/errortypes" | ||
"github.com/prebid/prebid-server/v3/openrtb_ext" | ||
"github.com/prebid/prebid-server/v3/util/jsonutil" | ||
"github.com/prebid/prebid-server/v3/version" | ||
) | ||
|
||
type adapter struct { | ||
endpoint string | ||
} | ||
|
||
type MissenaAdRequest struct { | ||
RequestId string `json:"request_id"` | ||
Timeout int `json:"timeout"` | ||
Referer string `json:"referer"` | ||
RefererCanonical string `json:"referer_canonical"` | ||
GDPRConsent string `json:"consent_string"` | ||
GDPR bool `json:"consent_required"` | ||
Placement string `json:"placement"` | ||
TestMode string `json:"test"` | ||
Adunit string `json:"adunit,omitempty"` | ||
COPPA int8 `json:"coppa,omitempty"` | ||
Currency string `json:"currency,omitempty"` | ||
EIDs []openrtb2.EID `json:"userEids,omitempty"` | ||
Floor float64 `json:"floor,omitempty"` | ||
FloorCurrency string `json:"floor_currency,omitempty"` | ||
GDPR bool `json:"consent_required,omitempty"` | ||
GDPRConsent string `json:"consent_string,omitempty"` | ||
IdempotencyKey string `json:"ik,omitempty"` | ||
Referer string `json:"referer,omitempty"` | ||
RefererCanonical string `json:"referer_canonical,omitempty"` | ||
RequestID string `json:"request_id,omitempty"` | ||
SChain *openrtb2.SupplyChain `json:"schain,omitempty"` | ||
Timeout int `json:"timeout,omitempty"` | ||
URL string `json:"url,omitempty"` | ||
UserParams MissenaUserParams `json:"params"` | ||
USPrivacy string `json:"us_privacy,omitempty"` | ||
Version string `json:"version,omitempty"` | ||
} | ||
|
||
type MissenaBidServerResponse struct { | ||
Ad string `json:"ad"` | ||
Cpm float64 `json:"cpm"` | ||
Currency string `json:"currency"` | ||
RequestId string `json:"requestId"` | ||
RequestID string `json:"requestId"` | ||
} | ||
|
||
type MissenaUserParams struct { | ||
Formats []string `json:"formats,omitempty"` | ||
Placement string `json:"placement,omitempty" default:"sticky"` | ||
Sample string `json:"sample,omitempty"` | ||
Settings map[string]any `json:"settings,omitempty"` | ||
} | ||
|
||
type MissenaInternalParams struct { | ||
ApiKey string | ||
RequestId string | ||
Timeout int | ||
Referer string | ||
RefererCanonical string | ||
GDPRConsent string | ||
Formats []string | ||
GDPR bool | ||
GDPRConsent string | ||
Placement string | ||
TestMode string | ||
Referer string | ||
RefererCanonical string | ||
RequestId string | ||
Sample string | ||
Settings map[string]any | ||
Timeout int | ||
} | ||
|
||
type MissenaAdapter struct { | ||
|
@@ -60,23 +80,61 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co | |
return bidder, nil | ||
} | ||
|
||
func (a *adapter) makeRequest(missenaParams MissenaInternalParams, reqInfo *adapters.ExtraRequestInfo, impID string, request *openrtb2.BidRequest) (*adapters.RequestData, error) { | ||
func getCurrency(currencies []string) (string, error) { | ||
eurAvailable := false | ||
for _, cur := range currencies { | ||
if cur == "USD" { | ||
return "USD", nil | ||
} | ||
if cur == "EUR" { | ||
eurAvailable = true | ||
} | ||
} | ||
if eurAvailable { | ||
return "EUR", nil | ||
} | ||
return "", fmt.Errorf("no currency supported %v", currencies) | ||
} | ||
|
||
func (a *adapter) makeRequest(missenaParams MissenaInternalParams, _ *adapters.ExtraRequestInfo, imp openrtb2.Imp, request *openrtb2.BidRequest) (*adapters.RequestData, error) { | ||
url := a.endpoint + "?t=" + missenaParams.ApiKey | ||
currency, err := getCurrency(request.Cur) | ||
if err != nil { | ||
// TODO: convert unsupported currency on response | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please resolve the TODO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd actually like to manage it on a next release. is it possible? should I remove the comment and consider some currencies unsupported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
return nil, err | ||
} | ||
|
||
var schain *openrtb2.SupplyChain | ||
if request.Source != nil { | ||
schain = request.Source.SChain | ||
} | ||
|
||
missenaRequest := MissenaAdRequest{ | ||
RequestId: request.ID, | ||
Timeout: 2000, | ||
Adunit: imp.ID, | ||
COPPA: request.Regs.COPPA, | ||
Currency: currency, | ||
EIDs: request.User.EIDs, | ||
Floor: imp.BidFloor, | ||
FloorCurrency: imp.BidFloorCur, | ||
GDPR: missenaParams.GDPR, | ||
GDPRConsent: missenaParams.GDPRConsent, | ||
IdempotencyKey: request.ID, | ||
Referer: request.Site.Page, | ||
RefererCanonical: request.Site.Domain, | ||
GDPRConsent: missenaParams.GDPRConsent, | ||
GDPR: missenaParams.GDPR, | ||
Placement: missenaParams.Placement, | ||
TestMode: missenaParams.TestMode, | ||
RequestID: request.ID, | ||
SChain: schain, | ||
Timeout: 2000, | ||
UserParams: MissenaUserParams{ | ||
Formats: missenaParams.Formats, | ||
Placement: missenaParams.Placement, | ||
Settings: missenaParams.Settings, | ||
}, | ||
Version: version.Ver, | ||
} | ||
|
||
body, errm := json.Marshal(missenaRequest) | ||
if errm != nil { | ||
return nil, errm | ||
body, err := json.Marshal(missenaRequest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
headers := http.Header{} | ||
|
@@ -100,7 +158,7 @@ func (a *adapter) makeRequest(missenaParams MissenaInternalParams, reqInfo *adap | |
Uri: url, | ||
Headers: headers, | ||
Body: body, | ||
ImpIDs: []string{impID}, | ||
ImpIDs: []string{imp.ID}, | ||
}, nil | ||
} | ||
|
||
|
@@ -110,7 +168,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte | |
var errors []error | ||
gdprApplies, consentString := readGDPR(request) | ||
|
||
missenaInternalParams := MissenaInternalParams{ | ||
params := MissenaInternalParams{ | ||
GDPR: gdprApplies, | ||
GDPRConsent: consentString, | ||
} | ||
|
@@ -132,18 +190,16 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte | |
continue | ||
} | ||
|
||
missenaInternalParams.ApiKey = missenaExt.ApiKey | ||
missenaInternalParams.Placement = missenaExt.Placement | ||
missenaInternalParams.TestMode = missenaExt.TestMode | ||
params.ApiKey = missenaExt.APIKey | ||
params.Placement = missenaExt.Placement | ||
params.Sample = missenaExt.Sample | ||
|
||
newHttpRequest, err := a.makeRequest(missenaInternalParams, requestInfo, imp.ID, request) | ||
newHttpRequest, err := a.makeRequest(params, requestInfo, imp, request) | ||
if err != nil { | ||
errors = append(errors, err) | ||
continue | ||
} | ||
|
||
httpRequests = append(httpRequests, newHttpRequest) | ||
|
||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. break in the loop causes only the first imp to be processed. If this is intentional, it's worth making it clearer in the code, e.g., with a comment or better naming. |
||
} | ||
|
||
|
@@ -194,23 +250,23 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R | |
return nil, []error{err} | ||
} | ||
|
||
bidResponse := adapters.NewBidderResponseWithBidsCapacity(1) | ||
bidResponse.Currency = missenaResponse.Currency | ||
bidRes := adapters.NewBidderResponseWithBidsCapacity(1) | ||
bidRes.Currency = missenaResponse.Currency | ||
|
||
responseBid := &openrtb2.Bid{ | ||
ID: request.ID, | ||
Price: float64(missenaResponse.Cpm), | ||
ImpID: request.Imp[0].ID, | ||
AdM: missenaResponse.Ad, | ||
CrID: missenaResponse.RequestId, | ||
CrID: missenaResponse.RequestID, | ||
} | ||
|
||
b := &adapters.TypedBid{ | ||
Bid: responseBid, | ||
BidType: openrtb_ext.BidTypeBanner, | ||
} | ||
|
||
bidResponse.Bids = append(bidResponse.Bids, b) | ||
bidRes.Bids = append(bidRes.Bids, b) | ||
|
||
return bidResponse, nil | ||
return bidRes, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is better to use MAP: