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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -0
  3. data/lib/lita/handlers/cricket.rb +25 -13
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c638ba5ba8f85f6a7ec494d3dd863571b068cf5d
4
- data.tar.gz: 47f8400449b02dedc21fb73b1423a1b314bd620d
3
+ metadata.gz: bc6176aa9d1a016b6fe0afeebce549d554db81e7
4
+ data.tar.gz: a98b714bb1d4c4d197dae5cad64aa9e9082c0195
5
5
  SHA512:
6
- metadata.gz: 5a3e9bbdeb8b625047cd39704a7c020258895af0a095cccad3eac88c4249fa7e741f7f99d5dd3c5fcb6607833180575290639379f9c3decca6b62ad7e59a4518
7
- data.tar.gz: bca90ad637245dd4c17a5c262f47708eb774acc7b661419d7cd0890bd5d4ea0eacb7b556518c5933105a891d1fcd3c550551babcbef44941a5d9d0e4230c0479
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.3'
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
- elsif
88
- matches = get_list_of_live_matches
89
- matches.each do |m|
90
- unless ([ m['t1'], m['t2']] & my_favourites).empty?
91
- subscribe_to(response,m['id'],'match')
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
- #TODO: parse this list and keep going!!!
128
- response.reply("There are #{resp.count} live matches on!")
129
- resp.each do |r|
130
- response.reply("#{r['t1']} vs #{r['t2']} (http://www.espncricinfo.com/c/engine/match/#{r['id']}.html)")
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
- rescue
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).parsed_response
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.3
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-07-27 00:00:00.000000000 Z
11
+ date: 2015-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita