geogle 0.2.2 → 0.2.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 420f8dc09e9f029c43118d8657382817e7c3c4f8
4
- data.tar.gz: 307cf748f3fcb120c21f6022dc11613e84b4c140
3
+ metadata.gz: f470b89b70dfc743b33fa0acc1efd0da3bfebc84
4
+ data.tar.gz: 059ef9de83990d21fb60370b919c36354883b398
5
5
  SHA512:
6
- metadata.gz: 7dbffd7b45e1688419d70177f8b3762050bb499b766fff93838886706f3cb568fd81ccf69c4701114f0ef88cd83c6851bb8223e9fff8002bd0d5e44e00c2f603
7
- data.tar.gz: fc46aa55ac9c5126a4001132f81a4d83b369a6bb587a8e6c6e8499a85d20b6059aca31b613db433250f6dd1ca6babe687459ab23f5b463252c7ded7fc8f48464
6
+ metadata.gz: 252efd684801b8f1398f35f1e4fa49b080cc4c67c1f3b8904e4761d1f5e3dc64f67e29983e70e2270dd45015436ba0655e8c69aee09727d4fd960631263ae634
7
+ data.tar.gz: 6df63d56ec93a7415ce1bcab5d8839ae9b5a4ca621197269d90902aa7ae3c1ec941b51193dbe7471fc5ae7974f3602d929e5f090bf26685626ce9b4084fed2b6
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ spec/integration/business_geocoder_spec.rb
19
+ spec/fixtures/cassettes/business_geocode_by_address.yml
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  # Geogle
2
2
 
3
- [![wercker status](https://app.wercker.com/status/6122e4f0966ee255949e2eb465aefd10/m "wercker status")](https://app.wercker.com/project/bykey/6122e4f0966ee255949e2eb465aefd10)
3
+ Still in development!
4
4
 
5
- Still in development. Ruby wrapper for the Geocoding service provided from the Google Maps API.
5
+ [![wercker status](https://app.wercker.com/status/6122e4f0966ee255949e2eb465aefd10/m "wercker status")](https://app.wercker.com/project/bykey/6122e4f0966ee255949e2eb465aefd10)
6
6
 
7
-
8
- Documentation
9
- https://developers.google.com/maps/documentation/geocoding/
7
+ Ruby wrapper for the Geocoding and Directions services provided from the Google Maps API.
10
8
 
11
9
 
12
10
  ## Installation
@@ -25,39 +23,86 @@ Or install it yourself as:
25
23
 
26
24
  ## Usage
27
25
 
28
- When creating the Geogle::Client instance you can pass:
26
+ ### Geocoding
27
+ Google geocoding documentation:
28
+ https://developers.google.com/maps/documentation/geocoding/
29
+
30
+ When creating the Geogle::Geocoder instance you can pass:
29
31
 
30
- * sensor: true or false (false by default)
31
- * language: ("en" by default).
32
+ * **sensor**: true or false (false by default)
33
+ * **language**: ("en" by default).
32
34
 
33
35
  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
+ * **client_id**: ID of the client. It starts with "gme-" prefix.
37
+ * **crypto_key**: Criptographic key.
36
38
 
37
39
  Here's more information about Google Maps API for Business:
38
40
  https://developers.google.com/maps/documentation/business/webservices
39
41
 
40
- ### Geocode by address with non-Business account
41
-
42
- $ client = Geogle::Client.new({ sensor: false, language: "es" })
42
+ There are two methods that can be called:
43
+ * **address**: Geocoding by name of the location.
44
+ * **latlng**: Reverse geocode.
45
+
46
+ Both methods return an array of Geogle::Model::Place. Each place is composed by:
47
+ * **geometry**:
48
+ * **location**:
49
+ * **lat**: Float
50
+ * **lng**: Float
51
+ * **location_type**: String
52
+ * **bounds**:
53
+ * **northeast**:
54
+ * **lat**: Float
55
+ * **lng**: Float
56
+ * **southwest**:
57
+ * **lat**: Float
58
+ * **lng**: Float
59
+ * **viewport**:
60
+ * **northeast**:
61
+ * **lat**: Float
62
+ * **lng**: Float
63
+ * **southwest**:
64
+ * **lat**: Float
65
+ * **lng**: Float
66
+ * **address**:
67
+ * **street_number**: String
68
+ * **street**: String
69
+ * **locality**: String
70
+ * **area_level_1**: String
71
+ * **area_level_1_code**: String
72
+ * **area_level_2**: String
73
+ * **area_level_2_code**: String
74
+ * **country**: String
75
+ * **country_code**: String
76
+ * **formatted**: String
77
+
78
+ ### By address without an account
79
+
80
+ $ client = Geogle::Geocoder.new({ sensor: false, language: "es" })
43
81
  $ client.address("Blasco Ibañez, Valencia")
44
82
 
45
- ### Geocode by address making use of the components
83
+ ### By address making use of the components
46
84
 
47
- $ client = Geogle::Client.new({ sensor: false, language: "es" })
85
+ $ client = Geogle::Geocoder.new({ sensor: false, language: "es" })
48
86
  $ components = { country: 'ES' }
49
87
  $ client.address("Blasco Ibañez, Valencia", components)
50
88
 
51
89
  Available components to be used can be found here:
52
90
  https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering
53
91
 
92
+ ### Reverse geocoding (by latitude and longitude)
93
+
94
+ $ Geogle::Geocoder.new.latlng(39.5073225, -0.2914778)
95
+
54
96
  ### Using a business account
55
97
 
56
- $ client = Geogle::Client.new({ client_id: "gme-client-id", crypto_key: "crypto-key" })
57
- $ Geogle::Client.new.latlng(39.5073225, -0.2914778)
98
+ $ client = Geogle::Geocoder.new({ client_id: "gme-client-id", crypto_key: "crypto-key" })
99
+ $ client.latlng(39.5073225, -0.2914778)
58
100
 
59
101
  The signature required to do the request will be included in the URL.
60
102
 
103
+ ### Directions
104
+ Directions service is still in development
105
+
61
106
 
62
107
  ## Contributing
63
108
 
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'faraday'
22
21
  spec.add_dependency 'virtus'
23
22
  spec.add_dependency 'ruby-hmac'
24
23
 
@@ -1,20 +1,21 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "faraday"
4
3
  require "json"
4
+ require "net/http"
5
5
 
6
6
  module Geogle
7
7
  class Base
8
8
  def initialize(args = {})
9
9
  @args = args
10
10
  @parametizer = Parametizer.new(args)
11
- @conn = Faraday.new
12
11
  end
13
12
 
14
13
  protected
15
14
 
16
15
  def request(url, params)
17
- response = @conn.get(UrlBuilder.new(url, @args).build(params))
16
+ uri = UrlBuilder.new(url, @args).build(params)
17
+ response = Net::HTTP.get_response(uri)
18
+ raise InvalidKeyError if response.code == "403"
18
19
  body = JSON.parse(response.body)
19
20
  ErrorHandler.check(body['status'])
20
21
  body
@@ -33,7 +33,7 @@ module Geogle
33
33
 
34
34
  # encode the signature into base64 for url use form.
35
35
  signature = url_safe_base64_encode(raw_signature)
36
- "#{url.scheme}://#{url.host}#{url_to_sign}&signature=#{signature}"
36
+ URI("#{url.scheme}://#{url.host}#{url_to_sign}&signature=#{signature}")
37
37
  end
38
38
 
39
39
  def url_safe_base64_decode(base64_string)
@@ -1,3 +1,3 @@
1
1
  module Geogle
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -0,0 +1,99 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://maps.googleapis.com/maps/api/geocode/json?address=Berlin&components=country:DE&language=de&sensor=false
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=UTF-8
23
+ Date:
24
+ - Thu, 28 Aug 2014 08:52:39 GMT
25
+ Expires:
26
+ - Fri, 29 Aug 2014 08:52:39 GMT
27
+ Cache-Control:
28
+ - public, max-age=86400
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ Server:
32
+ - mafe
33
+ X-Xss-Protection:
34
+ - 1; mode=block
35
+ X-Frame-Options:
36
+ - SAMEORIGIN
37
+ Alternate-Protocol:
38
+ - 443:quic
39
+ Transfer-Encoding:
40
+ - chunked
41
+ body:
42
+ encoding: UTF-8
43
+ string: |
44
+ {
45
+ "results" : [
46
+ {
47
+ "address_components" : [
48
+ {
49
+ "long_name" : "Berlin",
50
+ "short_name" : "Berlin",
51
+ "types" : [ "locality", "political" ]
52
+ },
53
+ {
54
+ "long_name" : "Berlin",
55
+ "short_name" : "Berlin",
56
+ "types" : [ "administrative_area_level_1", "political" ]
57
+ },
58
+ {
59
+ "long_name" : "Deutschland",
60
+ "short_name" : "DE",
61
+ "types" : [ "country", "political" ]
62
+ }
63
+ ],
64
+ "formatted_address" : "Berlin, Deutschland",
65
+ "geometry" : {
66
+ "bounds" : {
67
+ "northeast" : {
68
+ "lat" : 52.6754542,
69
+ "lng" : 13.7611176
70
+ },
71
+ "southwest" : {
72
+ "lat" : 52.33962959999999,
73
+ "lng" : 13.0911663
74
+ }
75
+ },
76
+ "location" : {
77
+ "lat" : 52.52000659999999,
78
+ "lng" : 13.404954
79
+ },
80
+ "location_type" : "APPROXIMATE",
81
+ "viewport" : {
82
+ "northeast" : {
83
+ "lat" : 52.6754542,
84
+ "lng" : 13.7611176
85
+ },
86
+ "southwest" : {
87
+ "lat" : 52.33962959999999,
88
+ "lng" : 13.0911663
89
+ }
90
+ }
91
+ },
92
+ "types" : [ "locality", "political" ]
93
+ }
94
+ ],
95
+ "status" : "OK"
96
+ }
97
+ http_version:
98
+ recorded_at: Thu, 28 Aug 2014 08:52:39 GMT
99
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://maps.googleapis.com/maps/api/geocode/json?client=gme-foo&language=en&latlng=39.4699075,-0.3762881&sensor=false&signature=hDQSukmnhjyDe6y81ph3C_tbs_M=
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 403
19
+ message: Forbidden
20
+ headers:
21
+ Content-Type:
22
+ - text/plain; charset=UTF-8
23
+ Date:
24
+ - Thu, 28 Aug 2014 12:31:17 GMT
25
+ Pragma:
26
+ - no-cache
27
+ Expires:
28
+ - Fri, 01 Jan 1990 00:00:00 GMT
29
+ Cache-Control:
30
+ - no-cache, must-revalidate
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Server:
34
+ - mafe
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ X-Frame-Options:
38
+ - SAMEORIGIN
39
+ Alternate-Protocol:
40
+ - 443:quic
41
+ Transfer-Encoding:
42
+ - chunked
43
+ body:
44
+ encoding: UTF-8
45
+ string: 'Unable to authenticate the request. Provided ''signature'' is not valid
46
+ for the provided client ID, or the provided ''client'' is not valid. Learn
47
+ more: https://developers.google.com/maps/documentation/business/webservices/auth'
48
+ http_version:
49
+ recorded_at: Thu, 28 Aug 2014 12:31:17 GMT
50
+ recorded_with: VCR 2.8.0
@@ -11,6 +11,18 @@ describe Geogle::Geocoder do
11
11
  end
12
12
  end
13
13
 
14
+ describe 'searching with a non-default locale' do
15
+ let(:places) do
16
+ VCR.use_cassette('geocode_by_address_DE') do
17
+ described_class.new(language: "de").address('Berlin', { country: 'DE' })
18
+ end
19
+ end
20
+
21
+ it "returns an array" do
22
+ expect(places).to be_kind_of(Array)
23
+ end
24
+ end
25
+
14
26
  describe 'searching by latlng' do
15
27
  let(:places) do
16
28
  VCR.use_cassette('geocode_by_latlng') do
@@ -32,4 +44,17 @@ describe Geogle::Geocoder do
32
44
  end
33
45
  end
34
46
  end
47
+
48
+ describe "when using non-valid business credentials" do
49
+ let(:places) do
50
+ VCR.use_cassette('geocode_by_latlng_invalid_business') do
51
+ geocoder = described_class.new(client_id: "gme-foo", crypto_key: "bar")
52
+ geocoder.latlng(39.4699075, -0.3762881)
53
+ end
54
+ end
55
+
56
+ it "an exception InvalidKeyError is raised" do
57
+ expect{ places }.to raise_error(Geogle::InvalidKeyError)
58
+ end
59
+ end
35
60
  end
@@ -4,6 +4,7 @@ describe Geogle::UrlBuilder do
4
4
  let(:params) do
5
5
  {
6
6
  address: "Street FooBar",
7
+ language: "de",
7
8
  sensor: true
8
9
  }
9
10
  end
@@ -13,7 +14,7 @@ describe Geogle::UrlBuilder do
13
14
  let(:business_attrs) { {} }
14
15
 
15
16
  it "the built url doesn't contain a query param signature" do
16
- expect(built_url.to_s).to eq("https://www.foo.com?address=Street+FooBar&sensor=true")
17
+ expect(built_url.to_s).to eq("https://www.foo.com?address=Street+FooBar&language=de&sensor=true")
17
18
  end
18
19
  end
19
20
 
@@ -26,7 +27,7 @@ describe Geogle::UrlBuilder do
26
27
  end
27
28
 
28
29
  it "the built url contains a query param signature" do
29
- expect(built_url).to eq("https://www.foo.com?client=gme-clientid&address=Street+FooBar&sensor=true&signature=JiUf5yTKyPSuD8TebiKdA5kg-kg=\n")
30
+ expect(built_url.to_s).to eq("https://www.foo.com?client=gme-clientid&address=Street+FooBar&language=de&sensor=true&signature=1klekRivPNXr3vOpOixX16LNGuI=")
30
31
  end
31
32
  end
32
33
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geogle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yone_lc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-27 00:00:00.000000000 Z
11
+ date: 2014-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: faraday
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: virtus
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -183,8 +169,10 @@ files:
183
169
  - lib/geogle/url_builder.rb
184
170
  - lib/geogle/version.rb
185
171
  - spec/fixtures/cassettes/geocode_by_address.yml
172
+ - spec/fixtures/cassettes/geocode_by_address_DE.yml
186
173
  - spec/fixtures/cassettes/geocode_by_latlng.yml
187
- - spec/geogle/client_spec.rb
174
+ - spec/fixtures/cassettes/geocode_by_latlng_invalid_business.yml
175
+ - spec/geogle/geocoder_spec.rb
188
176
  - spec/geogle/parser_spec.rb
189
177
  - spec/geogle/url_builder_spec.rb
190
178
  - spec/spec_helper.rb
@@ -216,8 +204,10 @@ summary: Provides a Ruby interface to geocode requests to Google Maps API V3 and
216
204
  the response
217
205
  test_files:
218
206
  - spec/fixtures/cassettes/geocode_by_address.yml
207
+ - spec/fixtures/cassettes/geocode_by_address_DE.yml
219
208
  - spec/fixtures/cassettes/geocode_by_latlng.yml
220
- - spec/geogle/client_spec.rb
209
+ - spec/fixtures/cassettes/geocode_by_latlng_invalid_business.yml
210
+ - spec/geogle/geocoder_spec.rb
221
211
  - spec/geogle/parser_spec.rb
222
212
  - spec/geogle/url_builder_spec.rb
223
213
  - spec/spec_helper.rb