lita-onewheel-garfield 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cfa0ea1c6729d3092d1ff03bc00d87921604116
4
+ data.tar.gz: c61d5465e20092e56dc4beb3d75e5eb772b6095a
5
+ SHA512:
6
+ metadata.gz: 0d8fc55333b56ecf7be0c869ff0ad3fb8f492ddb1a1b38b4dddcde8907a7aeda08f851fa1f737e84ecc69f0fc72a076f958a673d7e79dcc7b7fef6beea9f50ac
7
+ data.tar.gz: ff9e826cc8ab276c931e32c87df3dce372476df31639853f598f4cae357b1b07fac957f14c10fc72948707dc84122c77134d91b5efbc9bb417da1747629e6822
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
18
+ .idea
19
+ *~
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.5
5
+ - 2.2.2
6
+ script: bundle exec rake
7
+ before_install:
8
+ - gem update --system
9
+ services:
10
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # lita-garfield
2
+
3
+ [![Build Status](https://travis-ci.org/onewheelskyward/lita-garfield.png?branch=master)](https://travis-ci.org/onewheelskyward/lita-garfield)
4
+ [![Coverage Status](https://coveralls.io/repos/onewheelskyward/lita-garfield/badge.png)](https://coveralls.io/r/onewheelskyward/lita-garfield)
5
+ [![Documentation Status](https://readthedocs.org/projects/lita-garfield/badge/?version=latest)](https://readthedocs.org/projects/lita-garfield/?badge=latest)
6
+
7
+ Display a Garfield™® comic in IRC. http://www.garfield.com
8
+
9
+ ## Installation
10
+
11
+ Add lita-garfield to your Lita instance's Gemfile:
12
+
13
+ ``` ruby
14
+ gem 'lita-garfield'
15
+ ```
16
+
17
+ ## Usage, command mode (e.g. directed at bot or using config.robot.alias = '!')
18
+
19
+ garfield random - Get a random garfield comic.
20
+
21
+ garfield - Get today's garfield, or a random one if you've already seen today's.*
22
+
23
+ garfield 1/1/1980 - Get a garfield for a m/d/y date.
24
+
25
+ garfield 1980-1-1 - Get a garfield for a y-m-d date.
26
+
27
+ garfield 1-1-1980 - Get a garfield for a m-d-y date.
28
+
29
+ garfield first - Get the first garfield comic.
30
+
31
+ garfield last - Get the last garfield comic.
32
+
33
+ garfield today - Get today's garfield comic.
34
+
35
+ garfield prev - Get the previous day's comic based on the last one you displayed.
36
+
37
+ garfield next - Get the next day's comic based on the last on you displayed.
38
+
39
+ \* Coming soon to a Lita handler near you.
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,91 @@
1
+ module Lita
2
+ module Handlers
3
+ class OnewheelGarfield < Handler
4
+ route(/^garfield random$/i, :handle_random_garfield, command: true,
5
+ help: { 'garfield random' => 'Get a random garfield comic.'})
6
+ route(/^garfield$/i, :handle_default_garfield, command: true,
7
+ help: { 'garfield' => 'Get today\'s garfield, or a random one if you\'ve already seen today\'s.'})
8
+ route(/^garfield (\d{1,2})-(\d{1,2})-(\d{2,4})$/i, :handle_mdy_garfield, command: true,
9
+ help: { 'garfield' => 'Get a garfield for a m/d/y date.'})
10
+ route(/^garfield (\d{2,4})-(\d{1,2})-(\d{1,2})$/i, :handle_ymd_garfield, command: true,
11
+ help: { 'garfield' => 'Get a garfield for a y-m-d date.'})
12
+ route(/^garfield (\d{1,2})\/(\d{1,2})\/(\d{2,4})$/i, :handle_mdy_garfield, command: true,
13
+ help: { 'garfield' => 'Get a garfield for a m-d-y date.'})
14
+ route(/^garfield first$/i, :handle_first_garfield, command: true,
15
+ help: { 'garfield first' => 'Get the first garfield comic.'})
16
+ route(/^garfield last$/i, :handle_today_garfield, command: true,
17
+ help: { 'garfield last' => 'Get the last garfield comic.'})
18
+ route(/^garfield today$/i, :handle_today_garfield, command: true,
19
+ help: { 'garfield today' => 'Get today\'s garfield comic.'})
20
+ route(/^garfield prev$/i, :handle_prev_garfield, command: true,
21
+ help: { 'garfield prev' => 'Get the previous garfield comic.'})
22
+ route(/^garfield next$/i, :handle_next_garfield, command: true,
23
+ help: { 'garfield next' => 'Get next garfield comic.'})
24
+
25
+ def get_garfield_for_today(username)
26
+ date = Date.today
27
+ get_garfield_for_date(date, username)
28
+ end
29
+
30
+ def get_garfield_for_date(date, username)
31
+ redis.set(username, date)
32
+ "https://garfield.com/uploads/strips/#{date.year}-#{zero_prefix date.month}-#{zero_prefix date.day}.jpg"
33
+ end
34
+
35
+ def zero_prefix(dat)
36
+ if dat.to_i < 10
37
+ "0#{dat}"
38
+ else
39
+ dat
40
+ end
41
+ end
42
+
43
+ def handle_random_garfield(response)
44
+ # get a random date between 1978-06-19 and now
45
+ date = rand(Date.civil(1978, 6, 19)..Date.today())
46
+ response.reply get_garfield_for_date(date, response.user.name)
47
+ end
48
+
49
+ def handle_default_garfield(response)
50
+ response.reply get_garfield_for_today response.user.name
51
+ end
52
+
53
+ def handle_first_garfield(response)
54
+ date = Date.civil(1978, 6, 19)
55
+ response.reply get_garfield_for_date(date, response.user.name)
56
+ end
57
+
58
+ def handle_today_garfield(response)
59
+ response.reply get_garfield_for_today response.user.name
60
+ end
61
+
62
+ def handle_ymd_garfield(response)
63
+ date = Date.civil(response.match_data[1].to_i, response.match_data[2].to_i, response.match_data[3].to_i)
64
+ response.reply get_garfield_for_date(date, response.user.name)
65
+ end
66
+
67
+ def handle_mdy_garfield(response)
68
+ date = Date.civil(response.match_data[3].to_i, response.match_data[1].to_i, response.match_data[2].to_i)
69
+ response.reply get_garfield_for_date(date, response.user.name)
70
+ end
71
+
72
+ def handle_next_garfield(response)
73
+ date = Date.parse redis.get(response.user.name)
74
+ unless date == Date.today
75
+ date += 1
76
+ end
77
+ response.reply get_garfield_for_date(date, response.user.name)
78
+ end
79
+
80
+ def handle_prev_garfield(response)
81
+ date = Date.parse redis.get(response.user.name)
82
+ unless date == Date.civil(1978, 6, 19)
83
+ date -= 1
84
+ end
85
+ response.reply get_garfield_for_date(date, response.user.name)
86
+ end
87
+ end
88
+
89
+ Lita.register_handler(OnewheelGarfield)
90
+ end
91
+ end
@@ -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/onewheel_garfield'
8
+
9
+ Lita::Handlers::OnewheelGarfield.template_root File.expand_path(
10
+ File.join('..', '..', 'templates'),
11
+ __FILE__
12
+ )
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'lita-onewheel-garfield'
3
+ spec.version = '0.0.2'
4
+ spec.authors = ['Andrew Kreps']
5
+ spec.email = ['andrew.kreps@gmail.com']
6
+ spec.description = 'Tosses links to Garfield comics into chat.'
7
+ spec.summary = 'An alternative way to get your comic fix.'
8
+ spec.homepage = 'https://github.com/onewheelskyward/lita-onewheel-garfield'
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.3'
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.3'
20
+ # spec.add_development_dependency 'pry-byebug', '~> 3.1'
21
+ spec.add_development_dependency 'rake', '~> 10.4'
22
+ spec.add_development_dependency 'rack-test', '~> 0.6'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency 'simplecov', '~> 0.10'
25
+ spec.add_development_dependency 'coveralls', '~> 0.8'
26
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::OnewheelGarfield, lita_handler: true do
4
+
5
+ it { is_expected.to route_command('garfield') }
6
+ it { is_expected.to route_command('garfield random') }
7
+ it { is_expected.to route_command('garfield first') }
8
+ it { is_expected.to route_command('garfield last') }
9
+ it { is_expected.to route_command('garfield today') }
10
+ it { is_expected.to route_command('garfield 5/5/1998') }
11
+ it { is_expected.to route_command('garfield 5-5-1998') }
12
+ it { is_expected.to route_command('garfield 1998-5-5') }
13
+ it { is_expected.to route_command('garfield prev') }
14
+ it { is_expected.to route_command('garfield next') }
15
+
16
+ def zero_prefix(dat)
17
+ if dat.to_i < 10
18
+ "0#{dat}"
19
+ else
20
+ dat
21
+ end
22
+ end
23
+
24
+ def get_todays_image_filename
25
+ date = Date.today
26
+ "#{date.year}-#{zero_prefix date.month}-#{zero_prefix date.day}"
27
+ end
28
+
29
+ it 'will return a random garfield comic' do
30
+ send_command 'garfield random'
31
+ expect(replies.last).to include('https://garfield.com/uploads/strips/')
32
+ end
33
+
34
+ it 'will return a today\'s then a random garfield comic' do
35
+ send_command 'garfield'
36
+ expect(replies.last).to include("https://garfield.com/uploads/strips/#{get_todays_image_filename}.jpg")
37
+ send_command 'garfield'
38
+ expect(replies.last).to include('https://garfield.com/uploads/strips/')
39
+ end
40
+
41
+ it 'will return today\'s garfield comic' do
42
+ send_command 'garfield today'
43
+ expect(replies.last).to include("https://garfield.com/uploads/strips/#{get_todays_image_filename}.jpg")
44
+ end
45
+
46
+ it 'will return today\'s garfield comic' do
47
+ send_command 'garfield last'
48
+ expect(replies.last).to include("https://garfield.com/uploads/strips/#{get_todays_image_filename}.jpg")
49
+ end
50
+
51
+ it 'will return the first garfield comic' do
52
+ send_command 'garfield first'
53
+ expect(replies.last).to include('https://garfield.com/uploads/strips/1978-06-19.jpg')
54
+ end
55
+
56
+ it 'will return a garfield comic for a specific y-m-d date' do
57
+ send_command 'garfield 1998-5-5'
58
+ expect(replies.last).to include('https://garfield.com/uploads/strips/1998-05-05.jpg')
59
+ end
60
+
61
+ it 'will return a garfield comic for a specific m-d-y date' do
62
+ send_command 'garfield 5-5-1998'
63
+ expect(replies.last).to include('https://garfield.com/uploads/strips/1998-05-05.jpg')
64
+ end
65
+
66
+ it 'will return a garfield comic for a specific / date' do
67
+ send_command 'garfield 5/5/1998'
68
+ expect(replies.last).to include('https://garfield.com/uploads/strips/1998-05-05.jpg')
69
+ end
70
+
71
+ # Test the saved state of the last comic you requested.
72
+ it 'will return the first and then the next and then the previous garfield comic' do
73
+ send_command 'garfield first'
74
+ expect(replies.last).to include('https://garfield.com/uploads/strips/1978-06-19.jpg')
75
+ send_command 'garfield next'
76
+ expect(replies.last).to include('https://garfield.com/uploads/strips/1978-06-20.jpg')
77
+ send_command 'garfield prev'
78
+ expect(replies.last).to include('https://garfield.com/uploads/strips/1978-06-19.jpg')
79
+ end
80
+
81
+ it 'will edge case prev and next' do
82
+ today = Date.today
83
+
84
+ first = 'https://garfield.com/uploads/strips/1978-06-19.jpg'
85
+ last = "https://garfield.com/uploads/strips/#{today.year}-#{zero_prefix today.month}-#{zero_prefix today.day}.jpg"
86
+
87
+ send_command 'garfield first'
88
+ expect(replies.last).to include(first)
89
+ send_command 'garfield prev'
90
+ expect(replies.last).to include(first)
91
+ send_command 'garfield last'
92
+ expect(replies.last).to include(last)
93
+ send_command 'garfield next'
94
+ expect(replies.last).to include(last)
95
+ end
96
+ 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-onewheel-garfield'
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
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-onewheel-garfield
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kreps
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-22 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.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.8'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.8'
111
+ description: Tosses links to Garfield comics into chat.
112
+ email:
113
+ - andrew.kreps@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - README.md
122
+ - Rakefile
123
+ - lib/lita-onewheel-garfield.rb
124
+ - lib/lita/handlers/onewheel_garfield.rb
125
+ - lita-onewheel-garfield.gemspec
126
+ - spec/lita/handlers/onewheel_garfield_spec.rb
127
+ - spec/spec_helper.rb
128
+ homepage: https://github.com/onewheelskyward/lita-onewheel-garfield
129
+ licenses:
130
+ - MIT
131
+ metadata:
132
+ lita_plugin_type: handler
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.4.5
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: An alternative way to get your comic fix.
153
+ test_files:
154
+ - spec/lita/handlers/onewheel_garfield_spec.rb
155
+ - spec/spec_helper.rb