Module: Cambio

Defined in:
lib/cambio.rb,
lib/cambio/error.rb,
lib/cambio/version.rb,
lib/cambio/configuration.rb

Overview

Wrapper for the Open Exchange Rates API

Defined Under Namespace

Classes: Configuration, Error, NotFoundError, ServerError, UnauthorisedError

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.configurationObject

Public: Access to the underlying configuration object



25
26
27
# File 'lib/cambio.rb', line 25

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Public: Configure the API wrapper. A convenience method that yields a configuration object on which you can set the app_id and endpoint.

Examples

Cambio.configure do |config|
  config.app_id = 'YOUR_APP_ID'
end

Yields:



20
21
22
# File 'lib/cambio.rb', line 20

def configure
  yield(configuration)
end

.currencies(opts = {}) ⇒ Object

Public: Retrieve the currencies supplied by the API

opts - A hash of options to affect the returned result (default: {}):

:raw - A Boolean to describe whether you want the raw JSON response

Examples

Cambio.currencies
# => #<Hashie::Mash AED="United Arab Emirates Dirham" ... >

Cambio.currencies
# => "{\n\t\"AED\": \"United Arab Emirates Dirham\", ... }"

Returns a Hashie::Mash of the currencies (or raw JSON, if raw is passed)



62
63
64
65
# File 'lib/cambio.rb', line 62

def currencies(opts={})
  response = connection(opts).get 'currencies.json'
  response.body
end

.historical(date, opts = {}) ⇒ Object

Public: Retrieve the historical rates supplied by the API

date - A string in the format YYYY-MM-DD or a date object referring to the

day on which you want to get the rates from

opts - A hash of options to affect the returned result (default: {}):

:raw - A Boolean to describe whether you want the raw JSON response

Examples

Cambio.historical('2012-08-17')

Cambio.historical(Date.today)

Returns a Hashie::Mash of the rates from the date specified (or raw JSON, if raw is passsed)



82
83
84
85
86
# File 'lib/cambio.rb', line 82

def historical(date, opts={})
  date = date.strftime("%Y-%m-%d") if date.respond_to?(:strftime)
  response = connection(opts).get "historical/#{date}.json"
  response.body
end

.latest(opts = {}) ⇒ Object

Public: Retrieve the latest rates from the API

opts - A hash of options to affect the returned result (default: {}):

:raw - A Boolean to describe whether you want the raw JSON response

Examples

Cambio.latest
# => #<Hashie::Mash base="USD" ... >

Cambio.latest :raw => true
# => "{\n\t\"disclaimer\": \"This data..." ... }"

# Returns a Hashie::Mash of the rates (or raw JSON, if raw is passed)



43
44
45
46
# File 'lib/cambio.rb', line 43

def latest(opts={})
  response = connection(opts).get 'latest.json'
  response.body
end