pointy 0.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +2 -0
- data/lib/pointy.rb +54 -0
- data/lib/pointy/version.rb +3 -0
- data/pointy.gemspec +26 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2f1a3d3405897e0f0c33e507cd97ffe4c0ca827
|
4
|
+
data.tar.gz: 1d84ca813e3f761739da87dd9362864759285dab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 58c58e86aae685cba6e36c838943adf0ce087cf4008c5edbe356384fb93a7320301636f933a6692c053d71b72b142513b2bfc5e7292f63b9c1bba23f7a2fbcc6
|
7
|
+
data.tar.gz: 422ab752225df60506f7d932ccade2757b51465691a1a9d585e0f56e4d224c9eda5cc573e461fa46b98f314c52d24874f0ca53592a7c0a54a385d90b294c2b0f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Chris Sloey
|
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,50 @@
|
|
1
|
+
# Pointy
|
2
|
+
|
3
|
+
Uses Google Directions API to get a list of points between two locations.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pointy'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pointy
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
1) Set the environment variable `GOOGLE_DIRECTIONS_API_KEY` to your Google Directions API key.
|
24
|
+
|
25
|
+
2) Use the route method to retrieve points between two locations.
|
26
|
+
|
27
|
+
Pointy.route(from, to)
|
28
|
+
|
29
|
+
`from` and `to` should be hashes of the following format
|
30
|
+
|
31
|
+
{
|
32
|
+
lat: 55.8580,
|
33
|
+
long: -4.2590
|
34
|
+
}
|
35
|
+
|
36
|
+
The returned array of points are of the same format.
|
37
|
+
|
38
|
+
You can also pass in any other query parameters accepted by Google, so you override the API key or transport mode
|
39
|
+
|
40
|
+
Pointy.route(from, to, {key: 'my-api-key', mode: 'walking'})
|
41
|
+
|
42
|
+
The mode defaults to 'walking' and sensor defaults to false.
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it ( https://github.com/addjam/pointy/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/pointy.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative "./pointy/version"
|
2
|
+
require "httparty"
|
3
|
+
require "polylines"
|
4
|
+
|
5
|
+
module Pointy
|
6
|
+
include HTTParty
|
7
|
+
base_uri 'https://maps.googleapis.com/maps/api'
|
8
|
+
|
9
|
+
default_params mode: 'walking'
|
10
|
+
default_params sensor: 'false'
|
11
|
+
default_params key: ENV['GOOGLE_DIRECTIONS_API_KEY']
|
12
|
+
|
13
|
+
# from and to should be of format:
|
14
|
+
# {
|
15
|
+
# lat: float
|
16
|
+
# long: float
|
17
|
+
# }
|
18
|
+
def self.route(from, to, opts={})
|
19
|
+
# Format points for Google API
|
20
|
+
opts.merge!({
|
21
|
+
origin: "#{from[:lat]},#{from[:long]}",
|
22
|
+
destination: "#{to[:lat]},#{to[:long]}"
|
23
|
+
})
|
24
|
+
|
25
|
+
response = get('/directions/json', query: opts)
|
26
|
+
|
27
|
+
# Check there are routes
|
28
|
+
routes = response['routes']
|
29
|
+
return if routes.nil? or routes.empty?
|
30
|
+
|
31
|
+
# Gather all route points
|
32
|
+
route = routes.first
|
33
|
+
legs = route['legs']
|
34
|
+
return if legs.nil? or legs.empty?
|
35
|
+
|
36
|
+
points = []
|
37
|
+
legs.each do |leg|
|
38
|
+
steps = leg['steps']
|
39
|
+
next unless steps
|
40
|
+
steps.each_with_index do |step, index|
|
41
|
+
polyline = step['polyline']['points']
|
42
|
+
decoded_poly = Polylines::Decoder.decode_polyline(polyline)
|
43
|
+
points += decoded_poly.map do |coord|
|
44
|
+
{
|
45
|
+
lat: coord.first,
|
46
|
+
long: coord.last
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
points
|
53
|
+
end
|
54
|
+
end
|
data/pointy.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pointy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pointy"
|
8
|
+
spec.version = Pointy::VERSION
|
9
|
+
spec.authors = ["Chris Sloey"]
|
10
|
+
spec.email = ["chris@addjam.com"]
|
11
|
+
spec.summary = %q{Uses Google Directions API to get a list of points between two locations.}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/AddJam/pointy"
|
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
|
+
|
24
|
+
spec.add_dependency "httparty", "~> 0.13.1"
|
25
|
+
spec.add_dependency "polylines", "~> 0.1.1"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pointy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Sloey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-16 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: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.13.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.13.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: polylines
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.1.1
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- chris@addjam.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/pointy.rb
|
82
|
+
- lib/pointy/version.rb
|
83
|
+
- pointy.gemspec
|
84
|
+
homepage: https://github.com/AddJam/pointy
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.2.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Uses Google Directions API to get a list of points between two locations.
|
108
|
+
test_files: []
|