lita-cricket 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfecadb970dc64839f1ddc5bc55733e6c9dae11f
4
- data.tar.gz: ddde15366790faa03f50044e7f06e99c60e72cb5
3
+ metadata.gz: c638ba5ba8f85f6a7ec494d3dd863571b068cf5d
4
+ data.tar.gz: 47f8400449b02dedc21fb73b1423a1b314bd620d
5
5
  SHA512:
6
- metadata.gz: 66ddcade9bde399e134029dff984b61bc70f2f1fd0d38e6f411568f1bc05c3e9c912c7c3bb00c8c6a0deefd9313475a7e4314713b9dab5b05752605a299d6bb7
7
- data.tar.gz: 4a27ddfe693dd4dd654c0ad9fb63373b7d05827361b8b3830f5cfc5142a4fb392a346328234fbb448124bb3b63c3396fa7e4d0addd43e50c0ea2895322830a19
6
+ metadata.gz: 5a3e9bbdeb8b625047cd39704a7c020258895af0a095cccad3eac88c4249fa7e741f7f99d5dd3c5fcb6607833180575290639379f9c3decca6b62ad7e59a4518
7
+ data.tar.gz: bca90ad637245dd4c17a5c262f47708eb774acc7b661419d7cd0890bd5d4ea0eacb7b556518c5933105a891d1fcd3c550551babcbef44941a5d9d0e4230c0479
@@ -2,7 +2,7 @@ module Lita
2
2
  module Handlers
3
3
  class Cricket < Handler
4
4
  # Version
5
- VERSION = '0.0.2'
5
+ VERSION = '0.0.3'
6
6
 
7
7
  # Dependencies
8
8
  require 'json'
@@ -80,22 +80,22 @@ module Lita
80
80
  )
81
81
 
82
82
  def refresh_user(response)
83
- my_favourites = get_my_favourites(response)
83
+ my_favourites = get_my_subscriptions(response,'favourite')
84
84
  if my_favourites.empty?
85
- redis.set("#{response.user.id}-favourites",['Australia'].to_json)
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
87
  elsif
88
88
  matches = get_list_of_live_matches
89
89
  matches.each do |m|
90
90
  unless ([ m['t1'], m['t2']] & my_favourites).empty?
91
- subscribe_to_match(response,m['id'])
91
+ subscribe_to(response,m['id'],'match')
92
92
  end
93
93
  end
94
94
  end
95
95
  end
96
96
 
97
97
  def scores(response)
98
- subs = get_my_subscriptions(response)
98
+ subs = get_my_subscriptions(response,'match')
99
99
  subs.each do |match|
100
100
  get_match_score(response,match)
101
101
  end
@@ -108,16 +108,16 @@ module Lita
108
108
 
109
109
  def subscribe(response)
110
110
  match = response.matches[0][0].to_i
111
- subscribe_to_match(response,match)
111
+ subscribe_to(response,match,'match')
112
112
  end
113
113
 
114
114
  def unsubscribe(response)
115
115
  match = response.matches[0][0].to_i
116
- subs = get_my_subscriptions(response)
116
+ subs = get_my_subscriptions(response,'match')
117
117
  if subs.delete(match) == nil
118
118
  response.reply("You weren't subscribed to match #{match}!")
119
119
  else
120
- resp = set_my_subscriptions(response,subs)
120
+ resp = set_my_subscriptions(response,subs,'match')
121
121
  response.reply("Unsubscribed you to match #{match}: #{resp}")
122
122
  end
123
123
  end
@@ -135,45 +135,27 @@ module Lita
135
135
 
136
136
  def favourite(response)
137
137
  match = response.matches[0][0]
138
- favs = get_my_favourites(response)
139
- favs << match
140
- favs.uniq!
141
- resp = set_my_favourites(response,favs)
142
- response.reply("Added #{match} to your favourites: #{resp}")
138
+ subscribe_to(response,match,'favourite')
143
139
  end
144
140
 
145
141
  def unfavourite(response)
146
142
  match = response.matches[0][0]
147
- favs = get_my_favourites(response)
148
- if favs.delete(match) == nil
149
- response.reply("#{match} wasn't in your favourite list!")
150
- else
151
- resp = set_my_favourites(response,favs)
152
- response.reply("Removed #{match} from your favourites: #{resp}")
153
- end
143
+ unsubscribe_to(response,match,'favourite')
154
144
  end
155
145
 
156
146
  def info(response)
157
- subs = get_my_subscriptions(response)
158
- favs = get_my_favourites(response)
147
+ subs = get_my_subscriptions(response,'match')
148
+ favs = get_my_subscriptions(response,'favourite')
159
149
  response.reply("Subscriptions: #{subs.join(' | ')}")
160
150
  response.reply("Favourites: #{favs.join(' | ')}")
161
151
  end
162
152
 
163
- def get_my_subscriptions(response)
164
- JSON.parse(redis.get("#{response.user.id}-subscriptions")) rescue []
165
- end
166
-
167
- def set_my_subscriptions(response,subs)
168
- redis.set("#{response.user.id}-subscriptions",subs)
169
- end
170
-
171
- def get_my_favourites(response)
172
- JSON.parse(redis.get("#{response.user.id}-favourites")) rescue []
153
+ def get_my_subscriptions(response,type)
154
+ JSON.parse(redis.get("#{response.user.id}-#{type}")) rescue []
173
155
  end
174
156
 
175
- def set_my_favourites(response,favs)
176
- redis.set("#{response.user.id}-favourites",favs)
157
+ def set_my_subscriptions(response,subs,type)
158
+ redis.set("#{response.user.id}-#{type}",subs)
177
159
  end
178
160
 
179
161
  def get_list_of_live_matches
@@ -189,12 +171,22 @@ module Lita
189
171
  end
190
172
  end
191
173
 
192
- def subscribe_to_match(response,id)
193
- subs = get_my_subscriptions(response)
194
- if (subs && [id]).empty?
174
+ def subscribe_to(response,id,type)
175
+ subs = get_my_subscriptions(response,type)
176
+ if (subs & [id]).empty?
195
177
  subs << id
196
- resp = set_my_subscriptions(response,subs)
197
- response.reply("Subscribed you to match #{id}: #{resp}")
178
+ resp = set_my_subscriptions(response,subs,type)
179
+ response.reply("Subscribed you to #{type} #{id}: #{resp}")
180
+ end
181
+ end
182
+
183
+ def unsubscribe_to(response,id,type)
184
+ subs = get_my_subscriptions(response,type)
185
+ if subs.delete(id) == nil
186
+ response.reply("#{id} wasn't in your #{type} list!")
187
+ else
188
+ resp = set_my_subscriptions(response,subs,type)
189
+ response.reply("Unsubscribed you from #{type} #{id}: #{resp}")
198
190
  end
199
191
  end
200
192
 
@@ -46,13 +46,15 @@ describe Lita::Handlers::Cricket, lita_handler: true do
46
46
 
47
47
  it 'adds or removes a favourite team and also updates your favourite teams if you mention cricket' do
48
48
  send_message('cricket -f Cromer Cricket Club')
49
- expect(replies.last).to eq('Added Cromer Cricket Club to your favourites: OK')
49
+ expect(replies.last).to eq('Subscribed you to favourite Cromer Cricket Club: OK')
50
50
  send_message('cricket is grouse')
51
51
  # it is tricky to test this last feature
52
52
  send_message('cricket -r Cromer Cricket Club')
53
- expect(replies.last).to eq('Removed Cromer Cricket Club from your favourites: OK')
53
+ expect(replies.last).to eq('Unsubscribed you from favourite Cromer Cricket Club: OK')
54
54
  send_message('cricket -r Dee Why Cricket Club')
55
55
  expect(replies.last).to eq('Dee Why Cricket Club wasn\'t in your favourite list!')
56
+ send_message('cricket -f Derbyshire')
57
+ send_message('cricket')
56
58
  end
57
59
 
58
60
  it 'lists your favourite teams and subscribed matches' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-cricket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Auld