giphy-api-0.6.0.1: Giphy HTTP API wrapper and CLI search tool.

Safe HaskellNone
LanguageHaskell2010

Web.Giphy

Contents

Description

Provides a Giphy monad that can be used to issue selected API calls under a selected API key.

import qualified Web.Giphy as Giphy

let apiKey = Giphy.Key "dc6zaTOxFJmzC"
let config = Giphy.GiphyConfig apiKey
resp <- Giphy.runGiphy (Giphy.search $ Giphy.query "puppies") config
let fstUrl = resp ^? _Right
                   . Giphy.searchItems
                   . _head
                   . Giphy.gifImages
                   . at "original"
                   . traverse
                   . Giphy.imageUrl
                   . traverse
print fstUrl
Synopsis

Request Data Types

These data types are used to encapsulate otherwise weakly typed arguments.

newtype Key #

Constructors

Key Text 
Instances
Eq Key # 
Instance details

Defined in Web.Giphy

Methods

(==) :: Key -> Key -> Bool #

(/=) :: Key -> Key -> Bool #

Show Key # 
Instance details

Defined in Web.Giphy

Methods

showsPrec :: Int -> Key -> ShowS #

show :: Key -> String #

showList :: [Key] -> ShowS #

ToHttpApiData Key # 
Instance details

Defined in Web.Giphy

FromHttpApiData Key # 
Instance details

Defined in Web.Giphy

newtype Query #

A search query.

Constructors

Query Text 
Instances
Eq Query # 
Instance details

Defined in Web.Giphy

Methods

(==) :: Query -> Query -> Bool #

(/=) :: Query -> Query -> Bool #

Show Query # 
Instance details

Defined in Web.Giphy

Methods

showsPrec :: Int -> Query -> ShowS #

show :: Query -> String #

showList :: [Query] -> ShowS #

ToHttpApiData Query # 
Instance details

Defined in Web.Giphy

FromHttpApiData Query # 
Instance details

Defined in Web.Giphy

newtype Phrase #

A phrase or term used for translation.

Constructors

Phrase Text 
Instances
Eq Phrase # 
Instance details

Defined in Web.Giphy

Methods

(==) :: Phrase -> Phrase -> Bool #

(/=) :: Phrase -> Phrase -> Bool #

Show Phrase # 
Instance details

Defined in Web.Giphy

ToHttpApiData Phrase # 
Instance details

Defined in Web.Giphy

FromHttpApiData Phrase # 
Instance details

Defined in Web.Giphy

newtype Tag #

A tag to retrieve a random GIF for.

Constructors

Tag Text 
Instances
Eq Tag # 
Instance details

Defined in Web.Giphy

Methods

(==) :: Tag -> Tag -> Bool #

(/=) :: Tag -> Tag -> Bool #

Show Tag # 
Instance details

Defined in Web.Giphy

Methods

showsPrec :: Int -> Tag -> ShowS #

show :: Tag -> String #

showList :: [Tag] -> ShowS #

ToHttpApiData Tag # 
Instance details

Defined in Web.Giphy

FromHttpApiData Tag # 
Instance details

Defined in Web.Giphy

data Pagination #

Metadata about pagination in a response.

Instances
Eq Pagination # 
Instance details

Defined in Web.Giphy

Ord Pagination # 
Instance details

Defined in Web.Giphy

Show Pagination # 
Instance details

Defined in Web.Giphy

Generic Pagination # 
Instance details

Defined in Web.Giphy

Associated Types

type Rep Pagination :: * -> * #

FromJSON Pagination # 
Instance details

Defined in Web.Giphy

type Rep Pagination # 
Instance details

Defined in Web.Giphy

type Rep Pagination = D1 (MetaData "Pagination" "Web.Giphy" "giphy-api-0.6.0.1-3fvDMKnbmELCesDdiDEJGO" False) (C1 (MetaCons "Pagination" PrefixI True) (S1 (MetaSel (Just "_paginationTotalCount") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int) :*: (S1 (MetaSel (Just "_paginationCount") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int) :*: S1 (MetaSel (Just "_paginationOffset") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int))))

newtype GifId #

A unique gif identifier.

Constructors

GifId Text 
Instances
Eq GifId # 
Instance details

Defined in Web.Giphy

Methods

(==) :: GifId -> GifId -> Bool #

(/=) :: GifId -> GifId -> Bool #

Show GifId # 
Instance details

Defined in Web.Giphy

Methods

showsPrec :: Int -> GifId -> ShowS #

show :: GifId -> String #

showList :: [GifId] -> ShowS #

ToHttpApiData GifId # 
Instance details

Defined in Web.Giphy

FromHttpApiData GifId # 
Instance details

Defined in Web.Giphy

Response Data Types

These data types contain are the parsed JSON responses from the Giphy API.

data Gif #

A search response item.

Constructors

Gif 
Instances
Eq Gif # 
Instance details

Defined in Web.Giphy

Methods

(==) :: Gif -> Gif -> Bool #

(/=) :: Gif -> Gif -> Bool #

Ord Gif # 
Instance details

Defined in Web.Giphy

Methods

compare :: Gif -> Gif -> Ordering #

(<) :: Gif -> Gif -> Bool #

(<=) :: Gif -> Gif -> Bool #

(>) :: Gif -> Gif -> Bool #

(>=) :: Gif -> Gif -> Bool #

max :: Gif -> Gif -> Gif #

min :: Gif -> Gif -> Gif #

Show Gif # 
Instance details

Defined in Web.Giphy

Methods

showsPrec :: Int -> Gif -> ShowS #

show :: Gif -> String #

showList :: [Gif] -> ShowS #

Generic Gif # 
Instance details

Defined in Web.Giphy

Associated Types

type Rep Gif :: * -> * #

Methods

from :: Gif -> Rep Gif x #

to :: Rep Gif x -> Gif #

FromJSON Gif # 
Instance details

Defined in Web.Giphy

type Rep Gif # 
Instance details

Defined in Web.Giphy

data Image #

An image contained in a Giphy response.

Instances
Eq Image # 
Instance details

Defined in Web.Giphy

Methods

(==) :: Image -> Image -> Bool #

(/=) :: Image -> Image -> Bool #

Ord Image # 
Instance details

Defined in Web.Giphy

Methods

compare :: Image -> Image -> Ordering #

(<) :: Image -> Image -> Bool #

(<=) :: Image -> Image -> Bool #

(>) :: Image -> Image -> Bool #

(>=) :: Image -> Image -> Bool #

max :: Image -> Image -> Image #

min :: Image -> Image -> Image #

Show Image # 
Instance details

Defined in Web.Giphy

Methods

showsPrec :: Int -> Image -> ShowS #

show :: Image -> String #

showList :: [Image] -> ShowS #

Generic Image # 
Instance details

Defined in Web.Giphy

Associated Types

type Rep Image :: * -> * #

Methods

from :: Image -> Rep Image x #

to :: Rep Image x -> Image #

FromJSON Image # 
Instance details

Defined in Web.Giphy

type Rep Image # 
Instance details

Defined in Web.Giphy

type ImageMap = Map Text Image #

Mapping from a Text identifier to an Image.

data SearchResponse #

A collection of GIFs as part of a search response.

Instances
Eq SearchResponse # 
Instance details

Defined in Web.Giphy

Ord SearchResponse # 
Instance details

Defined in Web.Giphy

Show SearchResponse # 
Instance details

Defined in Web.Giphy

Generic SearchResponse # 
Instance details

Defined in Web.Giphy

Associated Types

type Rep SearchResponse :: * -> * #

FromJSON SearchResponse # 
Instance details

Defined in Web.Giphy

type Rep SearchResponse # 
Instance details

Defined in Web.Giphy

type Rep SearchResponse = D1 (MetaData "SearchResponse" "Web.Giphy" "giphy-api-0.6.0.1-3fvDMKnbmELCesDdiDEJGO" False) (C1 (MetaCons "SearchResponse" PrefixI True) (S1 (MetaSel (Just "_searchItems") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Gif]) :*: S1 (MetaSel (Just "_searchPagination") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Pagination)))

newtype SingleGifResponse #

A single gif as part of a response.

Constructors

SingleGifResponse 

Fields

Instances
Eq SingleGifResponse # 
Instance details

Defined in Web.Giphy

Ord SingleGifResponse # 
Instance details

Defined in Web.Giphy

Show SingleGifResponse # 
Instance details

Defined in Web.Giphy

Generic SingleGifResponse # 
Instance details

Defined in Web.Giphy

Associated Types

type Rep SingleGifResponse :: * -> * #

FromJSON SingleGifResponse # 
Instance details

Defined in Web.Giphy

type Rep SingleGifResponse # 
Instance details

Defined in Web.Giphy

type Rep SingleGifResponse = D1 (MetaData "SingleGifResponse" "Web.Giphy" "giphy-api-0.6.0.1-3fvDMKnbmELCesDdiDEJGO" True) (C1 (MetaCons "SingleGifResponse" PrefixI True) (S1 (MetaSel (Just "_singleGifItem") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Gif)))

newtype TranslateResponse #

A single GIF as part of a translate response.

Constructors

TranslateResponse 

Fields

Instances
Eq TranslateResponse # 
Instance details

Defined in Web.Giphy

Ord TranslateResponse # 
Instance details

Defined in Web.Giphy

Show TranslateResponse # 
Instance details

Defined in Web.Giphy

Generic TranslateResponse # 
Instance details

Defined in Web.Giphy

Associated Types

type Rep TranslateResponse :: * -> * #

FromJSON TranslateResponse # 
Instance details

Defined in Web.Giphy

type Rep TranslateResponse # 
Instance details

Defined in Web.Giphy

type Rep TranslateResponse = D1 (MetaData "TranslateResponse" "Web.Giphy" "giphy-api-0.6.0.1-3fvDMKnbmELCesDdiDEJGO" True) (C1 (MetaCons "TranslateResponse" PrefixI True) (S1 (MetaSel (Just "_translateItem") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Gif)))

newtype RandomResponse #

A single gif as part of a response.

Constructors

RandomResponse 

Fields

Instances
Eq RandomResponse # 
Instance details

Defined in Web.Giphy

Ord RandomResponse # 
Instance details

Defined in Web.Giphy

Show RandomResponse # 
Instance details

Defined in Web.Giphy

Generic RandomResponse # 
Instance details

Defined in Web.Giphy

Associated Types

type Rep RandomResponse :: * -> * #

FromJSON RandomResponse # 
Instance details

Defined in Web.Giphy

type Rep RandomResponse # 
Instance details

Defined in Web.Giphy

type Rep RandomResponse = D1 (MetaData "RandomResponse" "Web.Giphy" "giphy-api-0.6.0.1-3fvDMKnbmELCesDdiDEJGO" True) (C1 (MetaCons "RandomResponse" PrefixI True) (S1 (MetaSel (Just "_randomGifItem") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Gif)))

Giphy Monad

Use runGiphy to lift the Giphy monad into IO.

newtype GiphyConfig #

Contains the key to access the API.

Constructors

GiphyConfig 

Fields

Instances
Eq GiphyConfig # 
Instance details

Defined in Web.Giphy

Show GiphyConfig # 
Instance details

Defined in Web.Giphy

type Giphy = ReaderT GiphyContext ClientM #

The Giphy monad contains the execution context.

runGiphy :: MonadIO m => Giphy a -> GiphyConfig -> m (Either ServantError a) #

You need to provide a GiphyConfig to lift a Giphy computation into MonadIO.

runGiphy' #

Arguments

:: MonadIO m 
=> Manager

This must be a TLS-enabled Manager

-> Giphy a 
-> GiphyConfig 
-> m (Either ServantError a) 

Same as runGiphy but accepts an explicit Manager instead of implicitly creating one for you.

Lenses

You can use these lenses if you prefer them to manually accessing record fields.

API calls

Functions that directly access the Giphy API. All these functions run in the Giphy monad.

search :: Query -> Giphy SearchResponse #

Issue a search request for the given query without specifying an offset. E.g. https://api.giphy.com/v1/gifs/search?q=funny+cat&api_key=dc6zaTOxFJmzC

searchOffset #

Arguments

:: Query 
-> PaginationOffset

Offset as a number of items you want to skip.

-> Giphy SearchResponse 

Issue a search request for the given query by specifying a pagination offset. E.g. https://api.giphy.com/v1/gifs/search?q=funny+cat&api_key=dc6zaTOxFJmzC&offset=25

gif :: GifId -> Giphy SingleGifResponse #

Issue a request for a single GIF identified by its GifId. E.g. https://api.giphy.com/v1/gifs/feqkVgjJpYtjy?api_key=dc6zaTOxFJmzC

random :: Maybe Tag -> Giphy RandomResponse #

Issue a request for a random GIF for the given (optional) tag. E.g. https://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=american+psycho