Module: API::Giphy

Included in:
Hibot::Giphy
Defined in:
lib/api/giphy.rb

Constant Summary collapse

WS_URL =
"http://api.giphy.com/v1/gifs/search"
URI_REGEX =
/spotify:([a-z]+):(\w+)/

Instance Method Summary collapse

Instance Method Details

#search(query) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/api/giphy.rb', line 6

def search(query)
  puts "dans le seeeeaaartch !!!"
  query = query.gsub('!gsearch', '').strip
  # Check that parameters are correct or return the corresponding error
  return "Please provide something to search" if query.nil? || query == ""

  # Perform the search and return the result
  result = ""
  response = HTTParty.get("#{WS_URL}?q=#{URI.encode(query)}&api_key=#{@@api_key}")
  if response['data'] && response['data'].count > 0
    gif = response['data'].first
    result = "Check this : #{gif['url']}"
  else
    result = 'Nothing found with that parameter.'
  end
  result
end