lita-onewheel-giphy 0.2.2 → 0.3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97010ddbf7de2d19b3c68120fcdf2147426bc36a
|
4
|
+
data.tar.gz: 4cd35820d62d6cb8385d05325d6f780e5bb6bc44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a7b6c8500029e148686aafbd65212385e1d5178a1f0e80a5b48650a501c9c36e3090a75fe7c4b8a1792d2089954363c48869e7488e036c370f2147c02edfdf3
|
7
|
+
data.tar.gz: 3f2868ba00fbcb4701ab7ed65547e96abdced176e674dde3e83517f98b531200d4d963346ad305d606ea9d2f01fc8ebdffd34d0eba8bbe50053099163530b86c
|
@@ -8,9 +8,22 @@ module Lita
|
|
8
8
|
config :rating, default: nil
|
9
9
|
config :limit, default: 25
|
10
10
|
|
11
|
-
route /^giphy$/,
|
12
|
-
|
13
|
-
|
11
|
+
route /^giphy$/,
|
12
|
+
:random,
|
13
|
+
command: true,
|
14
|
+
help: {'giphy' => 'Returns a random Giphy image. Powered by Giphy! http://giphy.com'}
|
15
|
+
route /^giphy\s+(.+)$/,
|
16
|
+
:search,
|
17
|
+
command: true,
|
18
|
+
help: {'giphy [keyword]' => 'Returns a random Giphy image with the specified keyword applied.'}
|
19
|
+
route /^giphytrending$/,
|
20
|
+
:trending,
|
21
|
+
command: true,
|
22
|
+
help: {'giphytrending' => 'Returns a trending Giphy image.'}
|
23
|
+
route /^giphytranslate\s+(.+)$/,
|
24
|
+
:translate,
|
25
|
+
command: true,
|
26
|
+
help: {'giphytranslate' => 'Turns your words into a sweet, sweet Giphy gif.'}
|
14
27
|
|
15
28
|
def search(response)
|
16
29
|
keywords = response.matches[0][0]
|
@@ -34,6 +47,14 @@ module Lita
|
|
34
47
|
response.reply image
|
35
48
|
end
|
36
49
|
|
50
|
+
def translate(response)
|
51
|
+
keywords = response.matches[0][0]
|
52
|
+
uri = get_translate_uri(keywords)
|
53
|
+
giphy_data = call_giphy(uri)
|
54
|
+
image = get_translate_image(giphy_data.body)
|
55
|
+
response.reply image
|
56
|
+
end
|
57
|
+
|
37
58
|
def get_search_uri(keywords)
|
38
59
|
# q - search query term or phrase
|
39
60
|
# limit - (optional) number of results to return, maximum 100. Default 25.
|
@@ -57,6 +78,13 @@ module Lita
|
|
57
78
|
config.api_uri + 'trending?'
|
58
79
|
end
|
59
80
|
|
81
|
+
def get_translate_uri(keywords)
|
82
|
+
# s - term or phrase to translate into a GIF
|
83
|
+
# rating - limit results to those rated (y,g, pg, pg-13 or r).
|
84
|
+
# fmt - (optional) return results in html or json format (useful for viewing responses as GIFs to debug/test)
|
85
|
+
config.api_uri + 'translate?s=' + URI.encode(keywords) + '&'
|
86
|
+
end
|
87
|
+
|
60
88
|
def get_random(data)
|
61
89
|
image_data = JSON.parse(data)
|
62
90
|
image_data['data'][get_random_number(image_data['data'].count)]['images']['original']['url']
|
@@ -74,6 +102,11 @@ module Lita
|
|
74
102
|
image_data['data']['image_original_url']
|
75
103
|
end
|
76
104
|
|
105
|
+
def get_translate_image(data)
|
106
|
+
image_data = JSON.parse(data)
|
107
|
+
image_data['data']['url']
|
108
|
+
end
|
109
|
+
|
77
110
|
def call_giphy(uri)
|
78
111
|
Lita.logger.debug("Calling giphy with #{uri}")
|
79
112
|
RestClient.get uri + 'api_key=' + config.api_key
|
data/lita-onewheel-giphy.gemspec
CHANGED
@@ -0,0 +1,128 @@
|
|
1
|
+
{
|
2
|
+
"data": {
|
3
|
+
"type": "gif",
|
4
|
+
"id": "wWAIKcFASEFz2",
|
5
|
+
"url": "http://giphy.com/gifs/superman-santa-chandler-bing-wWAIKcFASEFz2",
|
6
|
+
"bitly_gif_url": "http://gph.is/XMD6gE",
|
7
|
+
"bitly_url": "http://gph.is/XMD6gE",
|
8
|
+
"embed_url": "http://giphy.com/embed/wWAIKcFASEFz2",
|
9
|
+
"username": "",
|
10
|
+
"source": "http://daytripperrevolution.tumblr.com/post/13729531842",
|
11
|
+
"rating": "g",
|
12
|
+
"caption": "",
|
13
|
+
"content_url": "",
|
14
|
+
"import_datetime": "2013-03-24 17:48:35",
|
15
|
+
"trending_datetime": "1970-01-01 00:00:00",
|
16
|
+
"images": {
|
17
|
+
"fixed_height": {
|
18
|
+
"url": "http://media3.giphy.com/media/wWAIKcFASEFz2/200.gif",
|
19
|
+
"width": "358",
|
20
|
+
"height": "200",
|
21
|
+
"size": "126220",
|
22
|
+
"mp4": "http://media2.giphy.com/media/wWAIKcFASEFz2/200.mp4",
|
23
|
+
"mp4_size": "10967",
|
24
|
+
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/200.webp",
|
25
|
+
"webp_size": "186460"
|
26
|
+
},
|
27
|
+
"fixed_height_still": {
|
28
|
+
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/200_s.gif",
|
29
|
+
"width": "358",
|
30
|
+
"height": "200"
|
31
|
+
},
|
32
|
+
"fixed_height_downsampled": {
|
33
|
+
"url": "http://media3.giphy.com/media/wWAIKcFASEFz2/200_d.gif",
|
34
|
+
"width": "358",
|
35
|
+
"height": "200",
|
36
|
+
"size": "352636",
|
37
|
+
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/200_d.webp",
|
38
|
+
"webp_size": "159946"
|
39
|
+
},
|
40
|
+
"fixed_width": {
|
41
|
+
"url": "http://media3.giphy.com/media/wWAIKcFASEFz2/200w.gif",
|
42
|
+
"width": "200",
|
43
|
+
"height": "112",
|
44
|
+
"size": "51889",
|
45
|
+
"mp4": "http://media2.giphy.com/media/wWAIKcFASEFz2/200w.mp4",
|
46
|
+
"mp4_size": "16299",
|
47
|
+
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/200w.webp",
|
48
|
+
"webp_size": "70302"
|
49
|
+
},
|
50
|
+
"fixed_width_still": {
|
51
|
+
"url": "http://media1.giphy.com/media/wWAIKcFASEFz2/200w_s.gif",
|
52
|
+
"width": "200",
|
53
|
+
"height": "112"
|
54
|
+
},
|
55
|
+
"fixed_width_downsampled": {
|
56
|
+
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/200w_d.gif",
|
57
|
+
"width": "200",
|
58
|
+
"height": "112",
|
59
|
+
"size": "131311",
|
60
|
+
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/200w_d.webp",
|
61
|
+
"webp_size": "60336"
|
62
|
+
},
|
63
|
+
"fixed_height_small": {
|
64
|
+
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/100.gif",
|
65
|
+
"width": "179",
|
66
|
+
"height": "100",
|
67
|
+
"size": "126220",
|
68
|
+
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/100.webp",
|
69
|
+
"webp_size": "56790"
|
70
|
+
},
|
71
|
+
"fixed_height_small_still": {
|
72
|
+
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/100_s.gif",
|
73
|
+
"width": "179",
|
74
|
+
"height": "100"
|
75
|
+
},
|
76
|
+
"fixed_width_small": {
|
77
|
+
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/100w.gif",
|
78
|
+
"width": "100",
|
79
|
+
"height": "56",
|
80
|
+
"size": "51889",
|
81
|
+
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/100w.webp",
|
82
|
+
"webp_size": "21266"
|
83
|
+
},
|
84
|
+
"fixed_width_small_still": {
|
85
|
+
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/100w_s.gif",
|
86
|
+
"width": "100",
|
87
|
+
"height": "56"
|
88
|
+
},
|
89
|
+
"downsized": {
|
90
|
+
"url": "http://media0.giphy.com/media/wWAIKcFASEFz2/giphy.gif",
|
91
|
+
"width": "500",
|
92
|
+
"height": "279",
|
93
|
+
"size": "508488"
|
94
|
+
},
|
95
|
+
"downsized_still": {
|
96
|
+
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/giphy_s.gif",
|
97
|
+
"width": "500",
|
98
|
+
"height": "279"
|
99
|
+
},
|
100
|
+
"downsized_large": {
|
101
|
+
"url": "http://media0.giphy.com/media/wWAIKcFASEFz2/giphy.gif",
|
102
|
+
"width": "500",
|
103
|
+
"height": "279",
|
104
|
+
"size": "508488"
|
105
|
+
},
|
106
|
+
"original": {
|
107
|
+
"url": "http://media0.giphy.com/media/wWAIKcFASEFz2/giphy.gif",
|
108
|
+
"width": "500",
|
109
|
+
"height": "279",
|
110
|
+
"size": "508488",
|
111
|
+
"frames": "7",
|
112
|
+
"mp4": "http://media2.giphy.com/media/wWAIKcFASEFz2/giphy.mp4",
|
113
|
+
"mp4_size": "45225",
|
114
|
+
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/giphy.webp",
|
115
|
+
"webp_size": "305416"
|
116
|
+
},
|
117
|
+
"original_still": {
|
118
|
+
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/giphy_s.gif",
|
119
|
+
"width": "500",
|
120
|
+
"height": "279"
|
121
|
+
}
|
122
|
+
}
|
123
|
+
},
|
124
|
+
"meta": {
|
125
|
+
"status": 200,
|
126
|
+
"msg": "OK"
|
127
|
+
}
|
128
|
+
}
|
@@ -12,6 +12,7 @@ describe Lita::Handlers::OnewheelGiphy, lita_handler: true do
|
|
12
12
|
it { is_expected.to route_command('giphy') }
|
13
13
|
it { is_expected.to route_command('giphy soon') }
|
14
14
|
it { is_expected.to route_command('giphytrending') }
|
15
|
+
it { is_expected.to route_command('giphytranslate boom') }
|
15
16
|
|
16
17
|
it 'gets a giphy by string keywords' do
|
17
18
|
mock_fixture('search_good')
|
@@ -31,6 +32,12 @@ describe Lita::Handlers::OnewheelGiphy, lita_handler: true do
|
|
31
32
|
expect(replies.last).to eq('http://media0.giphy.com/media/op7uqYWBm3R04/giphy.gif')
|
32
33
|
end
|
33
34
|
|
35
|
+
it 'gets a translate giphy' do
|
36
|
+
mock_fixture('translate_good')
|
37
|
+
send_command 'giphytranslate boom'
|
38
|
+
expect(replies.last).to eq('http://giphy.com/gifs/superman-santa-chandler-bing-wWAIKcFASEFz2')
|
39
|
+
end
|
40
|
+
|
34
41
|
def mock_fixture(fixture)
|
35
42
|
mock_json = File.open("spec/fixtures/#{fixture}.json").read
|
36
43
|
response = double
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-onewheel-giphy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kreps
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- lita-onewheel-giphy.gemspec
|
140
140
|
- spec/fixtures/random_good.json
|
141
141
|
- spec/fixtures/search_good.json
|
142
|
+
- spec/fixtures/translate_good.json
|
142
143
|
- spec/fixtures/trending_good.json
|
143
144
|
- spec/lita/handlers/onewheel_giphy_spec.rb
|
144
145
|
- spec/spec_helper.rb
|
@@ -170,6 +171,7 @@ summary: Aims to be a complete implementation of the Giphy api. https://github.
|
|
170
171
|
test_files:
|
171
172
|
- spec/fixtures/random_good.json
|
172
173
|
- spec/fixtures/search_good.json
|
174
|
+
- spec/fixtures/translate_good.json
|
173
175
|
- spec/fixtures/trending_good.json
|
174
176
|
- spec/lita/handlers/onewheel_giphy_spec.rb
|
175
177
|
- spec/spec_helper.rb
|