robut-giphy 0.1.0
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 +7 -0
- data/.gitignore +35 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +42 -0
- data/LICENSE +23 -0
- data/README.md +67 -0
- data/Rakefile +11 -0
- data/lib/robut/plugin/giphy.rb +2 -0
- data/lib/robut/plugin/giphy/base.rb +22 -0
- data/lib/robut/plugin/giphy/giphy.rb +38 -0
- data/lib/robut/plugin/giphy/meme.rb +32 -0
- data/lib/robut/plugin/giphy/version.rb +8 -0
- data/robut-giphy.gemspec +26 -0
- data/test/giphy_test_base.rb +60 -0
- data/test/mocks/connection_mock.rb +22 -0
- data/test/mocks/presence_mock.rb +25 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/plugin/giphy_test.rb +39 -0
- data/test/unit/plugin/meme_test.rb +36 -0
- metadata +140 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 37302fd340a01863e7976c8dffb596f14efb6cce
|
|
4
|
+
data.tar.gz: 63d32e310acbcd7f9b9b2b246d9c509d06297c11
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 79bc307f3440d6befea0320cbdb625a926bcab93f8ccf33c0f523bb6fc35be13d4adc9004cb111033605966dc06079e4cf622d7ee4c4bf0930e2e51ff5cf7879
|
|
7
|
+
data.tar.gz: 3dfad789ba2b149abd1fbd0a7ba1995e8dceda5a89221ee4d7183d4c8d141797fd5f79bdd00627427861ee8fc120f0f4b62cf2fc28d4acdcf237a67ee6c75b02
|
data/.gitignore
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/test/tmp/
|
|
9
|
+
/test/version_tmp/
|
|
10
|
+
/tmp/
|
|
11
|
+
|
|
12
|
+
## Specific to RubyMotion:
|
|
13
|
+
.dat*
|
|
14
|
+
.repl_history
|
|
15
|
+
build/
|
|
16
|
+
|
|
17
|
+
## Documentation cache and generated files:
|
|
18
|
+
/.yardoc/
|
|
19
|
+
/_yardoc/
|
|
20
|
+
/doc/
|
|
21
|
+
/rdoc/
|
|
22
|
+
|
|
23
|
+
## Environment normalisation:
|
|
24
|
+
/.bundle/
|
|
25
|
+
/vendor/bundle
|
|
26
|
+
/lib/bundler/man/
|
|
27
|
+
|
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
30
|
+
# Gemfile.lock
|
|
31
|
+
# .ruby-version
|
|
32
|
+
# .ruby-gemset
|
|
33
|
+
|
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
35
|
+
.rvmrc
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
robut-giphy (0.1.0)
|
|
5
|
+
robut
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
addressable (2.3.8)
|
|
11
|
+
crack (0.4.2)
|
|
12
|
+
safe_yaml (~> 1.0.0)
|
|
13
|
+
power_assert (0.2.2)
|
|
14
|
+
rack (1.6.1)
|
|
15
|
+
rack-protection (1.5.3)
|
|
16
|
+
rack
|
|
17
|
+
rake (10.4.2)
|
|
18
|
+
robut (0.5.2)
|
|
19
|
+
sinatra (~> 1.3)
|
|
20
|
+
xmpp4r (~> 0.5.0)
|
|
21
|
+
safe_yaml (1.0.4)
|
|
22
|
+
sinatra (1.4.6)
|
|
23
|
+
rack (~> 1.4)
|
|
24
|
+
rack-protection (~> 1.4)
|
|
25
|
+
tilt (>= 1.3, < 3)
|
|
26
|
+
test-unit (3.0.8)
|
|
27
|
+
power_assert
|
|
28
|
+
tilt (2.0.1)
|
|
29
|
+
webmock (1.21.0)
|
|
30
|
+
addressable (>= 2.3.6)
|
|
31
|
+
crack (>= 0.3.2)
|
|
32
|
+
xmpp4r (0.5.6)
|
|
33
|
+
|
|
34
|
+
PLATFORMS
|
|
35
|
+
ruby
|
|
36
|
+
|
|
37
|
+
DEPENDENCIES
|
|
38
|
+
bundler (~> 1.6)
|
|
39
|
+
rake
|
|
40
|
+
robut-giphy!
|
|
41
|
+
test-unit
|
|
42
|
+
webmock
|
data/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
Copyright (c) 2015 Simon Detheridge
|
|
3
|
+
|
|
4
|
+
MIT License
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
+
a copy of this software and associated documentation files (the
|
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
12
|
+
the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Robut-giphy
|
|
2
|
+
|
|
3
|
+
A giphy plugin and meme generator for the robut hipchat bot.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the gem
|
|
8
|
+
|
|
9
|
+
gem install 'robut-giphy'
|
|
10
|
+
|
|
11
|
+
Add these lines to your Chatfile:
|
|
12
|
+
|
|
13
|
+
require 'robut/plugin/giphy'
|
|
14
|
+
|
|
15
|
+
Robut::Plugin.plugins << Robot::Plugin::Giphy
|
|
16
|
+
|
|
17
|
+
For meme-generation support, also add the following:
|
|
18
|
+
|
|
19
|
+
require 'robut/plugin/giphy/memes'
|
|
20
|
+
|
|
21
|
+
Robut::Plugin.plugins << Robut::Plugin::Giphy::Memes
|
|
22
|
+
|
|
23
|
+
By default, robut-giphy uses the Giphy beta API key. You may wish to replace
|
|
24
|
+
this with your own API key:
|
|
25
|
+
|
|
26
|
+
Robut::Plugin::Giphy.configure do |c|
|
|
27
|
+
c.api_key = 'your_api_key'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
robut-giphy filters results to those set to PG by default. If you want to
|
|
31
|
+
change this:
|
|
32
|
+
|
|
33
|
+
Robut::Plugin::Giphy.configure do |c|
|
|
34
|
+
c.rating = 'pg-13' # pg, pg-13 or r
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
This plugin searches giphy for a random gif matching a search phrase, and
|
|
40
|
+
displays it in chat. For example:
|
|
41
|
+
|
|
42
|
+
@robut giphy funny kitten
|
|
43
|
+
|
|
44
|
+
If the meme plugin is also loaded, the gif will be run through memecaption to
|
|
45
|
+
add up to two lines of text
|
|
46
|
+
|
|
47
|
+
@robut giphy funny kitten; a top caption goes here
|
|
48
|
+
|
|
49
|
+
@robut giphy cat wig; a top caption; a bottom caption
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## Contributing
|
|
53
|
+
|
|
54
|
+
You probably know the drill already...
|
|
55
|
+
|
|
56
|
+
1. Fork it
|
|
57
|
+
2. Create a feature branch
|
|
58
|
+
3. Write some tests
|
|
59
|
+
4. Commit your changes
|
|
60
|
+
5. Push to the branch
|
|
61
|
+
6. Create a new Pull Request
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
(c) Simon Detheridge, 2015
|
|
66
|
+
Released under the MIT License
|
|
67
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'robut/plugin'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
class Robut::Plugin::Giphy
|
|
6
|
+
module Base
|
|
7
|
+
def giphy_uri(gif)
|
|
8
|
+
uri = "http://api.giphy.com/v1/gifs/random?api_key=#{CGI::escape(Robut::Plugin::Giphy.api_key)}&tag=#{CGI::escape(gif)}&rating=#{CGI::escape(Robut::Plugin::Giphy.rating)}"
|
|
9
|
+
|
|
10
|
+
response = Net::HTTP.get_response(URI.parse(uri))
|
|
11
|
+
raise "Giphy didn't like it" unless response.code.to_i == 200
|
|
12
|
+
|
|
13
|
+
result = JSON.parse(response.body)
|
|
14
|
+
if result['data'] && result['data'].include?('image_url')
|
|
15
|
+
result['data']['image_url']
|
|
16
|
+
else
|
|
17
|
+
nil
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'robut/plugin'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'ostruct'
|
|
5
|
+
require 'robut/plugin/giphy/base'
|
|
6
|
+
|
|
7
|
+
class Robut::Plugin::Giphy
|
|
8
|
+
include Robut::Plugin
|
|
9
|
+
include Robut::Plugin::Giphy::Base
|
|
10
|
+
|
|
11
|
+
def self.configuration
|
|
12
|
+
@config ||= OpenStruct.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.configure
|
|
16
|
+
yield(configuration) if block_given?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
desc "giphy <subject> - searches for and displays a gif matching <subject> from giphy"
|
|
20
|
+
match /^giphy ([^;]+)$/, :sent_to_me => true do |gif|
|
|
21
|
+
begin
|
|
22
|
+
uri = giphy_uri(gif)
|
|
23
|
+
reply(uri ? "#{uri}\nPowered by Giphy" : "Sorry, I couldn't find a gif for that.")
|
|
24
|
+
rescue
|
|
25
|
+
reply('Giphy returned an error')
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
def self.api_key
|
|
31
|
+
Robut::Plugin::Giphy.configuration.api_key || 'dc6zaTOxFJmzC'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.rating
|
|
35
|
+
Robut::Plugin::Giphy.configuration.rating || 'pg'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'robut/plugin'
|
|
2
|
+
require 'robut/plugin/giphy/base'
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
class Robut::Plugin::Giphy::Meme
|
|
7
|
+
include Robut::Plugin
|
|
8
|
+
include Robut::Plugin::Giphy::Base
|
|
9
|
+
|
|
10
|
+
desc "giphy <subject>; <line_1> [; <line_2>] - searches for and displays a gif matching <subject> from giphy, with meme text line_1 and line_2 overlaid"
|
|
11
|
+
match /^giphy ([^;]+);(.*)$/, :sent_to_me => true do |gif, text|
|
|
12
|
+
begin
|
|
13
|
+
uri = giphy_uri(gif)
|
|
14
|
+
if uri
|
|
15
|
+
lines = text.split(';').map {|t| t.strip}
|
|
16
|
+
meme = "http://v1.memecaptain.com/i?u=#{uri}&tt=#{CGI.escape(lines[0])}"
|
|
17
|
+
meme += "&tb=#{CGI.escape(lines[1])}" if lines.count == 2
|
|
18
|
+
|
|
19
|
+
if lines.count < 3
|
|
20
|
+
reply("#{meme}\nPowered by Giphy and MemeCaptain")
|
|
21
|
+
else
|
|
22
|
+
reply("That's too much text. Don't be greedy.")
|
|
23
|
+
end
|
|
24
|
+
else
|
|
25
|
+
reply("Sorry, I couldn't find a gif for that.")
|
|
26
|
+
end
|
|
27
|
+
rescue
|
|
28
|
+
reply('Giphy returned an error')
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
data/robut-giphy.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'robut/plugin/giphy/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "robut-giphy"
|
|
8
|
+
spec.version = Robut::Plugin::Giphy::VERSION
|
|
9
|
+
spec.authors = ["Simon Detheridge"]
|
|
10
|
+
spec.email = ["simon.detheridge@gmail.com"]
|
|
11
|
+
spec.summary = %q{Robut giphy plugin and meme generator}
|
|
12
|
+
spec.description = %q{Enables robut to search for gipy images, and generate memes from those images using memecaptain}
|
|
13
|
+
spec.homepage = "http://github.com/gh2k/robut-giphy"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_dependency "robut"
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
23
|
+
spec.add_development_dependency "rake"
|
|
24
|
+
spec.add_development_dependency "test-unit"
|
|
25
|
+
spec.add_development_dependency "webmock"
|
|
26
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'robut/plugin/giphy'
|
|
2
|
+
require 'webmock/test_unit'
|
|
3
|
+
|
|
4
|
+
module GiphyTestBase
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
@connection = Robut::ConnectionMock.new
|
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
|
9
|
+
@plugin = new_plugin(@presence)
|
|
10
|
+
|
|
11
|
+
Robut::Plugin::Giphy.configure do |config|
|
|
12
|
+
config.api_key = 'dc6zaTOxFJmzC'
|
|
13
|
+
config.rating = 'pg'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
stub_request(:any, "http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=hjklxxxx&rating=pg")
|
|
17
|
+
.to_return(status: 200, body: <<EOT)
|
|
18
|
+
{"data":[],"meta":{"status":200,"msg":"OK"}}
|
|
19
|
+
EOT
|
|
20
|
+
|
|
21
|
+
stub_request(:any, "http://api.giphy.com/v1/gifs/random?api_key=your-mom&tag=american+psycho&rating=pg")
|
|
22
|
+
.to_return(status: 500)
|
|
23
|
+
|
|
24
|
+
stub_request(:any, "http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=american+psycho&rating=pg")
|
|
25
|
+
.to_return(status: 200, body: <<EOT)
|
|
26
|
+
{
|
|
27
|
+
"data": {
|
|
28
|
+
"type": "gif",
|
|
29
|
+
"id": "Ggjwvmqktuvf2",
|
|
30
|
+
"url": "http://giphy.com/gifs/american-psycho-christian-bale-Ggjwvmqktuvf2",
|
|
31
|
+
"image_original_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.gif",
|
|
32
|
+
"image_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.gif",
|
|
33
|
+
"image_mp4_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.mp4",
|
|
34
|
+
"image_frames": "11",
|
|
35
|
+
"image_width": "500",
|
|
36
|
+
"image_height": "256",
|
|
37
|
+
"fixed_height_downsampled_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/200_d.gif",
|
|
38
|
+
"fixed_height_downsampled_width": "391",
|
|
39
|
+
"fixed_height_downsampled_height": "200",
|
|
40
|
+
"fixed_width_downsampled_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/200w_d.gif",
|
|
41
|
+
"fixed_width_downsampled_width": "200",
|
|
42
|
+
"fixed_width_downsampled_height": "102",
|
|
43
|
+
"fixed_height_small_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/100.gif",
|
|
44
|
+
"fixed_height_small_still_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/100_s.gif",
|
|
45
|
+
"fixed_height_small_width": "195",
|
|
46
|
+
"fixed_height_small_height": "100",
|
|
47
|
+
"fixed_width_small_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/100w.gif",
|
|
48
|
+
"fixed_width_small_still_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/100w_s.gif",
|
|
49
|
+
"fixed_width_small_width": "100",
|
|
50
|
+
"fixed_width_small_height": "51"
|
|
51
|
+
},
|
|
52
|
+
"meta": {
|
|
53
|
+
"status": 200,
|
|
54
|
+
"msg": "OK"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
EOT
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'robut/storage/hash_store'
|
|
2
|
+
|
|
3
|
+
class Robut::ConnectionMock < Robut::Connection
|
|
4
|
+
|
|
5
|
+
attr_accessor :messages
|
|
6
|
+
|
|
7
|
+
def initialize(config = nil)
|
|
8
|
+
self.messages = []
|
|
9
|
+
self.config = config || self.class.config
|
|
10
|
+
self.store = Robut::Storage::HashStore
|
|
11
|
+
self.client = Jabber::Client.new ''
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def connect
|
|
15
|
+
self.rooms = []
|
|
16
|
+
self
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def reply(message, to)
|
|
20
|
+
self.messages << [message, to]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'robut/storage/hash_store'
|
|
2
|
+
|
|
3
|
+
class Robut::PresenceMock < Robut::Room
|
|
4
|
+
|
|
5
|
+
def initialize(connection)
|
|
6
|
+
self.connection = connection
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def replies
|
|
10
|
+
@replies ||= []
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def reply(msg, to = nil)
|
|
14
|
+
replies << msg
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def handle_message(plugins, time, nick, message)
|
|
18
|
+
messages << [time, nick, message]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def messages
|
|
22
|
+
@messages ||= []
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'robut/plugin/giphy'
|
|
3
|
+
|
|
4
|
+
class Robut::Plugin::GiphyTest < Test::Unit::TestCase
|
|
5
|
+
include GiphyTestBase
|
|
6
|
+
|
|
7
|
+
def test_replies_with_gif
|
|
8
|
+
@plugin.handle(Time.now, "@john", "@robut giphy american psycho")
|
|
9
|
+
assert_equal ["http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.gif\nPowered by Giphy"], @plugin.reply_to.replies
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_replies_without_gif
|
|
13
|
+
@plugin.handle(Time.now, "@john", "@robut giphy hjklxxxx")
|
|
14
|
+
assert_equal ["Sorry, I couldn't find a gif for that."], @plugin.reply_to.replies
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_doesnt_reply_with_empty
|
|
18
|
+
@plugin.handle(Time.now, "@john", "@robut giphy")
|
|
19
|
+
assert_equal [], @plugin.reply_to.replies
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_doesnt_reply_with_semicolon
|
|
23
|
+
@plugin.handle(Time.now, "@john", "@robut giphy cat; look at this cat")
|
|
24
|
+
assert_equal [], @plugin.reply_to.replies
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_fails_with_invalid_api_key
|
|
28
|
+
Robut::Plugin::Giphy.configure do |config|
|
|
29
|
+
config.api_key = 'your-mom'
|
|
30
|
+
@plugin.handle(Time.now, "@john", "@robut giphy american psycho")
|
|
31
|
+
assert_equal ["Giphy returned an error"], @plugin.reply_to.replies
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
protected
|
|
36
|
+
def new_plugin(presence)
|
|
37
|
+
Robut::Plugin::Giphy.new(presence)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'robut/plugin/giphy/meme'
|
|
3
|
+
|
|
4
|
+
class Robut::Plugin::Giphy::MemeTest < Test::Unit::TestCase
|
|
5
|
+
include GiphyTestBase
|
|
6
|
+
|
|
7
|
+
def test_replies_with_one_line
|
|
8
|
+
@plugin.handle(Time.now, "@john", "@robut giphy american psycho; text on a picture")
|
|
9
|
+
assert_equal ["http://v1.memecaptain.com/i?u=http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.gif&tt=text+on+a+picture\nPowered by Giphy and MemeCaptain"], @plugin.reply_to.replies
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_replies_with_two_lines
|
|
13
|
+
@plugin.handle(Time.now, "@john", "@robut giphy american psycho; text on a picture; isn't it awesome")
|
|
14
|
+
assert_equal ["http://v1.memecaptain.com/i?u=http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.gif&tt=text+on+a+picture&tb=isn%27t+it+awesome\nPowered by Giphy and MemeCaptain"], @plugin.reply_to.replies
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_replies_without_gif
|
|
18
|
+
@plugin.handle(Time.now, "@john", "@robut giphy hjklxxxx; blargh")
|
|
19
|
+
assert_equal ["Sorry, I couldn't find a gif for that."], @plugin.reply_to.replies
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_replies_with_three_semicolons
|
|
23
|
+
@plugin.handle(Time.now, "@john", "@robut giphy american psycho; text on a picture; isn't it awesome; so very awesome")
|
|
24
|
+
assert_equal ["That's too much text. Don't be greedy."], @plugin.reply_to.replies
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_ignores_giphy_without_semicolons
|
|
28
|
+
@plugin.handle(Time.now, "@john", "@robut giphy cat")
|
|
29
|
+
assert_equal [], @plugin.reply_to.replies
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
protected
|
|
33
|
+
def new_plugin(presence)
|
|
34
|
+
Robut::Plugin::Giphy::Meme.new(presence)
|
|
35
|
+
end
|
|
36
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: robut-giphy
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Simon Detheridge
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-06-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: robut
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
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.6'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.6'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: test-unit
|
|
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: webmock
|
|
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
|
+
description: Enables robut to search for gipy images, and generate memes from those
|
|
84
|
+
images using memecaptain
|
|
85
|
+
email:
|
|
86
|
+
- simon.detheridge@gmail.com
|
|
87
|
+
executables: []
|
|
88
|
+
extensions: []
|
|
89
|
+
extra_rdoc_files: []
|
|
90
|
+
files:
|
|
91
|
+
- ".gitignore"
|
|
92
|
+
- ".travis.yml"
|
|
93
|
+
- Gemfile
|
|
94
|
+
- Gemfile.lock
|
|
95
|
+
- LICENSE
|
|
96
|
+
- README.md
|
|
97
|
+
- Rakefile
|
|
98
|
+
- lib/robut/plugin/giphy.rb
|
|
99
|
+
- lib/robut/plugin/giphy/base.rb
|
|
100
|
+
- lib/robut/plugin/giphy/giphy.rb
|
|
101
|
+
- lib/robut/plugin/giphy/meme.rb
|
|
102
|
+
- lib/robut/plugin/giphy/version.rb
|
|
103
|
+
- robut-giphy.gemspec
|
|
104
|
+
- test/giphy_test_base.rb
|
|
105
|
+
- test/mocks/connection_mock.rb
|
|
106
|
+
- test/mocks/presence_mock.rb
|
|
107
|
+
- test/test_helper.rb
|
|
108
|
+
- test/unit/plugin/giphy_test.rb
|
|
109
|
+
- test/unit/plugin/meme_test.rb
|
|
110
|
+
homepage: http://github.com/gh2k/robut-giphy
|
|
111
|
+
licenses:
|
|
112
|
+
- MIT
|
|
113
|
+
metadata: {}
|
|
114
|
+
post_install_message:
|
|
115
|
+
rdoc_options: []
|
|
116
|
+
require_paths:
|
|
117
|
+
- lib
|
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- - ">="
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: '0'
|
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
|
+
requirements:
|
|
125
|
+
- - ">="
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: '0'
|
|
128
|
+
requirements: []
|
|
129
|
+
rubyforge_project:
|
|
130
|
+
rubygems_version: 2.4.5
|
|
131
|
+
signing_key:
|
|
132
|
+
specification_version: 4
|
|
133
|
+
summary: Robut giphy plugin and meme generator
|
|
134
|
+
test_files:
|
|
135
|
+
- test/giphy_test_base.rb
|
|
136
|
+
- test/mocks/connection_mock.rb
|
|
137
|
+
- test/mocks/presence_mock.rb
|
|
138
|
+
- test/test_helper.rb
|
|
139
|
+
- test/unit/plugin/giphy_test.rb
|
|
140
|
+
- test/unit/plugin/meme_test.rb
|