Class: FredAsDataframe::Client
- Inherits:
-
Object
- Object
- FredAsDataframe::Client
- Includes:
- HTTParty
- Defined in:
- lib/fred_as_dataframe/client.rb
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
Instance Attribute Summary collapse
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch(start: nil, fin: nil, interval: '1d') ⇒ Object
-
#initialize(series, options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(series, options = {}) ⇒ Client
Returns a new instance of Client.
20 21 22 23 |
# File 'lib/fred_as_dataframe/client.rb', line 20 def initialize(series, ={}) @api_key = [:api_key] || FredAsDataframe::Client.api_key @tag = series end |
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
17 18 19 |
# File 'lib/fred_as_dataframe/client.rb', line 17 def api_key @api_key end |
Instance Attribute Details
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
9 10 11 |
# File 'lib/fred_as_dataframe/client.rb', line 9 def tag @tag end |
Class Method Details
.configure {|_self| ... } ⇒ Object
11 12 13 14 |
# File 'lib/fred_as_dataframe/client.rb', line 11 def self.configure yield self true end |
Instance Method Details
#fetch(start: nil, fin: nil, interval: '1d') ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fred_as_dataframe/client.rb', line 25 def fetch(start: nil, fin: nil, interval: '1d') data = _fetch_data(interval) i = interval[0..-2].to_i begin data = data.select{ |date, _| (start.nil? || date >= Date.parse(start.to_s)) } unless start.nil? data = data.select{ |date, _| (fin.nil? || date <= Date.parse(fin.to_s)) } unless fin.nil? data = data.each_slice(i).map(&:first) rescue KeyError => e if data.keys[3].to_s[7, 5] == "Error" raise IOError, "Failed to get the data. Check that '#{@tag}' is a valid FRED series." else raise e end end Polars::DataFrame.new({Timestamps: data.map(&:first), tag.to_sym => data.map(&:last)}) end |