geocoda-ruby 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # The MIT License (MIT)
2
+ # Copyright (c) 2012 Geocoda, LLC
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ #
6
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+
10
+ source "http://rubygems.org"
11
+
12
+ # Specify your gem's dependencies in geocoda.gemspec
13
+ gemspec
@@ -0,0 +1,8 @@
1
+ # The MIT License (MIT)
2
+ # Copyright (c) 2012 Geocoda, LLC
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ #
6
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,10 @@
1
+ # The MIT License (MIT)
2
+ # Copyright (c) 2012 Geocoda, LLC
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ #
6
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+
10
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>documents</key>
6
+ <array>
7
+ <dict>
8
+ <key>name</key>
9
+ <string>geocoda-gem</string>
10
+ <key>regexFolderFilter</key>
11
+ <string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
12
+ <key>selected</key>
13
+ <true/>
14
+ <key>sourceDirectory</key>
15
+ <string></string>
16
+ </dict>
17
+ </array>
18
+ <key>fileHierarchyDrawerWidth</key>
19
+ <integer>200</integer>
20
+ <key>metaData</key>
21
+ <dict/>
22
+ <key>showFileHierarchyDrawer</key>
23
+ <true/>
24
+ <key>windowFrame</key>
25
+ <string>{{397, 265}, {760, 701}}</string>
26
+ </dict>
27
+ </plist>
@@ -0,0 +1,35 @@
1
+ # The MIT License (MIT)
2
+ # Copyright (c) 2012 Geocoda, LLC
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ #
6
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+
10
+ # -*- encoding: utf-8 -*-
11
+ $:.push File.expand_path("../lib", __FILE__)
12
+ require "geocoda-ruby/version"
13
+
14
+ Gem::Specification.new do |s|
15
+ s.name = "geocoda-ruby"
16
+ s.version = Geocoda::VERSION
17
+ s.authors = ["Runako Godfrey", "C. G. Brown"]
18
+ s.email = ["runako@geocoda.com", "cgbrown@geocoda.com"]
19
+ s.homepage = "http://www.geocoda.com"
20
+ s.summary = %q{Allows Ruby connections to Geocoda.}
21
+ s.description = %q{This gem allows code to easily connect to the Geocoda geocoding and location service.}
22
+
23
+ s.rubyforge_project = "geocoda-ruby"
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+
30
+ # specify any dependencies here; for example:
31
+ # s.add_development_dependency "rspec"
32
+
33
+ s.add_runtime_dependency "rest-client"
34
+ s.add_runtime_dependency "json"
35
+ end
@@ -0,0 +1,13 @@
1
+ # The MIT License (MIT)
2
+ # Copyright (c) 2012 Geocoda, LLC
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ #
6
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ require "geocoda-ruby/version"
10
+
11
+ module Geocoda; end
12
+
13
+ require "geocoda-ruby/client"
@@ -0,0 +1,224 @@
1
+ # The MIT License (MIT)
2
+ # Copyright (c) 2012 Geocoda, LLC
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ #
6
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+
10
+ require "rest_client"
11
+ require "json"
12
+
13
+ module Geocoda
14
+ class Client
15
+ attr_accessor :api_key
16
+
17
+ def initialize(api_key)
18
+ @api_key = api_key
19
+ end
20
+
21
+ def geocode(address)
22
+ request = RestClient::Request.new(:method => :get,
23
+ :url => Geocoda::Client::geocode_url(address),
24
+ :user => api_key,
25
+ :password => "x")
26
+ raw = request.execute
27
+
28
+ JSON::parse(raw)
29
+ end
30
+
31
+ def coord(lat, lon)
32
+ request = RestClient::Request.new(:method => :get,
33
+ :url => Geocoda::Client::coord_url(lat, lon),
34
+ :user => api_key,
35
+ :password => "x")
36
+ raw = request.execute
37
+
38
+ JSON::parse(raw)
39
+ end
40
+
41
+ def layers()
42
+ request = RestClient::Request.new(:method => :get,
43
+ :url=>Geocoda::Client::layers_url,
44
+ :user => api_key,
45
+ :password => "x")
46
+ body = request.execute
47
+ JSON::parse(body)
48
+ end
49
+
50
+ def layer(name)
51
+ request = RestClient::Request.new(:method => :get,
52
+ :url=>Geocoda::Client::layer_url(name),
53
+ :user => api_key,
54
+ :password => "x")
55
+ body = request.execute
56
+ JSON::parse(body)
57
+ end
58
+
59
+ def save_layer(name, payload={})
60
+ new_layer = payload.is_a?(String) ? payload : payload.to_json
61
+ request = RestClient::Request.new(:method => :post,
62
+ :url=>Geocoda::Client::layer_url(name),
63
+ :payload=> new_layer,
64
+ :user => api_key,
65
+ :password => "x")
66
+ body = request.execute
67
+ JSON::parse(body)
68
+ end
69
+
70
+ def delete_layer(name)
71
+ request = RestClient::Request.new(:method => :delete,
72
+ :url=>Geocoda::Client::layer_url(name),
73
+ :user => api_key,
74
+ :password => "x")
75
+ body = request.execute
76
+ JSON::parse(body)
77
+ end
78
+
79
+ def records(layer)
80
+ request = RestClient::Request.new(:method => :get,
81
+ :url=>Geocoda::Client::records_url(layer),
82
+ :user => api_key,
83
+ :password => "x")
84
+ body = request.execute
85
+ JSON::parse(body)
86
+ end
87
+
88
+ def record(layer, name)
89
+ request = RestClient::Request.new(:method => :get,
90
+ :url=>Geocoda::Client::record_url(layer, name),
91
+ :user => api_key,
92
+ :password => "x")
93
+ body = request.execute
94
+ JSON::parse(body)
95
+ end
96
+
97
+ def save_record(layer, name, payload)
98
+ new_record = payload.is_a?(String) ? payload : payload.to_json
99
+ request = RestClient::Request.new(:method => :post,
100
+ :url=>Geocoda::Client::record_url(layer, name),
101
+ :payload=> new_record,
102
+ :user => api_key,
103
+ :password => "x")
104
+ body = request.execute
105
+ JSON::parse(body)
106
+ end
107
+
108
+ def save_records(layer, payload)
109
+ record_collection = payload.is_a?(String) ? payload : payload.to_json
110
+ request = RestClient::Request.new(:method => :post,
111
+ :url=>Geocoda::Client::records_url(layer),
112
+ :payload=> record_collection,
113
+ :user => api_key,
114
+ :password => "x")
115
+ body = request.execute
116
+ JSON::parse(body)
117
+ end
118
+
119
+ def save_point(layer, name, latitude, longitude)
120
+ new_record = {:type=>"Feature", :geometry=>{:type=>"Point", :coordinates=>[longitude, latitude]}}.to_json
121
+ save_record(layer, name, new_record)
122
+ end
123
+
124
+ def delete_record(layer, name)
125
+ request = RestClient::Request.new(:method => :delete,
126
+ :url=>Geocoda::Client::record_url(layer, name),
127
+ :user => api_key,
128
+ :password => "x")
129
+ body = request.execute
130
+ JSON::parse(body)
131
+ end
132
+
133
+ def record_history(layer, name)
134
+ request = RestClient::Request.new(:method => :get,
135
+ :url=>Geocoda::Client::record_history_url(layer, name),
136
+ :user => api_key,
137
+ :password => "x")
138
+ body = request.execute
139
+ JSON::parse(body)
140
+ end
141
+
142
+ def nearby_radius(layer, latitude, longitude, radius)
143
+ query_string = "?radius=#{radius}"
144
+ request = RestClient::Request.new(:method => :get,
145
+ :url=>Geocoda::Client::nearby_url(layer, latitude, longitude) + query_string,
146
+ :user => api_key,
147
+ :password => "x")
148
+ body = request.execute
149
+ JSON::parse(body)
150
+ end
151
+
152
+ def nearby_bounding_box(layer, latitude, longitude, swlat, swlon, nelat, nelon)
153
+ query_string = "?bounding_box=#{swlat},#{swlon},#{nelat},#{nelon}"
154
+ request = RestClient::Request.new(:method => :get,
155
+ :url=>Geocoda::Client::nearby_url(layer, latitude, longitude) + query_string,
156
+ :user => api_key,
157
+ :password => "x")
158
+ body = request.execute
159
+ JSON::parse(body)
160
+ end
161
+
162
+ class <<self
163
+ def version
164
+ Geocoda::VERSION
165
+ end
166
+
167
+ def gem_version_string
168
+ "geocoda-gem/#{version}"
169
+ end
170
+
171
+ def base_address
172
+ "https://api.geocoda.com/v1"
173
+ end
174
+
175
+ def location_address
176
+ "#{base_address}/loc"
177
+ end
178
+
179
+ def geocode_address
180
+ "#{location_address}/geocode"
181
+ end
182
+
183
+ def coord_address
184
+ "#{location_address}/coord"
185
+ end
186
+
187
+ def storage_address
188
+ "#{base_address}/storage"
189
+ end
190
+
191
+ def geocode_url(address)
192
+ "#{geocode_address}/#{URI.encode(address)}"
193
+ end
194
+
195
+ def coord_url(lat, lon)
196
+ "#{coord_address}/#{lat},#{lon}"
197
+ end
198
+
199
+ def layers_url
200
+ "#{storage_address}/layers"
201
+ end
202
+
203
+ def layer_url(name)
204
+ "#{layers_url}/#{URI.encode(name)}"
205
+ end
206
+
207
+ def records_url(layer)
208
+ "#{storage_address}/records/#{URI.encode(layer)}"
209
+ end
210
+
211
+ def record_url(layer, name)
212
+ "#{records_url(layer)}/#{URI.encode(name)}"
213
+ end
214
+
215
+ def record_history_url(layer, name)
216
+ "#{record_url(layer, name)}/history"
217
+ end
218
+
219
+ def nearby_url(layer, lat, lon)
220
+ "#{records_url(layer)}/nearby/#{lat},#{lon}"
221
+ end
222
+ end
223
+ end
224
+ end
@@ -0,0 +1,11 @@
1
+ # The MIT License (MIT)
2
+ # Copyright (c) 2012 Geocoda, LLC
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ #
6
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ module Geocoda
10
+ VERSION = "0.1.2"
11
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geocoda-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Runako Godfrey
9
+ - C. G. Brown
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-03-31 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ requirement: &70352282052540 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70352282052540
26
+ - !ruby/object:Gem::Dependency
27
+ name: json
28
+ requirement: &70352282051340 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70352282051340
37
+ description: This gem allows code to easily connect to the Geocoda geocoding and location
38
+ service.
39
+ email:
40
+ - runako@geocoda.com
41
+ - cgbrown@geocoda.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - MIT-LICENSE.txt
49
+ - Rakefile
50
+ - geocoda-gem-cgb.tmproj
51
+ - geocoda.gemspec
52
+ - lib/geocoda-ruby.rb
53
+ - lib/geocoda-ruby/client.rb
54
+ - lib/geocoda-ruby/version.rb
55
+ homepage: http://www.geocoda.com
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project: geocoda-ruby
75
+ rubygems_version: 1.8.11
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Allows Ruby connections to Geocoda.
79
+ test_files: []