Class: OpenExchangeRate::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/open-exchange-rate/open-exchange-rate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id: "insert_app_id", https: false) ⇒ Api



5
6
7
8
9
10
11
# File 'lib/open-exchange-rate/open-exchange-rate.rb', line 5

def initialize(
  app_id: "insert_app_id",
  https:  false)

  @app_id = app_id
  @https  = https
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



3
4
5
# File 'lib/open-exchange-rate/open-exchange-rate.rb', line 3

def app_id
  @app_id
end

#httpsObject

Returns the value of attribute https.



3
4
5
# File 'lib/open-exchange-rate/open-exchange-rate.rb', line 3

def https
  @https
end

Instance Method Details

#currenciesObject



25
26
27
28
29
# File 'lib/open-exchange-rate/open-exchange-rate.rb', line 25

def currencies
  url = "http://openexchangerates.org/api/currencies.json" # no app_id required
  http = Curl.get url
  Oj.load(http.body_str)
end

#latestObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/open-exchange-rate/open-exchange-rate.rb', line 13

def latest
  if @https
    prefix = "https"
  else
    prefix = "http"
  end

  url  = "#{prefix}://openexchangerates.org/api/latest.json?app_id=#{app_id}"
  http = Curl.get url
  Oj.load(http.body_str)
end