Class: Currencyapi::Endpoints
- Inherits:
-
Object
- Object
- Currencyapi::Endpoints
- Defined in:
- lib/currencyapi/endpoints.rb
Instance Attribute Summary collapse
-
#apikey ⇒ Object
writeonly
Sets the attribute apikey.
Instance Method Summary collapse
- #call_api(route) ⇒ Object
- #convert(value, date = '', baseCurrency = 'USD', currencies = '') ⇒ Object
- #currencies(currencies = '') ⇒ Object
- #historical(date, baseCurrency = 'USD', currencies = '') ⇒ Object
-
#initialize(options = {}) ⇒ Endpoints
constructor
A new instance of Endpoints.
- #latest(baseCurrency = 'USD', currencies = '') ⇒ Object
- #range(datetime_start, datetime_end, accuracy = 'day', baseCurrency = 'USD', currencies = '') ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Endpoints
Returns a new instance of Endpoints.
6 7 8 |
# File 'lib/currencyapi/endpoints.rb', line 6 def initialize( = {}) @apikey = [:apikey] || Currencyapi.configuration.apikey end |
Instance Attribute Details
#apikey=(value) ⇒ Object (writeonly)
Sets the attribute apikey
4 5 6 |
# File 'lib/currencyapi/endpoints.rb', line 4 def apikey=(value) @apikey = value end |
Instance Method Details
#call_api(route) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/currencyapi/endpoints.rb', line 34 def call_api(route) begin @response = RestClient.get "#{Currencyapi::BASE_URL}#{route}&apikey=#{@apikey}", { 'Accept' => 'application/json' } rescue RestClient::ExceptionWithResponse => e @data = e.response end end |
#convert(value, date = '', baseCurrency = 'USD', currencies = '') ⇒ Object
30 31 32 |
# File 'lib/currencyapi/endpoints.rb', line 30 def convert(value, date = '', baseCurrency = 'USD', currencies = '') @result = call_api(sprintf('convert?value=%s&date=%s&base_currency=%s¤cies=%s', value, date, baseCurrency, currencies)) end |
#currencies(currencies = '') ⇒ Object
14 15 16 |
# File 'lib/currencyapi/endpoints.rb', line 14 def currencies(currencies = '') @result = call_api(sprintf('currencies?currencies=%s', currencies)) end |
#historical(date, baseCurrency = 'USD', currencies = '') ⇒ Object
22 23 24 |
# File 'lib/currencyapi/endpoints.rb', line 22 def historical(date, baseCurrency = 'USD', currencies = '') @result = call_api(sprintf('historical?date=%s&base_currency=%s¤cies=%s', date, baseCurrency, currencies)) end |
#latest(baseCurrency = 'USD', currencies = '') ⇒ Object
18 19 20 |
# File 'lib/currencyapi/endpoints.rb', line 18 def latest(baseCurrency = 'USD', currencies = '') @result = call_api(sprintf('latest?base_currency=%s¤cies=%s', baseCurrency, currencies)) end |
#range(datetime_start, datetime_end, accuracy = 'day', baseCurrency = 'USD', currencies = '') ⇒ Object
26 27 28 |
# File 'lib/currencyapi/endpoints.rb', line 26 def range(datetime_start, datetime_end, accuracy = 'day', baseCurrency = 'USD', currencies = '') @result = call_api(sprintf('range?datetime_start=%s&datetime_end=%s&accuracy=%s&base_currency=%s¤cies=%s', datetime_start, datetime_end, accuracy, baseCurrency, currencies)) end |
#status ⇒ Object
10 11 12 |
# File 'lib/currencyapi/endpoints.rb', line 10 def status() @result = call_api('status?type=quota') end |