Code Monkey home page Code Monkey logo

giphy-api's Introduction

giphy-api

Build Status Hackage Stackage 8 Stackage 9 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.

giphy-api's People

Contributors

dbanck avatar passy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

brandonhamilton

giphy-api's Issues

Build failure with Servant 0.16

> /tmp/stackage-build13/giphy-api-0.6.0.1$ ghc -clear-package-db -global-package-db -package-db=/var/stackage/work/builds/nightly/pkgdb Setup
[1 of 1] Compiling Main             ( Setup.hs, Setup.o )
Linking Setup ...
> /tmp/stackage-build13/giphy-api-0.6.0.1$ ./Setup configure --package-db=clear --package-db=global --package-db=/var/stackage/work/builds/nightly/pkgdb --libdir=/var/stackage/work/builds/nightly/lib --bindir=/var/stackage/work/builds/nightly/bin --datadir=/var/stackage/work/builds/nightly/share --libexecdir=/var/stackage/work/builds/nightly/libexec --sysconfdir=/var/stackage/work/builds/nightly/etc --docdir=/var/stackage/work/builds/nightly/doc/giphy-api-0.6.0.1 --htmldir=/var/stackage/work/builds/nightly/doc/giphy-api-0.6.0.1 --haddockdir=/var/stackage/work/builds/nightly/doc/giphy-api-0.6.0.1
Configuring giphy-api-0.6.0.1...
> /tmp/stackage-build13/giphy-api-0.6.0.1$ ghc -clear-package-db -global-package-db -package-db=/var/stackage/work/builds/nightly/pkgdb Setup
> /tmp/stackage-build13/giphy-api-0.6.0.1$ ./Setup build
Preprocessing library for giphy-api-0.6.0.1..
Building library for giphy-api-0.6.0.1..
[1 of 2] Compiling Paths_giphy_api  ( dist/build/autogen/Paths_giphy_api.hs, dist/build/Paths_giphy_api.o )
[2 of 2] Compiling Web.Giphy        ( src/Web/Giphy.hs, dist/build/Web/Giphy.o )

src/Web/Giphy.hs:413:62: error:
    Not in scope: type constructor or class ‘Servant.ServantError’
    Perhaps you meant ‘Servant.ClientError’ (imported from Servant.Client)
    Neither ‘Servant.API’ nor ‘Servant.Client’ exports ‘ServantError’.
    |
413 | runGiphy :: MonadIO m => Giphy a -> GiphyConfig -> m (Either Servant.ServantError a)
    |                                                              ^^^^^^^^^^^^^^^^^^^^

src/Web/Giphy.hs:425:16: error:
    Not in scope: type constructor or class ‘Servant.ServantError’
    Perhaps you meant ‘Servant.ClientError’ (imported from Servant.Client)
    Neither ‘Servant.API’ nor ‘Servant.Client’ exports ‘ServantError’.
    |
425 |   -> m (Either Servant.ServantError a)
    |                ^^^^^^^^^^^^^^^^^^^^

Build failure with servant 0.9

As seen on the Stackage build server trying to build giphy-api-0.4.0.0:

[2 of 2] Compiling Web.Giphy        ( src/Web/Giphy.hs, dist/build/Web/Giphy.o )

src/Web/Giphy.hs:351:1: error:
    • Couldn't match type ‘Servant.ClientM SearchResponse’
                     with ‘HTTP.Manager
                           -> Servant.BaseUrl
                           -> ExceptT Servant.ServantError IO SearchResponse’
      Expected type: Maybe Key
                     -> Maybe PaginationOffset
                     -> Maybe Query
                     -> HTTP.Manager
                     -> Servant.BaseUrl
                     -> ExceptT Servant.ServantError IO SearchResponse
        Actual type: Maybe Key
                     -> Maybe PaginationOffset
                     -> Maybe Query
                     -> Servant.ClientM SearchResponse
    • When checking that the inferred type
        search' :: Maybe Key
                   -> Maybe PaginationOffset
                   -> Maybe Query
                   -> Servant.ClientM SearchResponse
      is as general as its signature
        search' :: Maybe Key
                   -> Maybe PaginationOffset
                   -> Maybe Query
                   -> HTTP.Manager
                   -> Servant.BaseUrl
                   -> ExceptT Servant.ServantError IO SearchResponse

Compile failure with GHC 7.8

The Hackage matrix builder detected the following compile failure:

Configuring component lib from giphy-api-0.5.1.0
Preprocessing library giphy-api-0.5.1.0...
[1 of 2] Compiling Paths_giphy_api  ( /tmp/matrix-worker/1480361044/dist-newstyle/build/x86_64-linux/ghc-7.8.4/giphy-api-0.5.1.0/build/autogen/Paths_giphy_api.hs, /tmp/matrix-worker/1480361044/dist-newstyle/build/x86_64-linux/ghc-7.8.4/giphy-api-0.5.1.0/build/Paths_giphy_api.o )
[2 of 2] Compiling Web.Giphy        ( src/Web/Giphy.hs, /tmp/matrix-worker/1480361044/dist-newstyle/build/x86_64-linux/ghc-7.8.4/giphy-api-0.5.1.0/build/Web/Giphy.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package bytestring-0.10.4.0 ... linking ... done.
Loading package containers-0.5.5.1 ... linking ... done.
Loading package fail-4.9.0.0 ... linking ... done.
Loading package binary-0.7.1.0 ... linking ... done.
Loading package text-1.2.2.1 ... linking ... done.
Loading package hashable-1.2.4.0 ... linking ... done.
Loading package transformers-0.5.2.0 ... linking ... done.
Loading package primitive-0.6.1.0 ... linking ... done.
Loading package vector-0.11.0.0 ... linking ... done.
Loading package scientific-0.3.4.9 ... linking ... done.
Loading package pretty-1.1.1.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package nats-1.1.1 ... linking ... done.
Loading package transformers-compat-0.5.1.4 ... linking ... done.
Loading package tagged-0.8.5 ... linking ... done.
Loading package unordered-containers-0.2.7.1 ... linking ... done.
Loading package semigroups-0.18.2 ... linking ... done.
Loading package attoparsec-0.13.1.0 ... linking ... done.
Loading package old-locale-1.0.0.6 ... linking ... done.
Loading package time-1.4.2 ... linking ... done.
Loading package unix-2.7.0.1 ... linking ... done.
Loading package base-compat-0.9.1 ... linking ... done.
Loading package dlist-0.8.0.2 ... linking ... done.
Loading package time-locale-compat-0.1.1.3 ... linking ... done.
Loading package aeson-1.0.2.1 ... linking ... done.
Loading package base64-bytestring-1.0.0.1 ... linking ... done.
Loading package mtl-2.2.1 ... linking ... done.
Loading package stm-2.4.4.1 ... linking ... done.
Loading package exceptions-0.8.3 ... linking ... done.
Loading package blaze-builder-0.4.0.2 ... linking ... done.
Loading package uri-bytestring-0.2.2.1 ... linking ... done.
Loading package random-1.1 ... linking ... done.
Loading package uuid-types-1.0.3 ... linking ... done.
Loading package http-api-data-0.3.3 ... linking ... done.
Loading package case-insensitive-1.2.0.7 ... linking ... done.
Loading package data-default-class-0.1.2.0 ... linking ... done.
Loading package cookie-0.4.2.1 ... linking ... done.
Loading package filepath-1.3.0.2 ... linking ... done.
Loading package http-types-0.9.1 ... linking ... done.
Loading package mime-types-0.1.0.7 ... linking ... done.
Loading package network-2.6.3.1 ... linking ... done.
Loading package parsec-3.1.11 ... linking ... done.
Loading package network-uri-2.6.1.0 ... linking ... done.
Loading package async-2.1.1 ... linking ... done.
Loading package directory-1.2.1.0 ... linking ... done.
Loading package process-1.2.0.0 ... linking ... done.
Loading package zlib-0.6.1.2 ... linking ... done.
Loading package streaming-commons-0.1.16 ... linking ... done.
Loading package http-client-0.5.4 ... linking ... done.
Loading package byteable-0.1.1 ... linking ... done.
Loading package cereal-0.5.4.0 ... linking ... done.
Loading package socks-0.5.5 ... linking ... done.
Loading package hourglass-0.2.10 ... linking ... done.
Loading package memory-0.13 ... linking ... done.
Loading package asn1-types-0.3.2 ... linking ... done.
Loading package asn1-encoding-0.9.4 ... linking ... done.
Loading package cryptonite-0.20 ... linking ... done.
Loading package asn1-parse-0.9.4 ... linking ... done.
Loading package pem-0.2.2 ... linking ... done.
Loading package x509-1.6.4 ... linking ... done.
Loading package x509-store-1.6.2 ... linking ... done.
Loading package x509-validation-1.6.5 ... linking ... done.
Loading package tls-1.3.8 ... linking ... done.
Loading package x509-system-1.6.4 ... linking ... done.
Loading package connection-0.2.6 ... linking ... done.
Loading package http-client-tls-0.3.3 ... linking ... done.
Loading package http-media-0.6.4 ... linking ... done.
Loading package safe-0.3.10 ... linking ... done.
Loading package mmorph-1.0.9 ... linking ... done.
Loading package utf8-string-1.0.1.1 ... linking ... done.
Loading package string-conversions-0.4 ... linking ... done.
Loading package vault-0.3.0.6 ... linking ... done.
Loading package servant-0.9.1.1 ... linking ... done.
Loading package servant-client-0.9.1.1 ... linking ... done.
Loading package microlens-0.4.7.0 ... linking ... done.
Loading package microlens-th-0.4.1.0 ... linking ... done.

src/Web/Giphy.hs:170:12:
    Not in scope: ‘<$>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:170:25:
    Not in scope: ‘<$>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:171:12:
    Not in scope: ‘<*>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:171:25:
    Not in scope: ‘<$>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:172:12:
    Not in scope: ‘<*>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:172:25:
    Not in scope: ‘<$>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:173:12:
    Not in scope: ‘<*>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:173:25:
    Not in scope: ‘<$>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:174:12:
    Not in scope: ‘<*>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:174:25:
    Not in scope: ‘<$>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:175:12:
    Not in scope: ‘<*>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:175:25:
    Not in scope: ‘<$>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:176:12:
    Not in scope: ‘<*>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:176:25:
    Not in scope: ‘<$>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:177:12:
    Not in scope: ‘<*>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

src/Web/Giphy.hs:177:25:
    Not in scope: ‘<$>’
    Perhaps you meant ‘<>’ (imported from Data.Monoid)

giphy-api-0.5.2.0 build failure with servant-0.13

As seen on the Stackage build server:

[2 of 2] Compiling Web.Giphy        ( src/Web/Giphy.hs, dist/build/Web/Giphy.o )

src/Web/Giphy.hs:430:28: error:
    • Couldn't match expected type ‘Servant.ClientEnv’
                  with actual type ‘Maybe (GHC.Conc.Sync.TVar HTTP.CookieJar)
                                    -> Servant.ClientEnv’
    • Probable cause: ‘env’ is applied to too few arguments
      In the first argument of ‘runClientM'’, namely ‘env’
      In the first argument of ‘(.)’, namely ‘runClientM' env’
      In the second argument of ‘(.)’, namely
        ‘runClientM' env . Reader.runReaderT giphy’
    |
430 |       liftIO . runClientM' env . Reader.runReaderT giphy $ GiphyContext conf
    |                            ^^^

I was able to reproduce this failure locally like so:

stack unpack giphy-api-0.5.2.0 && cd giphy-api-0.5.2.0
edit stack.yaml # add the following stack.yaml
stack build 
# stack.yaml
resolver: nightly-2018-03-10
extra-deps:
- servant-0.13
- http-types-0.12.1
- servant-client-0.13
- servant-client-core-0.13

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.