lita-google-images 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4bc36412c0c5156ab0ffed74fe5fbcdff1e23d5
4
- data.tar.gz: 96e450e761edcdf46b67eac2bd56b8156718cf87
3
+ metadata.gz: a7f8e2ee12d735f4214e6aac5a3438ff770b5620
4
+ data.tar.gz: 7e2b9dcbfdf686ad7e4a3df44d7d3cf3d08e2d43
5
5
  SHA512:
6
- metadata.gz: 2fbcff89238256c8e7022f49542956aba93dbed8e23d4a54d453d5832551b3a73e6bc306de89fac4b898704e914fa55510cfe71ea56cb63705b2afef19d63617
7
- data.tar.gz: 5839266460ac7db8b237edb1513ec48893f5a4d471d0e13ac6ab56b02586392c544d09ece53b6f42b6e3b22cc4a6acb77e02b38e53e8479a96dfc82d9204c219
6
+ metadata.gz: 92a46e59c670f62deb8550edf192856486a295bcffe6d60c84eea205d8f967e364e1fd8dd497dec384428c7028b888ea83b138a27df3c2d1f7ead6d74aac47fe
7
+ data.tar.gz: 54c4f0e5109430feaca1e0fa45ef8931ded17e1d3795c67571164a5ef3ec7a4dd81d2a906b64440134b50873a2b12e5d46364e3231763deee01e1fe70f991174
data/README.md CHANGED
@@ -46,7 +46,16 @@ Lita: img carl the pug
46
46
  Lita: img me carl the pug
47
47
  ```
48
48
 
49
- The second form is for those coming from [Hubot](http://hubot.github.com/).
49
+ The following are all equivalent ways of askign Lita to search for an animated GIF of "carl the pug":
50
+
51
+ ```
52
+ Lita: animate carl the pug
53
+ Lita: animate me carl the pug
54
+ Lita: gif carl the pug
55
+ Lita: gif me carl the pug
56
+ ```
57
+
58
+ The second form ("verb me") is to ease the transition for people coming from [Hubot](http://hubot.github.com/).
50
59
 
51
60
  ## License
52
61
 
@@ -21,11 +21,18 @@ module Lita
21
21
  "image QUERY" => "Displays a random image from Google Images matching the query."
22
22
  })
23
23
 
24
- def fetch(response)
24
+ route(/(?:animate|gif)(?:\s+me)? (.+)/i, :fetch_anim, command: true, help: {
25
+ "animate QUERY" => "Displays a random animation from Google Images matching the query."
26
+ })
27
+
28
+ def fetch_anim(response)
29
+ fetch(response, true)
30
+ end
31
+
32
+ def fetch(response, animated = false)
25
33
  query = response.matches[0][0]
26
34
 
27
- http_response = http.get(
28
- URL,
35
+ query_params = {
29
36
  v: "1.0",
30
37
  searchType: 'image',
31
38
  q: query,
@@ -34,6 +41,20 @@ module Lita
34
41
  rsz: 8,
35
42
  cx: config.google_cse_id,
36
43
  key: config.google_cse_key
44
+ }
45
+
46
+ if animated
47
+ animated_params = {
48
+ fileType: "gif",
49
+ hq: "animated",
50
+ tbs: "itp:animated"
51
+ }
52
+ query_params.merge!(animated_params)
53
+ end
54
+
55
+ http_response = http.get(
56
+ URL,
57
+ query_params
37
58
  )
38
59
 
39
60
  data = MultiJson.load(http_response.body)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-google-images"
3
- spec.version = "3.0.0"
3
+ spec.version = "3.1.0"
4
4
  spec.authors = ["Jimmy Cuadra"]
5
5
  spec.email = ["jimmy@jimmycuadra.com"]
6
6
  spec.description = %q{A Lita handler for fetching images from Google.}
@@ -7,6 +7,12 @@ describe Lita::Handlers::GoogleImages, lita_handler: true do
7
7
  it { is_expected.to route_command("img me foo").to(:fetch) }
8
8
  it { is_expected.to route_command("IMAGE FOO").to(:fetch) }
9
9
 
10
+ it { is_expected.to route_command("animate me foo").to(:fetch_anim) }
11
+ it { is_expected.to route_command("animate foo").to(:fetch_anim) }
12
+ it { is_expected.to route_command("gif foo").to(:fetch_anim) }
13
+ it { is_expected.to route_command("gif me foo").to(:fetch_anim) }
14
+ it { is_expected.to route_command("ANIMATE FOO").to(:fetch_anim) }
15
+
10
16
  describe "#foo" do
11
17
  let(:response) { double("Faraday::Response", status: 200,) }
12
18
  let(:fail_response) { double("Faraday::Response", status: 500) }
@@ -60,6 +66,23 @@ JSON
60
66
  send_command("image carl")
61
67
  expect(replies.last).to eq(%{No images found for "carl".})
62
68
  end
69
+
70
+ it 'replies with an animation when requested' do
71
+ allow(response).to receive(:body).and_return(<<-JSON.chomp
72
+ {
73
+ "items": [
74
+ {
75
+ "link": "http://www.example.com/path/to/an/animation.gif"
76
+ }
77
+ ]
78
+ }
79
+ JSON
80
+ )
81
+ send_command("animate carl")
82
+ expect(replies.last).to eq(
83
+ "http://www.example.com/path/to/an/animation.gif"
84
+ )
85
+ end
63
86
  end
64
87
 
65
88
  context "Failure" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-google-images
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Cuadra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-20 00:00:00.000000000 Z
11
+ date: 2016-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.4.5.1
136
+ rubygems_version: 2.5.1
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: A Lita handler for fetching images from Google.