lita-cricket 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +9 -0
- data/lib/lita/handlers/cricket.rb +25 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc6176aa9d1a016b6fe0afeebce549d554db81e7
|
4
|
+
data.tar.gz: a98b714bb1d4c4d197dae5cad64aa9e9082c0195
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 303277d220fbcc0fb3574a87471853048b279cef20760756e28ccbe145e92c83dd31c1ffe0ede776ff73f02451eb3215b79e59cabf5a754abf583d3dd0fcb981
|
7
|
+
data.tar.gz: 44ac23ec8fe8aac2cd01d4317d068b803669564da930cfca9ce98e8c393c78232065c4dcf6de833e53667f8ba3387eadb96f19808eb5f260f8694a36ce287c2a
|
data/Rakefile
CHANGED
@@ -4,3 +4,12 @@ require "rspec/core/rake_task"
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
6
|
task default: :spec
|
7
|
+
|
8
|
+
# rake console is fun!
|
9
|
+
task :console do
|
10
|
+
require 'irb'
|
11
|
+
require 'irb/completion'
|
12
|
+
require 'lita-cricket' # You know what to do.
|
13
|
+
ARGV.clear
|
14
|
+
IRB.start
|
15
|
+
end
|
@@ -2,7 +2,7 @@ module Lita
|
|
2
2
|
module Handlers
|
3
3
|
class Cricket < Handler
|
4
4
|
# Version
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.4'
|
6
6
|
|
7
7
|
# Dependencies
|
8
8
|
require 'json'
|
@@ -84,11 +84,13 @@ module Lita
|
|
84
84
|
if my_favourites.empty?
|
85
85
|
set_my_subscriptions(response,['Australia'].to_json,'favourite')
|
86
86
|
response.reply('I can give you live cricket updates! Type `help cricket` for more information.')
|
87
|
-
|
88
|
-
matches = get_list_of_live_matches
|
89
|
-
|
90
|
-
|
91
|
-
|
87
|
+
else
|
88
|
+
status, matches = get_list_of_live_matches
|
89
|
+
if status == :success
|
90
|
+
matches.each do |m|
|
91
|
+
unless ([ m['t1'], m['t2']] & my_favourites).empty?
|
92
|
+
subscribe_to(response,m['id'],'match')
|
93
|
+
end
|
92
94
|
end
|
93
95
|
end
|
94
96
|
end
|
@@ -123,13 +125,18 @@ module Lita
|
|
123
125
|
end
|
124
126
|
|
125
127
|
def list(response)
|
126
|
-
resp = get_list_of_live_matches
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
status, resp = get_list_of_live_matches
|
129
|
+
if status == :success
|
130
|
+
response.reply("There are #{resp.count} live matches on!")
|
131
|
+
resp.each do |m|
|
132
|
+
response.reply("#{m['t1']} vs #{m['t2']} (http://www.espncricinfo.com/c/engine/match/#{m['id']}.html)")
|
133
|
+
end
|
134
|
+
else
|
135
|
+
Lita.logger.error(resp.inspect)
|
136
|
+
response.reply("It looks like the API is down - #{resp.response.code}")
|
131
137
|
end
|
132
|
-
|
138
|
+
|
139
|
+
rescue => e
|
133
140
|
response.reply("An error may have occured, or maybe there are no live matches")
|
134
141
|
end
|
135
142
|
|
@@ -159,7 +166,12 @@ module Lita
|
|
159
166
|
end
|
160
167
|
|
161
168
|
def get_list_of_live_matches
|
162
|
-
HTTParty.get(@@ENDPOINT)
|
169
|
+
resp = HTTParty.get(@@ENDPOINT)
|
170
|
+
if resp.response.code.to_i > 299 || resp.response.code.to_i < 200
|
171
|
+
return :failure, resp
|
172
|
+
else
|
173
|
+
return :success, resp.parsed_response
|
174
|
+
end
|
163
175
|
end
|
164
176
|
|
165
177
|
def get_match_score(response,id)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-cricket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Auld
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|