Class: CurrencyQuote::InvertirOnline

Inherits:
Object
  • Object
show all
Defined in:
lib/currency_quote/invertir_online.rb

Constant Summary collapse

BASE_URL =
"https://api.invertironline.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:) ⇒ InvertirOnline

Returns a new instance of InvertirOnline.



8
9
10
11
12
# File 'lib/currency_quote/invertir_online.rb', line 8

def initialize(username:, password:)
  @username = username
  @password = password
  get_token
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



4
5
6
# File 'lib/currency_quote/invertir_online.rb', line 4

def access_token
  @access_token
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/currency_quote/invertir_online.rb', line 4

def password
  @password
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/currency_quote/invertir_online.rb', line 4

def username
  @username
end

Instance Method Details

#get_quote(simbol:, mercado: 'bCBA', plazo: 't1') ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/currency_quote/invertir_online.rb', line 14

def get_quote(simbol:, mercado: 'bCBA', plazo: 't1')
  url = BASE_URL + "/api/v2/#{mercado}/Titulos/#{simbol.upcase}/Cotizacion"
  HTTParty.get(url,
    body: {
      'mercado' => mercado,
      'simbol' => simbol.upcase,
      'model.mercado' => mercado,
      'model.plazo' => plazo
    },
    headers: {
    'Authorization' => "Bearer #{@access_token}",
    'Accept' => 'application/json'
    }
  ).parsed_response
end