Class: PolicyMap::Client
- Inherits:
-
Object
- Object
- PolicyMap::Client
- Defined in:
- lib/policymap_wrap/client.rb
Constant Summary collapse
- BOUNDARY_TYPES =
{ :state => 2, :county => 4, :city => 16, :zip => 8, :census_tract => 6, :block_group => 15, :congressional_district => 23, :assembly_district => 49, :senate_district => 48, :all => 'all' }
- INDICATORS =
{ :total_population => 9876598, :percent_african_american => 9876222, :percent_asian => 9876202, :percent_pacific_islander => 9876468, :percent_hispanic => 9876280, :percent_native_american => 9876623, :percent_mixed_race => 9876437, :percent_under_18 => 9869063, :percent_65_or_older => 9869059, :percent_foreign_born => 9869060, :percent_disabled => 9869050, :percent_high_school_or_less => 9873913, :percent_college_degree => 9873916, :percent_graduate_degree => 9873904, :median_home_value => 9873606, :median_rent => 9873661, :percent_moved_in_since_1990 => 9873776, :percent_homeowners => 9873049, :vacancy_rate => 9876608, :median_household_income => 9871831, :poverty_rate => 9871807, :percent_white => 9876415, :percent_households_wo_car => 0, :average_vehicles_per_household => 9873779, :percent_who_commute_to_work_using_public_transit => 9873811, :unemployment_rate => 9841103, :independent_artists => 9618303, :performing_arts_and_spectator_sports => 9584608, :movie_and_sound_industries => 9584731, :mueseums_and_historical_sites => 9584676, :publishing_industries => 9584638, :broadcasting => 9584691, :other_info_services => 9584624, :all => 'all' }
- @@connection =
nil
- @@debug =
false
- @@default_options =
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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/policymap_wrap/client.rb', line 73 def boundary_search(*args) = @@default_options [:t] = "bnd" = (args) raise InsufficientArgsForSearch unless .has_key?(:boundary_types) || .has_key?(:boundary_ids) [:boundary_types] = Array([:boundary_types]).collect {|bt| BOUNDARY_TYPES[bt] }.join(',') if .has_key?(: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, ) HashUtils.recursively_symbolize_keys(result["bnd"]) end |
.boundary_types ⇒ Object
44 45 46 |
# File 'lib/policymap_wrap/client.rb', line 44 def boundary_types BOUNDARY_TYPES end |
.containment_search(*args) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/policymap_wrap/client.rb', line 115 def containment_search(*args) = @@default_options [:t] = "cnt" = (args) raise InsufficientArgsForSearch unless .has_key?(:boundary_types) && .has_key?(:boundary_id) [:boundary_types] = Array([:boundary_types]).collect {|bt| BOUNDARY_TYPES[bt] }.join(',') HashUtils.rename_key!(, :boundary_types, :cbt) HashUtils.rename_key!(, :boundary_id, :bi) = .merge() result = get(Endpoint.endpoint_url, ) result['cnt'].first end |
.debug ⇒ Object
40 41 42 |
# File 'lib/policymap_wrap/client.rb', line 40 def debug @@debug end |
.debug=(debug_flag) ⇒ Object
35 36 37 38 |
# File 'lib/policymap_wrap/client.rb', line 35 def debug=(debug_flag) @@debug = debug_flag @@connection.debug = @@debug if @@connection end |
.get(endpoint, data = nil) ⇒ Object
134 135 136 137 |
# File 'lib/policymap_wrap/client.rb', line 134 def get(endpoint, data=nil) raise NoConnectionEstablished if @@connection.nil? @@connection.get endpoint, data end |
.indicator_search(*args) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/policymap_wrap/client.rb', line 93 def indicator_search(*args) = @@default_options [:t] = "ind" = (args) raise InsufficientArgsForSearch unless .has_key?(:indicators) && (.has_key?(:boundary_types) || .has_key?(:boundary_ids)) [:indicators] = Array([:indicators]).collect {|i| INDICATORS[i] }.join(',') [:boundary_types] = Array([:boundary_types]).collect {|bt| BOUNDARY_TYPES[bt] }.join(',') if .has_key?(: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, ) HashUtils.recursively_symbolize_keys(result["ind"]) end |
.indicators ⇒ Object
48 49 50 |
# File 'lib/policymap_wrap/client.rb', line 48 def indicators INDICATORS end |
.query_search(*args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/policymap_wrap/client.rb', line 52 def query_search(*args) = @@default_options [:t] = "sch" = (args) raise InsufficientArgsForSearch unless .has_key?(:boundary_types) && .has_key?(:query) [:boundary_types] = Array([:boundary_types]).collect {|bt| BOUNDARY_TYPES[bt] }.join(',') HashUtils.rename_key!(, :boundary_types, :bt) HashUtils.rename_key!(, :query, :s) HashUtils.rename_key!(, :state, :st) if .has_key?(:state) HashUtils.rename_key!(, :county, :co) if .has_key?(:county) HashUtils.rename_key!(, :census_tract, :ct) if .has_key?(:census_tract) = .merge() result = get(Endpoint.endpoint_url, ) result['sch'].collect {|hsh| HashUtils.symbolize_keys(hsh) } end |
.set_credentials(client_id, username, password, proxy_url = nil) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/policymap_wrap/client.rb', line 28 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 |