class Giphy::Client

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.cr

Constant Summary

HEADERS = HTTP::Headers {"Content-Type" => "application/json"}
HOST = "api.giphy.com"

Constructors

Instance Method Summary

Constructor Detail

def self.new(api_key : String) #

Creates a new Giphy with the specified api_key


[View source]

Instance Method Detail

def categories : CategoryCollection #

Returns a collection of GIF categories on the GIPHY network.


[View source]
def generate_random_id : String #

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


[View source]
def get_by_id(gif_id : String, random_id : String = "") : Gif #

Returns a gif based on the specified gif_id.

An ArgumentError is raised if gif_id is an empty string


[View source]
def get_by_ids(gif_ids : Array(String), random_id : String = "") : GifCollection #

Returns gifs based on the specified gif_ids.

An ArgumentError is raised if gif_ids is empty.


[View source]
def random(tag = "", params = RandomParam.new) : Gif #

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

[View source]
def search(q : String, params = SearchParam.new) : GifCollection #

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

[View source]
def translate(s : String, params = TranslateParam.new) : Gif #

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

[View source]
def trending(params = TrendingParam.new) : GifCollection #

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

[View source]