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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51a68d049f34c5463d1ee554288e7b3178915f49
4
- data.tar.gz: ad7a43f2fe5e49777237efbc6ca0a2873d7184ae
3
+ metadata.gz: 5dfdc875f01c283bc64a7dfe4f3fa7fd3e7677bf
4
+ data.tar.gz: 4654a535057de064c04b8263118d51ba5ccebfda
5
5
  SHA512:
6
- metadata.gz: d079cd0f62960e9b759e70eb219cc40046809cb9f050496fab198d2782ec3b4a8f395f8536476aa45e04a120391ecf9feda23d95dd222675b7a2b00000cad148
7
- data.tar.gz: 5338bfc6faacc5de7d5e057dde973bb31a6521b93db965d17ef6ae8a58955b12659b98c00f9e7458b6e0c63bb595c4e1e6e4a0c6602a48303414a1c41241a4ee
6
+ metadata.gz: 550620e8885b7c670887ee29dd6c22f1ba2763e509f1c0526a014e5673785322c6b74df5f8a52e3327bbf457c7941778e9a8cdc9a19b0ca8fdb68219eb4f15aa
7
+ data.tar.gz: 815ce9588b3437188a488dbd80bba8d101edb217fc8fb215b2374e44495d13820027c8dc58c975e3ee400a5b887283a5c3af0f673146116e6f8ef359a4013af4
@@ -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(IMGUR_API_KEY)
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
@@ -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(UrlCache.cached_radar_url(code))
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
@@ -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 self.cached_radar_url(radar_code)
9
- radar_url = REDIS.get("#{radar_code}_gif")
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
- REDIS.set("#{radar_code}_gif", radar_url, ex: CACHE_EXPIRY)
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.0.0
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-03-31 00:00:00.000000000 Z
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: Response is limited to locations around Australia that have a radar
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 slackbot that posts a GIF of the most recent weather radar of a given location
148
- in Australia
149
+ summary: A lita plugin that responds to requests to check the weather in Australia
149
150
  test_files: []