Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- newtype Key = Key Text
- newtype Query = Query Text
- newtype Phrase = Phrase Text
- newtype Tag = Tag Text
- data Pagination = Pagination {}
- data Gif = Gif {}
- data Image = Image {
- _imageUrl :: Maybe URI
- _imageSize :: Maybe Int
- _imageMp4Url :: Maybe URI
- _imageMp4Size :: Maybe Int
- _imageWebpUrl :: Maybe URI
- _imageWebpSize :: Maybe Int
- _imageWidth :: Maybe Int
- _imageHeight :: Maybe Int
- type ImageMap = Map Text Image
- newtype PaginationOffset = PaginationOffset Int
- data SearchResponse = SearchResponse {}
- newtype SingleGifResponse = SingleGifResponse {}
- newtype TranslateResponse = TranslateResponse {}
- data GiphyConfig = GiphyConfig {
- configApiKey :: Key
- type Giphy = ReaderT GiphyConfig (EitherT ServantError IO)
- runGiphy :: MonadIO m => Giphy a -> GiphyConfig -> m (Either ServantError a)
- gifId :: Lens' Gif Text
- gifImages :: Lens' Gif ImageMap
- gifSlug :: Lens' Gif Text
- gifUrl :: Lens' Gif URI
- imageHeight :: Lens' Image (Maybe Int)
- imageUrl :: Lens' Image (Maybe URI)
- imageSize :: Lens' Image (Maybe Int)
- imageWidth :: Lens' Image (Maybe Int)
- imageMp4Url :: Lens' Image (Maybe URI)
- imageMp4Size :: Lens' Image (Maybe Int)
- imageWebpUrl :: Lens' Image (Maybe URI)
- imageWebpSize :: Lens' Image (Maybe Int)
- paginationCount :: Lens' Pagination Int
- paginationOffset :: Lens' Pagination Int
- paginationTotalCount :: Lens' Pagination Int
- searchItems :: Lens' SearchResponse [Gif]
- searchPagination :: Lens' SearchResponse Pagination
- singleGifItem :: Lens' SingleGifResponse Gif
- translateItem :: Lens' TranslateResponse Gif
- randomGifItem :: Lens' RandomResponse Gif
- search :: Query -> Giphy SearchResponse
- searchOffset :: Query -> PaginationOffset -> Giphy SearchResponse
- translate :: Phrase -> Giphy TranslateResponse
- gif :: GifId -> Giphy SingleGifResponse
- random :: Maybe Tag -> Giphy RandomResponse
Request Data Types
These data types are used to encapsulate otherwise weakly typed arguments.
The API Key. See https://github.com/Giphy/GiphyAPI
A search query.
A phrase or term used for translation.
A tag to retrieve a random GIF for.
data Pagination Source
Metadata about pagination in a response.
Response Data Types
These data types contain are the parsed JSON responses from the Giphy API.
A search response item.
An image contained in a Giphy response.
Image | |
|
newtype PaginationOffset Source
Offset for paginated requests.
data SearchResponse Source
A collection of GIFs as part of a search response.
newtype SingleGifResponse Source
A single gif as part of a response.
newtype TranslateResponse Source
A single GIF as part of a translate response.
Giphy Monad
data GiphyConfig Source
Contains the key to access the API.
type Giphy = ReaderT GiphyConfig (EitherT 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.
randomGifItem :: Lens' RandomResponse Gif Source
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
translate :: Phrase -> Giphy TranslateResponse Source
Issue a translate request for a given phrase or term. E.g. https://api.giphy.com/v1/gifs/translate?s=superman&api_key=dc6zaTOxFJmzC
gif :: GifId -> Giphy SingleGifResponse Source
Issue a request for a single GIF identified by its GifId
.
E.g. https://api.giphy.com/v1/gifs/feqkVgjJpYtjy?api_key=dc6zaTOxFJmzC