census_api 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62d635eb4a50f1607cf754133ec5e2df2458f774
4
+ data.tar.gz: db81cacdbddc88f77a4202b59329b6ff7e2929b0
5
+ SHA512:
6
+ metadata.gz: 21714d668b24434213474a8a2647f7a5350a1cf65bcc227c4c402e789ce9c2f5adacbc5141b748575a0564a5faf5a5c1fd21923bb6f24118caa6656c3af45047
7
+ data.tar.gz: 715488e993f03ccde604f610840c234cd70e6dfdda0c75c05b48b8f011482f16d37bb3e51fcf7d29e9bd2f63e7894c535eba08d0bc100f61d173b7dcc4ca4d7c
data/README.md CHANGED
@@ -35,6 +35,7 @@ $ export $CENSUS_API_KEY='your-api-key'
35
35
  @client = CensusApi::Client.new(API_KEY)
36
36
  @client = CensusApi::Client.new(ENV['CENSUS_API_KEY']) # from the environment variable
37
37
  @client = CensusApi::Client.new(API_KEY, dataset: 'SF1') # with a dataset
38
+ @client = CensusApi::Client.new(API_KEY, {vintage: 2012, dataset: 'SF1'}) # specific vintage (year) data; defaults to 2010
38
39
  ```
39
40
 
40
41
  ### Query a Dataset
@@ -2,10 +2,10 @@ module CensusApi
2
2
  class Client
3
3
  require 'rest-client'
4
4
 
5
- attr_reader :api_key, :options
5
+ attr_reader :api_key, :api_vintage, :options
6
6
  attr_accessor :dataset
7
7
 
8
- DATASETS = %w( sf1 acs5 ) # can add more datasets as support becomes available
8
+ DATASETS = %w( sf1 acs1 acs3 acs5 ) # can add more datasets as support becomes available
9
9
 
10
10
  def initialize(api_key, options = {})
11
11
  raise ArgumentError, "You must set an api_key." unless api_key
@@ -10,10 +10,10 @@ module CensusApi
10
10
 
11
11
  @@census_shapes
12
12
 
13
- CENSUS_URL = "http://api.census.gov/data/2010"
13
+ CENSUS_URL = "http://api.census.gov/data"
14
14
 
15
- def initialize(url, source, options)
16
- path = "#{url}/#{source}?#{options.to_params}"
15
+ def initialize(url, vintage, source, options)
16
+ path = "#{url}/#{vintage}/#{source}?#{options.to_params}"
17
17
  @response = RestClient.get(path) do |response, request, result, &block|
18
18
  response
19
19
  end
@@ -27,7 +27,8 @@ module CensusApi
27
27
  fields = fields.push("NAME").join(",") if fields.kind_of? Array
28
28
  params = { :key => options[:key], :get => fields, :for => format(options[:level],false) }
29
29
  params.merge!({ :in => format(options[:within][0],true) }) if !options[:within].empty?
30
- request = new(CENSUS_URL, source, params)
30
+ options.merge!({ :vintage => 2010 }) unless options[:vintage]
31
+ request = new(CENSUS_URL, options[:vintage], source, params)
31
32
  request.parse_response
32
33
  end
33
34
 
@@ -1,3 +1,3 @@
1
1
  module CensusApi
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -54,44 +54,87 @@ describe CensusApi::Request do
54
54
  end
55
55
 
56
56
  describe "#{test[:source]} for a geography type in a geography type" do
57
- use_vcr_cassette "#{test[:source]}_find_counties_in_state"
58
-
59
- before(:each) do
60
- params = {:key=> api_key, :fields => test[:field], :level => 'COUNTY', :within=>['STATE:06']}
61
- @collection = CensusApi::Request.find(test[:source], params)
62
- end
63
-
64
- it 'should have one result' do
65
- @collection.count.should == 58
66
- end
67
-
68
- it 'should include fields for each result' do
69
- @collection.each do |result|
70
- result.should include(test[:field])
71
- result.should include('name')
72
- result.should include('state')
73
- end
74
- end
75
- end
76
-
77
- describe "#{test[:source]} for a geography type and id in a geography type" do
78
- use_vcr_cassette "#{test[:source]}_find_county_in_state"
79
-
80
- before(:each) do
81
- params = {:key=> api_key, :fields => test[:field], :level => 'COUNTY:001', :within=>['STATE:06']}
82
- @collection = CensusApi::Request.find(test[:source], params)
83
- end
84
-
85
- it 'should have one result' do
86
- @collection.count.should == 1
87
- end
88
-
89
- it 'should include fields for each result' do
90
- @collection.each do |result|
91
- result.should == test[:results][1]
92
- end
93
- end
94
- end
57
+ use_vcr_cassette "#{test[:source]}_find_counties_in_state"
58
+
59
+ before(:each) do
60
+ params = {:key=> api_key, :fields => test[:field], :level => 'COUNTY', :within=>['STATE:06']}
61
+ @collection = CensusApi::Request.find(test[:source], params)
62
+ end
63
+
64
+ it 'should have one result' do
65
+ @collection.count.should == 58
66
+ end
67
+
68
+ it 'should include fields for each result' do
69
+ @collection.each do |result|
70
+ result.should include(test[:field])
71
+ result.should include('name')
72
+ result.should include('state')
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#{test[:source]} for a geography type and id in a geography type" do
78
+ use_vcr_cassette "#{test[:source]}_find_county_in_state"
79
+
80
+ before(:each) do
81
+ params = {:key=> api_key, :fields => test[:field], :level => 'COUNTY:001', :within=>['STATE:06']}
82
+ @collection = CensusApi::Request.find(test[:source], params)
83
+ end
84
+
85
+ it 'should have one result' do
86
+ @collection.count.should == 1
87
+ end
88
+
89
+ it 'should include fields for each result' do
90
+ @collection.each do |result|
91
+ result.should == test[:results][1]
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ context "DATASETS" do
99
+ CensusApi::Client::DATASETS.each do |source|
100
+ describe "#{source}" do
101
+ use_vcr_cassette "dataset_#{source}_find_states"
102
+ let(:params) do
103
+ { :key=> api_key,
104
+ :vintage => !!(source.match('sf1')) ? 2010 : 2012,
105
+ :fields => !!(source.match('sf1')) ? 'P0010001' : 'B00001_001E',
106
+ :source => source,
107
+ :level => 'STATE',
108
+ :within=>[]
109
+ }
110
+ end
111
+
112
+ it "#{source} should be valid" do
113
+ @collection = CensusApi::Request.find(source, params)
114
+ @collection.count.should == 52
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ context ".vintage" do
121
+ describe "vintage" do
122
+ use_vcr_cassette "sf1_find_states_vintage"
123
+
124
+ before(:each) do
125
+ params = {:key=> api_key, :vintage => 2010, :fields => 'B00001_001E', :source => 'acs5', :level => 'STATE', :within=>[]}
126
+ @collection_2010 = CensusApi::Request.find(params[:source], params)
127
+ @collection_2012 = CensusApi::Request.find(params[:source], params.merge!({ :vintage => 2012 }))
128
+ end
129
+
130
+ it 'should be valid' do
131
+ @collection_2010.count.should == 52
132
+ @collection_2012.count.should == 52
133
+ end
134
+
135
+ it 'should not be same result set' do
136
+ @collection_2010.should_not == @collection_2012
137
+ end
95
138
  end
96
139
  end
97
140
 
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: census_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
5
- prerelease:
4
+ version: 1.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ty Rauber
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-03-16 00:00:00.000000000 Z
11
+ date: 2014-05-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rest-client
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: hpricot
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: fakeweb
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: vcr
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  description: A Ruby Gem for querying the US Census Bureau API
@@ -98,7 +87,7 @@ executables: []
98
87
  extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
101
- - .gitignore
90
+ - ".gitignore"
102
91
  - Gemfile
103
92
  - LICENSE.txt
104
93
  - README.md
@@ -117,27 +106,26 @@ files:
117
106
  homepage: https://github.com/tyrauber/census_api.git
118
107
  licenses:
119
108
  - MIT
109
+ metadata: {}
120
110
  post_install_message:
121
111
  rdoc_options: []
122
112
  require_paths:
123
113
  - lib
124
114
  required_ruby_version: !ruby/object:Gem::Requirement
125
- none: false
126
115
  requirements:
127
- - - ! '>='
116
+ - - ">="
128
117
  - !ruby/object:Gem::Version
129
118
  version: '0'
130
119
  required_rubygems_version: !ruby/object:Gem::Requirement
131
- none: false
132
120
  requirements:
133
- - - ! '>='
121
+ - - ">="
134
122
  - !ruby/object:Gem::Version
135
123
  version: '0'
136
124
  requirements: []
137
125
  rubyforge_project:
138
- rubygems_version: 1.8.24
126
+ rubygems_version: 2.2.2
139
127
  signing_key:
140
- specification_version: 3
128
+ specification_version: 4
141
129
  summary: A Ruby Wrapper for the US Census Bureau API, providing the ability to query
142
130
  both the 2010 Census and 2006-2010 ACS5 datasets.
143
131
  test_files:
@@ -146,4 +134,3 @@ test_files:
146
134
  - spec/census_api/request_spec.rb
147
135
  - spec/spec_helper.rb
148
136
  - spec/vcr_setup.rb
149
- has_rdoc: