class Giphy::Client
- Giphy::Client
- Reference
- Object
Overview
Giphy::Client is the object that communicates with the GIPHY API.
To create a Giphy::Client
giphy = Giphy::Client.new <api_key>
NOTE An api_key is required for Giphy::Client to communite with the GIHPY API.
Defined in:
lib-giphy.crConstant Summary
-
HEADERS =
HTTP::Headers {"Content-Type" => "application/json"}
-
HOST =
"api.giphy.com"
Constructors
-
.new(api_key : String)
Creates a new Giphy with the specified api_key
Instance Method Summary
-
#categories : CategoryCollection
Returns a collection of GIF categories on the GIPHY network.
-
#generate_random_id : String
Generates a random id that can be used as random_id 2when sending a request to GIPHY.
-
#get_by_id(gif_id : String, random_id : String = "") : Gif
Returns a gif based on the specified gif_id.
-
#get_by_ids(gif_ids : Array(String), random_id : String = "") : GifCollection
Returns gifs based on the specified gif_ids.
-
#random(tag = "", params = RandomParam.new) : Gif
Returns a random gif based on the specified tag.
-
#search(q : String, params = SearchParam.new) : GifCollection
Returns gifs from GIPHY based on search term q
-
#translate(s : String, params = TranslateParam.new) : Gif
Returns a single gif based on the search term s.
-
#trending(params = TrendingParam.new) : GifCollection
Returns the most relevant and engaging gifs
Constructor Detail
Instance Method Detail
Generates a random id that can be used as random_id 2when sending a request to GIPHY.
NOTE for more information see https://developers.giphy.com/docs/api/endpoint#random-id
Returns a gif based on the specified gif_id.
An ArgumentError
is raised if gif_id is an empty string
Returns gifs based on the specified gif_ids.
An ArgumentError
is raised if gif_ids is empty.
Returns a random gif based on the specified tag. If tag == "" the gif will be completely random.
Example: (default search)
g = Giphy::Client.new <api_key>
gif = g.random("oh weeew")
puts gif.data.url
Returns gifs from GIPHY based on search term q
Example: (default search)
g = Giphy::Client.new <api_key>
gifs = g.search("cats") # returns 25 gifs by default
gifs.data.each do |gif|
puts gif.title
end
Example: (search with params)
g = Giphy::Client.new <api_key>
params = Giphy::SearchParam.new 10
gifs = g.search("cats", params) # returns 10 gifs
Returns a single gif based on the search term s. Translate converts words and phrases to gifs using GIPHY's special sauce algorithm.
Example: (default search)
g = Giphy::Client.new <api_key>
gif = g.translate("oh weeew")
puts gif.data.title
Returns the most relevant and engaging gifs
Example: (default search)
g = Giphy::Client.new <api_key>
gifs = g.trending() # returns 25 gifs by default
gifs.data.each do |gif|
puts gif.title
end