lita-onewheel-images 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lita/handlers/onewheel_images.rb +15 -0
- data/lita-onewheel-images.gemspec +1 -1
- data/spec/fixtures/giphy_result.json +243 -0
- data/spec/lita/handlers/onewheel_images_spec.rb +14 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a76b6fcfa5b5becfae3a57e6b9cbbb1b138fa6ba
|
4
|
+
data.tar.gz: 2d0d7c7c4d4e03d2c4f57c4ba8f80683d702436d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 409de8ceec3b5f75808506d79331f52157082f2c35a5fdfed3f8a888937e9e537db6782b0956b935e36c8aaf63159292839a12056b9bae6371fc84acb5e87e3c
|
7
|
+
data.tar.gz: 20b28fac78f297e6f3175b48ec2871a293c438511955045422f519ff8559e3ded1621f0583a16e6f65c8f3523aff3674fd6d13de099ae4c91ffa71a4251e110b
|
@@ -8,6 +8,7 @@ module Lita
|
|
8
8
|
config :safe_search, required: false, default: 'medium'
|
9
9
|
|
10
10
|
route /^image\s+(.*)$/, :image, command: true
|
11
|
+
route /^giphy\s+(.*)$/, :giphy, command: true
|
11
12
|
|
12
13
|
def image(response)
|
13
14
|
query = response.matches[0][0]
|
@@ -15,6 +16,20 @@ module Lita
|
|
15
16
|
response.reply result['items'][0]['link']
|
16
17
|
end
|
17
18
|
|
19
|
+
def giphy(response)
|
20
|
+
query = 'giphy ' + response.matches[0][0]
|
21
|
+
result = ::OnewheelGoogle::search(query, config.custom_search_engine_id, config.google_api_key, config.safe_search, image = true)
|
22
|
+
|
23
|
+
if result
|
24
|
+
result['items'].each do |r|
|
25
|
+
if r['mime'] == 'image/gif'
|
26
|
+
response.reply r['link']
|
27
|
+
break
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
18
33
|
Lita.register_handler(self)
|
19
34
|
end
|
20
35
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'lita-onewheel-images'
|
3
|
-
spec.version = '0.
|
3
|
+
spec.version = '0.2.0'
|
4
4
|
spec.authors = ['Andrew Kreps']
|
5
5
|
spec.email = ['andrew.kreps@gmail.com']
|
6
6
|
spec.description = 'An implementation of Google Custom Search Engine for image searches in chat.'
|
@@ -0,0 +1,243 @@
|
|
1
|
+
{
|
2
|
+
"kind": "customsearch#search",
|
3
|
+
"url": {
|
4
|
+
"type": "application/json",
|
5
|
+
"template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
|
6
|
+
},
|
7
|
+
"queries": {
|
8
|
+
"request": [
|
9
|
+
{
|
10
|
+
"title": "Google Custom Search - giphy boop",
|
11
|
+
"totalResults": "983000",
|
12
|
+
"searchTerms": "giphy boop",
|
13
|
+
"count": 10,
|
14
|
+
"startIndex": 1,
|
15
|
+
"inputEncoding": "utf8",
|
16
|
+
"outputEncoding": "utf8",
|
17
|
+
"safe": "medium",
|
18
|
+
"cx": "016450909327860943906:3a3e35xbkzu",
|
19
|
+
"searchType": "image"
|
20
|
+
}
|
21
|
+
],
|
22
|
+
"nextPage": [
|
23
|
+
{
|
24
|
+
"title": "Google Custom Search - giphy boop",
|
25
|
+
"totalResults": "983000",
|
26
|
+
"searchTerms": "giphy boop",
|
27
|
+
"count": 10,
|
28
|
+
"startIndex": 11,
|
29
|
+
"inputEncoding": "utf8",
|
30
|
+
"outputEncoding": "utf8",
|
31
|
+
"safe": "medium",
|
32
|
+
"cx": "016450909327860943906:3a3e35xbkzu",
|
33
|
+
"searchType": "image"
|
34
|
+
}
|
35
|
+
]
|
36
|
+
},
|
37
|
+
"context": {
|
38
|
+
"title": "Google"
|
39
|
+
},
|
40
|
+
"searchInformation": {
|
41
|
+
"searchTime": 0.257185,
|
42
|
+
"formattedSearchTime": "0.26",
|
43
|
+
"totalResults": "983000",
|
44
|
+
"formattedTotalResults": "983,000"
|
45
|
+
},
|
46
|
+
"items": [
|
47
|
+
{
|
48
|
+
"kind": "customsearch#result",
|
49
|
+
"title": "Boop GIF - Find & Share on GIPHY",
|
50
|
+
"htmlTitle": "<b>Boop</b> GIF - Find & Share on <b>GIPHY</b>",
|
51
|
+
"link": "https://media.giphy.com/media/lcvjDNIJ8CS88/giphy.gif",
|
52
|
+
"displayLink": "giphy.com",
|
53
|
+
"snippet": "Download",
|
54
|
+
"htmlSnippet": "Download",
|
55
|
+
"mime": "image/gif",
|
56
|
+
"fileFormat": "Image Document",
|
57
|
+
"image": {
|
58
|
+
"contextLink": "http://giphy.com/gifs/boop-cat-dog-lcvjDNIJ8CS88",
|
59
|
+
"height": 221,
|
60
|
+
"width": 327,
|
61
|
+
"byteSize": 456668,
|
62
|
+
"thumbnailLink": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSW5ZuGyYPjT02SxK0eo74oO8oe-ZjyZ4akCbdjelvYwpMOy9D7aiYycQ",
|
63
|
+
"thumbnailHeight": 80,
|
64
|
+
"thumbnailWidth": 118
|
65
|
+
}
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"kind": "customsearch#result",
|
69
|
+
"title": "Boop GIFs - Find & Share on GIPHY",
|
70
|
+
"htmlTitle": "<b>Boop</b> GIFs - Find & Share on <b>GIPHY</b>",
|
71
|
+
"link": "https://media0.giphy.com/media/13eFBWrZEnJTGM/200_s.gif",
|
72
|
+
"displayLink": "giphy.com",
|
73
|
+
"snippet": "cat animals dolphin boop",
|
74
|
+
"htmlSnippet": "cat animals dolphin <b>boop</b>",
|
75
|
+
"mime": "image/gif",
|
76
|
+
"fileFormat": "Image Document",
|
77
|
+
"image": {
|
78
|
+
"contextLink": "http://giphy.com/search/boop",
|
79
|
+
"height": 200,
|
80
|
+
"width": 267,
|
81
|
+
"byteSize": 41044,
|
82
|
+
"thumbnailLink": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTQ-VJTyGJre8jiTRNXUd-XYBr3BVQK9N8xhrY3lALE9Ndev3Dtg5ZdwA",
|
83
|
+
"thumbnailHeight": 85,
|
84
|
+
"thumbnailWidth": 113
|
85
|
+
}
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"kind": "customsearch#result",
|
89
|
+
"title": "Boop GIFs - Find & Share on GIPHY",
|
90
|
+
"htmlTitle": "<b>Boop</b> GIFs - Find & Share on <b>GIPHY</b>",
|
91
|
+
"link": "https://media.giphy.com/media/Mf4NqZAknusBq/giphy-facebook_s.jpg",
|
92
|
+
"displayLink": "giphy.com",
|
93
|
+
"snippet": "cheezburger cat boop",
|
94
|
+
"htmlSnippet": "cheezburger cat <b>boop</b>",
|
95
|
+
"mime": "image/jpeg",
|
96
|
+
"image": {
|
97
|
+
"contextLink": "http://giphy.com/search/boop",
|
98
|
+
"height": 270,
|
99
|
+
"width": 480,
|
100
|
+
"byteSize": 69091,
|
101
|
+
"thumbnailLink": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRSLVvaau7zPfCgyNWJ3cQzd4tcbxwqB1w6Pn4Voqtn-5gx9EIww6-HXQE",
|
102
|
+
"thumbnailHeight": 73,
|
103
|
+
"thumbnailWidth": 129
|
104
|
+
}
|
105
|
+
},
|
106
|
+
{
|
107
|
+
"kind": "customsearch#result",
|
108
|
+
"title": "Boop GIFs - Find & Share on GIPHY",
|
109
|
+
"htmlTitle": "<b>Boop</b> GIFs - Find & Share on <b>GIPHY</b>",
|
110
|
+
"link": "https://media1.giphy.com/media/34SJjVcQuih1K/200_s.gif",
|
111
|
+
"displayLink": "giphy.com",
|
112
|
+
"snippet": "archer boop affectionate nose",
|
113
|
+
"htmlSnippet": "archer <b>boop</b> affectionate nose",
|
114
|
+
"mime": "image/gif",
|
115
|
+
"fileFormat": "Image Document",
|
116
|
+
"image": {
|
117
|
+
"contextLink": "http://giphy.com/search/boop",
|
118
|
+
"height": 200,
|
119
|
+
"width": 355,
|
120
|
+
"byteSize": 42424,
|
121
|
+
"thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ-MJrWoGpSfRP-DSrN94Wi36qfEPn6pQZlyo1DMau6luE1I79Ou74aUg",
|
122
|
+
"thumbnailHeight": 68,
|
123
|
+
"thumbnailWidth": 121
|
124
|
+
}
|
125
|
+
},
|
126
|
+
{
|
127
|
+
"kind": "customsearch#result",
|
128
|
+
"title": "Boop Gifs Find Share On Giphy - toublanc.info",
|
129
|
+
"htmlTitle": "<b>Boop</b> Gifs Find Share On <b>Giphy</b> - toublanc.info",
|
130
|
+
"link": "https://media.giphy.com/media/10MSCF1viNV7zy/giphy-facebook_s.jpg",
|
131
|
+
"displayLink": "www.toublanc.info",
|
132
|
+
"snippet": "Boop Gifs Find Share On Giphy",
|
133
|
+
"htmlSnippet": "<b>Boop</b> Gifs Find Share On <b>Giphy</b>",
|
134
|
+
"mime": "image/jpeg",
|
135
|
+
"image": {
|
136
|
+
"contextLink": "http://www.toublanc.info/boop/boop-gifs-find-share-on-giphy",
|
137
|
+
"height": 270,
|
138
|
+
"width": 480,
|
139
|
+
"byteSize": 25260,
|
140
|
+
"thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRtgNJp-NZsZiq9vrEG-sEs83CTau7AAWZlr25mzU__7Q_zp9FoJiJCodZB",
|
141
|
+
"thumbnailHeight": 73,
|
142
|
+
"thumbnailWidth": 129
|
143
|
+
}
|
144
|
+
},
|
145
|
+
{
|
146
|
+
"kind": "customsearch#result",
|
147
|
+
"title": "Kitty Boop Gifs Find Share On Giphy - toublanc.info",
|
148
|
+
"htmlTitle": "Kitty <b>Boop</b> Gifs Find Share On <b>Giphy</b> - toublanc.info",
|
149
|
+
"link": "https://media2.giphy.com/media/XkRVZy6zREE92/200_s.gif",
|
150
|
+
"displayLink": "www.toublanc.info",
|
151
|
+
"snippet": "Find Share On Giphy : Boop",
|
152
|
+
"htmlSnippet": "Find Share On <b>Giphy</b> : <b>Boop</b>",
|
153
|
+
"mime": "image/gif",
|
154
|
+
"fileFormat": "Image Document",
|
155
|
+
"image": {
|
156
|
+
"contextLink": "http://www.toublanc.info/kitty/kitty-boop-gifs-find-share-on-giphy",
|
157
|
+
"height": 200,
|
158
|
+
"width": 355,
|
159
|
+
"byteSize": 47765,
|
160
|
+
"thumbnailLink": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTqwyjfUsEinEoDi-f_5-DxDe7Ab3JI0e1JGVNQ8fwdJIefWLYSQ9aWs7Q",
|
161
|
+
"thumbnailHeight": 68,
|
162
|
+
"thumbnailWidth": 121
|
163
|
+
}
|
164
|
+
},
|
165
|
+
{
|
166
|
+
"kind": "customsearch#result",
|
167
|
+
"title": "Nose Boops Gifs Find Share On Giphy - toublanc.info",
|
168
|
+
"htmlTitle": "Nose Boops Gifs Find Share On <b>Giphy</b> - toublanc.info",
|
169
|
+
"link": "https://media.giphy.com/media/3o85xHdmOjqVj4Wp9u/giphy-facebook_s.jpg",
|
170
|
+
"displayLink": "www.toublanc.info",
|
171
|
+
"snippet": "Find Share On Giphy : Boop",
|
172
|
+
"htmlSnippet": "Find Share On <b>Giphy</b> : <b>Boop</b>",
|
173
|
+
"mime": "image/jpeg",
|
174
|
+
"image": {
|
175
|
+
"contextLink": "http://www.toublanc.info/nose/nose-boops-gifs-find-share-on-giphy",
|
176
|
+
"height": 270,
|
177
|
+
"width": 480,
|
178
|
+
"byteSize": 27159,
|
179
|
+
"thumbnailLink": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQxOsIZlXWN52BPrIRhAyHZ-6lJSFI5C_6d2-PciURlFVzrSZc-ra8DGAFn",
|
180
|
+
"thumbnailHeight": 73,
|
181
|
+
"thumbnailWidth": 129
|
182
|
+
}
|
183
|
+
},
|
184
|
+
{
|
185
|
+
"kind": "customsearch#result",
|
186
|
+
"title": "via GIPHY | Gif | Pinterest | Betty Boop, Gifs and Black And White",
|
187
|
+
"htmlTitle": "via <b>GIPHY</b> | Gif | Pinterest | Betty <b>Boop</b>, Gifs and Black And White",
|
188
|
+
"link": "https://s-media-cache-ak0.pinimg.com/736x/28/87/30/28873052e78c32db5f29d3f117adefd5.jpg",
|
189
|
+
"displayLink": "www.pinterest.com",
|
190
|
+
"snippet": "via GIPHY",
|
191
|
+
"htmlSnippet": "via <b>GIPHY</b>",
|
192
|
+
"mime": "image/jpeg",
|
193
|
+
"image": {
|
194
|
+
"contextLink": "https://www.pinterest.com/pin/175921929172738300/",
|
195
|
+
"height": 240,
|
196
|
+
"width": 320,
|
197
|
+
"byteSize": 19572,
|
198
|
+
"thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTNWZgIoUYpj3PlrV586GRK9dk_llCgpc_eL3GucYE2YZ_dbxp4b9-5ARM",
|
199
|
+
"thumbnailHeight": 89,
|
200
|
+
"thumbnailWidth": 118
|
201
|
+
}
|
202
|
+
},
|
203
|
+
{
|
204
|
+
"kind": "customsearch#result",
|
205
|
+
"title": "Kitty Boop Gifs Find Share On Giphy - toublanc.info",
|
206
|
+
"htmlTitle": "Kitty <b>Boop</b> Gifs Find Share On <b>Giphy</b> - toublanc.info",
|
207
|
+
"link": "https://media.giphy.com/media/beO6G4MleCWVW/giphy-facebook_s.jpg",
|
208
|
+
"displayLink": "www.toublanc.info",
|
209
|
+
"snippet": "Find Share On Giphy : Boop",
|
210
|
+
"htmlSnippet": "Find Share On <b>Giphy</b> : <b>Boop</b>",
|
211
|
+
"mime": "image/jpeg",
|
212
|
+
"image": {
|
213
|
+
"contextLink": "http://www.toublanc.info/kitty/kitty-boop-gifs-find-share-on-giphy",
|
214
|
+
"height": 270,
|
215
|
+
"width": 480,
|
216
|
+
"byteSize": 82398,
|
217
|
+
"thumbnailLink": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTWd_V_Zush_3p0UHFS5A1jMGNNKI5ZIOogzqylBRhOayZX7RVd1rxKii1B",
|
218
|
+
"thumbnailHeight": 73,
|
219
|
+
"thumbnailWidth": 129
|
220
|
+
}
|
221
|
+
},
|
222
|
+
{
|
223
|
+
"kind": "customsearch#result",
|
224
|
+
"title": "Boop GIF - Find & Share on GIPHY",
|
225
|
+
"htmlTitle": "<b>Boop</b> GIF - Find & Share on <b>GIPHY</b>",
|
226
|
+
"link": "https://media.giphy.com/media/ogIiGCBFL6PGE/giphy.gif",
|
227
|
+
"displayLink": "giphy.com",
|
228
|
+
"snippet": "Download",
|
229
|
+
"htmlSnippet": "Download",
|
230
|
+
"mime": "image/gif",
|
231
|
+
"fileFormat": "Image Document",
|
232
|
+
"image": {
|
233
|
+
"contextLink": "http://giphy.com/gifs/boop-snoot-ogIiGCBFL6PGE",
|
234
|
+
"height": 350,
|
235
|
+
"width": 350,
|
236
|
+
"byteSize": 2073426,
|
237
|
+
"thumbnailLink": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcT3oZIL0CV35gpLDrRYbWL7gNOvH0TIMEfgjSUj3O2LNinJ_OYL1psExTc",
|
238
|
+
"thumbnailHeight": 120,
|
239
|
+
"thumbnailWidth": 120
|
240
|
+
}
|
241
|
+
}
|
242
|
+
]
|
243
|
+
}
|
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'onewheel-google'
|
3
3
|
|
4
|
+
def mock_it_up(file)
|
5
|
+
mock_result_json = File.open("spec/fixtures/#{file}.json").read
|
6
|
+
allow(OnewheelGoogle).to receive(:search).and_return(JSON.parse mock_result_json)
|
7
|
+
end
|
8
|
+
|
4
9
|
describe Lita::Handlers::OnewheelImages, lita_handler: true do
|
5
10
|
|
6
11
|
before(:each) do
|
7
|
-
mock_result_json = File.open('spec/fixtures/mock_result.json').read
|
8
|
-
allow(OnewheelGoogle).to receive(:search).and_return(JSON.parse mock_result_json)
|
9
|
-
|
10
12
|
registry.configure do |config|
|
11
13
|
config.handlers.onewheel_images.custom_search_engine_id = ''
|
12
14
|
config.handlers.onewheel_images.google_api_key = ''
|
@@ -14,9 +16,18 @@ describe Lita::Handlers::OnewheelImages, lita_handler: true do
|
|
14
16
|
end
|
15
17
|
|
16
18
|
it { is_expected.to route_command('image something') }
|
19
|
+
it { is_expected.to route_command('giphy something') }
|
17
20
|
|
18
21
|
it 'does neat imagey things' do
|
22
|
+
mock_it_up('mock_result')
|
23
|
+
|
19
24
|
send_command 'image yo'
|
20
25
|
expect(replies.last).to eq('https://s-media-cache-ak0.pinimg.com/736x/4a/43/a4/4a43a4b6569cf8a197b6c9217de3f412.jpg')
|
21
26
|
end
|
27
|
+
|
28
|
+
it 'does neat gif-y things' do
|
29
|
+
mock_it_up('giphy_result')
|
30
|
+
send_command 'giphy boop'
|
31
|
+
expect(replies.last).to eq('https://media.giphy.com/media/lcvjDNIJ8CS88/giphy.gif')
|
32
|
+
end
|
22
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-onewheel-images
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kreps
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- lib/lita-onewheel-images.rb
|
140
140
|
- lib/lita/handlers/onewheel_images.rb
|
141
141
|
- lita-onewheel-images.gemspec
|
142
|
+
- spec/fixtures/giphy_result.json
|
142
143
|
- spec/fixtures/mock_result.json
|
143
144
|
- spec/lita/handlers/onewheel_images_spec.rb
|
144
145
|
- spec/spec_helper.rb
|
@@ -168,6 +169,7 @@ signing_key:
|
|
168
169
|
specification_version: 4
|
169
170
|
summary: CSE Details to follow
|
170
171
|
test_files:
|
172
|
+
- spec/fixtures/giphy_result.json
|
171
173
|
- spec/fixtures/mock_result.json
|
172
174
|
- spec/lita/handlers/onewheel_images_spec.rb
|
173
175
|
- spec/spec_helper.rb
|