geogle 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +4 -0
- data/Gemfile +4 -0
- data/Guardfile +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +8 -0
- data/geogle.gemspec +32 -0
- data/lib/geogle.rb +14 -0
- data/lib/geogle/base.rb +23 -0
- data/lib/geogle/directions.rb +7 -0
- data/lib/geogle/error.rb +10 -0
- data/lib/geogle/error_handler.rb +16 -0
- data/lib/geogle/geocoder.rb +20 -0
- data/lib/geogle/model.rb +11 -0
- data/lib/geogle/model/address.rb +24 -0
- data/lib/geogle/model/area.rb +15 -0
- data/lib/geogle/model/coordinates.rb +18 -0
- data/lib/geogle/model/geometry.rb +18 -0
- data/lib/geogle/model/place.rb +81 -0
- data/lib/geogle/parametizer.rb +31 -0
- data/lib/geogle/parser.rb +77 -0
- data/lib/geogle/url.rb +9 -0
- data/lib/geogle/url_builder.rb +51 -0
- data/lib/geogle/version.rb +3 -0
- data/spec/fixtures/cassettes/geocode_by_address.yml +137 -0
- data/spec/fixtures/cassettes/geocode_by_latlng.yml +509 -0
- data/spec/geogle/client_spec.rb +35 -0
- data/spec/geogle/parser_spec.rb +151 -0
- data/spec/geogle/url_builder_spec.rb +32 -0
- data/spec/spec_helper.rb +12 -0
- data/wercker.yml +15 -0
- metadata +223 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 420f8dc09e9f029c43118d8657382817e7c3c4f8
|
4
|
+
data.tar.gz: 307cf748f3fcb120c21f6022dc11613e84b4c140
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7dbffd7b45e1688419d70177f8b3762050bb499b766fff93838886706f3cb568fd81ccf69c4701114f0ef88cd83c6851bb8223e9fff8002bd0d5e44e00c2f603
|
7
|
+
data.tar.gz: fc46aa55ac9c5126a4001132f81a4d83b369a6bb587a8e6c6e8499a85d20b6059aca31b613db433250f6dd1ca6babe687459ab23f5b463252c7ded7fc8f48464
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara features specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 yone_lc
|
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,68 @@
|
|
1
|
+
# Geogle
|
2
|
+
|
3
|
+
[![wercker status](https://app.wercker.com/status/6122e4f0966ee255949e2eb465aefd10/m "wercker status")](https://app.wercker.com/project/bykey/6122e4f0966ee255949e2eb465aefd10)
|
4
|
+
|
5
|
+
Still in development. Ruby wrapper for the Geocoding service provided from the Google Maps API.
|
6
|
+
|
7
|
+
|
8
|
+
Documentation
|
9
|
+
https://developers.google.com/maps/documentation/geocoding/
|
10
|
+
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'geogle'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install geogle
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
When creating the Geogle::Client instance you can pass:
|
29
|
+
|
30
|
+
* sensor: true or false (false by default)
|
31
|
+
* language: ("en" by default).
|
32
|
+
|
33
|
+
In case you wanna use Google Maps API for Business, you'll need to pass the following attributes in order to sign the URL.
|
34
|
+
* client_id: ID of the client. It starts with "gme-" prefix.
|
35
|
+
* crypto_key: Criptographic key.
|
36
|
+
|
37
|
+
Here's more information about Google Maps API for Business:
|
38
|
+
https://developers.google.com/maps/documentation/business/webservices
|
39
|
+
|
40
|
+
### Geocode by address with non-Business account
|
41
|
+
|
42
|
+
$ client = Geogle::Client.new({ sensor: false, language: "es" })
|
43
|
+
$ client.address("Blasco Ibañez, Valencia")
|
44
|
+
|
45
|
+
### Geocode by address making use of the components
|
46
|
+
|
47
|
+
$ client = Geogle::Client.new({ sensor: false, language: "es" })
|
48
|
+
$ components = { country: 'ES' }
|
49
|
+
$ client.address("Blasco Ibañez, Valencia", components)
|
50
|
+
|
51
|
+
Available components to be used can be found here:
|
52
|
+
https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering
|
53
|
+
|
54
|
+
### Using a business account
|
55
|
+
|
56
|
+
$ client = Geogle::Client.new({ client_id: "gme-client-id", crypto_key: "crypto-key" })
|
57
|
+
$ Geogle::Client.new.latlng(39.5073225, -0.2914778)
|
58
|
+
|
59
|
+
The signature required to do the request will be included in the URL.
|
60
|
+
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
1. Fork it
|
65
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
67
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/geogle.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'geogle/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "geogle"
|
8
|
+
spec.version = Geogle::VERSION
|
9
|
+
spec.authors = ["yone_lc"]
|
10
|
+
spec.email = ["yonelacort@gmail.com"]
|
11
|
+
spec.description = %q{Ruby wrapper for Google MAPS API V3 geocode interface}
|
12
|
+
spec.summary = %q{Provides a Ruby interface to geocode requests to Google Maps API V3 and parse the response}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'faraday'
|
22
|
+
spec.add_dependency 'virtus'
|
23
|
+
spec.add_dependency 'ruby-hmac'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "vcr"
|
29
|
+
spec.add_development_dependency "webmock"
|
30
|
+
spec.add_development_dependency "byebug"
|
31
|
+
spec.add_development_dependency "guard-rspec"
|
32
|
+
end
|
data/lib/geogle.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Geogle
|
4
|
+
require "geogle/version"
|
5
|
+
require "geogle/model"
|
6
|
+
require "geogle/base"
|
7
|
+
require "geogle/geocoder"
|
8
|
+
require "geogle/error"
|
9
|
+
require "geogle/error_handler"
|
10
|
+
require "geogle/parametizer"
|
11
|
+
require "geogle/parser"
|
12
|
+
require "geogle/url"
|
13
|
+
require "geogle/url_builder"
|
14
|
+
end
|
data/lib/geogle/base.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Geogle
|
7
|
+
class Base
|
8
|
+
def initialize(args = {})
|
9
|
+
@args = args
|
10
|
+
@parametizer = Parametizer.new(args)
|
11
|
+
@conn = Faraday.new
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def request(url, params)
|
17
|
+
response = @conn.get(UrlBuilder.new(url, @args).build(params))
|
18
|
+
body = JSON.parse(response.body)
|
19
|
+
ErrorHandler.check(body['status'])
|
20
|
+
body
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/geogle/error.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Geogle
|
4
|
+
module ErrorHandler
|
5
|
+
def self.check(status)
|
6
|
+
case status
|
7
|
+
when 'REQUEST_DENIED'
|
8
|
+
raise RequestDeniedError
|
9
|
+
when 'INVALID_REQUEST'
|
10
|
+
raise BadRequestError
|
11
|
+
when 'OVER_QUERY_LIMIT'
|
12
|
+
raise OverQueryError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Geogle
|
4
|
+
class Geocoder < Base
|
5
|
+
def address(address, components = {})
|
6
|
+
executor(:address, address, components)
|
7
|
+
end
|
8
|
+
|
9
|
+
def latlng(lat, lng)
|
10
|
+
executor(:latlng, lat, lng)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def executor(method, arg1, arg2)
|
16
|
+
body = request(URL::GEOCODE, @parametizer.send(method, arg1, arg2))
|
17
|
+
Parser.places(body["results"])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/geogle/model.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'virtus'
|
4
|
+
|
5
|
+
module Geogle
|
6
|
+
module Model
|
7
|
+
|
8
|
+
class Address
|
9
|
+
include Virtus.model
|
10
|
+
|
11
|
+
attribute :street_number, String
|
12
|
+
attribute :street, String
|
13
|
+
attribute :locality, String
|
14
|
+
attribute :area_level_1, String
|
15
|
+
attribute :area_level_1_code, String
|
16
|
+
attribute :area_level_2, String
|
17
|
+
attribute :area_level_2_code, String
|
18
|
+
attribute :country, String
|
19
|
+
attribute :country_code, String
|
20
|
+
attribute :formatted, String
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'virtus'
|
4
|
+
require_relative 'area'
|
5
|
+
require_relative 'coordinates'
|
6
|
+
|
7
|
+
module Geogle
|
8
|
+
module Model
|
9
|
+
class Geometry
|
10
|
+
include Virtus.model
|
11
|
+
|
12
|
+
attribute :location, Coordinates
|
13
|
+
attribute :location_type, String
|
14
|
+
attribute :bounds, Area
|
15
|
+
attribute :viewport, Area
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'virtus'
|
4
|
+
require_relative 'address'
|
5
|
+
require_relative 'geometry'
|
6
|
+
|
7
|
+
module Geogle
|
8
|
+
module Model
|
9
|
+
class Place
|
10
|
+
include Virtus.model
|
11
|
+
|
12
|
+
TYPES = %w(street_address
|
13
|
+
route political
|
14
|
+
country
|
15
|
+
administrative_area_level_1
|
16
|
+
administrative_area_level_2
|
17
|
+
administrative_area_level_3
|
18
|
+
colloquial_area
|
19
|
+
locality
|
20
|
+
sublocality
|
21
|
+
neighborhood
|
22
|
+
premise
|
23
|
+
subpremise
|
24
|
+
postal_code
|
25
|
+
natural_feature
|
26
|
+
airport
|
27
|
+
park
|
28
|
+
point_of_interest
|
29
|
+
post_box
|
30
|
+
street_number
|
31
|
+
floor
|
32
|
+
room)
|
33
|
+
|
34
|
+
attribute :geometry, Geometry
|
35
|
+
attribute :address, Address
|
36
|
+
|
37
|
+
def geo_location
|
38
|
+
geometry.location
|
39
|
+
end
|
40
|
+
|
41
|
+
def street
|
42
|
+
address.street
|
43
|
+
end
|
44
|
+
|
45
|
+
def locality
|
46
|
+
address.locality
|
47
|
+
end
|
48
|
+
|
49
|
+
def city
|
50
|
+
address.area_level_2
|
51
|
+
end
|
52
|
+
|
53
|
+
def state
|
54
|
+
address.area_level_1
|
55
|
+
end
|
56
|
+
|
57
|
+
def country
|
58
|
+
address.country
|
59
|
+
end
|
60
|
+
|
61
|
+
def country_code
|
62
|
+
address.country_code
|
63
|
+
end
|
64
|
+
|
65
|
+
def method_missing(method, &block)
|
66
|
+
if method.to_s =~ /^is_(.+?)?$/ && TYPES.include?(method)
|
67
|
+
is_type?($1)
|
68
|
+
else
|
69
|
+
super
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def is_type?(type)
|
76
|
+
# TODO
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|