packages feed

http-client-session (empty) → 0.1.1

raw patch · 4 files changed

+126/−0 lines, 4 filesdep +base-preludedep +bytestringdep +eithersetup-changed

Dependencies added: base-prelude, bytestring, either, http-client, mtl-prelude

Files

+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2016, Sannsyn AS++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ http-client-session.cabal view
@@ -0,0 +1,54 @@+name:+  http-client-session+version:+  0.1.1+synopsis:+  A simple abstraction over the "http-client" connection manager+category:+  Network+homepage:+  https://github.com/sannsyn/http-client-session +bug-reports:+  https://github.com/sannsyn/http-client-session/issues +author:+  Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+  Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:+  (c) 2016, Sannsyn AS+license:+  MIT+license-file:+  LICENSE+build-type:+  Simple+cabal-version:+  >=1.10+++source-repository head+  type:+    git+  location:+    git://github.com/sannsyn/http-client-session.git+++library+  hs-source-dirs:+    library+  default-extensions:+    Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+  default-language:+    Haskell2010+  other-modules:+  exposed-modules:+    HTTPClient.Session+  build-depends:+    --+    http-client >= 0.4.27 && < 0.5,+    --+    bytestring >= 0.10 && < 0.11,+    --+    either >= 4.4 && < 5,+    mtl-prelude >= 2 && < 3,+    base-prelude >= 0.1.21 && < 2
+ library/HTTPClient/Session.hs view
@@ -0,0 +1,48 @@+module HTTPClient.Session+(+  Session,+  run,+  withManager,+  requestLBSResponse,+  requestLBSBody,+  requestBSBody,+  -- * Reexports+  A.Manager(..),+  A.HttpException(..),+  A.Request(..),+)+where++import BasePrelude+import MTLPrelude+import Control.Monad.Trans.Either+import qualified Network.HTTP.Client as A+import qualified Data.ByteString.Lazy as B+import qualified Data.ByteString as C+++-- |+-- A session on an HTTP manager.+newtype Session a =+  Session (ReaderT A.Manager (EitherT A.HttpException IO) a)+  deriving (Functor, Applicative, Monad, MonadIO, MonadError A.HttpException)++run :: Session a -> A.Manager -> IO (Either A.HttpException a)+run (Session reader) manager =+  runEitherT $ runReaderT reader manager++withManager :: (A.Manager -> IO (Either A.HttpException a)) -> Session a+withManager handler =+  Session $ ReaderT $ \manager -> EitherT $ handler manager++requestLBSResponse :: A.Request -> Session (A.Response B.ByteString)+requestLBSResponse request =+  withManager $ \manager -> try $ A.httpLbs request manager++requestLBSBody :: A.Request -> Session B.ByteString+requestLBSBody request =+  fmap A.responseBody $ requestLBSResponse request++requestBSBody :: A.Request -> Session C.ByteString+requestBSBody request =+  fmap B.toStrict $ requestLBSBody request