random response with web hook
This commit is contained in:
@ -1,7 +0,0 @@
|
||||
class Animations
|
||||
|
||||
def find string
|
||||
"looking for a gif related to: #{string}"
|
||||
end
|
||||
|
||||
end
|
48
app/workers/get_giphy.rb
Normal file
48
app/workers/get_giphy.rb
Normal file
@ -0,0 +1,48 @@
|
||||
require 'faraday'
|
||||
require 'faraday_middleware'
|
||||
|
||||
class GetGiphy
|
||||
|
||||
def random search=""
|
||||
url = "random?api_key=#{api_key}&rating=pg&tag=#{clean_search(search)}"
|
||||
response = connection.get(url)
|
||||
|
||||
response.body['data']
|
||||
end
|
||||
|
||||
def search search=""
|
||||
url = "search?api_key=#{api_key}&rating=pg&q=#{clean_search(search)}&limit=1&offset=#{rand(0..5)}"
|
||||
response = connection.get(url)
|
||||
|
||||
response.body['data']
|
||||
end
|
||||
|
||||
def translate search=""
|
||||
url = "translate?api_key=#{api_key}&rating=pg&tag=#{search}"
|
||||
response = connection.get(url)
|
||||
|
||||
response.body['data']
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clean_search search
|
||||
search.gsub(/ */, '+')
|
||||
end
|
||||
|
||||
def connection
|
||||
Faraday.new(url: giphy_url) do |c|
|
||||
c.use FaradayMiddleware::ParseJson, content_type: 'application/json'
|
||||
c.adapter Faraday.default_adapter
|
||||
end
|
||||
end
|
||||
|
||||
def giphy_url
|
||||
"http://api.giphy.com/v1/gifs/"
|
||||
end
|
||||
|
||||
def api_key
|
||||
"dc6zaTOxFJmzC"
|
||||
end
|
||||
|
||||
end
|
@ -1,15 +1,23 @@
|
||||
class RandomSalutation
|
||||
|
||||
def short
|
||||
'Hi there!'
|
||||
[
|
||||
'Hi there!',
|
||||
'Hello',
|
||||
'Greetings!'
|
||||
].shuffle.first
|
||||
end
|
||||
|
||||
def medium
|
||||
"Well hello! So nice to see you here."
|
||||
[
|
||||
"Well hello! So nice to see you here.",
|
||||
].shuffle.first
|
||||
end
|
||||
|
||||
def long
|
||||
"My, what a wonderful day. Wouldn't you agree? I mean, it's even better now that you are here! Amirite?"
|
||||
[
|
||||
"My, what a wonderful day. Wouldn't you agree? I mean, it's even better now that you are here! Amirite?",
|
||||
].shuffle.first
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user