class Bovesparb::Client
Constants
- API_ENDPOINT
- DICTIONARY
Public Instance Methods
quotes(stocks)
click to toggle source
# File lib/bovesparb/client.rb, line 16 def quotes(stocks) response = request(params: { strListaCodigos: stocks }) parser(response) end
Private Instance Methods
client()
click to toggle source
# File lib/bovesparb/client.rb, line 30 def client @_client ||= Faraday.new(API_ENDPOINT, request: { open_timeout: 3, timeout: 5 }) do |client| client.request :url_encoded client.adapter Faraday.default_adapter end end
parser(response)
click to toggle source
# File lib/bovesparb/client.rb, line 23 def parser(response) tickets = response[:ComportamentoPapeis][:Papel].flatten tickets.collect do |ticket| ticket.transform_keys { |key| DICTIONARY[key] || key } end end
request(http_method: :get, endpoint: "cotacoes2000/FormConsultaCotacoes.asp", params: {})
click to toggle source
# File lib/bovesparb/client.rb, line 37 def request(http_method: :get, endpoint: "cotacoes2000/FormConsultaCotacoes.asp", params: {}) response = client.public_send(http_method, endpoint, params) Ox.load(response.body, mode: :hash) end