Skip to content

Commit

Permalink
Fixing random test.
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Jan 18, 2016
1 parent e31486e commit 3328bd1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
12 changes: 11 additions & 1 deletion lib/lita/handlers/onewheel_giphy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'pry'
require 'rest-client'

module Lita
module Handlers
Expand All @@ -15,14 +16,16 @@ def search(response)
keywords = response.matches[0][0]
uri = get_search_uri(keywords)
giphy_data = call_giphy(uri)
# binding.pry
image = get_first(giphy_data.body)
response.reply image
end

def random(response)
uri = get_random_uri
giphy_data = call_giphy(uri)
image = get_first(giphy_data.body)
# binding.pry
image = get_image(giphy_data.body)
response.reply image
end

Expand All @@ -44,9 +47,16 @@ def get_random_uri()

def get_first(data)
image_data = JSON.parse(data)
# binding.pry
image_data['data'][0]['images']['original']['url']
end

def get_image(data)
image_data = JSON.parse(data)
# binding.pry
image_data['data']['image_original_url']
end

def call_giphy(uri)
RestClient.get uri + 'api_key=' + config.api_key
end
Expand Down
31 changes: 31 additions & 0 deletions spec/fixtures/random_good.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"data": {
"type": "gif",
"id": "Ggjwvmqktuvf2",
"url": "http://giphy.com/gifs/american-psycho-christian-bale-Ggjwvmqktuvf2",
"image_original_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.gif",
"image_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.gif",
"image_mp4_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.mp4",
"image_frames": "11",
"image_width": "500",
"image_height": "256",
"fixed_height_downsampled_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/200_d.gif",
"fixed_height_downsampled_width": "391",
"fixed_height_downsampled_height": "200",
"fixed_width_downsampled_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/200w_d.gif",
"fixed_width_downsampled_width": "200",
"fixed_width_downsampled_height": "102",
"fixed_height_small_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/100.gif",
"fixed_height_small_still_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/100_s.gif",
"fixed_height_small_width": "195",
"fixed_height_small_height": "100",
"fixed_width_small_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/100w.gif",
"fixed_width_small_still_url": "http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/100w_s.gif",
"fixed_width_small_width": "100",
"fixed_width_small_height": "51"
},
"meta": {
"status": 200,
"msg": "OK"
}
}
4 changes: 2 additions & 2 deletions spec/lita/handlers/onewheel_giphy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
end

it 'gets a random giphy' do
mock_fixture('search_good')
mock_fixture('random_good')
send_command 'giphy'
expect(replies.last).to eq('http://media2.giphy.com/media/FiGiRei2ICzzG/giphy.gif')
expect(replies.last).to eq('http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.gif')
end

def mock_fixture(fixture)
Expand Down

0 comments on commit 3328bd1

Please sign in to comment.