lita-raindar 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/imgur_gateway.rb +7 -3
- data/lib/lita-raindar.rb +19 -1
- data/lib/url_cache.rb +7 -4
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dfdc875f01c283bc64a7dfe4f3fa7fd3e7677bf
|
4
|
+
data.tar.gz: 4654a535057de064c04b8263118d51ba5ccebfda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 550620e8885b7c670887ee29dd6c22f1ba2763e509f1c0526a014e5673785322c6b74df5f8a52e3327bbf457c7941778e9a8cdc9a19b0ca8fdb68219eb4f15aa
|
7
|
+
data.tar.gz: 815ce9588b3437188a488dbd80bba8d101edb217fc8fb215b2374e44495d13820027c8dc58c975e3ee400a5b887283a5c3af0f673146116e6f8ef359a4013af4
|
data/lib/imgur_gateway.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'imgur'
|
2
2
|
|
3
3
|
class ImgurGateway
|
4
|
-
IMGUR_API_KEY = ENV['IMGUR_API_KEY']
|
5
4
|
|
6
5
|
attr_accessor :filename, :title, :url
|
7
6
|
|
@@ -12,11 +11,12 @@ class ImgurGateway
|
|
12
11
|
|
13
12
|
def upload
|
14
13
|
return false unless filename
|
15
|
-
client = Imgur.new(
|
14
|
+
client = Imgur.new(imgur_api_key)
|
16
15
|
image = Imgur::LocalImage.new(filename, title: title)
|
17
16
|
uploaded = client.upload(image)
|
18
17
|
@url = uploaded.link
|
19
|
-
rescue
|
18
|
+
rescue Exception => e
|
19
|
+
puts "Error uploading to imgur #{e}"
|
20
20
|
return false
|
21
21
|
end
|
22
22
|
|
@@ -26,4 +26,8 @@ class ImgurGateway
|
|
26
26
|
"Raindar #{Time.now.strftime('%A, %B %d, %Y')}"
|
27
27
|
end
|
28
28
|
|
29
|
+
def imgur_api_key
|
30
|
+
Lita.config.handlers.raindar.imgur_api_key
|
31
|
+
end
|
32
|
+
|
29
33
|
end
|
data/lib/lita-raindar.rb
CHANGED
@@ -4,8 +4,10 @@ require_relative "url_cache"
|
|
4
4
|
module Lita
|
5
5
|
module Handlers
|
6
6
|
class Raindar < Handler
|
7
|
+
config :imgur_api_key
|
7
8
|
|
8
9
|
route(/^weather ([a-zA-Z0-9\s]*)$/i, :radar, command: true, help: { "weather LOCATION" => "Returns GIF of recent weather radar" })
|
10
|
+
route(/^(radar locations)$/i, :radar_locations, command: true, help: { "radar locations" => "Returns list of available radar locations" })
|
9
11
|
|
10
12
|
RADARS = {
|
11
13
|
"melbourne" => "IDR023",
|
@@ -67,11 +69,27 @@ module Lita
|
|
67
69
|
if code.nil?
|
68
70
|
response.reply("Location not currently available")
|
69
71
|
else
|
70
|
-
response.reply(
|
72
|
+
response.reply(url_cache.cached_radar_url(code))
|
71
73
|
end
|
72
74
|
|
73
75
|
end
|
74
76
|
|
77
|
+
def radar_locations(response)
|
78
|
+
response.reply(radar_list.join(", "))
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def url_cache
|
84
|
+
UrlCache.new(redis)
|
85
|
+
end
|
86
|
+
|
87
|
+
def radar_list
|
88
|
+
RADARS.keys.sort.map do |location|
|
89
|
+
location.capitalize
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
75
93
|
Lita.register_handler(self)
|
76
94
|
|
77
95
|
end
|
data/lib/url_cache.rb
CHANGED
@@ -2,14 +2,17 @@ require 'redis'
|
|
2
2
|
require_relative "radar_generator"
|
3
3
|
|
4
4
|
class UrlCache
|
5
|
-
REDIS = Redis.new(url: URI.parse(ENV["REDISTOGO_URL"] || "redis://127.0.0.1"))
|
6
5
|
CACHE_EXPIRY = 300 # seconds
|
7
6
|
|
8
|
-
def
|
9
|
-
|
7
|
+
def initialize(redis)
|
8
|
+
@redis = redis
|
9
|
+
end
|
10
|
+
|
11
|
+
def cached_radar_url(radar_code)
|
12
|
+
radar_url = @redis.get("#{radar_code}_gif")
|
10
13
|
unless radar_url
|
11
14
|
radar_url = RadarGenerator.gif(radar_code)
|
12
|
-
|
15
|
+
@redis.set("#{radar_code}_gif", radar_url, ex: CACHE_EXPIRY)
|
13
16
|
end
|
14
17
|
radar_url
|
15
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-raindar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eleanor Kiefel Haggerty
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,7 +108,9 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description:
|
111
|
+
description: Lita chatbot reponds to user requests of 'weather LOCATION' with a GIF
|
112
|
+
of the weather in specified location. Response is limited to Australian locations
|
113
|
+
with a radar listed on the Bureau of Meteorology
|
112
114
|
email:
|
113
115
|
- eleanorakh@gmail.com
|
114
116
|
executables: []
|
@@ -144,6 +146,5 @@ rubyforge_project:
|
|
144
146
|
rubygems_version: 2.5.1
|
145
147
|
signing_key:
|
146
148
|
specification_version: 4
|
147
|
-
summary: A
|
148
|
-
in Australia
|
149
|
+
summary: A lita plugin that responds to requests to check the weather in Australia
|
149
150
|
test_files: []
|