lita-cricket 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45e98d5a2b61bdb62924c7063cbbae132c36b5b8
4
+ data.tar.gz: 02b92564461c0e05e8d7aebbb7bbe0e9d917db98
5
+ SHA512:
6
+ metadata.gz: e920b859da900ae6fbbf510319a94fa27227b1fdaf90f9c0008c31cb4b0c6dea4b700d8ff5145ead50800f7f75e32682fcead00527ea1a0cbbe238a0b3c4ba33
7
+ data.tar.gz: 67ffaa12f3bc4d1d61131a5b9a88cdc09a2a5794e0db385478f467c4ac7aee1d0dc45151f534d33dad2d8026c853704ba8a6365632600a928e09bee255fdb645
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 COzero Pty Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # lita-cricket
2
+
3
+ [![Coverage Status](https://coveralls.io/repos/sjauld/lita-cricket/badge.png)](https://coveralls.io/r/sjauld/lita-cricket)
4
+
5
+ Provides live cricket scores via the Cricscore API
6
+
7
+ ## Installation
8
+
9
+ Add lita-cricket to your Lita instance's Gemfile:
10
+
11
+ ``` ruby
12
+ gem "lita-cricket"
13
+ ```
14
+
15
+ ## Configuration
16
+
17
+ NIL
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ help cricket
23
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/cricket"
8
+
9
+ Lita::Handlers::Cricket.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,202 @@
1
+ module Lita
2
+ module Handlers
3
+ class Cricket < Handler
4
+ # Dependencies
5
+ require 'json'
6
+ require 'httparty'
7
+
8
+ @@ENDPOINT = 'http://cricscore-api.appspot.com/csa'
9
+
10
+ route(
11
+ /cricket/i,
12
+ :refresh_user
13
+ )
14
+
15
+ route(
16
+ /^\(?cricket\)?$/i,
17
+ :scores,
18
+ help: {
19
+ 'cricket' => 'Display the scores for your matches',
20
+ }
21
+ )
22
+
23
+ route(
24
+ /^\(?cricket\)?\s+(\d+)/i,
25
+ :score,
26
+ help: {
27
+ 'cricket 743965' => 'Display the score for match 743965'
28
+ }
29
+ )
30
+
31
+ route(
32
+ /^\(?cricket\)?\s+-s\s+(.*)$/i,
33
+ :subscribe,
34
+ help: {
35
+ 'cricket -s 743965' => 'Subscribe to match 743965'
36
+ }
37
+ )
38
+
39
+ route(
40
+ /^\(?cricket\)?\s+-u\s+(.*)$/i,
41
+ :unsubscribe,
42
+ help: {
43
+ 'cricket -u 743963' => 'Unsubscribe from match 743963'
44
+ }
45
+ )
46
+
47
+ route(
48
+ /^\(?cricket\)?\s+-l$/i,
49
+ :list,
50
+ help: {
51
+ 'cricket -l' => 'List the current live matches'
52
+ }
53
+ )
54
+
55
+ route(
56
+ /^\(?cricket\)?\s+-f\s+(.*)$/i,
57
+ :favourite,
58
+ help: {
59
+ 'cricket -f Cromer Cricket Club' => 'Add a favourite team!'
60
+ }
61
+ )
62
+
63
+ route(
64
+ /^\(?cricket\)?\s+-r\s+(.*)$/i,
65
+ :unfavourite,
66
+ help: {
67
+ 'cricket -r Cromer Cricket Club' => 'Remove a favourite team!'
68
+ }
69
+ )
70
+
71
+ route(
72
+ /^\(?cricket\)?\s+-i$/i,
73
+ :info,
74
+ help: {
75
+ 'cricket -i' => 'Display your favourites and subscriptions'
76
+ }
77
+ )
78
+
79
+ def refresh_user(response)
80
+ my_favourites = get_my_favourites(response)
81
+ if my_favourites.empty?
82
+ redis.set("#{response.user.id}-favourites",['Australia'].to_json)
83
+ response.reply('I can give you live cricket updates! Type `help cricket` for more information.')
84
+ elsif
85
+ matches = get_list_of_live_matches
86
+ matches.each do |m|
87
+ unless ([ m['t1'], m['t2']] & my_favourites).empty?
88
+ subscribe_to_match(response,m['id'])
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ def scores(response)
95
+ subs = get_my_subscriptions(response)
96
+ subs.each do |match|
97
+ get_match_score(response,match)
98
+ end
99
+ end
100
+
101
+ def score(response)
102
+ match = response.matches[0][0].to_i
103
+ get_match_score(response,match)
104
+ end
105
+
106
+ def subscribe(response)
107
+ match = response.matches[0][0].to_i
108
+ subscribe_to_match(response,match)
109
+ end
110
+
111
+ def unsubscribe(response)
112
+ match = response.matches[0][0].to_i
113
+ subs = get_my_subscriptions(response)
114
+ if subs.delete(match) == nil
115
+ response.reply("You weren't subscribed to match #{match}!")
116
+ else
117
+ resp = set_my_subscriptions(response,subs)
118
+ response.reply("Unsubscribed you to match #{match}: #{resp}")
119
+ end
120
+ end
121
+
122
+ def list(response)
123
+ resp = get_list_of_live_matches
124
+ #TODO: parse this list and keep going!!!
125
+ response.reply("There are #{resp.count} live matches on!")
126
+ resp.each do |r|
127
+ response.reply("#{r['t1']} vs #{r['t2']} (http://www.espncricinfo.com/c/engine/match/#{r['id']}.html)")
128
+ end
129
+ rescue
130
+ response.reply("An error may have occured, or maybe there are no live matches")
131
+ end
132
+
133
+ def favourite(response)
134
+ match = response.matches[0][0]
135
+ favs = get_my_favourites(response)
136
+ favs << match
137
+ favs.uniq!
138
+ resp = set_my_favourites(response,favs)
139
+ response.reply("Added #{match} to your favourites: #{resp}")
140
+ end
141
+
142
+ def unfavourite(response)
143
+ match = response.matches[0][0]
144
+ favs = get_my_favourites(response)
145
+ if favs.delete(match) == nil
146
+ response.reply("#{match} wasn't in your favourite list!")
147
+ else
148
+ resp = set_my_favourites(response,favs)
149
+ response.reply("Removed #{match} from your favourites: #{resp}")
150
+ end
151
+ end
152
+
153
+ def info(response)
154
+ subs = get_my_subscriptions(response)
155
+ favs = get_my_favourites(response)
156
+ response.reply("Subscriptions: #{subs.join(' | ')}")
157
+ response.reply("Favourites: #{favs.join(' | ')}")
158
+ end
159
+
160
+ def get_my_subscriptions(response)
161
+ JSON.parse(redis.get("#{response.user.id}-subscriptions")) rescue []
162
+ end
163
+
164
+ def set_my_subscriptions(response,subs)
165
+ redis.set("#{response.user.id}-subscriptions",subs)
166
+ end
167
+
168
+ def get_my_favourites(response)
169
+ JSON.parse(redis.get("#{response.user.id}-favourites")) rescue []
170
+ end
171
+
172
+ def set_my_favourites(response,favs)
173
+ redis.set("#{response.user.id}-favourites",favs)
174
+ end
175
+
176
+ def get_list_of_live_matches
177
+ HTTParty.get(@@ENDPOINT).parsed_response
178
+ end
179
+
180
+ def get_match_score(response,id)
181
+ if id == 0
182
+ Lita.logger.debug("Skipping a 0 match")
183
+ elsif
184
+ resp = HTTParty.get(@@ENDPOINT, query: { id: id })
185
+ response.reply(resp.parsed_response[0]['de']) rescue Lita.logger.debug("Skipping a bad match")
186
+ end
187
+ end
188
+
189
+ def subscribe_to_match(response,id)
190
+ subs = get_my_subscriptions(response)
191
+ if (subs && [id]).empty
192
+ subs << id
193
+ resp = set_my_subscriptions(response,subs)
194
+ response.reply("Subscribed you to match #{id}: #{resp}")
195
+ end
196
+ end
197
+
198
+ end
199
+
200
+ Lita.register_handler(Cricket)
201
+ end
202
+ end
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-cricket"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Stuart Auld"]
5
+ spec.email = ["sja@marsupialmusic.net"]
6
+ spec.description = "Provides live cricket scores directly in Lita"
7
+ spec.summary = "Live cricket scores! Such wow!"
8
+ spec.homepage = "https://github.com/sjauld/lita-cricket"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.4"
18
+ spec.add_runtime_dependency "httparty"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "pry-byebug"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rack-test"
24
+ spec.add_development_dependency "rspec", ">= 3.0.0"
25
+ spec.add_development_dependency "simplecov"
26
+ spec.add_development_dependency "coveralls"
27
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ cricket:
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Cricket, lita_handler: true do
4
+ it {is_expected.to route('cricket').to(:scores)}
5
+ it {is_expected.to route('do youses like cricket?').to(:refresh_user)}
6
+ it {is_expected.to route('cricket -s 743965').to(:subscribe)}
7
+ it {is_expected.to route('cricket -u 743963').to(:unsubscribe)}
8
+ it {is_expected.to route('cricket -l').to(:list)}
9
+ it {is_expected.to route('cricket -f Cromer Cricket Club').to(:favourite)}
10
+ it {is_expected.to route('cricket -r Cromer Cricket Club').to(:unfavourite)}
11
+ it {is_expected.to route('cricket 743965').to(:score)}
12
+ before{robot.trigger(:loaded)}
13
+
14
+ it 'welcomes you if you have never mentioned cricket before' do
15
+ send_message('do youses all want to go to the cricket on sunday?')
16
+ expect(replies.first).to eq('I can give you live cricket updates! Type `help cricket` for more information.')
17
+ end
18
+
19
+ it 'displays the current live matches' do
20
+ send_message('cricket -l')
21
+ expect(replies.detect{|x| ( x =~/There are/ ) == 0}.nil?).to eq(false)
22
+ end
23
+
24
+ it 'subscribes/unsubscribes you to some match if you like' do
25
+ send_message('cricket -s 743965')
26
+ expect(replies.last).to eq('Subscribed you to match 743965: OK')
27
+ send_message('cricket -s 743963')
28
+ expect(replies.last).to eq('Subscribed you to match 743963: OK')
29
+ send_message('cricket -u 743963')
30
+ expect(replies.last).to eq('Unsubscribed you to match 743963: OK')
31
+ send_message('cricket -u 743964')
32
+ expect(replies.last).to eq('You weren\'t subscribed to match 743964!')
33
+ end
34
+
35
+ it 'displays scores for your cricket matches' do
36
+ send_message('cricket -s 743963')
37
+ send_message('cricket')
38
+ # Not sure what to test for here :(
39
+ end
40
+
41
+ it 'displays the score for a specific match' do
42
+ send_message('cricket 743963')
43
+ send_message('cricket 0')
44
+ # Not sure what to test for here :(
45
+ end
46
+
47
+ it 'adds or removes a favourite team and also updates your favourite teams if you mention cricket' do
48
+ send_message('cricket -f Cromer Cricket Club')
49
+ expect(replies.last).to eq('Added Cromer Cricket Club to your favourites: OK')
50
+ send_message('cricket is grouse')
51
+ # it is tricky to test this last feature
52
+ send_message('cricket -r Cromer Cricket Club')
53
+ expect(replies.last).to eq('Removed Cromer Cricket Club from your favourites: OK')
54
+ send_message('cricket -r Dee Why Cricket Club')
55
+ expect(replies.last).to eq('Dee Why Cricket Club wasn\'t in your favourite list!')
56
+ end
57
+
58
+ it 'lists your favourite teams and subscribed matches' do
59
+ send_message('cricket -i')
60
+ expect(replies.detect{|x| ( x =~/Subscriptions:/ ) == 0}.nil?).to eq(false)
61
+ expect(replies.detect{|x| ( x =~/Favourites:/ ) == 0}.nil?).to eq(false)
62
+ end
63
+
64
+ end
@@ -0,0 +1,14 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-cricket"
10
+ require "lita/rspec"
11
+
12
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
13
+ # was generated with Lita 4, the compatibility mode should be left disabled.
14
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-cricket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stuart Auld
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Provides live cricket scores directly in Lita
140
+ email:
141
+ - sja@marsupialmusic.net
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - Gemfile
148
+ - LICENSE
149
+ - README.md
150
+ - Rakefile
151
+ - lib/lita-cricket.rb
152
+ - lib/lita/handlers/cricket.rb
153
+ - lita-cricket.gemspec
154
+ - locales/en.yml
155
+ - spec/lita/handlers/cricket_spec.rb
156
+ - spec/spec_helper.rb
157
+ - templates/.gitkeep
158
+ homepage: https://github.com/sjauld/lita-cricket
159
+ licenses:
160
+ - MIT
161
+ metadata:
162
+ lita_plugin_type: handler
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.4.6
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Live cricket scores! Such wow!
183
+ test_files:
184
+ - spec/lita/handlers/cricket_spec.rb
185
+ - spec/spec_helper.rb
186
+ has_rdoc: