packages feed

giphy-api 0.4.0.0 → 0.5.0.0

raw patch · 6 files changed

+55/−52 lines, 6 filesdep ~basedep ~servantdep ~servant-client

Dependency ranges changed: base, servant, servant-client

Files

README.md view
@@ -1,7 +1,11 @@ # giphy-api [![Build Status](https://travis-ci.org/passy/giphy-api.svg?branch=master)](https://travis-ci.org/passy/giphy-api) [![Hackage](http://img.shields.io/hackage/v/giphy-api.svg)](https://hackage.haskell.org/package/giphy-api)+[![Stackage 6](http://stackage.org/package/giphy-api/badge/lts-6)](http://stackage.org/lts-6/package/giphy-api)+[![Stackage 7](http://stackage.org/package/giphy-api/badge/lts-6)](http://stackage.org/lts-7/package/giphy-api)+[![Stackage Nightly](http://stackage.org/package/giphy-api/badge/nightly)](http://stackage.org/nightly/package/giphy-api) + A Haskell wrapper for the [Giphy HTTP API](https://github.com/Giphy/GiphyAPI) using [servant-client](https://hackage.haskell.org/package/servant-client). @@ -71,9 +75,6 @@ ```  ## Missing features--- No network configuration. No proxies, no TLS certificate pinning, no custom-  networking stack. I'm still learning, let me know how to do this better!  - 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
+ app/Sample.hs view
@@ -0,0 +1,21 @@+{-# LANGUAGE OverloadedStrings #-}++module Sample where++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
changelog.md view
@@ -1,5 +1,9 @@ # Changelog +## 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
giphy-api.cabal view
@@ -1,9 +1,9 @@--- This file has been generated from package.yaml by hpack version 0.11.2.+-- This file has been generated from package.yaml by hpack version 0.15.0. -- -- see: https://github.com/sol/hpack  name:           giphy-api-version:        0.4.0.0+version:        0.5.0.0 synopsis:       Giphy HTTP API wrapper and CLI search tool. description:    Please see README.md category:       Web@@ -41,8 +41,8 @@     , microlens     , microlens-th     , mtl-    , servant >= 0.6-    , servant-client >= 0.6+    , servant >= 0.9+    , servant-client >= 0.9     , transformers     , http-api-data     , http-client@@ -70,7 +70,7 @@   else     buildable: False   other-modules:-      Paths_giphy_api+      Sample   default-language: Haskell2010  test-suite spec
src/Web/Giphy.hs view
@@ -85,12 +85,9 @@   , translate   , gif   , random-  -- NO-  , liftQuery   ) where  import           Control.Monad             (MonadPlus (), forM, join, mzero)-import           Control.Monad.Except      (ExceptT, runExceptT) import qualified Control.Monad.Reader      as Reader import           Control.Monad.Trans       (MonadIO (), lift, liftIO) import           Data.Aeson                ((.:), (.:?))@@ -110,13 +107,13 @@ import qualified Text.Read                 as Read import qualified Web.HttpApiData           as Data -maybeParse :: (Monad m, MonadPlus m) => (a -> Maybe b) -> m a -> m b+maybeParse :: MonadPlus m => (a -> Maybe b) -> m a -> m b maybeParse f = (maybe mzero return . f =<<) -fromURI :: (Monad m, MonadPlus m) => m String -> m Servant.URI+fromURI :: MonadPlus m => m String -> m Servant.URI fromURI = maybeParse URI.parseURI -fromInt :: (Monad m, MonadPlus m) => m String -> m Int+fromInt :: MonadPlus m => m String -> m Int fromInt = maybeParse Read.readMaybe  -- $request@@ -323,30 +320,22 @@   :: Maybe Key   -> Maybe PaginationOffset   -> Maybe Query-  -> HTTP.Manager-  -> Servant.BaseUrl-  -> ExceptT Servant.ServantError IO SearchResponse+  -> Servant.ClientM SearchResponse  translate'   :: Maybe Key   -> Maybe Phrase-  -> HTTP.Manager-  -> Servant.BaseUrl-  -> ExceptT Servant.ServantError IO TranslateResponse+  -> Servant.ClientM TranslateResponse  gif'   :: GifId   -> Maybe Key-  -> HTTP.Manager-  -> Servant.BaseUrl-  -> ExceptT Servant.ServantError IO SingleGifResponse+  -> Servant.ClientM SingleGifResponse  random'   :: Maybe Key   -> Maybe Tag-  -> HTTP.Manager-  -> Servant.BaseUrl-  -> ExceptT Servant.ServantError IO RandomResponse+  -> Servant.ClientM RandomResponse  search' :<|> translate' :<|> gif' :<|> random' = Servant.client api @@ -356,17 +345,6 @@ -- the 'Giphy' monad. -- --- | Lift a partially applied request function into the Giphy monad.-liftQuery-  :: forall b (t :: (* -> *) -> * -> *) (m :: * -> *).-     (Monad m, Reader.MonadTrans t, Reader.MonadReader GiphyContext (t m))-  => (HTTP.Manager -> Servant.BaseUrl -> m b)-  -> t m b-liftQuery f = do-  manager <- Reader.asks ctxManager-  url <- Reader.asks ctxBaseUrl-  lift $ f manager url- -- | 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> search@@ -374,7 +352,7 @@   -> Giphy SearchResponse search query = do   key <- Reader.asks (configApiKey . ctxConfig)-  liftQuery $ search' (pure key) (pure $ PaginationOffset 0) (pure query)+  lift $ search' (pure key) (pure $ PaginationOffset 0) (pure query)  -- | Issue a search request for the given query by specifying a -- pagination offset.@@ -385,7 +363,7 @@   -> Giphy SearchResponse searchOffset query offset = do   key <- Reader.asks (configApiKey . ctxConfig)-  liftQuery $ search' (pure key) (pure offset) (pure query)+  lift $ search' (pure key) (pure offset) (pure query)  -- | Issue a request for a single GIF identified by its 'GifId'. -- E.g. <https://api.giphy.com/v1/gifs/feqkVgjJpYtjy?api_key=dc6zaTOxFJmzC>@@ -394,7 +372,7 @@   -> Giphy SingleGifResponse gif gifid = do   key <- Reader.asks (configApiKey . ctxConfig)-  liftQuery $ gif' gifid (pure key)+  lift $ gif' gifid (pure key)  -- | Issue a translate request for a given phrase or term. -- E.g. <https://api.giphy.com/v1/gifs/translate?s=superman&api_key=dc6zaTOxFJmzC>@@ -403,7 +381,7 @@   -> Giphy TranslateResponse translate phrase = do   key <- Reader.asks (configApiKey . ctxConfig)-  liftQuery $ translate' (pure key) (pure phrase)+  lift $ translate' (pure key) (pure phrase)  -- | 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>@@ -412,7 +390,7 @@   -> Giphy RandomResponse random tag = do   key <- Reader.asks (configApiKey . ctxConfig)-  liftQuery $ random' (pure key) tag+  lift $ random' (pure key) tag  -- $giphy --@@ -423,13 +401,11 @@ data GiphyConfig = GiphyConfig { configApiKey :: Key }   deriving (Show, Eq) --- | Internal data structure holding the base url, http manager and config.-data GiphyContext = GiphyContext { ctxConfig  :: GiphyConfig-                                 , ctxManager :: HTTP.Manager-                                 , ctxBaseUrl :: Servant.BaseUrl }+-- | Internal data structure holding the config.+data GiphyContext = GiphyContext { ctxConfig  :: GiphyConfig }  -- | The Giphy monad contains the execution context.-type Giphy = Reader.ReaderT GiphyContext (ExceptT Servant.ServantError IO)+type Giphy = Reader.ReaderT GiphyContext Servant.ClientM  -- | You need to provide a 'GiphyConfig' to lift a 'Giphy' computation -- into 'MonadIO'.@@ -446,7 +422,11 @@   -> Giphy a   -> GiphyConfig   -> m (Either Servant.ServantError a)-runGiphy' manager giphy conf = liftIO . runExceptT . Reader.runReaderT giphy $ GiphyContext conf manager baseUrl+runGiphy' manager giphy conf =+  let env = Servant.ClientEnv manager baseUrl+      runClientM' = flip Servant.runClientM+  in+      liftIO . runClientM' env . Reader.runReaderT giphy $ GiphyContext conf  -- $lenses --
stack.yaml view
@@ -2,7 +2,4 @@ extra-package-dbs: [] packages: - '.'-extra-deps:-- servant-0.6-- servant-client-0.6-resolver: nightly-2016-04-04+resolver: nightly-2016-09-29