giphy-api-0.3.0.0: 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 Phrase Source

A phrase or term used for translation.

Constructors

Phrase Text 

newtype Tag Source

A tag to retrieve a random GIF for.

Constructors

Tag Text 

newtype GifId Source

A unique gif identifier.

Constructors

GifId Text 

Response Data Types

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

data Gif Source

A search response item.

Constructors

Gif 

type ImageMap = Map Text Image Source

Mapping from a Text identifier to an Image.

Giphy Monad

Use runGiphy to lift the Giphy monad into IO.

data GiphyConfig Source

Contains the key to access the API.

Constructors

GiphyConfig 

Fields

configApiKey :: Key
 

type Giphy = ReaderT GiphyConfig (ExceptT ServantError IO) Source

The Giphy monad contains the execution context.

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

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

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 Source

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 :: Query -> PaginationOffset -> Giphy SearchResponse Source

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

random :: Maybe Tag -> Giphy RandomResponse Source

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