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

Missena: Update params #4057

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
132 changes: 94 additions & 38 deletions adapters/missena/missena.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Copy link
Collaborator

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:

    currencySet := make(map[string]struct{}, len(currencies))
    for _, cur := range currencies {
        currencySet[cur] = struct{}{}
    }

    if _, found := currencySet[defaultCur]; found {
        return defaultCur, nil
    }
    if _, found := currencySet["EUR"]; found {
        return "EUR", nil
    }
    return "", fmt.Errorf("no currency supported %v", currencies)
}```
what Do You think? 

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Please resolve the TODO.

Copy link
Author

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use jsonutil.Marshal as a drop in replacement for json.Marshal.

if err != nil {
return nil, err
}

headers := http.Header{}
Expand All @@ -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
}

Expand All @@ -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,
}
Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

}

Expand Down Expand Up @@ -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
}
Loading
Loading