Class: UsdaNdb::Client

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

Class Method Summary collapse

Class Method Details

.fetch(endpoint, params = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/usda_ndb/client.rb', line 3

def self.fetch(endpoint, params={})
  defaults = {
    api_key: UsdaNdb.configuration.api_key,
    format: UsdaNdb.configuration.response_format
  }
  address = UsdaNdb.configuration.endpoint_base
  params = defaults.merge(params)
  response = RestClient.get "#{address}/#{endpoint}", params: params
  result = response.body
  result = JSON.parse(result) if UsdaNdb.configuration.response_format == 'json'
  result
end