Class: PolicyMap::Client
- Inherits:
-
Object
- Object
- PolicyMap::Client
- Defined in:
- lib/policymap_wrap/client.rb
Constant Summary collapse
- BOUNDARY_TYPES =
{ :state => 2, :county => 4, :census_tract => 6, :zip => 8, :block_group => 15, :city => 16, :congressional_district => 23, :assembly_district => 25, :senate_district => 24 }.freeze
- INDICATORS =
{ :average_vehicles_per_household => 9873779, :broadcasting => 9584691, :distressed_community => 9629156, :percent_homeowners => 9873049, :total_population => 9876593, :independent_artists => 9618303, :median_gross_rent => 9873661, :median_gross_rent_2009 => 9873663, :median_home_value => 9873606, :median_household_income => 9871831, :movie_and_sound_industries => 9584731, :museums_and_historical_sites => 9584676, :other_info_services => 9584624, :percent_moved_in_since_1990 => 9873776, :percent_who_commute_to_work_using_public_transit => 9873811, :percent_african_american => 9876222, :percent_native_american => 9876623, :percent_asian => 9876202, :percent_foreign_born => 9869060, :percent_hispanic => 9876280, :percent_pacific_islander => 9876468, :poverty_rate => 9871807, :percent_disabled => 9869050, :percent_65_or_older => 9869059, :percent_under_18 => 9869063, :percent_college_degree => 9873916, :percent_high_school_or_less => 9873913, :percent_mixed_race => 9876437, :percent_vacant_units => 9631221, :percent_white => 9876415, :percent_graduate_degree => 9873904, :performing_arts_and_spectator_sports => 9584608, :publishing_industries => 9584638, :unemployment_rate => 9841103, :vacancy_rate => 9876608 }.freeze
- @@connection =
nil- @@debug =
false- @@default_options =
nil- @@boundary_types_by_id =
nil
Class Method Summary collapse
- .boundary_search(*args) ⇒ Object
- .boundary_types ⇒ Object
- .containment_search(*args) ⇒ Object
- .debug ⇒ Object
- .debug=(debug_flag) ⇒ Object
- .get(endpoint, data = nil) ⇒ Object
- .indicator_search(*args) ⇒ Object
- .indicators ⇒ Object
- .query_search(*args) ⇒ Object
- .set_credentials(client_id, username, password, proxy_url = nil) ⇒ Object
Class Method Details
.boundary_search(*args) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/policymap_wrap/client.rb', line 107 def boundary_search(*args) = @@default_options [:t] = "bnd" = (args) raise InsufficientArgsForSearch unless .has_key?(:boundary_types) || .has_key?(:boundary_ids) [:boundary_types] = sanitized_boundary_types([:boundary_types]) [:boundary_ids] = Array([:boundary_ids]).join(',') if .has_key?(:boundary_ids) HashUtils.rename_key!(, :boundary_types, :bt) if .has_key?(:boundary_types) HashUtils.rename_key!(, :boundary_ids, :bi) if .has_key?(:boundary_ids) HashUtils.rename_key!(, :lng, :lon) if .has_key?(:lng) = .merge() result = get(Endpoint.endpoint_url, ) result["bnd"] end |
.boundary_types ⇒ Object
78 79 80 |
# File 'lib/policymap_wrap/client.rb', line 78 def boundary_types BOUNDARY_TYPES end |
.containment_search(*args) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/policymap_wrap/client.rb', line 149 def containment_search(*args) = @@default_options [:t] = 'bnd' = (args) raise InsufficientArgsForSearch unless .has_key?(:boundary_types) && .has_key?(:boundary_id) [:boundary_types] = sanitized_boundary_types([:boundary_types]) HashUtils.rename_key!(, :boundary_types, :cbt) HashUtils.rename_key!(, :boundary_id, :bi) = .merge() result = get(Endpoint.endpoint_url, ) result['bnd'] end |
.debug ⇒ Object
74 75 76 |
# File 'lib/policymap_wrap/client.rb', line 74 def debug @@debug end |
.debug=(debug_flag) ⇒ Object
69 70 71 72 |
# File 'lib/policymap_wrap/client.rb', line 69 def debug=(debug_flag) @@debug = debug_flag @@connection.debug = @@debug if @@connection end |
.get(endpoint, data = nil) ⇒ Object
168 169 170 171 |
# File 'lib/policymap_wrap/client.rb', line 168 def get(endpoint, data=nil) raise NoConnectionEstablished if @@connection.nil? @@connection.get endpoint, data end |
.indicator_search(*args) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/policymap_wrap/client.rb', line 127 def indicator_search(*args) = @@default_options [:t] = "ind" = (args) raise InsufficientArgsForSearch unless .has_key?(:indicators) && (.has_key?(:boundary_types) || .has_key?(:boundary_ids)) [:indicators] = sanitized_indicators([:indicators]) [:boundary_types] = sanitized_boundary_types([:boundary_types]) [:boundary_ids] = Array([:boundary_ids]).join(',') if .has_key?(:boundary_ids) HashUtils.rename_key!(, :indicators, :ii) HashUtils.rename_key!(, :boundary_types, :bt) if .has_key?(:boundary_types) HashUtils.rename_key!(, :boundary_ids, :bi) if .has_key?(:boundary_ids) HashUtils.rename_key!(, :lng, :lon) if .has_key?(:lng) = .merge() result = get(Endpoint.endpoint_url, ) result["ind"] end |
.indicators ⇒ Object
82 83 84 |
# File 'lib/policymap_wrap/client.rb', line 82 def indicators INDICATORS end |
.query_search(*args) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/policymap_wrap/client.rb', line 86 def query_search(*args) = @@default_options [:t] = "sch" = (args) raise InsufficientArgsForSearch unless .has_key?(:boundary_types) && .has_key?(:query) [:boundary_types] = sanitized_boundary_types([:boundary_types]) HashUtils.rename_key!(, :boundary_types, :bt) HashUtils.rename_key!(, :query, :ss) HashUtils.rename_key!(, :state, :sst) if .has_key?(:state) HashUtils.rename_key!(, :county, :sco) if .has_key?(:county) HashUtils.rename_key!(, :census_tract, :sct) if .has_key?(:census_tract) = .merge() result = get(Endpoint.endpoint_url, ) result['sch'] end |
.set_credentials(client_id, username, password, proxy_url = nil) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/policymap_wrap/client.rb', line 62 def set_credentials(client_id, username, password, proxy_url=nil) @@default_options = { :id => client_id, :ty => 'data', :f => 'j', :af => '1' } @@connection = Connection.new(client_id, username, password, proxy_url) @@connection.debug = @@debug true end |