Class: Alphavantage::Client
- Inherits:
-
Object
- Object
- Alphavantage::Client
- Defined in:
- lib/alphavantage/client.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #csv ⇒ Object
-
#initialize(params) ⇒ Client
constructor
A new instance of Client.
- #json ⇒ Object
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
#params ⇒ Object (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
#csv ⇒ Object
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 |
#json ⇒ Object
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. if response. end end |