policymap_wrap 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4241a7309e07251b272b7feb04aa8abfae58e86b
4
- data.tar.gz: 6ba8fa4e33c85e7ee4da876c541c102743d2954b
3
+ metadata.gz: 0f185ed4a2bb58653a469276d87771b09f65439c
4
+ data.tar.gz: 10069fc06644d7d16efddb0aa03d2d01fd6874d6
5
5
  SHA512:
6
- metadata.gz: 44d445671782ee826e6a3ec05f0f1d902f044541493a149cad6150e216d2afd6544a519bca37e1b6955ef2c786a4ef7bdba21711efb6a7c2a73d64dffd544c88
7
- data.tar.gz: 1388e55d59d4ecab6439b3009eeb5e52720fb0a48661d3ed5f1bf785b590f8f5058af8ae60197f4c02d7b54d56da0c5c8798cb24795280c2d20088295e072be8
6
+ metadata.gz: 7e5845dfb609f079d5bb0e66b2267c6ddc18631ad4c6d4b81221e660f3e2330135ad779988fe6baf7c34e2b85da017b14d3727a3656dcb3ae9bcbf0ab52bf3a9
7
+ data.tar.gz: 12fc72f21c2a6f6ad499d47ba004279e7b5a049ac4fae749ed978dd63651a0f8034d12a8abe52a4c91f7b022af5997441f4eecaf5962064bbd31dcc4b6456145
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ policymap_wrap (1.0.0)
5
+ rest-client (~> 1.6)
6
+ yajl-ruby (~> 1.1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ mime-types (1.23)
12
+ rest-client (1.6.7)
13
+ mime-types (>= 1.16)
14
+ yajl-ruby (1.1.0)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ policymap_wrap!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -2,26 +2,60 @@ module PolicyMap
2
2
 
3
3
  class Client
4
4
 
5
- BOUNDARY_TYPES = { :state => 2, :county => 4, :city => 16, :zip => 8, :census_tract => 6,
6
- :block_group => 15, :congressional_district => 23, :assembly_district => 49,
7
- :senate_district => 48, :all => 'all' }
8
-
9
- INDICATORS = { :total_population => 9876598, :percent_african_american => 9876222, :percent_asian => 9876202,
10
- :percent_pacific_islander => 9876468, :percent_hispanic => 9876280, :percent_native_american => 9876623,
11
- :percent_mixed_race => 9876437, :percent_under_18 => 9869063, :percent_65_or_older => 9869059,
12
- :percent_foreign_born => 9869060, :percent_disabled => 9869050, :percent_high_school_or_less => 9873913,
13
- :percent_college_degree => 9873916, :percent_graduate_degree => 9873904, :median_home_value => 9873606,
14
- :median_rent => 9873661, :percent_moved_in_since_1990 => 9873776, :percent_homeowners => 9873049,
15
- :vacancy_rate => 9876608, :median_household_income => 9871831, :poverty_rate => 9871807,
16
- :percent_white => 9876415, :percent_households_wo_car => 0, :average_vehicles_per_household => 9873779,
17
- :percent_who_commute_to_work_using_public_transit => 9873811, :unemployment_rate => 9841103,
18
- :independent_artists => 9618303, :performing_arts_and_spectator_sports => 9584608,
19
- :movie_and_sound_industries => 9584731, :mueseums_and_historical_sites => 9584676,
20
- :publishing_industries => 9584638, :broadcasting => 9584691, :other_info_services => 9584624, :all => 'all' }
5
+ BOUNDARY_TYPES = {
6
+ :state => 2,
7
+ :county => 4,
8
+ :census_tract => 6,
9
+ :zip => 8,
10
+ :block_group => 15,
11
+ :city => 16,
12
+ :congressional_district => 23,
13
+ :assembly_district => 25,
14
+ :senate_district => 24
15
+ }.freeze
16
+
17
+ INDICATORS = {
18
+ :average_vehicles_per_household => 9873779,
19
+ :broadcasting => 9584691,
20
+ :distressed_community => 9629156,
21
+ :percent_homeowners => 9873049,
22
+ :total_population => 9876593,
23
+ :independent_artists => 9618303,
24
+ :median_gross_rent => 9873661,
25
+ :median_gross_rent_2009 => 9873663,
26
+ :median_home_value => 9873606,
27
+ :median_household_income => 9871831,
28
+ :movie_and_sound_industries => 9584731,
29
+ :museums_and_historical_sites => 9584676,
30
+ :other_info_services => 9584624,
31
+ :percent_moved_in_since_1990 => 9873776,
32
+ :percent_who_commute_to_work_using_public_transit => 9873811,
33
+ :percent_african_american => 9876222,
34
+ :percent_native_american => 9876623,
35
+ :percent_asian => 9876202,
36
+ :percent_foreign_born => 9869060,
37
+ :percent_hispanic => 9876280,
38
+ :percent_pacific_islander => 9876468,
39
+ :poverty_rate => 9871807,
40
+ :percent_disabled => 9869050,
41
+ :percent_65_or_older => 9869059,
42
+ :percent_under_18 => 9869063,
43
+ :percent_college_degree => 9873916,
44
+ :percent_high_school_or_less => 9873913,
45
+ :percent_mixed_race => 9876437,
46
+ :percent_vacant_units => 9631221,
47
+ :percent_white => 9876415,
48
+ :percent_graduate_degree => 9873904,
49
+ :performing_arts_and_spectator_sports => 9584608,
50
+ :publishing_industries => 9584638,
51
+ :unemployment_rate => 9841103,
52
+ :vacancy_rate => 9876608
53
+ }.freeze
21
54
 
22
55
  @@connection = nil
23
56
  @@debug = false
24
57
  @@default_options = nil
58
+ @@boundary_types_by_id = nil
25
59
 
26
60
  class << self
27
61
 
@@ -57,17 +91,17 @@ module PolicyMap
57
91
 
58
92
  raise InsufficientArgsForSearch unless options.has_key?(:boundary_types) && options.has_key?(:query)
59
93
 
60
- options[:boundary_types] = Array(options[:boundary_types]).collect {|bt| BOUNDARY_TYPES[bt] }.join(',')
94
+ options[:boundary_types] = sanitized_boundary_types(options[:boundary_types])
61
95
  HashUtils.rename_key!(options, :boundary_types, :bt)
62
- HashUtils.rename_key!(options, :query, :s)
63
- HashUtils.rename_key!(options, :state, :st) if options.has_key?(:state)
64
- HashUtils.rename_key!(options, :county, :co) if options.has_key?(:county)
65
- HashUtils.rename_key!(options, :census_tract, :ct) if options.has_key?(:census_tract)
96
+ HashUtils.rename_key!(options, :query, :ss)
97
+ HashUtils.rename_key!(options, :state, :sst) if options.has_key?(:state)
98
+ HashUtils.rename_key!(options, :county, :sco) if options.has_key?(:county)
99
+ HashUtils.rename_key!(options, :census_tract, :sct) if options.has_key?(:census_tract)
66
100
 
67
101
  options = default_options.merge(options)
68
102
 
69
103
  result = get(Endpoint.endpoint_url, options)
70
- result['sch'].collect {|hsh| HashUtils.symbolize_keys(hsh) }
104
+ result['sch']
71
105
  end
72
106
 
73
107
  def boundary_search(*args)
@@ -78,7 +112,7 @@ module PolicyMap
78
112
 
79
113
  raise InsufficientArgsForSearch unless options.has_key?(:boundary_types) || options.has_key?(:boundary_ids)
80
114
 
81
- options[:boundary_types] = Array(options[:boundary_types]).collect {|bt| BOUNDARY_TYPES[bt] }.join(',') if options.has_key?(:boundary_types)
115
+ options[:boundary_types] = sanitized_boundary_types(options[:boundary_types])
82
116
  options[:boundary_ids] = Array(options[:boundary_ids]).join(',') if options.has_key?(:boundary_ids)
83
117
  HashUtils.rename_key!(options, :boundary_types, :bt) if options.has_key?(:boundary_types)
84
118
  HashUtils.rename_key!(options, :boundary_ids, :bi) if options.has_key?(:boundary_ids)
@@ -87,7 +121,7 @@ module PolicyMap
87
121
  options = default_options.merge(options)
88
122
 
89
123
  result = get(Endpoint.endpoint_url, options)
90
- HashUtils.recursively_symbolize_keys(result["bnd"])
124
+ result["bnd"]
91
125
  end
92
126
 
93
127
  def indicator_search(*args)
@@ -98,8 +132,8 @@ module PolicyMap
98
132
 
99
133
  raise InsufficientArgsForSearch unless options.has_key?(:indicators) && (options.has_key?(:boundary_types) || options.has_key?(:boundary_ids))
100
134
 
101
- options[:indicators] = Array(options[:indicators]).collect {|i| INDICATORS[i] }.join(',')
102
- options[:boundary_types] = Array(options[:boundary_types]).collect {|bt| BOUNDARY_TYPES[bt] }.join(',') if options.has_key?(:boundary_types)
135
+ options[:indicators] = sanitized_indicators(options[:indicators])
136
+ options[:boundary_types] = sanitized_boundary_types(options[:boundary_types])
103
137
  options[:boundary_ids] = Array(options[:boundary_ids]).join(',') if options.has_key?(:boundary_ids)
104
138
  HashUtils.rename_key!(options, :indicators, :ii)
105
139
  HashUtils.rename_key!(options, :boundary_types, :bt) if options.has_key?(:boundary_types)
@@ -109,18 +143,18 @@ module PolicyMap
109
143
  options = default_options.merge(options)
110
144
 
111
145
  result = get(Endpoint.endpoint_url, options)
112
- HashUtils.recursively_symbolize_keys(result["ind"])
146
+ result["ind"]
113
147
  end
114
148
 
115
149
  def containment_search(*args)
116
150
  default_options = @@default_options
117
- default_options[:t] = "cnt"
151
+ default_options[:t] = 'bnd'
118
152
 
119
153
  options = extract_options!(args)
120
154
 
121
155
  raise InsufficientArgsForSearch unless options.has_key?(:boundary_types) && options.has_key?(:boundary_id)
122
156
 
123
- options[:boundary_types] = Array(options[:boundary_types]).collect {|bt| BOUNDARY_TYPES[bt] }.join(',')
157
+ options[:boundary_types] = sanitized_boundary_types(options[:boundary_types])
124
158
  HashUtils.rename_key!(options, :boundary_types, :cbt)
125
159
  HashUtils.rename_key!(options, :boundary_id, :bi)
126
160
 
@@ -128,7 +162,7 @@ module PolicyMap
128
162
  options = default_options.merge(options)
129
163
 
130
164
  result = get(Endpoint.endpoint_url, options)
131
- result['cnt'].first
165
+ result['bnd']
132
166
  end
133
167
 
134
168
  def get(endpoint, data=nil)
@@ -146,6 +180,24 @@ module PolicyMap
146
180
  end
147
181
  end
148
182
 
183
+ def sanitized_boundary_types(types)
184
+ # Convert :all to an array of all types
185
+ types = Array(types)
186
+ types = BOUNDARY_TYPES.keys if !types.empty? && :all == types.first.to_sym
187
+
188
+ # Convert symbols to a list of numbers
189
+ types.map { |bt| BOUNDARY_TYPES[bt] }.join(',')
190
+ end
191
+
192
+ def sanitized_indicators(indicators)
193
+ # Convert :all to an array of all types
194
+ indicators = Array(indicators)
195
+ indicators = INDICATORS.keys if !indicators.empty? && :all == indicators.first.to_sym
196
+
197
+ # Convert symbols to a list of numbers
198
+ indicators.map { |i| INDICATORS[i] }.join(',')
199
+ end
200
+
149
201
  end
150
202
 
151
203
  end
@@ -48,7 +48,7 @@ module PolicyMap
48
48
  if debug
49
49
  puts "\nresponse: #{response.code}"
50
50
  puts "headers:"
51
- response.header.each do |key, value|
51
+ response.headers.each do |key, value|
52
52
  puts "#{key}=#{value}"
53
53
  end
54
54
  puts "body:"
@@ -11,11 +11,10 @@ Gem::Specification.new do |s|
11
11
  s.email = "mgomes@geminisbs.com"
12
12
 
13
13
  s.add_dependency "yajl-ruby", "~> 1.1.0"
14
- s.add_dependency "rest-client", "~> 1.6"
14
+ s.add_dependency "rest-client", "~> 1.8"
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
  end
21
-
metadata CHANGED
@@ -1,51 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: policymap_wrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Gomes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-03 00:00:00.000000000 Z
11
+ date: 2016-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rest-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: '1.8'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.6'
40
+ version: '1.8'
41
41
  description: Ruby wrapper around the PolicyMap API v2
42
42
  email: mgomes@geminisbs.com
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
- - .document
48
- - .gitignore
47
+ - ".document"
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - Gemfile.lock
49
51
  - LICENSE
50
52
  - README.rdoc
51
53
  - Rakefile
@@ -69,17 +71,17 @@ require_paths:
69
71
  - lib
70
72
  required_ruby_version: !ruby/object:Gem::Requirement
71
73
  requirements:
72
- - - '>='
74
+ - - ">="
73
75
  - !ruby/object:Gem::Version
74
76
  version: '0'
75
77
  required_rubygems_version: !ruby/object:Gem::Requirement
76
78
  requirements:
77
- - - '>='
79
+ - - ">="
78
80
  - !ruby/object:Gem::Version
79
81
  version: '0'
80
82
  requirements: []
81
83
  rubyforge_project:
82
- rubygems_version: 2.0.3
84
+ rubygems_version: 2.5.1
83
85
  signing_key:
84
86
  specification_version: 4
85
87
  summary: Ruby wrapper around the PolicyMap API v2