Skip to content

Commit

Permalink
Added !gif and updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Aug 23, 2017
1 parent d48aa2e commit 720eec6
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 106 deletions.
9 changes: 0 additions & 9 deletions lib/lita-onewheel-giphy.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
require 'lita'

Lita.load_locales Dir[File.expand_path(
File.join('..', '..', 'locales', '*.yml'), __FILE__
)]

require 'lita/handlers/onewheel_giphy'

Lita::Handlers::OnewheelGiphy.template_root File.expand_path(
File.join('..', '..', 'templates'),
__FILE__
)
8 changes: 8 additions & 0 deletions lib/lita/handlers/onewheel_giphy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ class OnewheelGiphy < Handler
:random,
command: true,
help: {'giphy' => 'Returns a random Giphy image. Powered by Giphy! http://giphy.com'}
route /^gif$/i,
:random,
command: true,
help: {'gif' => 'Returns a random Giphy image. Powered by Giphy! http://giphy.com'}
route /^giphy\s+(.+)$/i,
:translate,
# :search,
command: true,
help: {'giphy [keyword]' => 'Returns a random Giphy image with the specified keyword applied.'}
route /^gif\s+(.+)$/i,
:translate,
command: true,
help: {'gif [keyword]' => 'Returns a random Giphy image with the specified keyword applied.'}
route /^giphytrending$/i,
:trending,
command: true,
Expand Down
2 changes: 1 addition & 1 deletion lita-onewheel-giphy.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'lita-onewheel-giphy'
spec.version = '0.4.1'
spec.version = '0.4.2'
spec.authors = ['Andrew Kreps']
spec.email = ['andrew.kreps@gmail.com']
spec.description = 'Lita chat interface to giphy api for MOAR GIFS'
Expand Down
233 changes: 141 additions & 92 deletions spec/fixtures/translate_good.json
Original file line number Diff line number Diff line change
@@ -1,128 +1,177 @@
{
"data": {
"type": "gif",
"id": "wWAIKcFASEFz2",
"url": "http://giphy.com/gifs/superman-santa-chandler-bing-wWAIKcFASEFz2",
"bitly_gif_url": "http://gph.is/XMD6gE",
"bitly_url": "http://gph.is/XMD6gE",
"embed_url": "http://giphy.com/embed/wWAIKcFASEFz2",
"id": "T2NINhwlHgOSk",
"slug": "T2NINhwlHgOSk",
"url": "https:\/\/giphy.com\/gifs\/T2NINhwlHgOSk",
"bitly_gif_url": "http:\/\/gph.is\/1KsF9wP",
"bitly_url": "http:\/\/gph.is\/1KsF9wP",
"embed_url": "https:\/\/giphy.com\/embed\/T2NINhwlHgOSk",
"username": "",
"source": "http://daytripperrevolution.tumblr.com/post/13729531842",
"source": "http:\/\/www.reddit.com\/r\/reactiongifs\/comments\/3bss8a\/mfw_my_girlfriend_says_its_my_fault_she_peed_on\/",
"rating": "g",
"caption": "",
"content_url": "",
"import_datetime": "2013-03-24 17:48:35",
"trending_datetime": "1970-01-01 00:00:00",
"source_tld": "www.reddit.com",
"source_post_url": "http:\/\/www.reddit.com\/r\/reactiongifs\/comments\/3bss8a\/mfw_my_girlfriend_says_its_my_fault_she_peed_on\/",
"is_indexable": 0,
"import_datetime": "2015-07-01 21:23:36",
"trending_datetime": "2017-02-16 17:57:48",
"images": {
"fixed_height": {
"url": "http://media3.giphy.com/media/wWAIKcFASEFz2/200.gif",
"width": "358",
"height": "200",
"size": "126220",
"mp4": "http://media2.giphy.com/media/wWAIKcFASEFz2/200.mp4",
"mp4_size": "10967",
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/200.webp",
"webp_size": "186460"
},
"fixed_height_still": {
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/200_s.gif",
"width": "358",
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200_s.gif",
"width": "346",
"height": "200"
},
"fixed_height_downsampled": {
"url": "http://media3.giphy.com/media/wWAIKcFASEFz2/200_d.gif",
"width": "358",
"height": "200",
"size": "352636",
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/200_d.webp",
"webp_size": "159946"
"original_still": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy_s.gif",
"width": "223",
"height": "129"
},
"fixed_width": {
"url": "http://media3.giphy.com/media/wWAIKcFASEFz2/200w.gif",
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200w.gif",
"width": "200",
"height": "112",
"size": "51889",
"mp4": "http://media2.giphy.com/media/wWAIKcFASEFz2/200w.mp4",
"mp4_size": "16299",
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/200w.webp",
"webp_size": "70302"
"height": "116",
"size": "2003465",
"mp4": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200w.mp4",
"mp4_size": "28449",
"webp": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200w.webp",
"webp_size": "588938"
},
"fixed_width_still": {
"url": "http://media1.giphy.com/media/wWAIKcFASEFz2/200w_s.gif",
"width": "200",
"height": "112"
"fixed_height_small_still": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/100_s.gif",
"width": "173",
"height": "100"
},
"fixed_width_downsampled": {
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/200w_d.gif",
"width": "200",
"height": "112",
"size": "131311",
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/200w_d.webp",
"webp_size": "60336"
"fixed_height_downsampled": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200_d.gif",
"width": "346",
"height": "200",
"size": "290094",
"webp": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200_d.webp",
"webp_size": "72520"
},
"preview": {
"width": "222",
"height": "128",
"mp4": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy-preview.mp4",
"mp4_size": "32305"
},
"fixed_height_small": {
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/100.gif",
"width": "179",
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/100.gif",
"width": "173",
"height": "100",
"size": "126220",
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/100.webp",
"webp_size": "56790"
"size": "1572931",
"mp4": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/100.mp4",
"mp4_size": "22526",
"webp": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/100.webp",
"webp_size": "483610"
},
"fixed_height_small_still": {
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/100_s.gif",
"width": "179",
"height": "100"
"downsized_still": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy-downsized_s.gif",
"width": "223",
"height": "129",
"size": "20185"
},
"fixed_width_small": {
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/100w.gif",
"width": "100",
"height": "56",
"size": "51889",
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/100w.webp",
"webp_size": "21266"
"downsized": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy-downsized.gif",
"width": "223",
"height": "129",
"size": "1478990"
},
"downsized_large": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy.gif",
"width": "223",
"height": "129",
"size": "1478990"
},
"fixed_width_small_still": {
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/100w_s.gif",
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/100w_s.gif",
"width": "100",
"height": "56"
"height": "58"
},
"downsized": {
"url": "http://media0.giphy.com/media/wWAIKcFASEFz2/giphy.gif",
"width": "500",
"height": "279",
"size": "508488"
"preview_webp": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy-preview.webp",
"width": "185",
"height": "107",
"size": "49742"
},
"downsized_still": {
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/giphy_s.gif",
"width": "500",
"height": "279"
"fixed_width_still": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200w_s.gif",
"width": "200",
"height": "116"
},
"downsized_large": {
"url": "http://media0.giphy.com/media/wWAIKcFASEFz2/giphy.gif",
"width": "500",
"height": "279",
"size": "508488"
"fixed_width_small": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/100w.gif",
"width": "100",
"height": "58",
"size": "649699",
"mp4": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/100w.mp4",
"mp4_size": "12834",
"webp": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/100w.webp",
"webp_size": "222072"
},
"downsized_small": {
"width": "222",
"height": "128",
"mp4": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy-downsized-small.mp4",
"mp4_size": "32305"
},
"fixed_width_downsampled": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200w_d.gif",
"width": "200",
"height": "116",
"size": "113625",
"webp": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200w_d.webp",
"webp_size": "33742"
},
"downsized_medium": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy.gif",
"width": "223",
"height": "129",
"size": "1478990"
},
"original": {
"url": "http://media0.giphy.com/media/wWAIKcFASEFz2/giphy.gif",
"width": "500",
"height": "279",
"size": "508488",
"frames": "7",
"mp4": "http://media2.giphy.com/media/wWAIKcFASEFz2/giphy.mp4",
"mp4_size": "45225",
"webp": "http://media2.giphy.com/media/wWAIKcFASEFz2/giphy.webp",
"webp_size": "305416"
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy.gif",
"width": "223",
"height": "129",
"size": "1478990",
"frames": "108",
"mp4": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy.mp4",
"mp4_size": "88305",
"webp": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy.webp",
"webp_size": "733090"
},
"original_still": {
"url": "http://media2.giphy.com/media/wWAIKcFASEFz2/giphy_s.gif",
"width": "500",
"height": "279"
"fixed_height": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200.gif",
"width": "346",
"height": "200",
"size": "5113607",
"mp4": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200.mp4",
"mp4_size": "54692",
"webp": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/200.webp",
"webp_size": "1263464"
},
"looping": {
"mp4": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy-loop.mp4",
"mp4_size": "678282"
},
"original_mp4": {
"width": "480",
"height": "276",
"mp4": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy.mp4",
"mp4_size": "88305"
},
"preview_gif": {
"url": "https:\/\/media1.giphy.com\/media\/T2NINhwlHgOSk\/giphy-preview.gif",
"width": "121",
"height": "70",
"size": "49260"
}
}
},
"meta": {
"status": 200,
"msg": "OK"
"msg": "OK",
"response_id": "599dad7a366d6e534551b31b"
}
}
14 changes: 11 additions & 3 deletions spec/lita/handlers/onewheel_giphy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@
end

it { is_expected.to route_command('giphy') }
it { is_expected.to route_command('gif') }
it { is_expected.to route_command('gif x') }
it { is_expected.to route_command('giphy soon') }
it { is_expected.to route_command('giphytrending') }
it { is_expected.to route_command('giphytranslate boom') }

it 'gets a giphy by string keywords' do
mock_fixture('search_good')
mock_fixture('translate_good')
send_command 'giphy wat'
expect(replies.last).to eq('http://media2.giphy.com/media/FiGiRei2ICzzG/giphy.gif')
expect(replies.last).to eq('https://media1.giphy.com/media/T2NINhwlHgOSk/giphy.gif')
end

it 'gets a gif by string keywords' do
mock_fixture('translate_good')
send_command 'gif wat'
expect(replies.last).to eq('https://media1.giphy.com/media/T2NINhwlHgOSk/giphy.gif')
end

it 'gets a random giphy' do
Expand All @@ -35,7 +43,7 @@
it 'gets a translate giphy' do
mock_fixture('translate_good')
send_command 'giphytranslate boom'
expect(replies.last).to eq('http://media0.giphy.com/media/wWAIKcFASEFz2/giphy.gif')
expect(replies.last).to eq('https://media1.giphy.com/media/T2NINhwlHgOSk/giphy.gif')
end

def mock_fixture(fixture)
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'simplecov'
require 'coveralls'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
Expand Down

0 comments on commit 720eec6

Please sign in to comment.