Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
CheckResponse checks the API response for errors. A response is considered an error if it has a status code outside the 200 range. API error responses map to ErrorResponse.
Types ¶
type CacheService ¶
type CacheService service
CacheService handles in-memory caching of our exchange rates.
func (*CacheService) Expire ¶
func (s *CacheService) Expire(base string)
Expire will expire the cache for a given base currency.
func (*CacheService) Get ¶
func (s *CacheService) Get(base string) *RatesStore
Get will return our stored in-memory forex rates, if we have them.
func (*CacheService) IsExpired ¶
func (s *CacheService) IsExpired(base string) bool
IsExpired checks if we have stored cache and that it isn't expired.
type Client ¶
type Client struct {
AppID string
UserAgent string
BackendURL *url.URL
// Services used for communicating with the API.
Rates *RatesService
Update *UpdateService
Cache *CacheService
// contains filtered or unexported fields
}
Client holds a connection to the OXR API.
func NewClient ¶
NewClient creates a new Client with the appropriate connection details and services used for communicating with the API.
type ErrorResponse ¶
type ErrorResponse struct {
*http.Response
ErrorCode int64 `json:"status"`
Message string `json:"message"`
Description string `json:"description"`
}
An ErrorResponse reports the error caused by an API request
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type RatesService ¶
type RatesService service
RatesService handles retrieving forex rates for a given currency, either from in-memory cache or by fetching fresh results.
func (*RatesService) All ¶
func (s *RatesService) All() (*RatesStore, error)
All will build and execute request to fetch the latest rates for given base currency either from the in-memory cache or OXR API.
func (*RatesService) GetBaseCurrency ¶
func (s *RatesService) GetBaseCurrency() string
GetBaseCurrency will return the baseCurrency.
func (*RatesService) SetBaseCurrency ¶
func (s *RatesService) SetBaseCurrency(base string)
SetBaseCurrency will set the base currency to be used for requests.
type RatesStore ¶
type RatesStore struct {
Rates map[string]decimal.Decimal `json:"rates"`
UpdatedAt *time.Time `json:"updated_at"`
Base string `json:"base"`
}
RatesStore holds our forex rates for a given base currency
type Response ¶
Response is a OXR response. This wraps the standard http.Response returned from the OXR API.
type UpdateResponse ¶
type UpdateResponse struct {
Timestamp int64
UpdatedAt time.Time
Base string
Rates map[string]decimal.Decimal
}
UpdateResponse is the set of parameters that is used in response to a send request
type UpdateService ¶
type UpdateService service
UpdateService handles communication with /latest.json methods of the https://docs.openexchangerates.org/docs/latest-json
func (*UpdateService) LatestRates ¶
func (s *UpdateService) LatestRates(base string) error
LatestRates will build and execute request to /latest.json using the base currency provided.