lita-directions 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/lita/handlers/directions.rb +23 -24
- data/lita-directions.gemspec +4 -2
- data/spec/spec_helper.rb +0 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64e721e5fe4ab244ec7d56fae01fb4010d2dfd8c
|
4
|
+
data.tar.gz: a434f529efaf90a707c57afd93044fb21b063c87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2985257c6128ae38018d8aa115b75514b1c73711dac01320ceedcb54a7914067410ad7aa00f06fe7fbf65fa9bd5a07d9b96b7356934b52021cbd59645be2a844
|
7
|
+
data.tar.gz: cc82ca6cc34bbb077ae5eecc35205a125ec49a20efcfcfaaffd8080b09a13c41c0d743e19c8ea636544ac965e84f63e81e02b75e639b8a118f5643c193a35a05
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ This plugin requires a api key from The Google Directions api.
|
|
16
16
|
|
17
17
|
``` ruby
|
18
18
|
Lita.configure do |config|
|
19
|
-
config.handlers.directions.
|
19
|
+
config.handlers.directions.google_api_key = "xxxxxxxxxxxx-1234567890"
|
20
20
|
end
|
21
21
|
```
|
22
22
|
|
@@ -1,30 +1,29 @@
|
|
1
1
|
module Lita
|
2
2
|
module Handlers
|
3
3
|
class Directions < Handler
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
4
|
+
require 'rest-client'
|
5
|
+
|
6
|
+
config :google_api_key
|
7
|
+
|
8
|
+
route(/^(?:how\s+do\s+I\s+you\s+get\s+far\s+is\s+it\s+from\s+)?(.+)\s+to(.+)/i, :get_directions, command: true)
|
9
|
+
|
10
|
+
def get_directions(response)
|
11
|
+
if Lita.config.handlers.directions.google_api_key.nil?
|
12
|
+
response.reply("Please get an API key from https://console.developers.google.com, and follow the instructions on https://github.com/cashman04/lita-directions to configure.")
|
13
|
+
return
|
14
|
+
end
|
15
|
+
from = response.matches[0][0]
|
16
|
+
to = response.matches[0][1]
|
17
|
+
json_ip_url = "https://maps.googleapis.com/maps/api/directions/json?origin=#{from}&destination=#{to}&key=#{Lita.config.handlers.directions.google_api_key}"
|
18
|
+
results = JSON.parse(RestClient.get(json_ip_url))
|
19
|
+
if results['routes'].any?
|
20
|
+
response.reply("It is a #{results['routes'][0]['legs'][0]['distance']['text'].gsub('mi', 'miles')} drive from #{results['routes'][0]['legs'][0]['start_address'].gsub(', USA', '').gsub(/\d{5}/, '')} to #{results['routes'][0]['legs'][0]['end_address'].gsub(', USA', '').gsub(/\d{5}/, '')}. The approximate drive time is #{results['routes'][0]['legs'][0]['duration']['text'].gsub('mins', 'minutes')}.")
|
21
|
+
response.reply(URI.encode("https://www.google.com/maps/dir/#{from}/#{to}/"))
|
22
|
+
else
|
23
|
+
response.reply(["Umm, you might want to double-check that.", "I think you did it wrong.", "There was an error, I think it was your fault.", "I'm pretty sure you messed up.", "Are you sure you read the directions?"].sample)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
28
27
|
end
|
29
28
|
|
30
29
|
Lita.register_handler(Directions)
|
data/lita-directions.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-directions"
|
3
|
-
spec.version = "0.0.
|
3
|
+
spec.version = "0.0.9"
|
4
4
|
spec.authors = ["Dan Cash"]
|
5
5
|
spec.email = ["dancash04@gmail.com"]
|
6
6
|
spec.description = %q{A Lita handler to get time/distance calculations and provide directions from google maps}
|
@@ -15,8 +15,10 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
|
17
17
|
spec.add_runtime_dependency "lita", ">= 4.1"
|
18
|
+
spec.add_runtime_dependency 'rest-client'
|
18
19
|
|
19
20
|
spec.add_development_dependency "bundler", "~> 1.3"
|
20
21
|
spec.add_development_dependency "rspec", ">= 3.0.0"
|
21
|
-
|
22
|
+
|
23
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
22
24
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,7 +8,6 @@ SimpleCov.start { add_filter "/spec/" }
|
|
8
8
|
|
9
9
|
require "lita-directions"
|
10
10
|
require "lita/rspec"
|
11
|
-
|
12
11
|
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
|
13
12
|
# was generated with Lita 4, the compatibility mode should be left disabled.
|
14
13
|
Lita.version_3_compatibility_mode = false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-directions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Cash
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,20 +66,6 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 3.0.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rest-client
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.0'
|
69
69
|
description: A Lita handler to get time/distance calculations and provide directions
|
70
70
|
from google maps
|
71
71
|
email:
|