class Lita::Handlers::OnewheelGiphy
Public Instance Methods
call_giphy(uri)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 136 def call_giphy(uri) Lita.logger.debug("Calling giphy with #{uri + 'api_key=' + config.api_key}") RestClient.get uri + 'api_key=' + config.api_key end
get_image(data)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 122 def get_image(data) image_data = JSON.parse(data) image = image_data['data']['image_original_url'] Lita.logger.debug "get_image returning #{image}" image end
get_random(data)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 106 def get_random(data) image_data = JSON.parse(data) if image_data['data'].count == 0 Lita.logger.debug 'get_random: No images found.' return end image = image_data['data'][get_random_number(image_data['data'].count)]['images']['original']['url'] Lita.logger.debug "get_random returning #{image}" image end
get_random_number(max)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 117 def get_random_number(max) and_i = Random.new and_i.rand(max) end
get_random_uri()
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 85 def get_random_uri() # tag - the GIF tag to limit randomness by # rating - limit results to those rated (y,g, pg, pg-13 or r). # fmt - (optional) return results in html or json format (useful for viewing responses as GIFs to debug/test) config.api_uri + 'random?' #?q=' + URI.encode(keywords) end
get_search_uri(keywords)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 76 def get_search_uri(keywords) # q - search query term or phrase # limit - (optional) number of results to return, maximum 100. Default 25. # offset - (optional) results offset, defaults to 0. # rating - limit results to those rated (y,g, pg, pg-13 or r). # fmt - (optional) return results in html or json format (useful for viewing responses as GIFs to debug/test) config.api_uri + 'search?q=' + URI.encode(keywords) + '&' end
get_translate_image(data)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 129 def get_translate_image(data) image_data = JSON.parse(data) image = image_data['data']['images']['original']['url'] Lita.logger.debug "get_translate_image returning #{image}" image end
get_translate_uri(keywords)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 99 def get_translate_uri(keywords) # s - term or phrase to translate into a GIF # rating - limit results to those rated (y,g, pg, pg-13 or r). # fmt - (optional) return results in html or json format (useful for viewing responses as GIFs to debug/test) config.api_uri + 'translate?s=' + URI.encode(keywords) + '&' end
get_trending_uri()
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 92 def get_trending_uri() # limit (optional) limits the number of results returned. By default returns 25 results. # rating - limit results to those rated (y,g, pg, pg-13 or r). # fmt - (optional) return results in html or json format (useful for viewing responses as GIFs to debug/test) config.api_uri + 'trending?' end
random(response)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 51 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
search(response)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 41 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
translate(response)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 67 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 end
trending(response)
click to toggle source
# File lib/lita/handlers/onewheel_giphy.rb, line 59 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 end