gogo_maps 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +7 -0
- data/gogo_maps.gemspec +25 -0
- data/lib/gogo_maps/version.rb +3 -0
- data/lib/gogo_maps.rb +41 -0
- data/spec/gogo_maps_spec.rb +44 -0
- data/spec/spec_helper.rb +2 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 138dba58c1abed99303b17676aa6d3e35dacead5
|
4
|
+
data.tar.gz: c7f96e7a130276c9bfc530c2b96da6349cfad2b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34f9c1d25e107718b38eab66ad742e3223abc65f58069ba5116c7dc634df87b638067b9cb0fce9d69852dd4a4cb58a847e3372065aa5f9da429cebec26012df4
|
7
|
+
data.tar.gz: 1c16213c7932269e32d0048cae49cbaf689ce0d5b39f7c2d8915da3e10f578ea71420abdc4be57ea6b1d464a93ffa26f43148f6430b9f6fa638eef7f6333a3c0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 gogotanaka
|
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,31 @@
|
|
1
|
+
# GogoMaps
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gogo_maps'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gogo_maps
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/gogo_maps/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/gogo_maps.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gogo_maps/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gogo_maps"
|
8
|
+
spec.version = GogoMaps::VERSION
|
9
|
+
spec.authors = ["gogotanaka"]
|
10
|
+
spec.email = ["mail@tanakakazuki.com"]
|
11
|
+
spec.summary = %q{Super simple geocode interface for Ruby.}
|
12
|
+
spec.description = %q{Super simple geocode interface for Ruby.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "faraday"
|
25
|
+
end
|
data/lib/gogo_maps.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require "gogo_maps/version"
|
2
|
+
require 'faraday'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module GogoMaps
|
6
|
+
# @param Hash opts - to support below Ruby1.9x.
|
7
|
+
def self.get(opts={})
|
8
|
+
fail 'Should provide either address or latlng' unless opts[:address] || opts[:latlng]
|
9
|
+
|
10
|
+
GoogleMapClient.call(
|
11
|
+
{ language: :ja, sensor: false }.merge(opts),
|
12
|
+
opts[:address] ? :to_latlng : :to_address
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
class GoogleMapClient
|
17
|
+
ENDPOINT = 'http://maps.googleapis.com'
|
18
|
+
@@_conn ||= Faraday.new(url: ENDPOINT) do |faraday|
|
19
|
+
faraday.request :url_encoded
|
20
|
+
faraday.response :logger
|
21
|
+
faraday.adapter Faraday.default_adapter
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.call(params, sym)
|
25
|
+
response = @@_conn.get do |req|
|
26
|
+
req.url '/maps/api/geocode/json'
|
27
|
+
req.params = params
|
28
|
+
end
|
29
|
+
|
30
|
+
unless location = JSON.parse(response.body)['results'][0]
|
31
|
+
fail 'Something wrong with Google API or your params'
|
32
|
+
end
|
33
|
+
|
34
|
+
case sym
|
35
|
+
when :to_latlng then location['geometry']['location']
|
36
|
+
when :to_address then location['formatted_address']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GogoMaps do
|
4
|
+
it 'has a version number' do
|
5
|
+
expect(GogoMaps::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.get' do
|
9
|
+
it 'should raise error' do
|
10
|
+
expect { GogoMaps.get }.to raise_error(RuntimeError)
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'to_latlng' do
|
14
|
+
it 'should return proper parameters' do
|
15
|
+
expect(
|
16
|
+
GogoMaps.get(address: '長野県上高井郡高山村')
|
17
|
+
).to eq(
|
18
|
+
{"lat"=>36.6797676, "lng"=>138.3632554}
|
19
|
+
)
|
20
|
+
expect(
|
21
|
+
GogoMaps.get(address: '神奈川県横浜市港北区日吉')
|
22
|
+
).to eq(
|
23
|
+
{"lat"=>35.5565107, "lng"=>139.6460026}
|
24
|
+
)
|
25
|
+
expect(
|
26
|
+
GogoMaps.get(address: '902 Rockefeller Dr, Sunnyvale, CA', language: :en)
|
27
|
+
).to eq(
|
28
|
+
{"lat"=>37.358126, "lng"=>-122.050636}
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'to_address' do
|
34
|
+
it 'should return proper parameters' do
|
35
|
+
expect(
|
36
|
+
GogoMaps.get(latlng: '35.6506135,139.7539103')
|
37
|
+
).to eq(
|
38
|
+
'日本, 東京都港区芝1丁目11−14'
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gogo_maps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- gogotanaka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Super simple geocode interface for Ruby.
|
70
|
+
email:
|
71
|
+
- mail@tanakakazuki.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- gogo_maps.gemspec
|
84
|
+
- lib/gogo_maps.rb
|
85
|
+
- lib/gogo_maps/version.rb
|
86
|
+
- spec/gogo_maps_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
homepage: ''
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Super simple geocode interface for Ruby.
|
112
|
+
test_files:
|
113
|
+
- spec/gogo_maps_spec.rb
|
114
|
+
- spec/spec_helper.rb
|