sg-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +120 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/simple_geo.rb +23 -0
- data/lib/simple_geo/client.rb +166 -0
- data/lib/simple_geo/connection.rb +109 -0
- data/lib/simple_geo/endpoint.rb +67 -0
- data/lib/simple_geo/hash_utils.rb +24 -0
- data/lib/simple_geo/record.rb +57 -0
- data/lib/simplegeo.rb +2 -0
- data/sg-ruby.gemspec +81 -0
- data/spec/client_spec.rb +1165 -0
- data/spec/fixtures/contains.json +127 -0
- data/spec/fixtures/get_density_by_day.json +833 -0
- data/spec/fixtures/get_density_by_hour.json +36 -0
- data/spec/fixtures/get_history.json +13 -0
- data/spec/fixtures/get_nearby.json +84 -0
- data/spec/fixtures/get_record.json +38 -0
- data/spec/fixtures/get_records.json +197 -0
- data/spec/fixtures/layer_info.json +8 -0
- data/spec/fixtures/nearby_address.json +21 -0
- data/spec/fixtures/no_such_record.json +4 -0
- data/spec/fixtures/nonetype_not_iterable.json +4 -0
- data/spec/fixtures/overlaps.json +41 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +29 -0
- metadata +145 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
module SimpleGeo
|
2
|
+
|
3
|
+
class Endpoint
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def record(layer, id)
|
7
|
+
endpoint_url "records/#{layer}/#{id}.json"
|
8
|
+
end
|
9
|
+
|
10
|
+
def records(layer, ids)
|
11
|
+
ids = ids.join(',') if ids.is_a? Array
|
12
|
+
endpoint_url "records/#{layer}/#{ids}.json"
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_records(layer)
|
16
|
+
endpoint_url "records/#{layer}.json"
|
17
|
+
end
|
18
|
+
|
19
|
+
def history(layer, id)
|
20
|
+
endpoint_url "records/#{layer}/#{id}/history.json"
|
21
|
+
end
|
22
|
+
|
23
|
+
def nearby_geohash(layer, geohash)
|
24
|
+
endpoint_url "records/#{layer}/nearby/#{geohash}.json"
|
25
|
+
end
|
26
|
+
|
27
|
+
def nearby_coordinates(layer, lat, lon)
|
28
|
+
endpoint_url "records/#{layer}/nearby/#{lat},#{lon}.json"
|
29
|
+
end
|
30
|
+
|
31
|
+
def nearby_address(lat, lon)
|
32
|
+
endpoint_url "nearby/address/#{lat},#{lon}.json"
|
33
|
+
end
|
34
|
+
|
35
|
+
def density(lat, lon, day, hour=nil)
|
36
|
+
if hour.nil?
|
37
|
+
path = "density/#{day}/#{lat},#{lon}.json"
|
38
|
+
else
|
39
|
+
path = "density/#{day}/#{hour}/#{lat},#{lon}.json"
|
40
|
+
end
|
41
|
+
endpoint_url path
|
42
|
+
end
|
43
|
+
|
44
|
+
def layer(layer)
|
45
|
+
endpoint_url "layer/#{layer}.json"
|
46
|
+
end
|
47
|
+
|
48
|
+
def contains(lat, lon)
|
49
|
+
endpoint_url "contains/#{lat},#{lon}.json"
|
50
|
+
end
|
51
|
+
|
52
|
+
def overlaps(south, west, north, east)
|
53
|
+
endpoint_url "overlaps/#{south},#{west},#{north},#{east}.json"
|
54
|
+
end
|
55
|
+
|
56
|
+
def boundary(id)
|
57
|
+
endpoint_url "boundary/#{id}.json"
|
58
|
+
end
|
59
|
+
|
60
|
+
def endpoint_url(path)
|
61
|
+
[REALM, API_VERSION, path].join('/')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SimpleGeo
|
2
|
+
class HashUtils
|
3
|
+
def self.symbolize_keys(hash)
|
4
|
+
hash.inject({}) do |options, (key, value)|
|
5
|
+
options[(key.to_sym rescue key) || key] = value
|
6
|
+
options
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.recursively_symbolize_keys(object)
|
11
|
+
if object.is_a? Hash
|
12
|
+
symbolized_hash = symbolize_keys(object)
|
13
|
+
symbolized_hash.each do |key, value|
|
14
|
+
symbolized_hash[key] = recursively_symbolize_keys(value)
|
15
|
+
end
|
16
|
+
symbolized_hash
|
17
|
+
elsif object.is_a? Array
|
18
|
+
object.map { |value| recursively_symbolize_keys(value) }
|
19
|
+
else
|
20
|
+
object
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module SimpleGeo
|
2
|
+
class Record
|
3
|
+
attr_accessor :layer, :id, :lat, :lon, :type, :created, :properties
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
options = {
|
7
|
+
:created => Time.now,
|
8
|
+
:type => 'object',
|
9
|
+
:properties => {}
|
10
|
+
}.merge(options)
|
11
|
+
|
12
|
+
@id = options[:id]
|
13
|
+
@layer = options[:layer]
|
14
|
+
@type = options[:type]
|
15
|
+
@lat = options[:lat]
|
16
|
+
@lon = options[:lon]
|
17
|
+
@created = options[:created]
|
18
|
+
@properties = options[:properties]
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
{
|
23
|
+
:type => 'Feature',
|
24
|
+
:id => id,
|
25
|
+
:created => created.to_i,
|
26
|
+
:geometry => {
|
27
|
+
:type => 'Point',
|
28
|
+
:coordinates => [ lon, lat ]
|
29
|
+
},
|
30
|
+
:properties => properties.merge({
|
31
|
+
:type => type,
|
32
|
+
:layer => layer
|
33
|
+
})
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_json
|
38
|
+
self.to_hash.to_json
|
39
|
+
end
|
40
|
+
|
41
|
+
def ==(other)
|
42
|
+
other.class == self.class && self.to_hash == other.to_hash
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.parse_geojson_hash(json_hash)
|
46
|
+
Record.new(
|
47
|
+
:id => json_hash['id'],
|
48
|
+
:type => json_hash['properties'].delete('type'),
|
49
|
+
:lat => json_hash['geometry']['coordinates'][1],
|
50
|
+
:lon => json_hash['geometry']['coordinates'][0],
|
51
|
+
:created => Time.at(json_hash['created']),
|
52
|
+
:properties => HashUtils.recursively_symbolize_keys(json_hash['properties'])
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/simplegeo.rb
ADDED
data/sg-ruby.gemspec
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{sg-ruby}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dan Dofter"]
|
12
|
+
s.date = %q{2010-05-12}
|
13
|
+
s.email = %q{dan@dofter.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/simple_geo.rb",
|
26
|
+
"lib/simple_geo/client.rb",
|
27
|
+
"lib/simple_geo/connection.rb",
|
28
|
+
"lib/simple_geo/endpoint.rb",
|
29
|
+
"lib/simple_geo/hash_utils.rb",
|
30
|
+
"lib/simple_geo/record.rb",
|
31
|
+
"lib/simplegeo.rb",
|
32
|
+
"sg-ruby.gemspec",
|
33
|
+
"spec/client_spec.rb",
|
34
|
+
"spec/fixtures/contains.json",
|
35
|
+
"spec/fixtures/get_density_by_day.json",
|
36
|
+
"spec/fixtures/get_density_by_hour.json",
|
37
|
+
"spec/fixtures/get_history.json",
|
38
|
+
"spec/fixtures/get_nearby.json",
|
39
|
+
"spec/fixtures/get_record.json",
|
40
|
+
"spec/fixtures/get_records.json",
|
41
|
+
"spec/fixtures/layer_info.json",
|
42
|
+
"spec/fixtures/nearby_address.json",
|
43
|
+
"spec/fixtures/no_such_record.json",
|
44
|
+
"spec/fixtures/nonetype_not_iterable.json",
|
45
|
+
"spec/fixtures/overlaps.json",
|
46
|
+
"spec/spec.opts",
|
47
|
+
"spec/spec_helper.rb"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/archfear/sg-ruby}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.3.6}
|
53
|
+
s.summary = %q{A SimpleGeo Ruby Client}
|
54
|
+
s.test_files = [
|
55
|
+
"spec/client_spec.rb",
|
56
|
+
"spec/spec_helper.rb"
|
57
|
+
]
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
61
|
+
s.specification_version = 3
|
62
|
+
|
63
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
64
|
+
s.add_runtime_dependency(%q<oauth>, [">= 0.4.0"])
|
65
|
+
s.add_runtime_dependency(%q<json_pure>, [">= 0"])
|
66
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.0"])
|
67
|
+
s.add_development_dependency(%q<fakeweb>, [">= 1.2.0"])
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<oauth>, [">= 0.4.0"])
|
70
|
+
s.add_dependency(%q<json_pure>, [">= 0"])
|
71
|
+
s.add_dependency(%q<rspec>, [">= 1.2.0"])
|
72
|
+
s.add_dependency(%q<fakeweb>, [">= 1.2.0"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<oauth>, [">= 0.4.0"])
|
76
|
+
s.add_dependency(%q<json_pure>, [">= 0"])
|
77
|
+
s.add_dependency(%q<rspec>, [">= 1.2.0"])
|
78
|
+
s.add_dependency(%q<fakeweb>, [">= 1.2.0"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,1165 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Client" do
|
4
|
+
before do
|
5
|
+
SimpleGeo::Client.set_credentials 'token', 'secret'
|
6
|
+
end
|
7
|
+
|
8
|
+
context "getting a record" do
|
9
|
+
context "with an id for an existing record" do
|
10
|
+
before do
|
11
|
+
stub_request :get,
|
12
|
+
'http://api.simplegeo.com/0.1/records/com.simplegeo.global.geonames/5373629.json',
|
13
|
+
:fixture_file => 'get_record.json'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return a single record with the correct attributes" do
|
17
|
+
record = SimpleGeo::Client.get_record('com.simplegeo.global.geonames', 5373629)
|
18
|
+
record.class.should == SimpleGeo::Record
|
19
|
+
record.id.should == '5373629'
|
20
|
+
record.type.should == 'place'
|
21
|
+
record.layer.should == 'com.simplegeo.global.geonames'
|
22
|
+
record.created.should == Time.at(1269832510)
|
23
|
+
record.lat.should == 37.759650000000001
|
24
|
+
record.lon.should == -122.42608
|
25
|
+
record.properties.should == {
|
26
|
+
:layer => "com.simplegeo.global.geonames",
|
27
|
+
:elevation => "22",
|
28
|
+
:gtopo30 => "60",
|
29
|
+
:feature_code => "PRK",
|
30
|
+
:last_modified => "2006-01-15",
|
31
|
+
:country_code => "US",
|
32
|
+
:alternatenames => "",
|
33
|
+
:timezone => "America/Los_Angeles",
|
34
|
+
:population => "0",
|
35
|
+
:name => "Mission Dolores Park",
|
36
|
+
:feature_class => "L",
|
37
|
+
:cc2 => "",
|
38
|
+
:admin1 => "CA",
|
39
|
+
:admin3 => "",
|
40
|
+
:admin2 => "075",
|
41
|
+
:admin4 => "",
|
42
|
+
:asciiname => "Mission Dolores Park"
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with an id for a nonexistant record" do
|
48
|
+
before do
|
49
|
+
stub_request :get,
|
50
|
+
'http://api.simplegeo.com/0.1/records/com.simplegeo.global.geonames/foo.json',
|
51
|
+
:fixture_file => 'no_such_record.json', :status => 404
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should raise a NotFound exception" do
|
55
|
+
lambda {
|
56
|
+
SimpleGeo::Client.get_record('com.simplegeo.global.geonames', 'foo')
|
57
|
+
}.should raise_exception(SimpleGeo::NotFound)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
#TODO: verify request data contains correct record data
|
63
|
+
context "adding/updating a record" do
|
64
|
+
before do
|
65
|
+
stub_request :put,
|
66
|
+
'http://api.simplegeo.com/0.1/records/io.path.testlayer/1234.json',
|
67
|
+
:status => 202
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should create or update the record" do
|
71
|
+
lambda {
|
72
|
+
record = SimpleGeo::Record.new({
|
73
|
+
:id => '1234',
|
74
|
+
:created => 1269832510,
|
75
|
+
:lat => 37.759650000000001,
|
76
|
+
:lon => -122.42608,
|
77
|
+
:layer => 'io.path.testlayer',
|
78
|
+
:properties => {
|
79
|
+
:test_property => 'foobar'
|
80
|
+
}
|
81
|
+
})
|
82
|
+
SimpleGeo::Client.add_record(record)
|
83
|
+
}.should_not raise_exception
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "deleting a record" do
|
88
|
+
before do
|
89
|
+
stub_request :delete,
|
90
|
+
'http://api.simplegeo.com/0.1/records/io.path.testlayer/1234.json',
|
91
|
+
:status => 202
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should delete the record" do
|
95
|
+
lambda {
|
96
|
+
SimpleGeo::Client.delete_record('io.path.testlayer', '1234')
|
97
|
+
}.should_not raise_exception
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "getting multiple records" do
|
102
|
+
context "with ids for two existing records" do
|
103
|
+
before do
|
104
|
+
stub_request :get,
|
105
|
+
'http://api.simplegeo.com/0.1/records/com.simplegeo.us.business/41531696,41530629.json',
|
106
|
+
:fixture_file => 'get_records.json'
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should return an array of records with the correct attributes" do
|
110
|
+
records = SimpleGeo::Client.get_records('com.simplegeo.us.business', ['41531696', '41530629'])
|
111
|
+
records.size.should == 2
|
112
|
+
records[0].id.should == '41530629'
|
113
|
+
records[0].type.should == 'place'
|
114
|
+
records[0].layer.should == 'com.simplegeo.us.business'
|
115
|
+
records[0].created.should == Time.at(1271985142)
|
116
|
+
records[0].lat.should == 37.760350000000003
|
117
|
+
records[0].lon.should == -122.419043
|
118
|
+
records[0].properties.should == {
|
119
|
+
:state => "CA",
|
120
|
+
:census_block_group => "2",
|
121
|
+
:street_type => "St",
|
122
|
+
:city => "San Francisco",
|
123
|
+
:census_block_id => "002",
|
124
|
+
:plus4 => "1811",
|
125
|
+
:cbsa => "41860",
|
126
|
+
:time_zone => "4",
|
127
|
+
:censustract => "020800",
|
128
|
+
:pubdate => "2009-12-01",
|
129
|
+
:std_name => "Beauty Bar",
|
130
|
+
:phone_number => "0323",
|
131
|
+
:state_fips => "06",
|
132
|
+
:company_sics => [
|
133
|
+
{
|
134
|
+
:sic => "72310000",
|
135
|
+
:industry_class => "7",
|
136
|
+
:relevancy => "1",
|
137
|
+
:naics_description => "BEAUTY SALONS",
|
138
|
+
:naics => "812112",
|
139
|
+
:sic_4 => "7231",
|
140
|
+
:description => "BEAUTY SHOPS",
|
141
|
+
:sic_4_description => "BEAUTY SHOPS"
|
142
|
+
},
|
143
|
+
{
|
144
|
+
:sic => "58130101",
|
145
|
+
:industry_class => "5",
|
146
|
+
:relevancy => "2",
|
147
|
+
:naics_description => "DRINKING PLACES (ALCOHOLIC BEVERAGES)",
|
148
|
+
:naics => "72241",
|
149
|
+
:sic_4 => "5813",
|
150
|
+
:description => "BAR (DRINKING PLACES)",
|
151
|
+
:sic_4_description => "DRINKING PLACES"
|
152
|
+
},
|
153
|
+
{
|
154
|
+
:sic => "58120310",
|
155
|
+
:industry_class => "5",
|
156
|
+
:relevancy => "3",
|
157
|
+
:naics_description => "LIMITED-SERVICE RESTAURANTS",
|
158
|
+
:naics => "722211",
|
159
|
+
:sic_4 => "5812",
|
160
|
+
:description => "GRILLS, ( EATING PLACES)",
|
161
|
+
:sic_4_description => "EATING PLACES"
|
162
|
+
}
|
163
|
+
],
|
164
|
+
:dpv_confirm => "Y",
|
165
|
+
:zip => "94110",
|
166
|
+
:dpc => "996",
|
167
|
+
:street_name => "Mission",
|
168
|
+
:carrier_route => "C036",
|
169
|
+
:area_code => "415",
|
170
|
+
:company_headings => [
|
171
|
+
{
|
172
|
+
:category_name => "Bars, Taverns & Cocktail Lounges",
|
173
|
+
:condensed_name => "BARS GRILLS & PUBS",
|
174
|
+
:normalized_id => "138001000",
|
175
|
+
:category_id => "138000000",
|
176
|
+
:normalized_name => "BARS GRILLS & PUBS",
|
177
|
+
:condensed_id => "138001000"
|
178
|
+
}
|
179
|
+
],
|
180
|
+
:mlsc => "4",
|
181
|
+
:val_date => "2010-03-22",
|
182
|
+
:confidence_score => "100",
|
183
|
+
:exppubcity => "San Francisco",
|
184
|
+
:housenumber => "2299",
|
185
|
+
:z4_type => "S",
|
186
|
+
:exchange => "285",
|
187
|
+
:business_name => "Beauty Bar",
|
188
|
+
:county_fips => "075",
|
189
|
+
:ll_match_level => "R",
|
190
|
+
:dso => "1",
|
191
|
+
:company_phones => [
|
192
|
+
{
|
193
|
+
:val_flag => "C",
|
194
|
+
:val_date => "2010-03-22",
|
195
|
+
:phone_type => "P",
|
196
|
+
:dnc => "",
|
197
|
+
:exchange => "285",
|
198
|
+
:phone_number => "0323",
|
199
|
+
:areacode => "415"
|
200
|
+
}
|
201
|
+
],
|
202
|
+
:msa => "7360",
|
203
|
+
:val_flag => "C"
|
204
|
+
}
|
205
|
+
records[1].id.should == '41531696'
|
206
|
+
records[1].type.should == 'place'
|
207
|
+
records[1].layer.should == 'com.simplegeo.us.business'
|
208
|
+
records[1].created.should == Time.at(1271985146)
|
209
|
+
records[1].lat.should == 37.755470000000003
|
210
|
+
records[1].lon.should == -122.420646
|
211
|
+
records[1].properties.should == {
|
212
|
+
:carrier_route => "C010",
|
213
|
+
:pubdate => "2009-12-01",
|
214
|
+
:ll_match_level => "R",
|
215
|
+
:street_name => "22nd",
|
216
|
+
:std_name => "Latin American Club",
|
217
|
+
:val_flag => "C",
|
218
|
+
:census_block_id => "004",
|
219
|
+
:company_headings => [
|
220
|
+
{
|
221
|
+
:normalized_id => "138004000",
|
222
|
+
:condensed_name => "NIGHT CLUBS",
|
223
|
+
:condensed_id => "138004000",
|
224
|
+
:normalized_name => "NIGHT CLUBS",
|
225
|
+
:category_id => "138000000",
|
226
|
+
:category_name => "Bars, Taverns & Cocktail Lounges"
|
227
|
+
}
|
228
|
+
],
|
229
|
+
:company_sics => [
|
230
|
+
{
|
231
|
+
:sic_4 => "5813",
|
232
|
+
:relevancy => "1",
|
233
|
+
:description => "NIGHT CLUBS",
|
234
|
+
:naics => "72241",
|
235
|
+
:sic => "58130200",
|
236
|
+
:industry_class => "5",
|
237
|
+
:sic_4_description => "DRINKING PLACES",
|
238
|
+
:naics_description => "DRINKING PLACES (ALCOHOLIC BEVERAGES)"
|
239
|
+
}
|
240
|
+
],
|
241
|
+
:city => "San Francisco",
|
242
|
+
:county_fips => "075",
|
243
|
+
:zip => "94110",
|
244
|
+
:mlsc => "4",
|
245
|
+
:dso => "1",
|
246
|
+
:state => "CA",
|
247
|
+
:dpv_confirm => "Y",
|
248
|
+
:housenumber => "3286",
|
249
|
+
:msa => "7360",
|
250
|
+
:phone_number => "2732",
|
251
|
+
:exchange => "647",
|
252
|
+
:area_code => "415",
|
253
|
+
:censustract => "020800",
|
254
|
+
:state_fips => "06",
|
255
|
+
:street_type => "St",
|
256
|
+
:business_name => "Latin American Club",
|
257
|
+
:plus4 => "3033",
|
258
|
+
:val_date => "2010-03-22",
|
259
|
+
:dnc => "T",
|
260
|
+
:confidence_score => "100",
|
261
|
+
:time_zone => "4",
|
262
|
+
:cbsa => "41860",
|
263
|
+
:dpc => "862",
|
264
|
+
:company_phones => [
|
265
|
+
{
|
266
|
+
:phone_number => "2732",
|
267
|
+
:phone_type => "P",
|
268
|
+
:val_date => "2010-03-22",
|
269
|
+
:dnc => "T",
|
270
|
+
:exchange => "647",
|
271
|
+
:areacode => "415",
|
272
|
+
:val_flag => "C"
|
273
|
+
}
|
274
|
+
],
|
275
|
+
:census_block_group => "4",
|
276
|
+
:z4_type => "S"
|
277
|
+
}
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context "with ids for nonexistant records" do
|
282
|
+
before do
|
283
|
+
stub_request :get,
|
284
|
+
'http://api.simplegeo.com/0.1/records/com.simplegeo.global.geonames/foo,bar.json',
|
285
|
+
:fixture_file => 'nonetype_not_iterable.json', :status => 500
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should raise a NotFound exception" do
|
289
|
+
lambda {
|
290
|
+
SimpleGeo::Client.get_records('com.simplegeo.global.geonames', ['foo', 'bar'])
|
291
|
+
}.should raise_exception(SimpleGeo::ServerError)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
context "adding multiple records" do
|
297
|
+
before do
|
298
|
+
stub_request :post,
|
299
|
+
'http://api.simplegeo.com/0.1/records/io.path.testlayer.json',
|
300
|
+
:status => 202
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should create or update the record" do
|
304
|
+
layer = 'io.path.testlayer'
|
305
|
+
lambda {
|
306
|
+
records = [
|
307
|
+
SimpleGeo::Record.new({
|
308
|
+
:id => '1234',
|
309
|
+
:created => 1269832510,
|
310
|
+
:lat => 37.759650000000001,
|
311
|
+
:lon => -122.42608,
|
312
|
+
:layer => layer,
|
313
|
+
:properties => {
|
314
|
+
:test_property => 'foobar'
|
315
|
+
}
|
316
|
+
}),
|
317
|
+
SimpleGeo::Record.new({
|
318
|
+
:id => '5678',
|
319
|
+
:created => 1269832510,
|
320
|
+
:lat => 37.755470000000003,
|
321
|
+
:lon => -122.420646,
|
322
|
+
:layer => layer,
|
323
|
+
:properties => {
|
324
|
+
:mad_prop => 'baz'
|
325
|
+
}
|
326
|
+
})
|
327
|
+
]
|
328
|
+
SimpleGeo::Client.add_records(layer, records)
|
329
|
+
}.should_not raise_exception
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context "getting a record's history" do
|
334
|
+
before do
|
335
|
+
stub_request :get,
|
336
|
+
'http://api.simplegeo.com/0.1/records/com.simplegeo.global.geonames/5373629/history.json',
|
337
|
+
:fixture_file => 'get_history.json'
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should create or update the record" do
|
341
|
+
history = SimpleGeo::Client.get_history('com.simplegeo.global.geonames', '5373629')
|
342
|
+
history.should == [
|
343
|
+
{
|
344
|
+
:created => Time.at(1269832510),
|
345
|
+
:lat => 37.759650000000001,
|
346
|
+
:lon => -122.42608
|
347
|
+
}
|
348
|
+
]
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
context "getting nearby records" do
|
353
|
+
before do
|
354
|
+
@expected_records = {
|
355
|
+
:next_cursor => "QVSEifz7gri4J0w8FSQJ06Z5S5lOw6gZ75Co-fBbBQJEr7XMqN32bjMKNc9kwLKqKyqtVvxR_t5hgWW6XDgPnPTY",
|
356
|
+
:records => [
|
357
|
+
{
|
358
|
+
:distance => 0,
|
359
|
+
:record => SimpleGeo::Record.new(
|
360
|
+
:id => "5373629",
|
361
|
+
:lon => -122.42608,
|
362
|
+
:lat => 37.75965,
|
363
|
+
:type => "place",
|
364
|
+
:layer => "com.simplegeo.global.geonames",
|
365
|
+
:created => Time.at(1269832510),
|
366
|
+
:properties => {
|
367
|
+
:admin4 => "",
|
368
|
+
:feature_code => "PRK",
|
369
|
+
:feature_class => "L",
|
370
|
+
:last_modified => "2006-01-15",
|
371
|
+
:asciiname => "Mission Dolores Park",
|
372
|
+
:cc2 => "",
|
373
|
+
:country_code => "US",
|
374
|
+
:admin1 => "CA",
|
375
|
+
:alternatenames => "",
|
376
|
+
:admin3 => "",
|
377
|
+
:elevation => "22",
|
378
|
+
:layer => "com.simplegeo.global.geonames",
|
379
|
+
:timezone => "America/Los_Angeles",
|
380
|
+
:name => "Mission Dolores Park",
|
381
|
+
:gtopo30 => "60",
|
382
|
+
:admin2 => "075",
|
383
|
+
:population => "0"
|
384
|
+
}
|
385
|
+
)
|
386
|
+
},
|
387
|
+
{
|
388
|
+
:distance => 57.557068918956581,
|
389
|
+
:record => SimpleGeo::Record.new(
|
390
|
+
:id => "5352852",
|
391
|
+
:lon => -122.42553,
|
392
|
+
:lat => 37.75937,
|
393
|
+
:type => "place",
|
394
|
+
:layer => "com.simplegeo.global.geonames",
|
395
|
+
:created => Time.at(1269832039),
|
396
|
+
:properties => {
|
397
|
+
:admin4 => "",
|
398
|
+
:feature_code => "CH",
|
399
|
+
:feature_class => "S",
|
400
|
+
:last_modified => "2006-01-15",
|
401
|
+
:asciiname => "Golden Gate Lutheran Church",
|
402
|
+
:cc2 => "",
|
403
|
+
:country_code => "US",
|
404
|
+
:admin1 => "CA",
|
405
|
+
:alternatenames => "",
|
406
|
+
:admin3 => "",
|
407
|
+
:elevation => "23",
|
408
|
+
:layer => "com.simplegeo.global.geonames",
|
409
|
+
:timezone => "America/Los_Angeles",
|
410
|
+
:name=> "Golden Gate Lutheran Church",
|
411
|
+
:gtopo30 => "60",
|
412
|
+
:admin2 => "075",
|
413
|
+
:population => "0"
|
414
|
+
}
|
415
|
+
)
|
416
|
+
}
|
417
|
+
]
|
418
|
+
}
|
419
|
+
end
|
420
|
+
|
421
|
+
context "by lat and lon" do
|
422
|
+
before do
|
423
|
+
stub_request :get,
|
424
|
+
'http://api.simplegeo.com/0.1/records/com.simplegeo.global.geonames/nearby/37.75965,-122.42608.json',
|
425
|
+
:fixture_file => 'get_nearby.json'
|
426
|
+
end
|
427
|
+
|
428
|
+
it "should return a hash of nearby records" do
|
429
|
+
records = SimpleGeo::Client.get_nearby_records('com.simplegeo.global.geonames',
|
430
|
+
:lat => 37.759650000000001,
|
431
|
+
:lon => -122.42608)
|
432
|
+
records.should == @expected_records
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
context "by geohash" do
|
437
|
+
before do
|
438
|
+
stub_request :get,
|
439
|
+
'http://api.simplegeo.com/0.1/records/com.simplegeo.global.geonames/nearby/9q8yy1ujcsfm.json',
|
440
|
+
:fixture_file => 'get_nearby.json'
|
441
|
+
end
|
442
|
+
|
443
|
+
it "should return a hash of nearby records" do
|
444
|
+
records = SimpleGeo::Client.get_nearby_records('com.simplegeo.global.geonames',
|
445
|
+
:geohash => '9q8yy1ujcsfm')
|
446
|
+
records.should == @expected_records
|
447
|
+
end
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
context "getting a nearby address" do
|
452
|
+
before do
|
453
|
+
stub_request :get,
|
454
|
+
'http://api.simplegeo.com/0.1/nearby/address/37.75965,-122.42608.json',
|
455
|
+
:fixture_file => 'nearby_address.json'
|
456
|
+
end
|
457
|
+
|
458
|
+
it "should return a hash with the address information" do
|
459
|
+
nearby_address = SimpleGeo::Client.get_nearby_address(37.759650000000001, -122.42608)
|
460
|
+
nearby_address.should == {
|
461
|
+
:state_name => "California",
|
462
|
+
:street_number => "580",
|
463
|
+
:country => "US",
|
464
|
+
:street => "Dolores St",
|
465
|
+
:postal_code => "",
|
466
|
+
:county_name => "San Francisco",
|
467
|
+
:county_code => "075",
|
468
|
+
:state_code => "CA",
|
469
|
+
:place_name => "San Francisco"
|
470
|
+
}
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
context "getting layer information" do
|
475
|
+
context "for an existing layer" do
|
476
|
+
before do
|
477
|
+
stub_request :get,
|
478
|
+
'http://api.simplegeo.com/0.1/layer/io.path.testlayer.json',
|
479
|
+
:fixture_file => 'layer_info.json'
|
480
|
+
end
|
481
|
+
|
482
|
+
it "should return a hash containing the layer information" do
|
483
|
+
layer_info = SimpleGeo::Client.get_layer_information('io.path.testlayer')
|
484
|
+
layer_info.should == {
|
485
|
+
:name => "io.path.testlayer",
|
486
|
+
:public => false,
|
487
|
+
:callback_urls => []
|
488
|
+
}
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
context "for a nonexistant layer" do
|
493
|
+
before do
|
494
|
+
stub_request :get,
|
495
|
+
'http://api.simplegeo.com/0.1/layer/io.path.testlayer.json',
|
496
|
+
:status => 404
|
497
|
+
end
|
498
|
+
|
499
|
+
it "should raise a NotFound exception" do
|
500
|
+
lambda {
|
501
|
+
SimpleGeo::Client.get_layer_information('io.path.testlayer')
|
502
|
+
}.should raise_exception(SimpleGeo::NotFound)
|
503
|
+
end
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
context "getting SpotRank information for a day, hour and location" do
|
508
|
+
before do
|
509
|
+
stub_request :get,
|
510
|
+
'http://api.simplegeo.com/0.1/density/sat/16/37.75965,-122.42608.json',
|
511
|
+
:fixture_file => 'get_density_by_hour.json'
|
512
|
+
end
|
513
|
+
|
514
|
+
it "should return a hash containing the density information" do
|
515
|
+
density_info = SimpleGeo::Client.get_density(37.75965, -122.42608, 'sat', '16' )
|
516
|
+
density_info.should == {
|
517
|
+
:city_rank => 10,
|
518
|
+
:local_rank => 8,
|
519
|
+
:trending_rank => 0,
|
520
|
+
:dayname => "sat",
|
521
|
+
:hour => 16,
|
522
|
+
:worldwide_rank => 8,
|
523
|
+
:geometry => {
|
524
|
+
:type => "Polygon",
|
525
|
+
:coordinates => [
|
526
|
+
[ 37.7587890625, -122.4267578125 ],
|
527
|
+
[ 37.759765625, -122.4267578125 ],
|
528
|
+
[ 37.759765625, -122.42578125 ],
|
529
|
+
[ 37.7587890625, -122.42578125 ],
|
530
|
+
[ 37.7587890625, -122.4267578125 ]
|
531
|
+
]
|
532
|
+
}
|
533
|
+
}
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
context "getting SpotRank information for a day and location" do
|
538
|
+
before do
|
539
|
+
stub_request :get,
|
540
|
+
'http://api.simplegeo.com/0.1/density/sat/37.75965,-122.42608.json',
|
541
|
+
:fixture_file => 'get_density_by_day.json'
|
542
|
+
end
|
543
|
+
|
544
|
+
it "should return an array of hashes containing the density information" do
|
545
|
+
density_info = SimpleGeo::Client.get_density(37.75965, -122.42608, 'sat')
|
546
|
+
density_info.should == [
|
547
|
+
{
|
548
|
+
:geometry => {
|
549
|
+
:type => "Polygon",
|
550
|
+
:coordinates => [
|
551
|
+
[ 37.7587890625, -122.4267578125 ],
|
552
|
+
[ 37.759765625, -122.4267578125 ],
|
553
|
+
[ 37.759765625, -122.42578125 ],
|
554
|
+
[ 37.7587890625, -122.42578125 ],
|
555
|
+
[ 37.7587890625, -122.4267578125 ]
|
556
|
+
]
|
557
|
+
},
|
558
|
+
:hour => 0,
|
559
|
+
:trending_rank => 2,
|
560
|
+
:local_rank => 4,
|
561
|
+
:city_rank => 10,
|
562
|
+
:worldwide_rank => 4,
|
563
|
+
:dayname => "sat"
|
564
|
+
},
|
565
|
+
{
|
566
|
+
:geometry => {
|
567
|
+
:type => "Polygon",
|
568
|
+
:coordinates => [
|
569
|
+
[ 37.7587890625, -122.4267578125 ],
|
570
|
+
[ 37.759765625, -122.4267578125 ],
|
571
|
+
[ 37.759765625, -122.42578125 ],
|
572
|
+
[ 37.7587890625, -122.42578125 ],
|
573
|
+
[ 37.7587890625, -122.4267578125 ]
|
574
|
+
]
|
575
|
+
},
|
576
|
+
:hour => 1,
|
577
|
+
:trending_rank => -2,
|
578
|
+
:local_rank => 6,
|
579
|
+
:city_rank => 10,
|
580
|
+
:worldwide_rank => 6,
|
581
|
+
:dayname => "sat"
|
582
|
+
},
|
583
|
+
{
|
584
|
+
:geometry => {
|
585
|
+
:type => "Polygon",
|
586
|
+
:coordinates => [
|
587
|
+
[ 37.7587890625, -122.4267578125 ],
|
588
|
+
[ 37.759765625, -122.4267578125 ],
|
589
|
+
[ 37.759765625, -122.42578125 ],
|
590
|
+
[ 37.7587890625, -122.42578125 ],
|
591
|
+
[ 37.7587890625, -122.4267578125 ]
|
592
|
+
]
|
593
|
+
},
|
594
|
+
:hour => 2,
|
595
|
+
:trending_rank => 2,
|
596
|
+
:local_rank => 2,
|
597
|
+
:city_rank => 10,
|
598
|
+
:worldwide_rank => 2,
|
599
|
+
:dayname => "sat"
|
600
|
+
},
|
601
|
+
{
|
602
|
+
:geometry => {
|
603
|
+
:type => "Polygon",
|
604
|
+
:coordinates => [
|
605
|
+
[ 37.7587890625, -122.4267578125 ],
|
606
|
+
[ 37.759765625, -122.4267578125 ],
|
607
|
+
[ 37.759765625, -122.42578125 ],
|
608
|
+
[ 37.7587890625, -122.42578125 ],
|
609
|
+
[ 37.7587890625, -122.4267578125 ]
|
610
|
+
]
|
611
|
+
},
|
612
|
+
:hour => 3,
|
613
|
+
:trending_rank => -2,
|
614
|
+
:local_rank => 6,
|
615
|
+
:city_rank => 10,
|
616
|
+
:worldwide_rank => 6,
|
617
|
+
:dayname => "sat"
|
618
|
+
},
|
619
|
+
{
|
620
|
+
:geometry => {
|
621
|
+
:type => "Polygon",
|
622
|
+
:coordinates => [
|
623
|
+
[ 37.7587890625, -122.4267578125 ],
|
624
|
+
[ 37.759765625, -122.4267578125 ],
|
625
|
+
[ 37.759765625, -122.42578125 ],
|
626
|
+
[ 37.7587890625, -122.42578125 ],
|
627
|
+
[ 37.7587890625, -122.4267578125 ]
|
628
|
+
]
|
629
|
+
},
|
630
|
+
:hour => 4,
|
631
|
+
:trending_rank => -2,
|
632
|
+
:local_rank => 4,
|
633
|
+
:city_rank => 10,
|
634
|
+
:worldwide_rank => 4,
|
635
|
+
:dayname => "sat"
|
636
|
+
},
|
637
|
+
{
|
638
|
+
:geometry => {
|
639
|
+
:type => "Polygon",
|
640
|
+
:coordinates => [
|
641
|
+
[ 37.7587890625, -122.4267578125 ],
|
642
|
+
[ 37.759765625, -122.4267578125 ],
|
643
|
+
[ 37.759765625, -122.42578125 ],
|
644
|
+
[ 37.7587890625, -122.42578125 ],
|
645
|
+
[ 37.7587890625, -122.4267578125 ]
|
646
|
+
]
|
647
|
+
},
|
648
|
+
:hour => 6,
|
649
|
+
:trending_rank => 2,
|
650
|
+
:local_rank => 2,
|
651
|
+
:city_rank => 10,
|
652
|
+
:worldwide_rank => 2,
|
653
|
+
:dayname => "sat"
|
654
|
+
},
|
655
|
+
{
|
656
|
+
:geometry => {
|
657
|
+
:type => "Polygon",
|
658
|
+
:coordinates => [
|
659
|
+
[ 37.7587890625, -122.4267578125 ],
|
660
|
+
[ 37.759765625, -122.4267578125 ],
|
661
|
+
[ 37.759765625, -122.42578125 ],
|
662
|
+
[ 37.7587890625, -122.42578125 ],
|
663
|
+
[ 37.7587890625, -122.4267578125 ]
|
664
|
+
]
|
665
|
+
},
|
666
|
+
:hour => 7,
|
667
|
+
:trending_rank => 1,
|
668
|
+
:local_rank => 5,
|
669
|
+
:city_rank => 10,
|
670
|
+
:worldwide_rank => 5,
|
671
|
+
:dayname => "sat"
|
672
|
+
},
|
673
|
+
{
|
674
|
+
:geometry => {
|
675
|
+
:type => "Polygon",
|
676
|
+
:coordinates => [
|
677
|
+
[ 37.7587890625, -122.4267578125 ],
|
678
|
+
[ 37.759765625, -122.4267578125 ],
|
679
|
+
[ 37.759765625, -122.42578125 ],
|
680
|
+
[ 37.7587890625, -122.42578125 ],
|
681
|
+
[ 37.7587890625, -122.4267578125 ]
|
682
|
+
]
|
683
|
+
},
|
684
|
+
:hour => 8,
|
685
|
+
:trending_rank => 0,
|
686
|
+
:local_rank => 6,
|
687
|
+
:city_rank => 10,
|
688
|
+
:worldwide_rank => 6,
|
689
|
+
:dayname => "sat"
|
690
|
+
},
|
691
|
+
{
|
692
|
+
:geometry => {
|
693
|
+
:type => "Polygon",
|
694
|
+
:coordinates => [
|
695
|
+
[ 37.7587890625, -122.4267578125 ],
|
696
|
+
[ 37.759765625, -122.4267578125 ],
|
697
|
+
[ 37.759765625, -122.42578125 ],
|
698
|
+
[ 37.7587890625, -122.42578125 ],
|
699
|
+
[ 37.7587890625, -122.4267578125 ]
|
700
|
+
]
|
701
|
+
},
|
702
|
+
:hour => 9,
|
703
|
+
:trending_rank => 0,
|
704
|
+
:local_rank => 6,
|
705
|
+
:city_rank => 10,
|
706
|
+
:worldwide_rank => 6,
|
707
|
+
:dayname => "sat"
|
708
|
+
},
|
709
|
+
{
|
710
|
+
:geometry => {
|
711
|
+
:type => "Polygon",
|
712
|
+
:coordinates => [
|
713
|
+
[ 37.7587890625, -122.4267578125 ],
|
714
|
+
[ 37.759765625, -122.4267578125 ],
|
715
|
+
[ 37.759765625, -122.42578125 ],
|
716
|
+
[ 37.7587890625, -122.42578125 ],
|
717
|
+
[ 37.7587890625, -122.4267578125 ]
|
718
|
+
]
|
719
|
+
},
|
720
|
+
:hour => 10,
|
721
|
+
:trending_rank => 2,
|
722
|
+
:local_rank => 6,
|
723
|
+
:city_rank => 10,
|
724
|
+
:worldwide_rank => 6,
|
725
|
+
:dayname => "sat"
|
726
|
+
},
|
727
|
+
{
|
728
|
+
:geometry => {
|
729
|
+
:type => "Polygon",
|
730
|
+
:coordinates => [
|
731
|
+
[ 37.7587890625, -122.4267578125 ],
|
732
|
+
[ 37.759765625, -122.4267578125 ],
|
733
|
+
[ 37.759765625, -122.42578125 ],
|
734
|
+
[ 37.7587890625, -122.42578125 ],
|
735
|
+
[ 37.7587890625, -122.4267578125 ]
|
736
|
+
]
|
737
|
+
},
|
738
|
+
:hour => 11,
|
739
|
+
:trending_rank => -1,
|
740
|
+
:local_rank => 8,
|
741
|
+
:city_rank => 10,
|
742
|
+
:worldwide_rank => 8,
|
743
|
+
:dayname => "sat"
|
744
|
+
},
|
745
|
+
{
|
746
|
+
:geometry => {
|
747
|
+
:type => "Polygon",
|
748
|
+
:coordinates => [
|
749
|
+
[ 37.7587890625, -122.4267578125 ],
|
750
|
+
[ 37.759765625, -122.4267578125 ],
|
751
|
+
[ 37.759765625, -122.42578125 ],
|
752
|
+
[ 37.7587890625, -122.42578125 ],
|
753
|
+
[ 37.7587890625, -122.4267578125 ]
|
754
|
+
]
|
755
|
+
},
|
756
|
+
:hour => 12,
|
757
|
+
:trending_rank => 1,
|
758
|
+
:local_rank => 7,
|
759
|
+
:city_rank => 10,
|
760
|
+
:worldwide_rank => 7,
|
761
|
+
:dayname => "sat"
|
762
|
+
},
|
763
|
+
{
|
764
|
+
:geometry => {
|
765
|
+
:type => "Polygon",
|
766
|
+
:coordinates => [
|
767
|
+
[ 37.7587890625, -122.4267578125 ],
|
768
|
+
[ 37.759765625, -122.4267578125 ],
|
769
|
+
[ 37.759765625, -122.42578125 ],
|
770
|
+
[ 37.7587890625, -122.42578125 ],
|
771
|
+
[ 37.7587890625, -122.4267578125 ]
|
772
|
+
]
|
773
|
+
},
|
774
|
+
:hour => 13,
|
775
|
+
:trending_rank => 0,
|
776
|
+
:local_rank => 8,
|
777
|
+
:city_rank => 10,
|
778
|
+
:worldwide_rank => 8,
|
779
|
+
:dayname => "sat"
|
780
|
+
},
|
781
|
+
{
|
782
|
+
:geometry => {
|
783
|
+
:type => "Polygon",
|
784
|
+
:coordinates => [
|
785
|
+
[ 37.7587890625, -122.4267578125 ],
|
786
|
+
[ 37.759765625, -122.4267578125 ],
|
787
|
+
[ 37.759765625, -122.42578125 ],
|
788
|
+
[ 37.7587890625, -122.42578125 ],
|
789
|
+
[ 37.7587890625, -122.4267578125 ]
|
790
|
+
]
|
791
|
+
},
|
792
|
+
:hour => 14,
|
793
|
+
:trending_rank => 0,
|
794
|
+
:local_rank => 8,
|
795
|
+
:city_rank => 10,
|
796
|
+
:worldwide_rank => 8,
|
797
|
+
:dayname => "sat"
|
798
|
+
},
|
799
|
+
{
|
800
|
+
:geometry => {
|
801
|
+
:type => "Polygon",
|
802
|
+
:coordinates => [
|
803
|
+
[ 37.7587890625, -122.4267578125 ],
|
804
|
+
[ 37.759765625, -122.4267578125 ],
|
805
|
+
[ 37.759765625, -122.42578125 ],
|
806
|
+
[ 37.7587890625, -122.42578125 ],
|
807
|
+
[ 37.7587890625, -122.4267578125 ]
|
808
|
+
]
|
809
|
+
},
|
810
|
+
:hour => 15,
|
811
|
+
:trending_rank => 0,
|
812
|
+
:local_rank => 8,
|
813
|
+
:city_rank => 10,
|
814
|
+
:worldwide_rank => 8,
|
815
|
+
:dayname => "sat"
|
816
|
+
},
|
817
|
+
{
|
818
|
+
:geometry => {
|
819
|
+
:type => "Polygon",
|
820
|
+
:coordinates => [
|
821
|
+
[ 37.7587890625, -122.4267578125 ],
|
822
|
+
[ 37.759765625, -122.4267578125 ],
|
823
|
+
[ 37.759765625, -122.42578125 ],
|
824
|
+
[ 37.7587890625, -122.42578125 ],
|
825
|
+
[ 37.7587890625, -122.4267578125 ]
|
826
|
+
]
|
827
|
+
},
|
828
|
+
:hour => 16,
|
829
|
+
:trending_rank => 0,
|
830
|
+
:local_rank => 8,
|
831
|
+
:city_rank => 10,
|
832
|
+
:worldwide_rank => 8,
|
833
|
+
:dayname => "sat"
|
834
|
+
},
|
835
|
+
{
|
836
|
+
:geometry => {
|
837
|
+
:type => "Polygon",
|
838
|
+
:coordinates => [
|
839
|
+
[ 37.7587890625, -122.4267578125 ],
|
840
|
+
[ 37.759765625, -122.4267578125 ],
|
841
|
+
[ 37.759765625, -122.42578125 ],
|
842
|
+
[ 37.7587890625, -122.42578125 ],
|
843
|
+
[ 37.7587890625, -122.4267578125 ]
|
844
|
+
]
|
845
|
+
},
|
846
|
+
:hour => 17,
|
847
|
+
:trending_rank => 0,
|
848
|
+
:local_rank => 8,
|
849
|
+
:city_rank => 10,
|
850
|
+
:worldwide_rank => 8,
|
851
|
+
:dayname => "sat"
|
852
|
+
},
|
853
|
+
{
|
854
|
+
:geometry => {
|
855
|
+
:type => "Polygon",
|
856
|
+
:coordinates => [
|
857
|
+
[ 37.7587890625, -122.4267578125 ],
|
858
|
+
[ 37.759765625, -122.4267578125 ],
|
859
|
+
[ 37.759765625, -122.42578125 ],
|
860
|
+
[ 37.7587890625, -122.42578125 ],
|
861
|
+
[ 37.7587890625, -122.4267578125 ]
|
862
|
+
]
|
863
|
+
},
|
864
|
+
:hour => 18,
|
865
|
+
:trending_rank => 0,
|
866
|
+
:local_rank => 8,
|
867
|
+
:city_rank => 10,
|
868
|
+
:worldwide_rank => 8,
|
869
|
+
:dayname => "sat"
|
870
|
+
},
|
871
|
+
{
|
872
|
+
:geometry => {
|
873
|
+
:type => "Polygon",
|
874
|
+
:coordinates => [
|
875
|
+
[ 37.7587890625, -122.4267578125 ],
|
876
|
+
[ 37.759765625, -122.4267578125 ],
|
877
|
+
[ 37.759765625, -122.42578125 ],
|
878
|
+
[ 37.7587890625, -122.42578125 ],
|
879
|
+
[ 37.7587890625, -122.4267578125 ]
|
880
|
+
]
|
881
|
+
},
|
882
|
+
:hour => 19,
|
883
|
+
:trending_rank => 0,
|
884
|
+
:local_rank => 8,
|
885
|
+
:city_rank => 10,
|
886
|
+
:worldwide_rank => 8,
|
887
|
+
:dayname => "sat"
|
888
|
+
},
|
889
|
+
{
|
890
|
+
:geometry => {
|
891
|
+
:type => "Polygon",
|
892
|
+
:coordinates => [
|
893
|
+
[ 37.7587890625, -122.4267578125 ],
|
894
|
+
[ 37.759765625, -122.4267578125 ],
|
895
|
+
[ 37.759765625, -122.42578125 ],
|
896
|
+
[ 37.7587890625, -122.42578125 ],
|
897
|
+
[ 37.7587890625, -122.4267578125 ]
|
898
|
+
]
|
899
|
+
},
|
900
|
+
:hour => 20,
|
901
|
+
:trending_rank => 0,
|
902
|
+
:local_rank => 8,
|
903
|
+
:city_rank => 10,
|
904
|
+
:worldwide_rank => 8,
|
905
|
+
:dayname => "sat"
|
906
|
+
},
|
907
|
+
{
|
908
|
+
:geometry => {
|
909
|
+
:type => "Polygon",
|
910
|
+
:coordinates => [
|
911
|
+
[ 37.7587890625, -122.4267578125 ],
|
912
|
+
[ 37.759765625, -122.4267578125 ],
|
913
|
+
[ 37.759765625, -122.42578125 ],
|
914
|
+
[ 37.7587890625, -122.42578125 ],
|
915
|
+
[ 37.7587890625, -122.4267578125 ]
|
916
|
+
]
|
917
|
+
},
|
918
|
+
:hour => 21,
|
919
|
+
:trending_rank => -2,
|
920
|
+
:local_rank => 8,
|
921
|
+
:city_rank => 10,
|
922
|
+
:worldwide_rank => 8,
|
923
|
+
:dayname => "sat"
|
924
|
+
},
|
925
|
+
{
|
926
|
+
:geometry => {
|
927
|
+
:type => "Polygon",
|
928
|
+
:coordinates => [
|
929
|
+
[ 37.7587890625, -122.4267578125 ],
|
930
|
+
[ 37.759765625, -122.4267578125 ],
|
931
|
+
[ 37.759765625, -122.42578125 ],
|
932
|
+
[ 37.7587890625, -122.42578125 ],
|
933
|
+
[ 37.7587890625, -122.4267578125 ]
|
934
|
+
]
|
935
|
+
},
|
936
|
+
:hour => 22,
|
937
|
+
:trending_rank => 0,
|
938
|
+
:local_rank => 5,
|
939
|
+
:city_rank => 10,
|
940
|
+
:worldwide_rank => 6,
|
941
|
+
:dayname => "sat"
|
942
|
+
},
|
943
|
+
{
|
944
|
+
:geometry => {
|
945
|
+
:type => "Polygon",
|
946
|
+
:coordinates => [
|
947
|
+
[ 37.7587890625, -122.4267578125 ],
|
948
|
+
[ 37.759765625, -122.4267578125 ],
|
949
|
+
[ 37.759765625, -122.42578125 ],
|
950
|
+
[ 37.7587890625, -122.42578125 ],
|
951
|
+
[ 37.7587890625, -122.4267578125 ]
|
952
|
+
]
|
953
|
+
},
|
954
|
+
:hour => 23,
|
955
|
+
:trending_rank => 1,
|
956
|
+
:local_rank => 5,
|
957
|
+
:city_rank => 10,
|
958
|
+
:worldwide_rank => 5,
|
959
|
+
:dayname => "sat"
|
960
|
+
}
|
961
|
+
]
|
962
|
+
end
|
963
|
+
end
|
964
|
+
|
965
|
+
context "getting contains info for a set of coordinates" do
|
966
|
+
before do
|
967
|
+
stub_request :get,
|
968
|
+
'http://api.simplegeo.com/0.1/contains/37.7587890625,-122.4267578125.json',
|
969
|
+
:fixture_file => 'contains.json'
|
970
|
+
end
|
971
|
+
|
972
|
+
it "should return a hash with the correct info" do
|
973
|
+
info = SimpleGeo::Client.get_contains(37.7587890625, -122.4267578125)
|
974
|
+
info.should == [
|
975
|
+
{
|
976
|
+
:bounds =>
|
977
|
+
[
|
978
|
+
-122.435188,
|
979
|
+
37.756093,
|
980
|
+
-122.42555,
|
981
|
+
37.763030999999998
|
982
|
+
],
|
983
|
+
:type => "Census Tract",
|
984
|
+
:id => "Census_Tract:06075020600:9q8yy1",
|
985
|
+
:abbr => "",
|
986
|
+
:name => "06075020600"
|
987
|
+
},
|
988
|
+
{
|
989
|
+
:bounds =>
|
990
|
+
[
|
991
|
+
-123.17382499999999,
|
992
|
+
37.639829999999996,
|
993
|
+
-122.28178,
|
994
|
+
37.929823999999996
|
995
|
+
],
|
996
|
+
:type => "County",
|
997
|
+
:id => "County:San_Francisco:9q8yvv",
|
998
|
+
:abbr => "",
|
999
|
+
:name => "San Francisco"
|
1000
|
+
},
|
1001
|
+
{
|
1002
|
+
:bounds =>
|
1003
|
+
[
|
1004
|
+
-123.17382499999999,
|
1005
|
+
37.639829999999996,
|
1006
|
+
-122.28178,
|
1007
|
+
37.929823999999996
|
1008
|
+
],
|
1009
|
+
:type => "City",
|
1010
|
+
:id => "City:San_Francisco:9q8yvv",
|
1011
|
+
:abbr => "",
|
1012
|
+
:name => "San Francisco"
|
1013
|
+
},
|
1014
|
+
{
|
1015
|
+
:bounds =>
|
1016
|
+
[
|
1017
|
+
-122.612285,
|
1018
|
+
37.708131000000002,
|
1019
|
+
-122.28178,
|
1020
|
+
37.929823999999996
|
1021
|
+
],
|
1022
|
+
:type => "Congressional District",
|
1023
|
+
:id => "Congressional_District:Congressional_Di:9q8yyn",
|
1024
|
+
:abbr => "",
|
1025
|
+
:name => "Congressional District 8"
|
1026
|
+
},
|
1027
|
+
{
|
1028
|
+
:bounds =>
|
1029
|
+
[
|
1030
|
+
-179.14247147726383,
|
1031
|
+
18.930137634111077,
|
1032
|
+
179.78114994357418,
|
1033
|
+
71.412179667308919
|
1034
|
+
],
|
1035
|
+
:type => "Country",
|
1036
|
+
:id => "Country:United_States_of:9z12zg",
|
1037
|
+
:abbr => "",
|
1038
|
+
:name => "United States of America"
|
1039
|
+
},
|
1040
|
+
{
|
1041
|
+
:bounds =>
|
1042
|
+
[
|
1043
|
+
-122.428882,
|
1044
|
+
37.758029999999998,
|
1045
|
+
-122.42138199999999,
|
1046
|
+
37.772263000000002
|
1047
|
+
],
|
1048
|
+
:type => "Neighborhood",
|
1049
|
+
:id => "Neighborhood:Mission_Dolores:9q8yy4",
|
1050
|
+
:abbr => "",
|
1051
|
+
:name => "Mission Dolores"
|
1052
|
+
},
|
1053
|
+
{
|
1054
|
+
:bounds =>
|
1055
|
+
[
|
1056
|
+
-122.51666666668193,
|
1057
|
+
37.191666666628507,
|
1058
|
+
-121.73333333334497,
|
1059
|
+
38.041666666640907
|
1060
|
+
],
|
1061
|
+
:type => "Urban Area",
|
1062
|
+
:id => "Urban_Area:San_Francisco1:9q9jsg",
|
1063
|
+
:abbr => "",
|
1064
|
+
:name => "San Francisco1"
|
1065
|
+
},
|
1066
|
+
{
|
1067
|
+
:bounds =>
|
1068
|
+
[
|
1069
|
+
-122.451553,
|
1070
|
+
37.746687000000001,
|
1071
|
+
-122.424773,
|
1072
|
+
37.770451999999999
|
1073
|
+
],
|
1074
|
+
:type => "Postal",
|
1075
|
+
:id => "Postal:94114:9q8yvc",
|
1076
|
+
:abbr => "",
|
1077
|
+
:name => "94114"
|
1078
|
+
},
|
1079
|
+
{
|
1080
|
+
:bounds =>
|
1081
|
+
[
|
1082
|
+
-124.48200299999999,
|
1083
|
+
32.528832000000001,
|
1084
|
+
-114.13121099999999,
|
1085
|
+
42.009516999999995
|
1086
|
+
],
|
1087
|
+
:type => "Province",
|
1088
|
+
:id => "Province:CA:9qdguu",
|
1089
|
+
:abbr => "CA",
|
1090
|
+
:name => "California"
|
1091
|
+
}
|
1092
|
+
]
|
1093
|
+
end
|
1094
|
+
end
|
1095
|
+
|
1096
|
+
context "getting overlaps info for a set of coordinates" do
|
1097
|
+
before do
|
1098
|
+
stub_request :get,
|
1099
|
+
'http://api.simplegeo.com/0.1/overlaps/32.528832,-124.482003,42.009517,-114.131211.json',
|
1100
|
+
:fixture_file => 'overlaps.json'
|
1101
|
+
end
|
1102
|
+
|
1103
|
+
it "should return a hash with the correct info" do
|
1104
|
+
info = SimpleGeo::Client.get_overlaps(32.528832000000001, -124.48200299999999,
|
1105
|
+
42.009516999999995, -114.13121099999999)
|
1106
|
+
info.should == [
|
1107
|
+
{
|
1108
|
+
:bounds =>
|
1109
|
+
[
|
1110
|
+
-122.998802,
|
1111
|
+
42.002634,
|
1112
|
+
-122.597843,
|
1113
|
+
42.266379000000001
|
1114
|
+
],
|
1115
|
+
:type => "Census Tract",
|
1116
|
+
:id => "Census_Tract:41029002300:9r2xt4",
|
1117
|
+
:abbr => "",
|
1118
|
+
:name => "41029002300"
|
1119
|
+
},
|
1120
|
+
{
|
1121
|
+
:bounds =>
|
1122
|
+
[
|
1123
|
+
-123.858086,
|
1124
|
+
41.995095999999997,
|
1125
|
+
-123.22998200000001,
|
1126
|
+
42.272435999999999
|
1127
|
+
],
|
1128
|
+
:type => "Census Tract",
|
1129
|
+
:id => "Census_Tract:41033361600:9r2psc",
|
1130
|
+
:abbr => "",
|
1131
|
+
:name => "41033361600"
|
1132
|
+
},
|
1133
|
+
{
|
1134
|
+
:bounds =>
|
1135
|
+
[
|
1136
|
+
-123.231629,
|
1137
|
+
42.003022000000001,
|
1138
|
+
-122.907515,
|
1139
|
+
42.433349
|
1140
|
+
],
|
1141
|
+
:type => "Census Tract",
|
1142
|
+
:id => "Census_Tract:41029003002:9r2ryf",
|
1143
|
+
:abbr => "",
|
1144
|
+
:name => "41029003002"
|
1145
|
+
}
|
1146
|
+
]
|
1147
|
+
end
|
1148
|
+
end
|
1149
|
+
|
1150
|
+
# this API call seems to always return a 404
|
1151
|
+
# context "getting boundary info by id" do
|
1152
|
+
# before do
|
1153
|
+
# stub_request :get,
|
1154
|
+
# 'http://api.simplegeo.com/0.1/boundary/Neighborhood:Mission_Dolores:9q8yy4.json',
|
1155
|
+
# :fixture_file => 'boundary.json'
|
1156
|
+
# end
|
1157
|
+
#
|
1158
|
+
# it "should return a hash with the correct info" do
|
1159
|
+
# info = SimpleGeo::Client.get_boundary("Neighborhood:Mission_Dolores:9q8yy4")
|
1160
|
+
# info.should == [
|
1161
|
+
#
|
1162
|
+
# ]
|
1163
|
+
# end
|
1164
|
+
# end
|
1165
|
+
end
|