Skip to content

Commit

Permalink
Logging and test coverage run.
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Aug 23, 2017
1 parent 6b8acd7 commit a98ebfd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/lita/handlers/onewheel_giphy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ def search(response)
keywords = response.matches[0][0]
Lita.logger.debug "Searching giphy for #{keywords}"
uri = get_search_uri(keywords)
Lita.logger.debug "search: #{uri}"
giphy_data = call_giphy(uri)
image = get_random(giphy_data.body)
response.reply image
end

def random(response)
uri = get_random_uri
Lita.logger.debug "random: #{uri}"
giphy_data = call_giphy(uri)
image = get_image(giphy_data.body)
response.reply image
end

def trending(response)
uri = get_trending_uri
Lita.logger.debug "trending: #{uri}"
giphy_data = call_giphy(uri)
image = get_random(giphy_data.body)
response.reply image
Expand All @@ -64,6 +67,7 @@ def trending(response)
def translate(response)
keywords = response.matches[0][0]
uri = get_translate_uri(keywords)
Lita.logger.debug "translate: #{uri}"
giphy_data = call_giphy(uri)
image = get_translate_image(giphy_data.body)
response.reply image
Expand Down Expand Up @@ -102,7 +106,7 @@ def get_translate_uri(keywords)
def get_random(data)
image_data = JSON.parse(data)
if image_data['data'].count == 0
Lita.logger.debug 'No images found.'
Lita.logger.debug 'get_random: No images found.'
return
end
image = image_data['data'][get_random_number(image_data['data'].count)]['images']['original']['url']
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.2'
spec.version = '0.4.3'
spec.authors = ['Andrew Kreps']
spec.email = ['andrew.kreps@gmail.com']
spec.description = 'Lita chat interface to giphy api for MOAR GIFS'
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/trending_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"data": [],
"pagination": {
"count": 0,
"offset": 0
},
"meta": {
"status": 200,
"msg": "OK"
}
}
6 changes: 6 additions & 0 deletions spec/lita/handlers/onewheel_giphy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
expect(replies.last).to eq('http://s3.amazonaws.com/giphygifs/media/Ggjwvmqktuvf2/giphy.gif')
end

it 'gets no trending giphy' do
mock_fixture('trending_empty')
send_command 'giphytrending'
expect(replies.last).to eq(nil)
end

it 'gets a trending giphy' do
mock_fixture('trending_good')
send_command 'giphytrending'
Expand Down

0 comments on commit a98ebfd

Please sign in to comment.