simplegeo 0.2.0 → 0.2.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/README.rdoc +5 -91
- data/lib/simple_geo/client.rb +22 -0
- data/lib/simple_geo/endpoint.rb +36 -3
- data/simplegeo.gemspec +2 -2
- metadata +6 -6
data/README.rdoc
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
=
|
1
|
+
= simplegeo
|
2
2
|
|
3
3
|
A SimpleGeo Ruby client.
|
4
4
|
|
5
5
|
For the specific documentation on APIs (and the full list of parameters) see:
|
6
6
|
|
7
|
-
http://
|
7
|
+
* http://simplegeo.com/docs/api-endpoints
|
8
|
+
* http://simplegeo.com/docs/clients-code-libraries/ruby
|
9
|
+
* http://simplegeo.com/docs/tutorials/ruby
|
8
10
|
|
9
11
|
== Installation
|
10
12
|
|
11
13
|
Open the Terminal or other UNIX shell and type:
|
12
14
|
|
13
|
-
sudo gem install
|
15
|
+
sudo gem install simplegeo
|
14
16
|
|
15
17
|
== Examples
|
16
18
|
|
@@ -19,94 +21,6 @@ Start by requiring SimpleGeo and setting your authentication credentials:
|
|
19
21
|
require 'simple_geo'
|
20
22
|
SimpleGeo::Client.set_credentials('token', 'secret')
|
21
23
|
|
22
|
-
=== Getting a record
|
23
|
-
|
24
|
-
record = SimpleGeo::Client.get_record('com.simplegeo.global.geonames', '5373629')
|
25
|
-
|
26
|
-
=== Getting multiple records
|
27
|
-
|
28
|
-
records = SimpleGeo::Client.get_records('com.simplegeo.global.geonames', ['1234', '5678'])
|
29
|
-
|
30
|
-
=== Adding a record
|
31
|
-
|
32
|
-
record = SimpleGeo::Record.new({
|
33
|
-
:id => '1234',
|
34
|
-
:created => Time.now,
|
35
|
-
:lat => 37.759650000000001,
|
36
|
-
:lon => -122.42608,
|
37
|
-
:layer => 'com.example.testlayer',
|
38
|
-
:properties => {
|
39
|
-
:test_property => 'foobar'
|
40
|
-
}
|
41
|
-
})
|
42
|
-
SimpleGeo::Client.add_record(record)
|
43
|
-
|
44
|
-
=== Updating a record
|
45
|
-
|
46
|
-
record = SimpleGeo::Client.get_record('com.example.testlayer', '1234')
|
47
|
-
record.lat = 40.714269
|
48
|
-
record.lon = -74.005973
|
49
|
-
SimpleGeo::Client.add_record(record)
|
50
|
-
|
51
|
-
=== Adding / updating multiple records
|
52
|
-
|
53
|
-
records = [
|
54
|
-
SimpleGeo::Record.new({
|
55
|
-
:id => '1234',
|
56
|
-
:created => Time.now,
|
57
|
-
:lat => 37.759650000000001,
|
58
|
-
:lon => -122.42608,
|
59
|
-
:layer => 'com.example.testlayer',
|
60
|
-
:properties => {
|
61
|
-
:test_property => 'foobar'
|
62
|
-
}
|
63
|
-
}),
|
64
|
-
SimpleGeo::Record.new({
|
65
|
-
:id => '5678',
|
66
|
-
:created => Time.now,
|
67
|
-
:lat => 37.755470000000003,
|
68
|
-
:lon => -122.420646,
|
69
|
-
:layer => 'com.example.testlayer',
|
70
|
-
:properties => {
|
71
|
-
:mad_prop => 'baz'
|
72
|
-
}
|
73
|
-
})
|
74
|
-
]
|
75
|
-
SimpleGeo::Client.add_records('com.example.testlayer', records)
|
76
|
-
|
77
|
-
=== Deleting a record
|
78
|
-
|
79
|
-
SimpleGeo::Client.delete_record('1234')
|
80
|
-
|
81
|
-
=== Getting a record's history
|
82
|
-
|
83
|
-
history = SimpleGeo::Client.get_history('com.example.testlayer', '1234')
|
84
|
-
|
85
|
-
=== Getting nearby records
|
86
|
-
|
87
|
-
See http://help.simplegeo.com/faqs/api-documentation/endpoints for other optional params
|
88
|
-
|
89
|
-
# by lat, lon
|
90
|
-
records = SimpleGeo::Client.get_nearby_records('com.example.testlayer',
|
91
|
-
:lat => 37.759650000000001,
|
92
|
-
:lon => -122.42608)
|
93
|
-
|
94
|
-
# by geohash
|
95
|
-
records = SimpleGeo::Client.get_nearby_records('com.example.testlayer',
|
96
|
-
:geohash => '9q8yy1ujcsfm')
|
97
|
-
|
98
|
-
=== Getting a nearby address for a lat and lon
|
99
|
-
|
100
|
-
nearby_address = SimpleGeo::Client.get_nearby_address(37.759650000000001, -122.42608)
|
101
|
-
|
102
|
-
=== Getting SpotRank density information
|
103
|
-
|
104
|
-
# by day
|
105
|
-
density_info = SimpleGeo::Client.get_density(37.75965, -122.42608, 'sat')
|
106
|
-
|
107
|
-
# by hour
|
108
|
-
density_info = SimpleGeo::Client.get_density(37.75965, -122.42608, 'sat', '16' )
|
109
|
-
|
110
24
|
=== Other APIs
|
111
25
|
|
112
26
|
For more examples see: spec/client_spec.rb
|
data/lib/simple_geo/client.rb
CHANGED
@@ -110,6 +110,17 @@ module SimpleGeo
|
|
110
110
|
HashUtils.recursively_symbolize_keys geojson_hash
|
111
111
|
end
|
112
112
|
|
113
|
+
def get_context_by_address(address)
|
114
|
+
address = URI.escape(address, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
115
|
+
geojson_hash = get Endpoint.context_by_address(address)
|
116
|
+
HashUtils.recursively_symbolize_keys geojson_hash
|
117
|
+
end
|
118
|
+
|
119
|
+
def get_context_ip(ip)
|
120
|
+
geojson_hash = get Endpoint.context_ip(ip)
|
121
|
+
HashUtils.recursively_symbolize_keys geojson_hash
|
122
|
+
end
|
123
|
+
|
113
124
|
# Required
|
114
125
|
# lat - The latitude of the point
|
115
126
|
# lon - The longitude of the point
|
@@ -129,6 +140,17 @@ module SimpleGeo
|
|
129
140
|
HashUtils.recursively_symbolize_keys geojson_hash
|
130
141
|
end
|
131
142
|
|
143
|
+
def get_places_by_address(address, options={})
|
144
|
+
address = URI.escape(address, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
145
|
+
geojson_hash = get Endpoint.places_by_address(address, options)
|
146
|
+
HashUtils.recursively_symbolize_keys geojson_hash
|
147
|
+
end
|
148
|
+
|
149
|
+
def get_places_by_ip(ip='ip', options={})
|
150
|
+
geojson_hash = get Endpoint.places_by_ip(ip, options)
|
151
|
+
HashUtils.recursively_symbolize_keys geojson_hash
|
152
|
+
end
|
153
|
+
|
132
154
|
def get_density(lat, lon, day, hour=nil)
|
133
155
|
geojson_hash = get Endpoint.density(lat, lon, day, hour)
|
134
156
|
geojson_hash = HashUtils.recursively_symbolize_keys(geojson_hash)
|
data/lib/simple_geo/endpoint.rb
CHANGED
@@ -40,15 +40,48 @@ module SimpleGeo
|
|
40
40
|
endpoint_url "context/#{lat},#{lon}.json", '1.0'
|
41
41
|
end
|
42
42
|
|
43
|
+
def context_by_address(address)
|
44
|
+
endpoint_url "context/address.json?address=#{address}", '1.0'
|
45
|
+
end
|
46
|
+
|
47
|
+
def context_ip(ip)
|
48
|
+
endpoint_url "context/#{ip}.json", '1.0'
|
49
|
+
end
|
50
|
+
|
43
51
|
def places(lat, lon, options)
|
44
52
|
if options.empty?
|
45
53
|
endpoint_url "places/#{lat},#{lon}.json", '1.0'
|
46
54
|
else
|
47
|
-
params =
|
55
|
+
params = []
|
56
|
+
options.each do |k,v|
|
57
|
+
params << "#{k}=#{v}"
|
58
|
+
end
|
59
|
+
endpoint_url "places/#{lat},#{lon}.json?#{params.join("&")}", '1.0'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def places_by_address(address, options)
|
64
|
+
if options.empty?
|
65
|
+
endpoint_url "places/address.json?address=#{address}", '1.0'
|
66
|
+
else
|
67
|
+
params = []
|
68
|
+
params << "address=#{address}"
|
69
|
+
options.each do |k,v|
|
70
|
+
params << "#{k}=#{v}"
|
71
|
+
end
|
72
|
+
endpoint_url "places/address.json?#{params.join("&")}", '1.0'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def places_by_ip(ip, options)
|
77
|
+
if options.empty?
|
78
|
+
endpoint_url "places/#{ip}.json", '1.0'
|
79
|
+
else
|
80
|
+
params = []
|
48
81
|
options.each do |k,v|
|
49
|
-
params << "#{k}=#{v}
|
82
|
+
params << "#{k}=#{v}"
|
50
83
|
end
|
51
|
-
endpoint_url "places/#{
|
84
|
+
endpoint_url "places/#{ip}.json?#{params.join("&")}", '1.0'
|
52
85
|
end
|
53
86
|
end
|
54
87
|
|
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.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Ryckbost", "Andrew Mager"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-02-09}
|
13
13
|
s.email = %q{andrew@simplegeo.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplegeo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Ryckbost
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-02-09 00:00:00 -08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
requirements: []
|
151
151
|
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 1.
|
153
|
+
rubygems_version: 1.3.7
|
154
154
|
signing_key:
|
155
155
|
specification_version: 3
|
156
156
|
summary: A SimpleGeo Ruby Client
|