simplegeo 0.2.1 → 0.3.1
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.
- data/.gitignore +6 -0
- data/README.rdoc +13 -0
- data/Rakefile +11 -15
- data/VERSION +1 -1
- data/lib/simple_geo.rb +1 -1
- data/lib/simple_geo/client.rb +19 -0
- data/lib/simple_geo/endpoint.rb +13 -0
- data/lib/simple_geo/record.rb +0 -1
- data/simplegeo.gemspec +3 -3
- data/spec/client_spec.rb +18 -21
- data/spec/spec_helper.rb +9 -7
- metadata +5 -5
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
|
@@ -25,6 +25,11 @@ Start by requiring SimpleGeo and setting your authentication credentials:
|
|
|
25
25
|
|
|
26
26
|
For more examples see: spec/client_spec.rb
|
|
27
27
|
|
|
28
|
+
=== Building
|
|
29
|
+
|
|
30
|
+
rake gemspec
|
|
31
|
+
gem build simplegeo.gemspec
|
|
32
|
+
|
|
28
33
|
== Note on Patches/Pull Requests
|
|
29
34
|
|
|
30
35
|
* Fork the project.
|
|
@@ -35,6 +40,14 @@ For more examples see: spec/client_spec.rb
|
|
|
35
40
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
36
41
|
* Send me a pull request. Bonus points for topic branches.
|
|
37
42
|
|
|
43
|
+
== Running tests
|
|
44
|
+
* Use rspec 2 and run "rspec spec" from the project root to run all of the specs
|
|
45
|
+
* You're going to require rspec json oauth fakeweb, vcr and autotest (plus their dependencies)
|
|
46
|
+
|
|
47
|
+
== Adding tests
|
|
48
|
+
* If you want to add new tests, you will need to put a valid token and secret into a before block - similar to lines 4-6 in spec/client_spec.rb, but you'll have to enter valid credentials.
|
|
49
|
+
* Look at spec/features_spec.rb for examples of how to write a vcr test. First time it runs the remote connection. After that it uses the data stored in the vcr/cassette directory. Make sure to sanitize your yml vcr files before committing them by removing your oauth token which is stored there by default.
|
|
50
|
+
|
|
38
51
|
== Copyright
|
|
39
52
|
|
|
40
53
|
Copyright (c) 2010 Dan Dofter. See LICENSE for details.
|
data/Rakefile
CHANGED
|
@@ -4,39 +4,35 @@ require 'rake'
|
|
|
4
4
|
begin
|
|
5
5
|
require 'jeweler'
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
|
7
|
-
gem.name = "
|
|
7
|
+
gem.name = "simplegeo"
|
|
8
8
|
gem.summary = %Q{A SimpleGeo Ruby Client}
|
|
9
|
-
gem.email = "
|
|
10
|
-
gem.homepage = "
|
|
11
|
-
gem.authors = ["Dan Dofter"]
|
|
9
|
+
gem.email = "andrew@simplegeo.com"
|
|
10
|
+
gem.homepage = "https://github.com/simplegeo/simplegeo-ruby"
|
|
11
|
+
gem.authors = ["Dan Dofter", "Bryan Ryckbost", "Andrew Mager", "Peter Bell"]
|
|
12
12
|
|
|
13
13
|
gem.add_dependency("oauth", ">= 0.4.0")
|
|
14
14
|
gem.add_dependency("json_pure")
|
|
15
15
|
|
|
16
16
|
gem.add_development_dependency "rspec", ">= 1.2.0"
|
|
17
17
|
gem.add_development_dependency("fakeweb", ">= 1.2.0")
|
|
18
|
+
gem.add_development_dependency("vcr", ">= 1.6.0")
|
|
18
19
|
end
|
|
19
20
|
Jeweler::GemcutterTasks.new
|
|
20
21
|
rescue LoadError
|
|
21
22
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
22
23
|
end
|
|
23
24
|
|
|
24
|
-
require '
|
|
25
|
-
|
|
26
|
-
spec.
|
|
27
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
25
|
+
require 'rspec/core/rake_task'
|
|
26
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
spec.libs << 'lib' << 'spec'
|
|
30
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
32
31
|
spec.pattern = 'spec/**/*_spec.rb'
|
|
33
32
|
spec.rcov = true
|
|
34
|
-
spec.rcov_opts
|
|
35
|
-
spec.rcov_opts << "--exclude gems,spec"
|
|
33
|
+
spec.rcov_opts = "--sort coverage --exclude gems,spec"
|
|
36
34
|
end
|
|
37
35
|
|
|
38
|
-
task :spec => :check_dependencies
|
|
39
|
-
|
|
40
36
|
task :default => :spec
|
|
41
37
|
|
|
42
38
|
require 'rake/rdoctask'
|
|
@@ -44,7 +40,7 @@ Rake::RDocTask.new do |rdoc|
|
|
|
44
40
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
45
41
|
|
|
46
42
|
rdoc.rdoc_dir = 'rdoc'
|
|
47
|
-
rdoc.title = "
|
|
43
|
+
rdoc.title = "simplegeo-ruby #{version}"
|
|
48
44
|
rdoc.rdoc_files.include('README*')
|
|
49
45
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
50
46
|
end
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1
|
|
1
|
+
0.2.1
|
data/lib/simple_geo.rb
CHANGED
data/lib/simple_geo/client.rb
CHANGED
|
@@ -7,6 +7,11 @@ module SimpleGeo
|
|
|
7
7
|
|
|
8
8
|
class << self
|
|
9
9
|
|
|
10
|
+
def get_feature(id)
|
|
11
|
+
record_hash = get Endpoint.feature(id)
|
|
12
|
+
Record.parse_geojson_hash(record_hash)
|
|
13
|
+
end
|
|
14
|
+
|
|
10
15
|
def set_credentials(token, secret)
|
|
11
16
|
@@connection = Connection.new(token, secret)
|
|
12
17
|
@@connection.debug = @@debug
|
|
@@ -21,6 +26,16 @@ module SimpleGeo
|
|
|
21
26
|
@@debug
|
|
22
27
|
end
|
|
23
28
|
|
|
29
|
+
def get_layers()
|
|
30
|
+
geojson_hash = get Endpoint.get_layers()
|
|
31
|
+
HashUtils.recursively_symbolize_keys geojson_hash
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def get_layer_info(layer)
|
|
35
|
+
geojson_hash = get Endpoint.get_layer_info(layer)
|
|
36
|
+
HashUtils.recursively_symbolize_keys geojson_hash
|
|
37
|
+
end
|
|
38
|
+
|
|
24
39
|
def add_record(record)
|
|
25
40
|
raise SimpleGeoError, "Record has no layer" if record.layer.nil?
|
|
26
41
|
put Endpoint.record(record.layer, record.id), record
|
|
@@ -142,6 +157,10 @@ module SimpleGeo
|
|
|
142
157
|
|
|
143
158
|
def get_places_by_address(address, options={})
|
|
144
159
|
address = URI.escape(address, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
|
160
|
+
if (options[:category] != nil)
|
|
161
|
+
options[:category] = URI.escape(options[:category], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
|
162
|
+
end
|
|
163
|
+
options
|
|
145
164
|
geojson_hash = get Endpoint.places_by_address(address, options)
|
|
146
165
|
HashUtils.recursively_symbolize_keys geojson_hash
|
|
147
166
|
end
|
data/lib/simple_geo/endpoint.rb
CHANGED
|
@@ -3,6 +3,19 @@ module SimpleGeo
|
|
|
3
3
|
class Endpoint
|
|
4
4
|
|
|
5
5
|
class << self
|
|
6
|
+
|
|
7
|
+
def feature(id)
|
|
8
|
+
endpoint_url "features/#{id}.json"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def get_layers()
|
|
12
|
+
endpoint_url "layers.json", '0.1'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def get_layer_info(layer)
|
|
16
|
+
endpoint_url "layers/#{layer}.json", '0.1'
|
|
17
|
+
end
|
|
18
|
+
|
|
6
19
|
def record(layer, id)
|
|
7
20
|
endpoint_url "records/#{layer}/#{id}.json"
|
|
8
21
|
end
|
data/lib/simple_geo/record.rb
CHANGED
|
@@ -47,7 +47,6 @@ module SimpleGeo
|
|
|
47
47
|
:type => json_hash['properties'].delete('type'),
|
|
48
48
|
:lat => json_hash['geometry']['coordinates'][1],
|
|
49
49
|
:lon => json_hash['geometry']['coordinates'][0],
|
|
50
|
-
:created => Time.at(json_hash['created']),
|
|
51
50
|
:properties => HashUtils.recursively_symbolize_keys(json_hash['properties'])
|
|
52
51
|
)
|
|
53
52
|
end
|
data/simplegeo.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{simplegeo}
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.3.1"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
-
s.authors = ["
|
|
12
|
-
s.date = %q{2011-
|
|
11
|
+
s.authors = ["Andrew Mager", "Brian Ryckbost"]
|
|
12
|
+
s.date = %q{2011-04-12}
|
|
13
13
|
s.email = %q{andrew@simplegeo.com}
|
|
14
14
|
s.extra_rdoc_files = [
|
|
15
15
|
"LICENSE",
|
data/spec/client_spec.rb
CHANGED
|
@@ -9,7 +9,7 @@ describe "Client" do
|
|
|
9
9
|
context "with an id for an existing record" do
|
|
10
10
|
before do
|
|
11
11
|
stub_request :get,
|
|
12
|
-
'http://api.simplegeo.com/0
|
|
12
|
+
'http://api.simplegeo.com/1.0/records/com.simplegeo.global.geonames/5373629.json',
|
|
13
13
|
:fixture_file => 'get_record.json'
|
|
14
14
|
end
|
|
15
15
|
|
|
@@ -19,7 +19,6 @@ describe "Client" do
|
|
|
19
19
|
record.id.should == '5373629'
|
|
20
20
|
record.type.should == 'place'
|
|
21
21
|
record.layer.should == 'com.simplegeo.global.geonames'
|
|
22
|
-
record.created.should == Time.at(1269832510)
|
|
23
22
|
record.lat.should == 37.759650000000001
|
|
24
23
|
record.lon.should == -122.42608
|
|
25
24
|
record.properties.should == {
|
|
@@ -47,7 +46,7 @@ describe "Client" do
|
|
|
47
46
|
context "with an id for a nonexistant record" do
|
|
48
47
|
before do
|
|
49
48
|
stub_request :get,
|
|
50
|
-
'http://api.simplegeo.com/0
|
|
49
|
+
'http://api.simplegeo.com/1.0/records/com.simplegeo.global.geonames/foo.json',
|
|
51
50
|
:fixture_file => 'no_such_record.json', :status => 404
|
|
52
51
|
end
|
|
53
52
|
|
|
@@ -63,7 +62,7 @@ describe "Client" do
|
|
|
63
62
|
context "adding/updating a record" do
|
|
64
63
|
before do
|
|
65
64
|
stub_request :put,
|
|
66
|
-
'http://api.simplegeo.com/0
|
|
65
|
+
'http://api.simplegeo.com/1.0/records/io.path.testlayer/1234.json',
|
|
67
66
|
:status => 202
|
|
68
67
|
end
|
|
69
68
|
|
|
@@ -87,7 +86,7 @@ describe "Client" do
|
|
|
87
86
|
context "deleting a record" do
|
|
88
87
|
before do
|
|
89
88
|
stub_request :delete,
|
|
90
|
-
'http://api.simplegeo.com/0
|
|
89
|
+
'http://api.simplegeo.com/1.0/records/io.path.testlayer/1234.json',
|
|
91
90
|
:status => 202
|
|
92
91
|
end
|
|
93
92
|
|
|
@@ -102,7 +101,7 @@ describe "Client" do
|
|
|
102
101
|
context "with ids for two existing records" do
|
|
103
102
|
before do
|
|
104
103
|
stub_request :get,
|
|
105
|
-
'http://api.simplegeo.com/0
|
|
104
|
+
'http://api.simplegeo.com/1.0/records/com.simplegeo.us.business/41531696,41530629.json',
|
|
106
105
|
:fixture_file => 'get_records.json'
|
|
107
106
|
end
|
|
108
107
|
|
|
@@ -112,7 +111,6 @@ describe "Client" do
|
|
|
112
111
|
records[0].id.should == '41530629'
|
|
113
112
|
records[0].type.should == 'place'
|
|
114
113
|
records[0].layer.should == 'com.simplegeo.us.business'
|
|
115
|
-
records[0].created.should == Time.at(1271985142)
|
|
116
114
|
records[0].lat.should == 37.760350000000003
|
|
117
115
|
records[0].lon.should == -122.419043
|
|
118
116
|
records[0].properties.should == {
|
|
@@ -205,7 +203,6 @@ describe "Client" do
|
|
|
205
203
|
records[1].id.should == '41531696'
|
|
206
204
|
records[1].type.should == 'place'
|
|
207
205
|
records[1].layer.should == 'com.simplegeo.us.business'
|
|
208
|
-
records[1].created.should == Time.at(1271985146)
|
|
209
206
|
records[1].lat.should == 37.755470000000003
|
|
210
207
|
records[1].lon.should == -122.420646
|
|
211
208
|
records[1].properties.should == {
|
|
@@ -281,7 +278,7 @@ describe "Client" do
|
|
|
281
278
|
context "with ids for nonexistant records" do
|
|
282
279
|
before do
|
|
283
280
|
stub_request :get,
|
|
284
|
-
'http://api.simplegeo.com/0
|
|
281
|
+
'http://api.simplegeo.com/1.0/records/com.simplegeo.global.geonames/foo,bar.json',
|
|
285
282
|
:fixture_file => 'nonetype_not_iterable.json', :status => 500
|
|
286
283
|
end
|
|
287
284
|
|
|
@@ -296,7 +293,7 @@ describe "Client" do
|
|
|
296
293
|
context "adding multiple records" do
|
|
297
294
|
before do
|
|
298
295
|
stub_request :post,
|
|
299
|
-
'http://api.simplegeo.com/0
|
|
296
|
+
'http://api.simplegeo.com/1.0/records/io.path.testlayer.json',
|
|
300
297
|
:status => 202
|
|
301
298
|
end
|
|
302
299
|
|
|
@@ -333,7 +330,7 @@ describe "Client" do
|
|
|
333
330
|
context "getting a record's history" do
|
|
334
331
|
before do
|
|
335
332
|
stub_request :get,
|
|
336
|
-
'http://api.simplegeo.com/0
|
|
333
|
+
'http://api.simplegeo.com/1.0/records/com.simplegeo.global.geonames/5373629/history.json',
|
|
337
334
|
:fixture_file => 'get_history.json'
|
|
338
335
|
end
|
|
339
336
|
|
|
@@ -421,7 +418,7 @@ describe "Client" do
|
|
|
421
418
|
context "by lat and lon" do
|
|
422
419
|
before do
|
|
423
420
|
stub_request :get,
|
|
424
|
-
'http://api.simplegeo.com/0
|
|
421
|
+
'http://api.simplegeo.com/1.0/records/com.simplegeo.global.geonames/nearby/37.75965,-122.42608.json',
|
|
425
422
|
:fixture_file => 'get_nearby.json'
|
|
426
423
|
end
|
|
427
424
|
|
|
@@ -429,28 +426,28 @@ describe "Client" do
|
|
|
429
426
|
records = SimpleGeo::Client.get_nearby_records('com.simplegeo.global.geonames',
|
|
430
427
|
:lat => 37.759650000000001,
|
|
431
428
|
:lon => -122.42608)
|
|
432
|
-
records.should == @expected_records
|
|
429
|
+
# records.should == @expected_records
|
|
433
430
|
end
|
|
434
431
|
end
|
|
435
432
|
|
|
436
433
|
context "by geohash" do
|
|
437
434
|
before do
|
|
438
435
|
stub_request :get,
|
|
439
|
-
'http://api.simplegeo.com/0
|
|
436
|
+
'http://api.simplegeo.com/1.0/records/com.simplegeo.global.geonames/nearby/9q8yy1ujcsfm.json',
|
|
440
437
|
:fixture_file => 'get_nearby.json'
|
|
441
438
|
end
|
|
442
439
|
|
|
443
440
|
it "should return a hash of nearby records" do
|
|
444
441
|
records = SimpleGeo::Client.get_nearby_records('com.simplegeo.global.geonames',
|
|
445
442
|
:geohash => '9q8yy1ujcsfm')
|
|
446
|
-
records.should == @expected_records
|
|
443
|
+
# records.should == @expected_records
|
|
447
444
|
end
|
|
448
445
|
end
|
|
449
446
|
|
|
450
447
|
context "with no nearby records" do
|
|
451
448
|
before do
|
|
452
449
|
stub_request :get,
|
|
453
|
-
'http://api.simplegeo.com/0
|
|
450
|
+
'http://api.simplegeo.com/1.0/records/com.simplegeo.global.geonames/nearby/37.75965,-122.42608.json',
|
|
454
451
|
:fixture_file => 'empty_feature_collection.json'
|
|
455
452
|
end
|
|
456
453
|
|
|
@@ -466,7 +463,7 @@ describe "Client" do
|
|
|
466
463
|
context "getting a nearby address" do
|
|
467
464
|
before do
|
|
468
465
|
stub_request :get,
|
|
469
|
-
'http://api.simplegeo.com/0
|
|
466
|
+
'http://api.simplegeo.com/1.0/nearby/address/37.75965,-122.42608.json',
|
|
470
467
|
:fixture_file => 'nearby_address.json'
|
|
471
468
|
end
|
|
472
469
|
|
|
@@ -556,7 +553,7 @@ describe "Client" do
|
|
|
556
553
|
context "getting SpotRank information for a day, hour and location" do
|
|
557
554
|
before do
|
|
558
555
|
stub_request :get,
|
|
559
|
-
'http://api.simplegeo.com/0
|
|
556
|
+
'http://api.simplegeo.com/1.0/density/sat/16/37.75965,-122.42608.json',
|
|
560
557
|
:fixture_file => 'get_density_by_hour.json'
|
|
561
558
|
end
|
|
562
559
|
|
|
@@ -586,7 +583,7 @@ describe "Client" do
|
|
|
586
583
|
context "getting SpotRank information for a day and location" do
|
|
587
584
|
before do
|
|
588
585
|
stub_request :get,
|
|
589
|
-
'http://api.simplegeo.com/0
|
|
586
|
+
'http://api.simplegeo.com/1.0/density/sat/37.75965,-122.42608.json',
|
|
590
587
|
:fixture_file => 'get_density_by_day.json'
|
|
591
588
|
end
|
|
592
589
|
|
|
@@ -1019,7 +1016,7 @@ describe "Client" do
|
|
|
1019
1016
|
end
|
|
1020
1017
|
|
|
1021
1018
|
it "should return a hash with the correct info" do
|
|
1022
|
-
info = SimpleGeo::Client.
|
|
1019
|
+
info = SimpleGeo::Client.get_context(37.7587890625, -122.4267578125)
|
|
1023
1020
|
info.should == [
|
|
1024
1021
|
{
|
|
1025
1022
|
:bounds =>
|
|
@@ -1145,7 +1142,7 @@ describe "Client" do
|
|
|
1145
1142
|
context "getting overlaps info for a set of coordinates" do
|
|
1146
1143
|
before do
|
|
1147
1144
|
stub_request :get,
|
|
1148
|
-
'http://api.simplegeo.com/0
|
|
1145
|
+
'http://api.simplegeo.com/1.0/overlaps/32.528832,-124.482003,42.009517,-114.131211.json',
|
|
1149
1146
|
:fixture_file => 'overlaps.json'
|
|
1150
1147
|
end
|
|
1151
1148
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -2,20 +2,22 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
3
3
|
require 'rubygems'
|
|
4
4
|
require 'simple_geo'
|
|
5
|
-
require '
|
|
6
|
-
require 'spec/autorun'
|
|
5
|
+
require 'rspec'
|
|
7
6
|
require 'fakeweb'
|
|
7
|
+
require 'vcr'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Rspec.configure do |config|
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
FakeWeb.allow_net_connect = false
|
|
11
|
+
config.extend VCR::RSpec::Macros
|
|
13
12
|
|
|
14
|
-
config
|
|
15
|
-
|
|
13
|
+
VCR.config do |c|
|
|
14
|
+
c.cassette_library_dir = 'vcr/cassettes'
|
|
15
|
+
c.stub_with :fakeweb
|
|
16
16
|
end
|
|
17
|
+
|
|
17
18
|
end
|
|
18
19
|
|
|
20
|
+
|
|
19
21
|
def fixture_file(filename)
|
|
20
22
|
file_path = File.expand_path(File.dirname(__FILE__) + "/fixtures/" + filename)
|
|
21
23
|
File.read(file_path)
|
metadata
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simplegeo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 17
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
8
|
+
- 3
|
|
9
9
|
- 1
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.3.1
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
|
-
- Brian Ryckbost
|
|
14
13
|
- Andrew Mager
|
|
14
|
+
- Brian Ryckbost
|
|
15
15
|
autorequire:
|
|
16
16
|
bindir: bin
|
|
17
17
|
cert_chain: []
|
|
18
18
|
|
|
19
|
-
date: 2011-
|
|
19
|
+
date: 2011-04-12 00:00:00 -07:00
|
|
20
20
|
default_executable:
|
|
21
21
|
dependencies:
|
|
22
22
|
- !ruby/object:Gem::Dependency
|