census_api 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +1 -1
- data/census_api.gemspec +1 -0
- data/lib/census_api/client.rb +1 -11
- data/lib/census_api/request.rb +12 -1
- data/lib/census_api/version.rb +1 -1
- data/lib/census_api.rb +3 -3
- metadata +5 -3
data/LICENSE.txt
CHANGED
data/census_api.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = "census_api"
|
8
8
|
gem.version = CensusApi::VERSION
|
9
9
|
gem.authors = ["Ty Rauber"]
|
10
|
+
gem.license = 'MIT'
|
10
11
|
gem.email = ["tyrauber@mac.com"]
|
11
12
|
gem.description = %q{A Ruby Gem for querying the US Census Bureau API}
|
12
13
|
gem.summary = %q{A Ruby Wrapper for the US Census Bureau API, providing the ability to query both the 2010 Census and 2006-2010 ACS5 datasets.}
|
data/lib/census_api/client.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
module CensusApi
|
2
2
|
class Client
|
3
|
+
require 'rest-client'
|
3
4
|
|
4
|
-
require "yaml"
|
5
|
-
|
6
5
|
attr_reader :api_key, :options
|
7
6
|
attr_accessor :dataset
|
8
7
|
|
9
|
-
SUMMARY_LEVELS = {}
|
10
8
|
DATASETS = %w( sf1 acs5 ) # can add more datasets as support becomes available
|
11
9
|
|
12
10
|
def initialize(api_key, options = {})
|
@@ -24,19 +22,11 @@ module CensusApi
|
|
24
22
|
if options[:dataset]
|
25
23
|
@dataset = options[:dataset].downcase if DATASETS.include? options[:dataset].downcase
|
26
24
|
end
|
27
|
-
|
28
|
-
set_summary_levels
|
29
25
|
end
|
30
26
|
|
31
27
|
def find(fields, level, *within)
|
32
28
|
raise "Client has not been assigned a dataset to query. Try @client.dataset = 'SF1' or anything from #{DATASETS}" if self.dataset.nil?
|
33
29
|
Request.find(dataset, {key: @api_key, fields: fields, level: level, within: within})
|
34
30
|
end
|
35
|
-
|
36
|
-
def set_summary_levels
|
37
|
-
if SUMMARY_LEVELS.empty?
|
38
|
-
YAML.load_file(File.dirname(__FILE__).to_s + '/../yml/census_shapes.yml').each{ |k,v| SUMMARY_LEVELS[k] = v }
|
39
|
-
end
|
40
|
-
end
|
41
31
|
end
|
42
32
|
end
|
data/lib/census_api/request.rb
CHANGED
@@ -4,9 +4,12 @@ module CensusApi
|
|
4
4
|
require 'restclient'
|
5
5
|
require 'hpricot'
|
6
6
|
require 'json'
|
7
|
+
require "yaml"
|
7
8
|
|
8
9
|
attr_accessor :response
|
9
10
|
|
11
|
+
@@census_shapes
|
12
|
+
|
10
13
|
CENSUS_URL = "http://api.census.gov/data/2010"
|
11
14
|
|
12
15
|
def initialize(url, source, options)
|
@@ -49,13 +52,21 @@ module CensusApi
|
|
49
52
|
else
|
50
53
|
s = [s,"*"]
|
51
54
|
end
|
52
|
-
shp =
|
55
|
+
shp = shapes[s[0].upcase]
|
53
56
|
s.shift && s.unshift(shp['name'].downcase.gsub(" ", "+")) if !shp.nil?
|
54
57
|
s.unshift(s.shift.split("/")[0]) if !s[0].scan("home+land").empty? && truncate
|
55
58
|
s.join(":")
|
56
59
|
}
|
57
60
|
return result.join("+")
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.shapes
|
64
|
+
return @@census_shapes if defined?( @@census_shapes)
|
65
|
+
@@census_shapes = {}
|
66
|
+
YAML.load_file(File.dirname(__FILE__).to_s + '/../yml/census_shapes.yml').each{|k,v| @@census_shapes[k] = v}
|
67
|
+
return @@census_shapes
|
58
68
|
end
|
69
|
+
|
59
70
|
end
|
60
71
|
end
|
61
72
|
|
data/lib/census_api/version.rb
CHANGED
data/lib/census_api.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
1
|
+
require 'census_api/client'
|
2
|
+
require 'census_api/request'
|
3
|
+
require 'census_api/version'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: census_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -115,7 +115,8 @@ files:
|
|
115
115
|
- spec/spec_helper.rb
|
116
116
|
- spec/vcr_setup.rb
|
117
117
|
homepage: https://github.com/tyrauber/census_api.git
|
118
|
-
licenses:
|
118
|
+
licenses:
|
119
|
+
- MIT
|
119
120
|
post_install_message:
|
120
121
|
rdoc_options: []
|
121
122
|
require_paths:
|
@@ -145,3 +146,4 @@ test_files:
|
|
145
146
|
- spec/census_api/request_spec.rb
|
146
147
|
- spec/spec_helper.rb
|
147
148
|
- spec/vcr_setup.rb
|
149
|
+
has_rdoc:
|