gmaps_geocoding 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/.versions.conf +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +222 -0
- data/Rakefile +10 -0
- data/gmaps_geocoding.gemspec +30 -0
- data/lib/gmaps_geocoding/api.rb +70 -0
- data/lib/gmaps_geocoding/config.rb +79 -0
- data/lib/gmaps_geocoding/version.rb +3 -0
- data/lib/gmaps_geocoding.rb +5 -0
- data/test/gmaps_geocoding_test.rb +51 -0
- metadata +158 -0
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3-p392@gmaps_geocoding
|
data/.travis.yml
ADDED
data/.versions.conf
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Christian Kakesa
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
# GmapsGeocoding
|
2
|
+
|
3
|
+
A simple Ruby gem for Google Maps Geocoding API.
|
4
|
+
This gem return a Ruby Hash object of the result.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'gmaps_geocoding'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install gmaps_geocoding
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
### Global information
|
22
|
+
|
23
|
+
See [Google Maps Geocoding service documentation](https://developers.google.com/maps/documentation/geocoding/) for options parameters and *result* handling.
|
24
|
+
|
25
|
+
### JSON example
|
26
|
+
|
27
|
+
# json output example
|
28
|
+
opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'json'}
|
29
|
+
api = GmapsGeocoding::Api.new(opts)
|
30
|
+
result = api.get_location
|
31
|
+
|
32
|
+
**Ruby Hash object from json output**
|
33
|
+
|
34
|
+
{"results"=>
|
35
|
+
[{"address_components"=>
|
36
|
+
[{"long_name"=>"Eiffel Tower",
|
37
|
+
"short_name"=>"Eiffel Tower",
|
38
|
+
"types"=>["point_of_interest", "establishment"]},
|
39
|
+
{"long_name"=>"Champ de Mars",
|
40
|
+
"short_name"=>"Champ de Mars",
|
41
|
+
"types"=>["premise"]},
|
42
|
+
{"long_name"=>"5", "short_name"=>"5", "types"=>["street_number"]},
|
43
|
+
{"long_name"=>"Avenue Anatole France",
|
44
|
+
"short_name"=>"Av. Anatole France",
|
45
|
+
"types"=>["route"]},
|
46
|
+
{"long_name"=>"Paris",
|
47
|
+
"short_name"=>"Paris",
|
48
|
+
"types"=>["locality", "political"]},
|
49
|
+
{"long_name"=>"Paris",
|
50
|
+
"short_name"=>"75",
|
51
|
+
"types"=>["administrative_area_level_2", "political"]},
|
52
|
+
{"long_name"=>"Île-de-France",
|
53
|
+
"short_name"=>"IdF",
|
54
|
+
"types"=>["administrative_area_level_1", "political"]},
|
55
|
+
{"long_name"=>"France",
|
56
|
+
"short_name"=>"FR",
|
57
|
+
"types"=>["country", "political"]},
|
58
|
+
{"long_name"=>"75007", "short_name"=>"75007", "types"=>["postal_code"]}],
|
59
|
+
"formatted_address"=>
|
60
|
+
"Eiffel Tower, Champ de Mars, 5 Avenue Anatole France, 75007 Paris, France",
|
61
|
+
"geometry"=>
|
62
|
+
{"location"=>{"lat"=>48.858278, "lng"=>2.294254},
|
63
|
+
"location_type"=>"APPROXIMATE",
|
64
|
+
"viewport"=>
|
65
|
+
{"northeast"=>{"lat"=>48.8656186, "lng"=>2.3102614},
|
66
|
+
"southwest"=>{"lat"=>48.8509364, "lng"=>2.2782466}}},
|
67
|
+
"types"=>["point_of_interest", "establishment"]},
|
68
|
+
{"address_components"=>
|
69
|
+
[{"long_name"=>"Eiffel Tower", "short_name"=>"Eiffel Tower", "types"=>[]},
|
70
|
+
{"long_name"=>"Paris",
|
71
|
+
"short_name"=>"Paris",
|
72
|
+
"types"=>["locality", "political"]},
|
73
|
+
{"long_name"=>"Paris",
|
74
|
+
"short_name"=>"75",
|
75
|
+
"types"=>["administrative_area_level_2", "political"]},
|
76
|
+
{"long_name"=>"Île-de-France",
|
77
|
+
"short_name"=>"IdF",
|
78
|
+
"types"=>["administrative_area_level_1", "political"]},
|
79
|
+
{"long_name"=>"France",
|
80
|
+
"short_name"=>"FR",
|
81
|
+
"types"=>["country", "political"]},
|
82
|
+
{"long_name"=>"75007", "short_name"=>"75007", "types"=>["postal_code"]}],
|
83
|
+
"formatted_address"=>"Eiffel Tower, 75007 Paris, France",
|
84
|
+
"geometry"=>
|
85
|
+
{"bounds"=>
|
86
|
+
{"northeast"=>{"lat"=>48.858872, "lng"=>2.2952731},
|
87
|
+
"southwest"=>{"lat"=>48.8578587, "lng"=>2.2937331}},
|
88
|
+
"location"=>{"lat"=>48.8582222, "lng"=>2.2945},
|
89
|
+
"location_type"=>"APPROXIMATE",
|
90
|
+
"viewport"=>
|
91
|
+
{"northeast"=>{"lat"=>48.8597143302915, "lng"=>2.295852080291502},
|
92
|
+
"southwest"=>{"lat"=>48.8570163697085, "lng"=>2.293154119708498}}},
|
93
|
+
"types"=>[]},
|
94
|
+
{"address_components"=>
|
95
|
+
[{"long_name"=>"Tour Eiffel", "short_name"=>"Tour Eiffel", "types"=>[]},
|
96
|
+
{"long_name"=>"Paris",
|
97
|
+
"short_name"=>"Paris",
|
98
|
+
"types"=>["locality", "political"]},
|
99
|
+
{"long_name"=>"Paris",
|
100
|
+
"short_name"=>"75",
|
101
|
+
"types"=>["administrative_area_level_2", "political"]},
|
102
|
+
{"long_name"=>"Île-de-France",
|
103
|
+
"short_name"=>"IdF",
|
104
|
+
"types"=>["administrative_area_level_1", "political"]},
|
105
|
+
{"long_name"=>"France",
|
106
|
+
"short_name"=>"FR",
|
107
|
+
"types"=>["country", "political"]},
|
108
|
+
{"long_name"=>"75015", "short_name"=>"75015", "types"=>["postal_code"]}],
|
109
|
+
"formatted_address"=>"Tour Eiffel, 75015 Paris, France",
|
110
|
+
"geometry"=>
|
111
|
+
{"location"=>{"lat"=>48.857269, "lng"=>2.291018},
|
112
|
+
"location_type"=>"APPROXIMATE",
|
113
|
+
"viewport"=>
|
114
|
+
{"northeast"=>{"lat"=>48.8586179802915, "lng"=>2.292366980291502},
|
115
|
+
"southwest"=>{"lat"=>48.8559200197085, "lng"=>2.289669019708498}}},
|
116
|
+
"types"=>[]}],
|
117
|
+
"status"=>"OK"}
|
118
|
+
|
119
|
+
### XML example
|
120
|
+
|
121
|
+
# xml output example
|
122
|
+
opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'xml'}
|
123
|
+
api = GmapsGeocoding::Api.new(opts)
|
124
|
+
result = api.get_location
|
125
|
+
|
126
|
+
**Ruby Hash object from xml output**
|
127
|
+
|
128
|
+
{"status"=>"OK",
|
129
|
+
"result"=>
|
130
|
+
[{"type"=>["point_of_interest", "establishment"],
|
131
|
+
"formatted_address"=>
|
132
|
+
"Eiffel Tower, Champ de Mars, 5 Avenue Anatole France, 75007 Paris, France",
|
133
|
+
"address_component"=>
|
134
|
+
[{"long_name"=>"Eiffel Tower",
|
135
|
+
"short_name"=>"Eiffel Tower",
|
136
|
+
"type"=>["point_of_interest", "establishment"]},
|
137
|
+
{"long_name"=>"Champ de Mars",
|
138
|
+
"short_name"=>"Champ de Mars",
|
139
|
+
"type"=>"premise"},
|
140
|
+
{"long_name"=>"5", "short_name"=>"5", "type"=>"street_number"},
|
141
|
+
{"long_name"=>"Avenue Anatole France",
|
142
|
+
"short_name"=>"Av. Anatole France",
|
143
|
+
"type"=>"route"},
|
144
|
+
{"long_name"=>"Paris",
|
145
|
+
"short_name"=>"Paris",
|
146
|
+
"type"=>["locality", "political"]},
|
147
|
+
{"long_name"=>"Paris",
|
148
|
+
"short_name"=>"75",
|
149
|
+
"type"=>["administrative_area_level_2", "political"]},
|
150
|
+
{"long_name"=>"Île-de-France",
|
151
|
+
"short_name"=>"IdF",
|
152
|
+
"type"=>["administrative_area_level_1", "political"]},
|
153
|
+
{"long_name"=>"France",
|
154
|
+
"short_name"=>"FR",
|
155
|
+
"type"=>["country", "political"]},
|
156
|
+
{"long_name"=>"75007", "short_name"=>"75007", "type"=>"postal_code"}],
|
157
|
+
"geometry"=>
|
158
|
+
{"location"=>{"lat"=>"48.8582780", "lng"=>"2.2942540"},
|
159
|
+
"location_type"=>"APPROXIMATE",
|
160
|
+
"viewport"=>
|
161
|
+
{"southwest"=>{"lat"=>"48.8509364", "lng"=>"2.2782466"},
|
162
|
+
"northeast"=>{"lat"=>"48.8656186", "lng"=>"2.3102614"}}}},
|
163
|
+
{"formatted_address"=>"Eiffel Tower, 75007 Paris, France",
|
164
|
+
"address_component"=>
|
165
|
+
[{"long_name"=>"Eiffel Tower", "short_name"=>"Eiffel Tower"},
|
166
|
+
{"long_name"=>"Paris",
|
167
|
+
"short_name"=>"Paris",
|
168
|
+
"type"=>["locality", "political"]},
|
169
|
+
{"long_name"=>"Paris",
|
170
|
+
"short_name"=>"75",
|
171
|
+
"type"=>["administrative_area_level_2", "political"]},
|
172
|
+
{"long_name"=>"Île-de-France",
|
173
|
+
"short_name"=>"IdF",
|
174
|
+
"type"=>["administrative_area_level_1", "political"]},
|
175
|
+
{"long_name"=>"France",
|
176
|
+
"short_name"=>"FR",
|
177
|
+
"type"=>["country", "political"]},
|
178
|
+
{"long_name"=>"75007", "short_name"=>"75007", "type"=>"postal_code"}],
|
179
|
+
"geometry"=>
|
180
|
+
{"location"=>{"lat"=>"48.8582222", "lng"=>"2.2945000"},
|
181
|
+
"location_type"=>"APPROXIMATE",
|
182
|
+
"viewport"=>
|
183
|
+
{"southwest"=>{"lat"=>"48.8570164", "lng"=>"2.2931541"},
|
184
|
+
"northeast"=>{"lat"=>"48.8597143", "lng"=>"2.2958521"}},
|
185
|
+
"bounds"=>
|
186
|
+
{"southwest"=>{"lat"=>"48.8578587", "lng"=>"2.2937331"},
|
187
|
+
"northeast"=>{"lat"=>"48.8588720", "lng"=>"2.2952731"}}}},
|
188
|
+
{"formatted_address"=>"Tour Eiffel, 75015 Paris, France",
|
189
|
+
"address_component"=>
|
190
|
+
[{"long_name"=>"Tour Eiffel", "short_name"=>"Tour Eiffel"},
|
191
|
+
{"long_name"=>"Paris",
|
192
|
+
"short_name"=>"Paris",
|
193
|
+
"type"=>["locality", "political"]},
|
194
|
+
{"long_name"=>"Paris",
|
195
|
+
"short_name"=>"75",
|
196
|
+
"type"=>["administrative_area_level_2", "political"]},
|
197
|
+
{"long_name"=>"Île-de-France",
|
198
|
+
"short_name"=>"IdF",
|
199
|
+
"type"=>["administrative_area_level_1", "political"]},
|
200
|
+
{"long_name"=>"France",
|
201
|
+
"short_name"=>"FR",
|
202
|
+
"type"=>["country", "political"]},
|
203
|
+
{"long_name"=>"75015", "short_name"=>"75015", "type"=>"postal_code"}],
|
204
|
+
"geometry"=>
|
205
|
+
{"location"=>{"lat"=>"48.8572690", "lng"=>"2.2910180"},
|
206
|
+
"location_type"=>"APPROXIMATE",
|
207
|
+
"viewport"=>
|
208
|
+
{"southwest"=>{"lat"=>"48.8559200", "lng"=>"2.2896690"},
|
209
|
+
"northeast"=>{"lat"=>"48.8586180", "lng"=>"2.2923670"}}}}]}
|
210
|
+
|
211
|
+
|
212
|
+
## Contributing
|
213
|
+
|
214
|
+
1. Fork it
|
215
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
216
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
217
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
218
|
+
5. Create new Pull Request
|
219
|
+
|
220
|
+
## License
|
221
|
+
|
222
|
+
Copyright (c) 2013 Christian Kakesa. See LICENSE.txt for more details.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gmaps_geocoding/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'gmaps_geocoding'
|
8
|
+
s.version = GmapsGeocoding::VERSION
|
9
|
+
s.authors = ['Christian Kakesa']
|
10
|
+
s.email = ['christian.kakesa@gmail.com']
|
11
|
+
s.description = %q{
|
12
|
+
A simple Ruby gem for Google Maps Geocoding API.
|
13
|
+
This gem return a Ruby Hash object of the result.
|
14
|
+
}
|
15
|
+
s.summary = %q{Use Google Geocoding API from Ruby.}
|
16
|
+
s.homepage = 'https://github.com/fenicks/gmaps_geocoding'
|
17
|
+
s.license = 'MIT'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split($/)
|
20
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
22
|
+
s.require_paths = ['lib']
|
23
|
+
|
24
|
+
s.add_runtime_dependency 'rest-client', '~> 1.6.7'
|
25
|
+
s.add_runtime_dependency 'yajl-ruby', '~> 1.1.0'
|
26
|
+
s.add_runtime_dependency 'nori', '~> 2.0.4'
|
27
|
+
s.add_runtime_dependency 'nokogiri', '>= 1.4.0'
|
28
|
+
s.add_development_dependency 'bundler', '~> 1.3'
|
29
|
+
s.add_development_dependency 'rake'
|
30
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GmapsGeocoding
|
4
|
+
class Api
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
def initialize(opts = {})
|
8
|
+
@config = Config.new(opts)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_location
|
12
|
+
get_gmaps_data
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def get_gmaps_data
|
17
|
+
begin
|
18
|
+
if @config.valid?
|
19
|
+
rest_client = retrieve_geocoding_data
|
20
|
+
result = case @config.is_json_format?
|
21
|
+
when true
|
22
|
+
GmapsGeocoding.from_json(rest_client.to_s)
|
23
|
+
else
|
24
|
+
# Xml parser
|
25
|
+
GmapsGeocoding.from_xml(rest_client.to_s)
|
26
|
+
end
|
27
|
+
return result
|
28
|
+
end
|
29
|
+
rescue => e
|
30
|
+
puts "[error: gmaps_geocoding]: #{e}"
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_url_query
|
36
|
+
query = {}
|
37
|
+
query[:address] = @config.address if @config.address
|
38
|
+
query[:latlng] = @config.latlng if @config.latlng
|
39
|
+
query[:components] = @config.components if @config.components
|
40
|
+
query[:sensor] = @config.sensor if @config.sensor
|
41
|
+
query[:bounds] = @config.bounds if @config.bounds
|
42
|
+
query[:language] = @config.language if @config.language
|
43
|
+
query[:region] = @config.region if @config.region
|
44
|
+
url = "#{@config.url}/#{@config.output}"
|
45
|
+
{url: url, query: query}
|
46
|
+
end
|
47
|
+
|
48
|
+
def retrieve_geocoding_data
|
49
|
+
require 'rest-client'
|
50
|
+
data = build_url_query
|
51
|
+
RestClient.get data[:url], params: data[:query]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.from_json(json)
|
56
|
+
require 'yajl/json_gem'
|
57
|
+
Yajl::Parser.parse(json)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.from_xml(xml)
|
61
|
+
require 'nori'
|
62
|
+
n = Nori.new(parser: :nokogiri).parse(xml)
|
63
|
+
if n.include?('GeocodeResponse')
|
64
|
+
n = n['GeocodeResponse']
|
65
|
+
else
|
66
|
+
n = {'status' => 'UNKNOWN_ERROR'}
|
67
|
+
end
|
68
|
+
n
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module GmapsGeocoding
|
4
|
+
class Config
|
5
|
+
attr_reader :options
|
6
|
+
|
7
|
+
def initialize(opts = {})
|
8
|
+
@options = {url: 'https://maps.googleapis.com/maps/api/geocode'}
|
9
|
+
@options[:output] = ENV['GOOGLE_MAPS_GEOCODING_OUTPUT'] || opts[:output] || 'json'
|
10
|
+
@options[:address] = ENV['GOOGLE_MAPS_GEOCODING_ADDRESS'] || opts[:address] || ''
|
11
|
+
@options[:latlng] = ENV['GOOGLE_MAPS_GEOCODING_LATLNG'] || opts[:latlng] || ''
|
12
|
+
@options[:components] = ENV['GOOGLE_MAPS_GEOCODING_COMPONENTS'] || opts[:components] || ''
|
13
|
+
@options[:sensor] = ENV['GOOGLE_MAPS_GEOCODING_SENSOR'] || opts[:sensor] || 'false'
|
14
|
+
@options[:bounds] = ENV['GOOGLE_MAPS_GEOCODING_BOUNDS'] || opts[:bounds] || ''
|
15
|
+
@options[:language] = ENV['GOOGLE_MAPS_GEOCODING_LANGUAGE'] || opts[:language] || ''
|
16
|
+
@options[:region] = ENV['GOOGLE_MAPS_GEOCODING_REGION'] || opts[:region] || ''
|
17
|
+
@options.merge!(opts).reject!{|_, v| v.to_s.length == 0 }
|
18
|
+
end
|
19
|
+
|
20
|
+
def url
|
21
|
+
@options[:url]
|
22
|
+
end
|
23
|
+
|
24
|
+
def output
|
25
|
+
@options[:output]
|
26
|
+
end
|
27
|
+
|
28
|
+
def address
|
29
|
+
@options[:address]
|
30
|
+
end
|
31
|
+
|
32
|
+
def latlng
|
33
|
+
@options[:latlng]
|
34
|
+
end
|
35
|
+
|
36
|
+
def components
|
37
|
+
@options[:components]
|
38
|
+
end
|
39
|
+
|
40
|
+
def sensor
|
41
|
+
@options[:sensor]
|
42
|
+
end
|
43
|
+
|
44
|
+
def bounds
|
45
|
+
@options[:bounds]
|
46
|
+
end
|
47
|
+
|
48
|
+
def language
|
49
|
+
@options[:language]
|
50
|
+
end
|
51
|
+
|
52
|
+
def region
|
53
|
+
@options[:region]
|
54
|
+
end
|
55
|
+
|
56
|
+
def valid?
|
57
|
+
return is_query_valid? &&
|
58
|
+
is_output_param_valid?
|
59
|
+
end
|
60
|
+
|
61
|
+
def is_json_format?
|
62
|
+
'json'.eql?(output)
|
63
|
+
end
|
64
|
+
|
65
|
+
def is_xml_format?
|
66
|
+
'xml'.eql?(output)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def is_query_valid?
|
71
|
+
(@options[:address].to_s.length > 0 && @options[:latlng].to_s.length == 0) ||
|
72
|
+
(@options[:address].to_s.length == 0 && @options[:latlng].to_s.length > 0)
|
73
|
+
end
|
74
|
+
|
75
|
+
def is_output_param_valid?
|
76
|
+
['json', 'xml'].include?(output)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test/unit'
|
3
|
+
require 'gmaps_geocoding'
|
4
|
+
|
5
|
+
class GmapsGeocodingTest < Test::Unit::TestCase
|
6
|
+
def test_config_default
|
7
|
+
config = GmapsGeocoding::Config.new
|
8
|
+
assert_not_nil config
|
9
|
+
assert_equal false, config.valid?
|
10
|
+
assert_equal 3, config.options.length
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_config_address_set
|
14
|
+
config = GmapsGeocoding::Config.new({address: 'Tour Eiffel, IDF, Paris, France'})
|
15
|
+
assert_not_nil config
|
16
|
+
assert_equal true, config.valid?
|
17
|
+
assert_equal 4, config.options.length
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_config_latlng_set
|
21
|
+
config = GmapsGeocoding::Config.new({latlng: '40.714224,-73.961452'})
|
22
|
+
assert_not_nil config
|
23
|
+
assert_equal true, config.valid?
|
24
|
+
assert_equal 4, config.options.length
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_config_address_latlng_set
|
28
|
+
config = GmapsGeocoding::Config.new({address: 'Tour Eiffel, IDF, Paris, France', latlng: '40.714224,-73.961452'})
|
29
|
+
assert_not_nil config
|
30
|
+
assert_equal false, config.valid?
|
31
|
+
assert_equal 5, config.options.length
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_api_json_set
|
35
|
+
opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'json'}
|
36
|
+
api = GmapsGeocoding::Api.new(opts)
|
37
|
+
result = api.get_location
|
38
|
+
assert_not_nil api
|
39
|
+
assert_not_nil result
|
40
|
+
assert_equal 4, api.config.options.length
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_api_xml_set
|
44
|
+
opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'xml'}
|
45
|
+
api = GmapsGeocoding::Api.new(opts)
|
46
|
+
result = api.get_location
|
47
|
+
assert_not_nil api
|
48
|
+
assert_not_nil result
|
49
|
+
assert_equal 4, api.config.options.length
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gmaps_geocoding
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christian Kakesa
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.6.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.7
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: yajl-ruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.1.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.1.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: nori
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.0.4
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.4
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: nokogiri
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.4.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.4.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.3'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.3'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: ! "\n A simple Ruby gem for Google Maps Geocoding API.\n This gem
|
111
|
+
return a Ruby Hash object of the result.\n "
|
112
|
+
email:
|
113
|
+
- christian.kakesa@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .ruby-version
|
120
|
+
- .travis.yml
|
121
|
+
- .versions.conf
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- gmaps_geocoding.gemspec
|
127
|
+
- lib/gmaps_geocoding.rb
|
128
|
+
- lib/gmaps_geocoding/api.rb
|
129
|
+
- lib/gmaps_geocoding/config.rb
|
130
|
+
- lib/gmaps_geocoding/version.rb
|
131
|
+
- test/gmaps_geocoding_test.rb
|
132
|
+
homepage: https://github.com/fenicks/gmaps_geocoding
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ! '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 1.8.25
|
154
|
+
signing_key:
|
155
|
+
specification_version: 3
|
156
|
+
summary: Use Google Geocoding API from Ruby.
|
157
|
+
test_files:
|
158
|
+
- test/gmaps_geocoding_test.rb
|