lita-garfield 0.0.0

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: 7490702ec77f0f040e85757a2e9172f8ea50e58b
4
+ data.tar.gz: 2abf12c7c96322330414a67a91ad7823f470418b
5
+ SHA512:
6
+ metadata.gz: 8735b88b1fa85d776077a5f2487bfe5cf6e4936a40db0738b17cacfe63847f02d18c26e38921c466dbf7a06080000c40f6c53de1c3794b11e27a43d5855ae8ed
7
+ data.tar.gz: aac7f2dfeb98bd20247f3f161001d831a243b62d89fdc36f10843276488c9e4e69c58a1c7e10338ce16860e66bd75e4eedeb14088440d355e473592b15c5f199
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,30 @@
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
18
+
19
+ !garfield random - Get a random garfield comic.
20
+ !garfield - Get today's garfield, or a random one if you've already seen today's.*
21
+ !garfield 1/1/1980 - Get a garfield for a m/d/y date.
22
+ !garfield 1980-1-1 - Get a garfield for a y-m-d date.
23
+ !garfield 1-1-1980 - Get a garfield for a m-d-y date.
24
+ !garfield first - Get the first garfield comic.
25
+ !garfield last - Get the last garfield comic.
26
+ !garfield today - Get today's garfield comic.
27
+ !garfield prev - Get the previous day's comic based on the last one you displayed.
28
+ !garfield next - Get the next day's comic based on the last on you displayed.
29
+
30
+ * 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,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/garfield'
8
+
9
+ Lita::Handlers::Garfield.template_root File.expand_path(
10
+ File.join('..', '..', 'templates'),
11
+ __FILE__
12
+ )
@@ -0,0 +1,91 @@
1
+ module Lita
2
+ module Handlers
3
+ class Garfield < Handler
4
+ route(/^!garfield random$/i, :handle_random_garfield,
5
+ help: { '!garfield random' => 'Get a random garfield comic.'})
6
+ route(/^!garfield$/i, :handle_default_garfield,
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,
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,
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,
13
+ help: { '!garfield' => 'Get a garfield for a m-d-y date.'})
14
+ route(/^!garfield first$/i, :handle_first_garfield,
15
+ help: { '!garfield first' => 'Get the first garfield comic.'})
16
+ route(/^!garfield last$/i, :handle_today_garfield,
17
+ help: { '!garfield last' => 'Get the last garfield comic.'})
18
+ route(/^!garfield today$/i, :handle_today_garfield,
19
+ help: { '!garfield today' => 'Get today\'s garfield comic.'})
20
+ route(/^!garfield prev$/i, :handle_prev_garfield,
21
+ help: { '!garfield prev' => 'Get the previous garfield comic.'})
22
+ route(/^!garfield next$/i, :handle_next_garfield,
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(Garfield)
90
+ end
91
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'lita-garfield'
3
+ spec.version = '0.0.0'
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-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::Garfield, lita_handler: true do
4
+
5
+ it { is_expected.to route('!garfield') }
6
+ it { is_expected.to route('!garfield random') }
7
+ it { is_expected.to route('!garfield first') }
8
+ it { is_expected.to route('!garfield last') }
9
+ it { is_expected.to route('!garfield today') }
10
+ it { is_expected.to route('!garfield 5/5/1998') }
11
+ it { is_expected.to route('!garfield 5-5-1998') }
12
+ it { is_expected.to route('!garfield 1998-5-5') }
13
+ it { is_expected.to route('!garfield prev') }
14
+ it { is_expected.to route('!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_message '!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_message '!garfield'
36
+ expect(replies.last).to include("https://garfield.com/uploads/strips/#{get_todays_image_filename}.jpg")
37
+ send_message '!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_message '!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_message '!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_message '!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_message '!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_message '!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_message '!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_message '!garfield first'
74
+ expect(replies.last).to include('https://garfield.com/uploads/strips/1978-06-19.jpg')
75
+ send_message '!garfield next'
76
+ expect(replies.last).to include('https://garfield.com/uploads/strips/1978-06-20.jpg')
77
+ send_message '!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_message '!garfield first'
88
+ expect(replies.last).to include(first)
89
+ send_message '!garfield prev'
90
+ expect(replies.last).to include(first)
91
+ send_message '!garfield last'
92
+ expect(replies.last).to include(last)
93
+ send_message '!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-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,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-garfield
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kreps
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-24 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: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.10'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ description: Tosses links to Garfield comics into chat.
126
+ email:
127
+ - andrew.kreps@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - Gemfile
135
+ - README.md
136
+ - Rakefile
137
+ - lib/lita-garfield.rb
138
+ - lib/lita/handlers/garfield.rb
139
+ - lita-garfield.gemspec
140
+ - spec/lita/handlers/garfield_spec.rb
141
+ - spec/spec_helper.rb
142
+ homepage: https://github.com/onewheelskyward/lita-garfield
143
+ licenses:
144
+ - MIT
145
+ metadata:
146
+ lita_plugin_type: handler
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.4.5
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: An alternative way to get your comic fix.
167
+ test_files:
168
+ - spec/lita/handlers/garfield_spec.rb
169
+ - spec/spec_helper.rb