Class: WorldbankAsDataframe::Client
- Inherits:
-
Object
- Object
- WorldbankAsDataframe::Client
- Includes:
- HTTParty
- Defined in:
- lib/worldbank_as_dataframe/client.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
- #get(path, headers = {}) ⇒ Object
- #get_query ⇒ Object
-
#initialize(query, raw) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(query, raw) ⇒ Client
Returns a new instance of Client.
22 23 24 25 |
# File 'lib/worldbank_as_dataframe/client.rb', line 22 def initialize(query, raw) @query = query @raw = raw end |
Instance Attribute Details
#query ⇒ Object
Returns the value of attribute query.
20 21 22 |
# File 'lib/worldbank_as_dataframe/client.rb', line 20 def query @query end |
Instance Method Details
#get(path, headers = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/worldbank_as_dataframe/client.rb', line 38 def get(path, headers={}) begin # puts "#{__FILE__}:#{__LINE__} path = #{path.inspect}" response = self.class.get(path, headers) # puts "#{__FILE__}:#{__LINE__} response = #{response.inspect}" response.parsed_response rescue nil end end |
#get_query ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/worldbank_as_dataframe/client.rb', line 27 def get_query @path = 'https://api.worldbank.org/v2/' + @query[:dirs].map(&:downcase).join('/') @path += '?' params = [] @query[:params].each do |key, value| params << "#{key.to_s}=#{value.to_s}" end @path += params.join('&') get(@path) end |