Class: CensusApi::Client
- Inherits:
-
Object
- Object
- CensusApi::Client
- Defined in:
- lib/census_api/client.rb
Overview
> CensusApi::Client
client#initialize method takes an api_key and options hash, which includes dataset and vintage. client#where method accepts an options hash, including fields, level and within. Within is optional.
Constant Summary collapse
- DATASETS =
%w( sf1 acs1 acs3 acs5 )
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_vintage ⇒ Object
readonly
Returns the value of attribute api_vintage.
-
#dataset ⇒ Object
Returns the value of attribute dataset.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(api_key, options = {}) ⇒ Client
constructor
can add more datasets as support becomes available.
- #where(options = {}) ⇒ Object
Constructor Details
#initialize(api_key, options = {}) ⇒ Client
can add more datasets as support becomes available
16 17 18 19 20 21 22 23 24 |
# File 'lib/census_api/client.rb', line 16 def initialize(api_key, = {}) fail ArgumentError, 'You must set an api_key.' unless api_key validate_api_key(api_key) @api_key = api_key @api_vintage = [:vintage] || 2010 if [:dataset] && DATASETS.include?([:dataset].downcase) @dataset = [:dataset].downcase end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/census_api/client.rb', line 10 def api_key @api_key end |
#api_vintage ⇒ Object (readonly)
Returns the value of attribute api_vintage.
10 11 12 |
# File 'lib/census_api/client.rb', line 10 def api_vintage @api_vintage end |
#dataset ⇒ Object
Returns the value of attribute dataset.
11 12 13 |
# File 'lib/census_api/client.rb', line 11 def dataset @dataset end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/census_api/client.rb', line 10 def @options end |
Instance Method Details
#where(options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/census_api/client.rb', line 26 def where(={}) .merge!(key: @api_key, vintage: @api_vintage) fail "Client requires a dataset (#{DATASETS})." if @dataset.nil? [:fields, :level].each do |f| fail ArgumentError, "#{f} is a requied parameter" if [f].nil? end [:within] = [[:within]] Request.find(dataset, ) end |