lita-catme 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/README.md +34 -0
- data/Rakefile +6 -0
- data/dump.rdb +0 -0
- data/lib/lita/handlers/cat.rb +32 -0
- data/lib/lita/handlers/catme.rb +37 -0
- data/lib/lita-catme.rb +15 -0
- data/lita-catme.gemspec +28 -0
- data/locales/en.yml +11 -0
- data/spec/fixtures/vcr_cassettes/fetch_cat.yml +54 -0
- data/spec/fixtures/vcr_cassettes/fetch_multiple_cats.yml +99 -0
- data/spec/fixtures/vcr_cassettes/fetch_with_category.yml +54 -0
- data/spec/fixtures/vcr_cassettes/fetch_with_invalid_category.yml +48 -0
- data/spec/lita/handlers/cat_spec.rb +56 -0
- data/spec/lita/handlers/catme_spec.rb +115 -0
- data/spec/spec_helper.rb +13 -0
- data/templates/.gitkeep +0 -0
- metadata +197 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ba99bbe4641cc8613def014ac744ee29ae2b5c8
|
4
|
+
data.tar.gz: 1e27139c3c6466c2c3c62b99791f3feb78f59e4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d0d1764b77df4860f5452450c69d9d054aec990383873bf11c7b6fa68791e895dfc740a551bc3e414a509023ff12e0d01504236f9bbc90807d97041452b6997
|
7
|
+
data.tar.gz: 67b6888de0bc28edb777ccd86b0fc0a8f94a6034b4c55cd6b8cc9b360d3c510e8a5f15fd8aaa340d43154db315cb6a88151366502f934d060b0d744079f6565e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# lita-catme
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/Emile-Filteau/lita-catme.png?branch=master)](https://travis-ci.org/Emile-Filteau/lita-catme)
|
4
|
+
|
5
|
+
Lita handler that provides several commands to fetch random cat images from the cat api.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add lita-catme to your Lita instance's Gemfile:
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
gem "lita-catme"
|
13
|
+
```
|
14
|
+
|
15
|
+
## Example Usage
|
16
|
+
|
17
|
+
```
|
18
|
+
User>> lita cat me
|
19
|
+
Lita>> http://24.media.tumblr.com/tumblr_low6n5JHJF1qbhms5o1_500.jpg
|
20
|
+
User>> lita cat categories
|
21
|
+
Lita>>hats
|
22
|
+
space
|
23
|
+
funny
|
24
|
+
sunglasses
|
25
|
+
boxes
|
26
|
+
caturday
|
27
|
+
ties
|
28
|
+
dream
|
29
|
+
kittens
|
30
|
+
sinks
|
31
|
+
clothes
|
32
|
+
User>> lita cat in boxes
|
33
|
+
Lita>> http://25.media.tumblr.com/tumblr_lwwd01DBVo1r0mbi6o1_1280.jpg
|
34
|
+
```
|
data/Rakefile
ADDED
data/dump.rdb
ADDED
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
module Lita
|
3
|
+
module Handlers
|
4
|
+
class Cat
|
5
|
+
BASE_URL = 'http://thecatapi.com/api'.freeze
|
6
|
+
attr_accessor :url
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def fetch(count: nil, category: nil)
|
10
|
+
url = "#{BASE_URL}/images/get?format=xml"
|
11
|
+
url += "&results_per_page=#{count}" unless count.nil?
|
12
|
+
url += "&category=#{category}" unless category.nil?
|
13
|
+
|
14
|
+
Nokogiri::XML(open(url)).css('//url').each_with_object([]) do |cat, cats|
|
15
|
+
cats << new(cat.content)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def fetch_categories
|
20
|
+
url = "#{BASE_URL}/categories/list"
|
21
|
+
Nokogiri::XML(open(url)).css('//name').each_with_object([]) do |category, categories|
|
22
|
+
categories << category.content
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(url)
|
28
|
+
@url = url
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Lita
|
2
|
+
module Handlers
|
3
|
+
class Catme < Handler
|
4
|
+
BASE_URL = 'http://thecatapi.com/api/images/get'.freeze
|
5
|
+
|
6
|
+
route(/^cat( me)?$/i, :cat_me, command: true, help: { 'cat me' => t('help.cat_me') })
|
7
|
+
route(/^cat bomb( (\d+))?$/i, :cat_bomb, command: true, help: { 'cat bomb N' => t('help.cat_bomb') })
|
8
|
+
route(/^cat categories$/i, :cat_categories, command: true, help: { 'cat categories' => t('help.cat_categories') })
|
9
|
+
route(/^cat( me)? (with|in)( (\w+))?$/i, :cat_with_category, command: true, help: { 'cat (with|in) category' => t('help.cat_with_catgory') })
|
10
|
+
|
11
|
+
def cat_me(response)
|
12
|
+
response.reply(Cat.fetch.first.url)
|
13
|
+
end
|
14
|
+
|
15
|
+
def cat_bomb(response)
|
16
|
+
count = (response.args[1] || 5).to_i
|
17
|
+
count = 20 if count > 20
|
18
|
+
|
19
|
+
Cat.fetch(count: count).each { |cat| response.reply(cat.url) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def cat_categories(response)
|
23
|
+
Cat.fetch_categories.each { |category| response.reply(category) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def cat_with_category(response)
|
27
|
+
if cat = Cat.fetch(category: response.args[1]).first
|
28
|
+
response.reply(cat.url)
|
29
|
+
else
|
30
|
+
response.reply(t('cat_with_category.unrecognized_category'))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Lita.register_handler(self)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/lita-catme.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "lita"
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
Lita.load_locales Dir[File.expand_path(
|
6
|
+
File.join("..", "..", "locales", "*.yml"), __FILE__
|
7
|
+
)]
|
8
|
+
|
9
|
+
require "lita/handlers/cat"
|
10
|
+
require "lita/handlers/catme"
|
11
|
+
|
12
|
+
Lita::Handlers::Catme.template_root File.expand_path(
|
13
|
+
File.join("..", "..", "templates"),
|
14
|
+
__FILE__
|
15
|
+
)
|
data/lita-catme.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-catme"
|
3
|
+
spec.version = "0.1.0"
|
4
|
+
spec.authors = ["Emile Filteau"]
|
5
|
+
spec.email = ["emile.filteau@gmail.com"]
|
6
|
+
spec.description = %q(A lita handler that fetch random cat images)
|
7
|
+
spec.summary = %q(A lita handler that fetch random cat images)
|
8
|
+
spec.homepage = "https://github.com/Emile-Filteau/lita-catme"
|
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.7"
|
18
|
+
|
19
|
+
spec.add_dependency "nokogiri"
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "pry-byebug"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rack-test"
|
25
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
26
|
+
spec.add_development_dependency "vcr"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
en:
|
2
|
+
lita:
|
3
|
+
handlers:
|
4
|
+
catme:
|
5
|
+
help:
|
6
|
+
cat_me: Receive a random cat image
|
7
|
+
cat_bomb: Receive N a random cat image (max 20)
|
8
|
+
cat_categories: List all available categories
|
9
|
+
cat_with_category: Receive a cat in the given category
|
10
|
+
cat_with_category:
|
11
|
+
unrecognized_category: Enter a valid category (type "cat categories" for a list of valid categories)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://thecatapi.com/api/images/get?format=xml
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Tue, 12 Apr 2016 16:01:53 GMT
|
23
|
+
Server:
|
24
|
+
- Apache
|
25
|
+
X-Powered-By:
|
26
|
+
- PHP/5.4.45
|
27
|
+
Access-Control-Allow-Origin:
|
28
|
+
- "*"
|
29
|
+
Access-Control-Allow-Methods:
|
30
|
+
- GET, POST
|
31
|
+
Access-Control-Allow-Headers:
|
32
|
+
- X-Requested-With
|
33
|
+
Transfer-Encoding:
|
34
|
+
- chunked
|
35
|
+
Content-Type:
|
36
|
+
- text/xml
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: |
|
40
|
+
<?xml version="1.0"?>
|
41
|
+
<response>
|
42
|
+
<data>
|
43
|
+
<images>
|
44
|
+
<image>
|
45
|
+
<url>http://24.media.tumblr.com/tumblr_low6n5JHJF1qbhms5o1_500.jpg</url>
|
46
|
+
<id>6kf</id>
|
47
|
+
<source_url>http://thecatapi.com/?id=6kf</source_url>
|
48
|
+
</image>
|
49
|
+
</images>
|
50
|
+
</data>
|
51
|
+
</response>
|
52
|
+
http_version:
|
53
|
+
recorded_at: Tue, 12 Apr 2016 16:01:53 GMT
|
54
|
+
recorded_with: VCR 3.0.1
|
@@ -0,0 +1,99 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://thecatapi.com/api/images/get?format=xml&results_per_page=10
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Tue, 12 Apr 2016 16:06:10 GMT
|
23
|
+
Server:
|
24
|
+
- Apache
|
25
|
+
X-Powered-By:
|
26
|
+
- PHP/5.4.45
|
27
|
+
Access-Control-Allow-Origin:
|
28
|
+
- "*"
|
29
|
+
Access-Control-Allow-Methods:
|
30
|
+
- GET, POST
|
31
|
+
Access-Control-Allow-Headers:
|
32
|
+
- X-Requested-With
|
33
|
+
Transfer-Encoding:
|
34
|
+
- chunked
|
35
|
+
Content-Type:
|
36
|
+
- text/xml
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: |
|
40
|
+
<?xml version="1.0"?>
|
41
|
+
<response>
|
42
|
+
<data>
|
43
|
+
<images>
|
44
|
+
<image>
|
45
|
+
<url>http://25.media.tumblr.com/tumblr_lzv0qmw51M1qlyuwso1_1280.jpg</url>
|
46
|
+
<id>8ve</id>
|
47
|
+
<source_url>http://thecatapi.com/?id=8ve</source_url>
|
48
|
+
</image>
|
49
|
+
<image>
|
50
|
+
<url>http://25.media.tumblr.com/tumblr_mat8o75KS01rptlauo1_1280.jpg</url>
|
51
|
+
<id>MTY5Njc5Mg</id>
|
52
|
+
<source_url>http://thecatapi.com/?id=MTY5Njc5Mg</source_url>
|
53
|
+
</image>
|
54
|
+
<image>
|
55
|
+
<url>http://25.media.tumblr.com/tumblr_lmmuhbqBII1qd477zo1_1280.jpg</url>
|
56
|
+
<id>cn9</id>
|
57
|
+
<source_url>http://thecatapi.com/?id=cn9</source_url>
|
58
|
+
</image>
|
59
|
+
<image>
|
60
|
+
<url>http://24.media.tumblr.com/tumblr_lgqhdsGcgO1qfyzelo1_500.jpg</url>
|
61
|
+
<id>6s0</id>
|
62
|
+
<source_url>http://thecatapi.com/?id=6s0</source_url>
|
63
|
+
</image>
|
64
|
+
<image>
|
65
|
+
<url>http://25.media.tumblr.com/tumblr_m22h2qhwn61qcxyrro1_500.jpg</url>
|
66
|
+
<id>atp</id>
|
67
|
+
<source_url>http://thecatapi.com/?id=atp</source_url>
|
68
|
+
</image>
|
69
|
+
<image>
|
70
|
+
<url>http://24.media.tumblr.com/tumblr_lwidfjYoSI1qlyuwso1_1280.jpg</url>
|
71
|
+
<id>925</id>
|
72
|
+
<source_url>http://thecatapi.com/?id=925</source_url>
|
73
|
+
</image>
|
74
|
+
<image>
|
75
|
+
<url>http://25.media.tumblr.com/tumblr_luowluVKdx1qdth8zo1_1280.jpg</url>
|
76
|
+
<id>cev</id>
|
77
|
+
<source_url>http://thecatapi.com/?id=cev</source_url>
|
78
|
+
</image>
|
79
|
+
<image>
|
80
|
+
<url>http://24.media.tumblr.com/tumblr_m4pwtpa2Nw1r6jd7fo1_500.jpg</url>
|
81
|
+
<id>eb9</id>
|
82
|
+
<source_url>http://thecatapi.com/?id=eb9</source_url>
|
83
|
+
</image>
|
84
|
+
<image>
|
85
|
+
<url>http://24.media.tumblr.com/tumblr_lr8ng062t01qhwlspo1_500.jpg</url>
|
86
|
+
<id>53s</id>
|
87
|
+
<source_url>http://thecatapi.com/?id=53s</source_url>
|
88
|
+
</image>
|
89
|
+
<image>
|
90
|
+
<url>http://25.media.tumblr.com/tumblr_m33ib9ERyW1qflacro1_1280.jpg</url>
|
91
|
+
<id>9me</id>
|
92
|
+
<source_url>http://thecatapi.com/?id=9me</source_url>
|
93
|
+
</image>
|
94
|
+
</images>
|
95
|
+
</data>
|
96
|
+
</response>
|
97
|
+
http_version:
|
98
|
+
recorded_at: Tue, 12 Apr 2016 16:06:10 GMT
|
99
|
+
recorded_with: VCR 3.0.1
|
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://thecatapi.com/api/images/get?category=boxes&format=xml
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Tue, 12 Apr 2016 16:15:49 GMT
|
23
|
+
Server:
|
24
|
+
- Apache
|
25
|
+
X-Powered-By:
|
26
|
+
- PHP/5.4.45
|
27
|
+
Access-Control-Allow-Origin:
|
28
|
+
- "*"
|
29
|
+
Access-Control-Allow-Methods:
|
30
|
+
- GET, POST
|
31
|
+
Access-Control-Allow-Headers:
|
32
|
+
- X-Requested-With
|
33
|
+
Transfer-Encoding:
|
34
|
+
- chunked
|
35
|
+
Content-Type:
|
36
|
+
- text/xml
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: |
|
40
|
+
<?xml version="1.0"?>
|
41
|
+
<response>
|
42
|
+
<data>
|
43
|
+
<images>
|
44
|
+
<image>
|
45
|
+
<url>http://25.media.tumblr.com/tumblr_lwwd01DBVo1r0mbi6o1_1280.jpg</url>
|
46
|
+
<id>f6</id>
|
47
|
+
<source_url>http://thecatapi.com/?id=f6</source_url>
|
48
|
+
</image>
|
49
|
+
</images>
|
50
|
+
</data>
|
51
|
+
</response>
|
52
|
+
http_version:
|
53
|
+
recorded_at: Tue, 12 Apr 2016 16:15:49 GMT
|
54
|
+
recorded_with: VCR 3.0.1
|
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://thecatapi.com/api/images/get?category=foobar&format=xml
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Tue, 12 Apr 2016 16:18:16 GMT
|
23
|
+
Server:
|
24
|
+
- Apache
|
25
|
+
X-Powered-By:
|
26
|
+
- PHP/5.4.45
|
27
|
+
Access-Control-Allow-Origin:
|
28
|
+
- "*"
|
29
|
+
Access-Control-Allow-Methods:
|
30
|
+
- GET, POST
|
31
|
+
Access-Control-Allow-Headers:
|
32
|
+
- X-Requested-With
|
33
|
+
Transfer-Encoding:
|
34
|
+
- chunked
|
35
|
+
Content-Type:
|
36
|
+
- text/xml
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: |
|
40
|
+
<?xml version="1.0"?>
|
41
|
+
<response>
|
42
|
+
<data>
|
43
|
+
<images/>
|
44
|
+
</data>
|
45
|
+
</response>
|
46
|
+
http_version:
|
47
|
+
recorded_at: Tue, 12 Apr 2016 16:18:16 GMT
|
48
|
+
recorded_with: VCR 3.0.1
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::Cat do
|
4
|
+
describe '.fetch' do
|
5
|
+
context 'whith no argument', vcr: { cassette_name: 'fetch_cat' } do
|
6
|
+
it 'instantiate one cat object' do
|
7
|
+
expect(described_class).to receive(:new).once
|
8
|
+
described_class.fetch
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns an array containing one cat' do
|
12
|
+
cats = described_class.fetch
|
13
|
+
expect(cats.length).to eq(1)
|
14
|
+
expect(cats.first.url).to eq("http://24.media.tumblr.com/tumblr_low6n5JHJF1qbhms5o1_500.jpg")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with cout argument set', vcr: { cassette_name: 'fetch_multiple_cats' } do
|
19
|
+
it 'instantiate the right amount of cats' do
|
20
|
+
expect(described_class).to receive(:new).exactly(10).times
|
21
|
+
described_class.fetch(count: 10)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns an array containing the right amount Cat' do
|
25
|
+
cats= described_class.fetch(count: 10)
|
26
|
+
|
27
|
+
expect(cats.length).to eq(10)
|
28
|
+
cats.each { |cat| expect(cat.url).to match(URI.regexp) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with category argument set to valid value', vcr: { cassette_name: 'fetch_with_category' } do
|
33
|
+
it 'instaniate one cat object' do
|
34
|
+
expect(described_class).to receive(:new).once
|
35
|
+
described_class.fetch(category: 'boxes')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns an array containing one cat in the given category' do
|
39
|
+
cats = described_class.fetch(category: 'boxes')
|
40
|
+
expect(cats.length).to eq(1)
|
41
|
+
expect(cats.first.url).to eq("http://25.media.tumblr.com/tumblr_lwwd01DBVo1r0mbi6o1_1280.jpg")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with category argument set to invalid value', vcr: { cassette_name: 'fetch)with_invalid_category' } do
|
46
|
+
it 'instaniate no cat object' do
|
47
|
+
expect(described_class).to receive(:new).never
|
48
|
+
described_class.fetch(category: 'foobar')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns an empty array' do
|
52
|
+
expect(described_class.fetch(category: 'foobar')).to eq([])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::Catme, lita_handler: true do
|
4
|
+
it { is_expected.to route_command("cat").to(:cat_me) }
|
5
|
+
it { is_expected.to route_command("cat me").to(:cat_me) }
|
6
|
+
it { is_expected.to route_command("cat bomb").to(:cat_bomb) }
|
7
|
+
it { is_expected.to route_command("cat bomb 10").to(:cat_bomb) }
|
8
|
+
it { is_expected.to route_command("cat categories").to(:cat_categories) }
|
9
|
+
it { is_expected.to route_command("cat in boxes").to(:cat_with_category) }
|
10
|
+
it { is_expected.to route_command("cat with sunglasses").to(:cat_with_category) }
|
11
|
+
|
12
|
+
describe '#cat_me' do
|
13
|
+
let(:cat) { double(url: 'https://foobar.com/cat.jpg') }
|
14
|
+
before do
|
15
|
+
expect(Lita::Handlers::Cat).to receive(:fetch).and_return([cat])
|
16
|
+
send_command('cat me')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'writes an image url to the page' do
|
20
|
+
expect(replies.last).to eq('https://foobar.com/cat.jpg')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#cat_bomb' do
|
25
|
+
context 'when no number is passed to the command' do
|
26
|
+
let(:cats) do
|
27
|
+
(1..5).each_with_object([]) { |i, a| a << double(url: "https://foobar.com/cat#{i}.jpg") }
|
28
|
+
end
|
29
|
+
|
30
|
+
before do
|
31
|
+
expect(Lita::Handlers::Cat).to receive(:fetch).with(count: 5).and_return(cats)
|
32
|
+
send_command('cat bomb')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'sends 5 images' do
|
36
|
+
expect(replies.length).to eq(5)
|
37
|
+
expect(replies).to all match(URI.regexp)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when a number below 20 is passed to the command' do
|
42
|
+
let(:cats) do
|
43
|
+
(1..10).each_with_object([]) { |i, a| a << double(url: "https://foobar.com/cat#{i}.jpg") }
|
44
|
+
end
|
45
|
+
|
46
|
+
before do
|
47
|
+
expect(Lita::Handlers::Cat).to receive(:fetch).with(count: 10).and_return(cats)
|
48
|
+
send_command('cat bomb 10')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'sends the selected amount of images' do
|
52
|
+
expect(replies.length).to eq(10)
|
53
|
+
expect(replies).to all match(URI.regexp)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when a number above 20 is passed to the command' do
|
58
|
+
let(:cats) do
|
59
|
+
(1..20).each_with_object([]) { |i, a| a << double(url: "https://foobar.com/cat#{i}.jpg") }
|
60
|
+
end
|
61
|
+
|
62
|
+
before do
|
63
|
+
expect(Lita::Handlers::Cat).to receive(:fetch).with(count: 20).and_return(cats)
|
64
|
+
send_command('cat bomb 30')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'sends 20 images' do
|
68
|
+
expect(replies.length).to eq(20)
|
69
|
+
expect(replies).to all match(URI.regexp)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#cat_categories" do
|
75
|
+
let(:categories) { ['funny', 'boxes', 'sunglasses'] }
|
76
|
+
|
77
|
+
before do
|
78
|
+
expect(Lita::Handlers::Cat).to receive(:fetch_categories).and_return(categories)
|
79
|
+
send_command('cat categories')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'sends an array of strings' do
|
83
|
+
expect(replies.length).to eq(3)
|
84
|
+
expect(replies[0]).to eq 'funny'
|
85
|
+
expect(replies[1]).to eq 'boxes'
|
86
|
+
expect(replies[2]).to eq 'sunglasses'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#cat_with_category" do
|
91
|
+
context 'when the category is valid' do
|
92
|
+
let(:cat) { double(url: 'https://foobar.com/cat_in_box.png') }
|
93
|
+
|
94
|
+
before do
|
95
|
+
expect(Lita::Handlers::Cat).to receive(:fetch).with(category: 'boxes').and_return([cat])
|
96
|
+
send_command('cat in boxes')
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'sends an image url' do
|
100
|
+
expect(replies.last).to eq('https://foobar.com/cat_in_box.png')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when the category is valid' do
|
105
|
+
before do
|
106
|
+
expect(Lita::Handlers::Cat).to receive(:fetch).with(category: 'foobar').and_return([])
|
107
|
+
send_command('cat in foobar')
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'displays an error message' do
|
111
|
+
expect(replies.last).to eq('Enter a valid category (type "cat categories" for a list of valid categories)')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "lita-catme"
|
2
|
+
require "lita/rspec"
|
3
|
+
require "uri"
|
4
|
+
require 'vcr'
|
5
|
+
|
6
|
+
Lita.version_3_compatibility_mode = false
|
7
|
+
|
8
|
+
VCR.configure do |config|
|
9
|
+
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
|
10
|
+
config.hook_into :webmock
|
11
|
+
config.default_cassette_options = { allow_unused_http_interactions: false }
|
12
|
+
config.configure_rspec_metadata!
|
13
|
+
end
|
data/templates/.gitkeep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-catme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emile Filteau
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-12 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.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
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: vcr
|
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: webmock
|
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: A lita handler that fetch random cat images
|
140
|
+
email:
|
141
|
+
- emile.filteau@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".travis.yml"
|
148
|
+
- Gemfile
|
149
|
+
- README.md
|
150
|
+
- Rakefile
|
151
|
+
- dump.rdb
|
152
|
+
- lib/lita-catme.rb
|
153
|
+
- lib/lita/handlers/cat.rb
|
154
|
+
- lib/lita/handlers/catme.rb
|
155
|
+
- lita-catme.gemspec
|
156
|
+
- locales/en.yml
|
157
|
+
- spec/fixtures/vcr_cassettes/fetch_cat.yml
|
158
|
+
- spec/fixtures/vcr_cassettes/fetch_multiple_cats.yml
|
159
|
+
- spec/fixtures/vcr_cassettes/fetch_with_category.yml
|
160
|
+
- spec/fixtures/vcr_cassettes/fetch_with_invalid_category.yml
|
161
|
+
- spec/lita/handlers/cat_spec.rb
|
162
|
+
- spec/lita/handlers/catme_spec.rb
|
163
|
+
- spec/spec_helper.rb
|
164
|
+
- templates/.gitkeep
|
165
|
+
homepage: https://github.com/Emile-Filteau/lita-catme
|
166
|
+
licenses:
|
167
|
+
- MIT
|
168
|
+
metadata:
|
169
|
+
lita_plugin_type: handler
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
requirements: []
|
185
|
+
rubyforge_project:
|
186
|
+
rubygems_version: 2.5.1
|
187
|
+
signing_key:
|
188
|
+
specification_version: 4
|
189
|
+
summary: A lita handler that fetch random cat images
|
190
|
+
test_files:
|
191
|
+
- spec/fixtures/vcr_cassettes/fetch_cat.yml
|
192
|
+
- spec/fixtures/vcr_cassettes/fetch_multiple_cats.yml
|
193
|
+
- spec/fixtures/vcr_cassettes/fetch_with_category.yml
|
194
|
+
- spec/fixtures/vcr_cassettes/fetch_with_invalid_category.yml
|
195
|
+
- spec/lita/handlers/cat_spec.rb
|
196
|
+
- spec/lita/handlers/catme_spec.rb
|
197
|
+
- spec/spec_helper.rb
|