Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateCustomRates ¶
func ValidateCustomRates(bidReqCurrencyRates *openrtb_ext.ExtRequestCurrency) error
ValidateCustomRates throws a bad input error if any of the 3-digit currency codes found in the bidRequest.ext.prebid.currency field is invalid, malfomed or does not represent any actual currency. No error is thrown if bidRequest.ext.prebid.currency is invalid or empty.
Types ¶
type AggregateConversions ¶
type AggregateConversions struct {
// contains filtered or unexported fields
}
AggregateConversions contains both the request-defined currency rate map found in request.ext.prebid.currency and the currencies conversion rates fetched with the RateConverter object defined in rate_converter.go It implements the Conversions interface.
func NewAggregateConversions ¶
func NewAggregateConversions(customRates, pbsRates Conversions) *AggregateConversions
NewAggregateConversions expects both customRates and pbsRates to not be nil
func (*AggregateConversions) GetRate ¶
func (re *AggregateConversions) GetRate(from string, to string) (float64, error)
GetRate returns the conversion rate between two currencies prioritizing the customRates currency rate over that of the PBS currency rate service returns an error if both Conversions objects return error.
type ConstantRates ¶
type ConstantRates struct{}
ConstantRates doesn't do any currency conversions and accepts only conversions where both currencies (from and to) are the same. If not the same currencies, it returns an error.
func NewConstantRates ¶
func NewConstantRates() *ConstantRates
NewConstantRates creates a new ConstantRates object holding currencies rates
type ConversionNotFoundError ¶
type ConversionNotFoundError struct {
FromCur, ToCur string
}
ConversionNotFoundError is thrown by the currency.Conversions GetRate(from string, to string) method when the conversion rate between the two currencies, nor its reciprocal, can be found.
func (ConversionNotFoundError) Error ¶
func (err ConversionNotFoundError) Error() string
type Conversions ¶
type Conversions interface { GetRate(from string, to string) (float64, error) GetRates() *map[string]map[string]float64 }
Conversions allows to get a conversion rate between two currencies. if one of the currency string is not a currency or if there is not conversion between those currencies, then an err is returned and rate is 0.
type ConverterInfo ¶
type ConverterInfo interface { Source() string LastUpdated() time.Time Rates() *map[string]map[string]float64 AdditionalInfo() interface{} }
ConverterInfo holds information about converter setup
type RateConverter ¶
type RateConverter struct {
// contains filtered or unexported fields
}
RateConverter holds the currencies conversion rates dictionary
func NewRateConverter ¶
func NewRateConverter( httpClient httpClient, syncSourceURL string, staleRatesThreshold time.Duration, ) *RateConverter
NewRateConverter returns a new RateConverter
func (*RateConverter) GetInfo ¶
func (rc *RateConverter) GetInfo() ConverterInfo
GetInfo returns setup information about the converter
func (*RateConverter) LastUpdated ¶
func (rc *RateConverter) LastUpdated() time.Time
LastUpdated returns time when currencies rates were updated
func (*RateConverter) Rates ¶
func (rc *RateConverter) Rates() Conversions
Rates returns current conversions rates
func (*RateConverter) Run ¶
func (rc *RateConverter) Run() error
type Rates ¶
Rates holds data as represented on https://cdn.jsdelivr.net/gh/prebid/currency-file@1/latest.json note that `DataAsOfRaw` field is needed when parsing remote JSON as the date format if not standard and requires custom parsing to be properly set as Golang time.Time
func (*Rates) GetRate ¶
GetRate returns the conversion rate between two currencies or:
- An error if one of the currency strings is not well-formed
- An error if any of the currency strings is not a recognized currency code.
- A ConversionNotFoundError in case the conversion rate between the two given currencies is not in the currencies rates map