lita-giphy 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 560b4c0ee6ee239e1d15c4a601af895767cb1ba4
4
+ data.tar.gz: c2dfeebc218b2c83fe44b118b3bd6f7a4332c2d4
5
+ SHA512:
6
+ metadata.gz: 9df174eb71d11cc395cc201578750b5d094b24bb907a72b00186fab0884858352cc37ad10db698eb2cf4192b825d4e2ad764619a3a8e4d714fe1598ee12f19d0
7
+ data.tar.gz: cd0eccfb31408873acb8b44c7292e9c83e8f9235c7867cbf46bbcb9e9e9f190b3791c2e8d4719de502ee72a195f01d79eb8fbb9801c567fab1495b1d20fc2186
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lita-giphy (1.0.0)
5
+ lita (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ daemons (1.1.9)
11
+ diff-lcs (1.2.4)
12
+ eventmachine (1.0.3)
13
+ faraday (0.8.8)
14
+ multipart-post (~> 1.2.0)
15
+ lita (2.2.1)
16
+ bundler (~> 1.3)
17
+ faraday (~> 0.8.7)
18
+ multi_json (~> 1.7.7)
19
+ rack (~> 1.5.2)
20
+ redis-namespace (~> 1.3.0)
21
+ thin (~> 1.5.1)
22
+ thor (~> 0.18.1)
23
+ multi_json (1.7.9)
24
+ multipart-post (1.2.0)
25
+ rack (1.5.2)
26
+ rake (10.1.0)
27
+ redis (3.0.4)
28
+ redis-namespace (1.3.1)
29
+ redis (~> 3.0.0)
30
+ rspec (2.14.1)
31
+ rspec-core (~> 2.14.0)
32
+ rspec-expectations (~> 2.14.0)
33
+ rspec-mocks (~> 2.14.0)
34
+ rspec-core (2.14.5)
35
+ rspec-expectations (2.14.2)
36
+ diff-lcs (>= 1.1.3, < 2.0)
37
+ rspec-mocks (2.14.3)
38
+ thin (1.5.1)
39
+ daemons (>= 1.0.9)
40
+ eventmachine (>= 0.12.6)
41
+ rack (>= 1.0.0)
42
+ thor (0.18.1)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 1.3)
49
+ lita-giphy!
50
+ rake
51
+ rspec (~> 2.14)
@@ -0,0 +1,35 @@
1
+ # lita-giphy
2
+
3
+ **lita-giphy** is a handler for [Lita](https://github.com/jimmycuadra/lita) that adds gif-searching functionality backed by [Giphy](http://giphy.com).
4
+
5
+ Make gif searching fun again. :tada:
6
+
7
+ ## Installation
8
+
9
+ Add lita-giphy to your Lita instance's Gemfile:
10
+ ``` ruby
11
+ gem "lita-giphy"
12
+ ```
13
+
14
+ ## Configuration
15
+
16
+ ### Required attributes
17
+ * `api_key` - Your [Giphy API](https://github.com/giphy/GiphyAPI) key. You can either email the devs for a personal API key, or you can use the default public beta key-- `dc6zaTOxFJmzC`.
18
+
19
+ ### Example
20
+
21
+ ``` ruby
22
+ Lita.configure do |config|
23
+ config.handlers.giphy.api_key = "dc6zaTOxFJmzC"
24
+ end
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```
30
+ Lita: giphy swanson dance
31
+ ```
32
+
33
+ ```
34
+ Lita: giphy me emo spiderman
35
+ ```
@@ -0,0 +1 @@
1
+ require "lita/handlers/giphy"
@@ -0,0 +1,65 @@
1
+ require 'lita'
2
+ module Lita
3
+ module Handlers
4
+ class Giphy < Handler
5
+ URL = "http://api.giphy.com/v1/gifs/search"
6
+
7
+ route(/(?:giphy)(?:\s+me)?\s+(.+)/i, :giphy, command: true, help: {
8
+ "giphy QUERY" => "Grabs a gif tagged with QUERY."
9
+ })
10
+
11
+ def self.default_config(config)
12
+ config.api_key = nil
13
+ end
14
+
15
+ def giphy(response)
16
+ return unless validate(response)
17
+
18
+ query = response.matches[0][0]
19
+ response.reply get_gif(query)
20
+ end
21
+
22
+ private
23
+
24
+ def validate(response)
25
+ if Lita.config.handlers.giphy.api_key.nil?
26
+ response.reply "Giphy API key required"
27
+ return false
28
+ end
29
+
30
+ true
31
+ end
32
+
33
+ def get_gif(query)
34
+ process_response(http.get(
35
+ URL,
36
+ q: query,
37
+ api_key: Lita.config.handlers.giphy.api_key
38
+ ), query)
39
+ end
40
+
41
+ def process_response(http_response, query)
42
+ data = MultiJson.load(http_response.body)
43
+
44
+ if data["meta"]["status"] == 200
45
+ choice = data["data"].sample
46
+ if choice.nil?
47
+ reply_text = "I couldn't find anything for '#{query}'!"
48
+ else
49
+ reply_text = choice["images"]["original"]["url"]
50
+ end
51
+ else
52
+ reason = data["meta"]["error_message"] || "unknown error"
53
+ Lita.logger.warn(
54
+ "Couldn't get image from Giphy: #{reason}"
55
+ )
56
+ reply_text = "Giphy request failed-- please check my logs."
57
+ end
58
+
59
+ reply_text
60
+ end
61
+ end
62
+
63
+ Lita.register_handler(Giphy)
64
+ end
65
+ end
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-giphy"
3
+ spec.version = "1.0.0"
4
+ spec.authors = ["Jordan Killpack"]
5
+ spec.email = ["jordan.killpack@gatech.edu"]
6
+ spec.description = %q{Giphy gif search handler for Lita}
7
+ spec.summary = %q{Giphy gif search handler for Lita}
8
+ spec.homepage = "https://github.com/killpack/lita-giphy"
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency "lita", "~> 2.0"
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "rspec", "~> 2.14"
21
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::Giphy, lita_handler: true do
4
+ it { routes_command("giphy swanson dance").to :giphy }
5
+
6
+ it "sets the Giphy API key to nil by default" do
7
+ expect(Lita.config.handlers.giphy.api_key).to be_nil
8
+ end
9
+
10
+ describe "#giphy" do
11
+ it "replies that the Giphy API key is required" do
12
+ send_command("giphy swanson dance")
13
+ expect(replies.last).to include("Giphy API key required")
14
+ end
15
+
16
+ context "when the Giphy API key is set" do
17
+ before do
18
+ Lita.config.handlers.giphy.api_key = "foobarbaz"
19
+ end
20
+
21
+ context "with a result-returning query" do
22
+ let(:body) do
23
+ <<-BODY.chomp
24
+ { "data":[
25
+ {"type":"gif", "id":"11nMit55uRGIuc", "url":"http:\/\/giphy.com\/gifs\/11nMit55uRGIuc",
26
+ "bitly_gif_url":"http:\/\/gph.is\/18Abg9K", "bitly_fullscreen_url":"http:\/\/gph.is\/18AbeyG", "bitly_tiled_url":"http:\/\/gph.is\/17vT1VT", "embed_url":"http:\/\/giphy.com\/embed\/11nMit55uRGIuc", "images":
27
+ {
28
+ "fixed_height":
29
+ {"url":"http:\/\/media0.giphy.com\/media\/11nMit55uRGIuc\/200.gif", "width":"355", "height":"200"},
30
+ "fixed_height_still":
31
+ {"url":"http:\/\/media1.giphy.com\/media\/11nMit55uRGIuc\/200_s.gif","width":"355","height":"200"},
32
+ "fixed_height_downsampled":
33
+ {"url":"http:\/\/media0.giphy.com\/media\/11nMit55uRGIuc\/200_d.gif","width":"355","height":"200"},
34
+ "fixed_width":
35
+ {"url":"http:\/\/media1.giphy.com\/media\/11nMit55uRGIuc\/200w.gif","width":"200","height":"113"},
36
+ "fixed_width_still":
37
+ {"url":"http:\/\/media2.giphy.com\/media\/11nMit55uRGIuc\/200w_s.gif","width":"200","height":"113"},
38
+ "fixed_width_downsampled":
39
+ {"url":"http:\/\/media0.giphy.com\/media\/11nMit55uRGIuc\/200w_d.gif","width":"200","height":"113"},
40
+ "original":
41
+ {"url":"http:\/\/media3.giphy.com\/media\/11nMit55uRGIuc\/giphy.gif", "width":"500", "height":"282", "size":"507637","frames":"20"}
42
+ }
43
+ }
44
+ ],
45
+ "pagination":
46
+ {"total_count":5, "count":5, "offset":0},
47
+ "meta":
48
+ {"status":200,"msg":"OK"}
49
+ }
50
+ BODY
51
+ end
52
+
53
+ let(:response) { double("Faraday::Response", status: 200, body: body) }
54
+
55
+ before do
56
+ allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
57
+ end
58
+
59
+ it "replies with the original URL to a gif" do
60
+ send_command("giphy swanson dance")
61
+ expect(replies.last).to include("http:\/\/media3.giphy.com\/media\/11nMit55uRGIuc\/giphy.gif")
62
+ end
63
+ end
64
+
65
+ context "with a query that returns no results" do
66
+ let(:body) { '{"data":[],"pagination":{"total_count":0,"count":0,"offset":0},"meta":{"status":200,"msg":"OK"}}' }
67
+ let(:response) { double("Faraday::Response", status: 200, body: body) }
68
+
69
+ before do
70
+ allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(response)
71
+ end
72
+
73
+ it "responds with an informative message" do
74
+ send_command("giphy asdf")
75
+ expect(replies.last).to include("I couldn't find anything for 'asdf'!")
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,2 @@
1
+ require 'lita-giphy'
2
+ require 'lita/rspec'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-giphy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Killpack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-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: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.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.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: '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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ description: Giphy gif search handler for Lita
70
+ email:
71
+ - jordan.killpack@gatech.edu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - README.md
80
+ - lib/lita-giphy.rb
81
+ - lib/lita/handlers/giphy.rb
82
+ - lita-giphy.gemspec
83
+ - spec/lita/handlers/giphy_spec.rb
84
+ - spec/spec_helper.rb
85
+ homepage: https://github.com/killpack/lita-giphy
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.0.3
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Giphy gif search handler for Lita
109
+ test_files:
110
+ - spec/lita/handlers/giphy_spec.rb
111
+ - spec/spec_helper.rb
112
+ has_rdoc: