rest-client 0.5.1.1 → 0.5.2.1
raw patch · 4 files changed
+38/−19 lines, 4 filesdep ~http-conduit
Dependency ranges changed: http-conduit
Files
- CHANGELOG.md +5/−1
- rest-client.cabal +3/−3
- src/Rest/Client/Base.hs +18/−9
- src/Rest/Client/Internal.hs +12/−6
CHANGELOG.md view
@@ -1,6 +1,10 @@ # Changelog -### 0.5.1.1+### 0.5.2++* Add `toLbs` function to be used by rest-gen.++#### 0.5.1.1 * Allow http-conduit 2.2.*
rest-client.cabal view
@@ -1,5 +1,5 @@ name: rest-client-version: 0.5.1.1+version: 0.5.2.1 description: Utility library for use in generated API client libraries. synopsis: Utility library for use in generated API client libraries. maintainer: code@silk.co@@ -31,8 +31,8 @@ , data-default >= 0.5 && < 0.8 , exceptions == 0.8.* , http-client >= 0.3 && < 0.6- , http-conduit >= 2.1 && < 2.3- , http-types >= 0.7 && < 0.10+ , http-conduit >= 2.1 && < 2.4+ , http-types >= 0.7 && < 0.12 , hxt >= 9.2 && < 9.4 , hxt-pickle-utils == 0.1.* , monad-control (>= 0.3.3.1 && < 0.4) || (>= 1.0.0.3 && < 1.1)
src/Rest/Client/Base.hs view
@@ -1,4 +1,7 @@-{-# OPTIONS -fno-warn-orphans -fno-warn-deprecations #-}+{-# OPTIONS_GHC+ -fno-warn-deprecations+ -fno-warn-orphans+ #-} {-# LANGUAGE CPP , DeriveFunctor@@ -9,6 +12,10 @@ , TypeFamilies , UndecidableInstances #-}+#if MIN_VERSION_base(4,9,0)+{-# OPTIONS_GHC -Wno-redundant-constraints #-}+#endif+ module Rest.Client.Base ( ApiInfo(..) , ApiState(..)@@ -26,7 +33,6 @@ import Prelude hiding (catch) #endif -import Control.Applicative import Control.Monad.Base import Control.Monad.Catch (MonadCatch (catch)) import Control.Monad.Cont hiding (mapM)@@ -42,6 +48,7 @@ import Data.ByteString import Data.CaseInsensitive import Network.HTTP.Conduit hiding (method, responseBody)+import Network.HTTP.Client (defaultManagerSettings) import Rest.Types.Error @@ -53,10 +60,11 @@ , headers :: [(String, String)] } -data ApiState = ApiState { cookies :: CookieJar }+newtype ApiState = ApiState { cookies :: CookieJar } newtype ApiT m a = ApiT { unApiT :: StateT ApiState (ReaderT ApiInfo (ResourceT m)) a }- deriving ( Functor, Applicative+ deriving ( Applicative+ , Functor , Monad , MonadIO )@@ -92,8 +100,8 @@ #else instance MonadTransControl ApiT where newtype StT ApiT a = StTApiT { unStTApiT :: StT ResourceT (StT (ReaderT ApiInfo) (StT (StateT ApiState) a)) }- liftWith f = ApiT (liftWith (\runs -> liftWith (\runrr -> liftWith (\runrs -> f (liftM StTApiT . runrs . runrr . runs . unApiT)))))- restoreT = ApiT . restoreT . restoreT . restoreT . liftM unStTApiT+ liftWith f = ApiT (liftWith (\runs -> liftWith (\runrr -> liftWith (\runrs -> f (fmap StTApiT . runrs . runrr . runs . unApiT)))))+ restoreT = ApiT . restoreT . restoreT . restoreT . fmap unStTApiT instance MonadBaseControl v m => MonadBaseControl v (ApiT m) where newtype StM (ApiT m) a = StMApiT { unStMApiT :: ComposeSt ApiT m a }@@ -143,15 +151,16 @@ askApiInfo = lift askApiInfo putApiState = lift . putApiState -runT :: (MonadBaseControl IO m, Monad m) => ApiInfo -> ApiState -> ApiT m a -> ResourceT m a+runT :: MonadBaseControl IO m => ApiInfo -> ApiState -> ApiT m a -> ResourceT m a runT inf st api = runReaderT (evalStateT (unApiT api) st) inf run :: String -> ApiT IO a -> IO a run = flip runWithPort 80 runWithPort :: String -> Int -> ApiT IO a -> IO a-runWithPort hst prt api =- withManager $ \m ->+runWithPort hst prt api = do+ m <- newManager defaultManagerSettings+ runResourceT $ do runT (ApiInfo m hst prt []) (ApiState (createCookieJar [])) api data ApiResponse e a =
src/Rest/Client/Internal.hs view
@@ -1,10 +1,12 @@ {-# LANGUAGE CPP , FlexibleInstances- , OverlappingInstances , OverloadedStrings , UndecidableInstances #-}++#include "overlapping-compat.h"+ module Rest.Client.Internal ( module Control.Monad , module Data.String@@ -26,6 +28,7 @@ , toJSON , fromXML , toXML+ , toLbs , makeReq , doReq@@ -39,7 +42,6 @@ import Data.Default (def) #endif import Data.List-import Data.Monoid import Data.String import Data.String.ToString import Network.HTTP.Conduit hiding (method, responseBody, responseHeaders)@@ -58,6 +60,8 @@ import Rest.Client.Base +{-# ANN module ("HLint: ignore Use import/export shortcut"::String) #-}+ data ApiRequest = ApiRequest { method :: String , uri :: String@@ -88,9 +92,9 @@ splitHost = break (== '/') doRequest :: ApiStateC m => (L.ByteString -> Rest.Types.Error.Reason e) -> (L.ByteString -> a) -> ApiRequest -> m (ApiResponse e a)-doRequest a b = liftM (parseResult a b) . doReq+doRequest a b = fmap (parseResult a b) . doReq -doReq :: (ApiStateC m, MonadIO m) => ApiRequest -> m (Response L.ByteString)+doReq :: ApiStateC m => ApiRequest -> m (Response L.ByteString) doReq (ApiRequest m ur ps rhds bd) = do mn <- fmap manager askApiInfo hst <- fmap apiHost askApiInfo@@ -139,6 +143,9 @@ toJSON :: ToJSON a => a -> L.ByteString toJSON = encode +toLbs :: String -> L.ByteString+toLbs = L.fromString+ class XmlStringToType a where fromXML :: L.ByteString -> a toXML :: a -> L.ByteString@@ -147,7 +154,7 @@ fromXML = L.toString toXML = L.fromString -instance XmlPickler a => XmlStringToType a where+instance OVERLAPPABLE_ XmlPickler a => XmlStringToType a where fromXML v = ( either err id . P.eitherFromXML . L.toString@@ -158,4 +165,3 @@ makeReq :: String -> String -> [[String]] -> [(String, String)] -> Network.HTTP.Types.Header.RequestHeaders -> L.ByteString -> ApiRequest makeReq meth v ls = ApiRequest meth (intercalate "/" (v : map URI.encode (concat ls)))-