giphy-api

Giphy HTTP API wrapper and CLI search tool. http://github.com/passy/giphy-api#readme

Version on this page:0.4.0.0
LTS Haskell 8.19:0.5.2.0
Stackage Nightly 2017-06-23:0.5.2.0
Latest on Hackage:0.5.2.0
BSD3 licensed by Pascal Hartig
Maintained by Pascal Hartig

Module documentation for 0.4.0.0

giphy-api

Build Status Hackage Stackage 6 Stackage 7 Stackage Nightly

A Haskell wrapper for the Giphy HTTP API using servant-client.

Usage

The module provides a Giphy monad which can be run with runGiphy to lift it into IO. Here's a simple usage example:

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Text as T
import qualified Web.Giphy as Giphy

apiKey :: Giphy.Key
apiKey = Giphy.Key "dc6zaTOxFJmzC"

sample :: IO ()
sample = do
  let config = Giphy.GiphyConfig apiKey
  resp <- Giphy.runGiphy (app "puppies") config
  print resp

  where
    app :: T.Text -> Giphy.Giphy [Giphy.Gif]
    app q = do
      resp <- Giphy.search $ Giphy.Query q
      return $ Giphy._searchItems resp

For a slightly more complex example, check out the sample app, which also features the use of lenses.

Building

Use stack to build this library.

$ stack setup
$ stack test
# Drop the flag if you don't want the sample app to be built.
$ stack build --flag=giphy-api:buildSample
# To install the sample tool
$ stack install

Sample CLI Tool Usage

$ giphy-search --help
giphy-search

Usage: giphy-search ([-s|--search ARG] | [-t|--translate ARG] | [RANDOM_TAG])
  Find GIFs on the command line.

Available options:
  -h,--help                Show this help text
  -s,--search ARG          Use search to find a matching GIF.
  -t,--translate ARG       Use translate to find a matching GIF.
  -V,--version             Show version information
$ giphy-search puppies
Just https://media2.giphy.com/media/PjQFtJnmdOlwI/giphy.gif
$ giphy-search --translate superman
Just https://media3.giphy.com/media/eOewytQL4tOOA/giphy.gif
$ giphy-search "1C4D539A-B787-497F-B1DC-8FCF8D2C026D"
Nothing

Missing features

  • There is no compiler flag at the moment to disable lenses if those aren't needed. The library, however, uses microlens so the overhead should be minimal.

  • The "Stickers" API endpoints are currently not covered. If you need them, let me know. PRs obviously very welcome.

  • Some fields are currently not exposed. Again, if you need them, open an issue. For example, I have never seen a type value other than "gif" so I decided to skip it.

Changes

Changelog

v0.5.2.0

  • Fix #12: Compilation error with base 4.7

v0.5.0.0

  • Upgrade to Servant 0.9. User-facing API should remain unchanged.

v0.4.0.0

  • Upgrade to Servant 0.6. When running the Giphy monad it is now possible to provide a custom HTTP manager.

v0.3.0.0

  • Upgrade to Servant 0.5. No changes in the API, but it's not in Stackage yet (as of 2016-03-30).

v0.2.5.0

  • Clarify servant bounds.

v0.2.4.0

  • Include extra source files for stackage test suite.

v0.2.3.0

  • Losen upper bounds for Stackage inclusion (aeson 0.11 compat).

v0.2.2.0

  • Retrieve single GIFs via GifId.
  • Another attempt in reducing the deps on Hackage.

v0.2.1.0

  • Expose RandomResponse(..) type for non-lens use.

v0.2.0.0

  • Make sample app optional via build flag buildSample. This dramatically reduces the dependency graph.

v0.1.0.0

  • Initial release.
comments powered byDisqus