Class: Alphavantage::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/alphavantage/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Client

Returns a new instance of Client.



14
15
16
# File 'lib/alphavantage/client.rb', line 14

def initialize params
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



17
18
19
# File 'lib/alphavantage/client.rb', line 17

def params
  @params
end

Class Method Details

.get(params:, datatype: :json) ⇒ Object



9
10
11
# File 'lib/alphavantage/client.rb', line 9

def get(params:, datatype: :json)
  new(params).public_send(datatype)
end

Instance Method Details

#csvObject



25
26
27
28
29
30
31
# File 'lib/alphavantage/client.rb', line 25

def csv
  CSV.parse response.body
rescue CSV::MalformedCSVError
  # if we can not parse it, we probably have JSON from API with an error
  json
  raise
end

#jsonObject



19
20
21
22
23
# File 'lib/alphavantage/client.rb', line 19

def json
  Hashie::Mash.new(convert_hash_keys(JSON.parse(response.body))).tap do |response|
    raise Error, response.error_message if response.error_message
  end
end