packages feed

scotty-params-parser (empty) → 0.3

raw patch · 4 files changed

+137/−0 lines, 4 filesdep +base-preludedep +scottydep +successsetup-changed

Dependencies added: base-prelude, scotty, success, text, transformers, unordered-containers

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
+ library/Scotty/QueryParser.hs view
@@ -0,0 +1,58 @@+-- |+-- A DSL for parsing of an HTTP request query parameters.+module Scotty.QueryParser+(+  Params,+  run,+  lookup,+  param,+  Param,+)+where++import BasePrelude hiding (lookup)+import Control.Monad.Trans.Class+import Control.Monad.Trans.Reader+import Data.Text.Lazy (Text)+import qualified Web.Scotty.Trans as Scotty+import qualified Success.Pure as Success+import qualified Data.HashMap.Strict as HashMap+import qualified Data.Text.Lazy+++-- |+-- A multiple parameters parser.+newtype Params a =+  Params (ReaderT (HashMap.HashMap Text Text) (Success.Success Text) a)+  deriving (Functor, Applicative, Alternative, Monad, MonadPlus)++run :: Params a -> forall m e. (Scotty.ScottyError e, Monad m) => Scotty.ActionT e m a+run (Params (ReaderT success')) =+  Scotty.params >>= onParams+  where+    onParams params =+      either (Scotty.raise . Scotty.stringError . Data.Text.Lazy.unpack . fromMaybe "") return $+      Success.asEither $+      success' $+      HashMap.fromList params++lookup :: Text -> Params Text+lookup name =+  Params $ ReaderT $ \hashMap ->+    maybe (Success.failure $ "No parameter named" <> name) Success.success $+    HashMap.lookup name hashMap++-- |+-- Given a parameter parser and name attempts to get it.+param :: Param a -> Text -> Params a+param paramParser name =+  lookup name >>= onText+  where+    onText text =+      Params $ ReaderT $ const $ either Success.failure Success.success $ paramParser text++-- |+-- A single parameter parser.+type Param a =+  Text -> Either Text a+
+ scotty-params-parser.cabal view
@@ -0,0 +1,55 @@+name:+  scotty-params-parser+version:+  0.3+synopsis:+  HTTP-request's query parameters parser abstraction for "scotty"+category:+  Web, Parser+homepage:+  https://github.com/sannsyn/scotty-params-parser +bug-reports:+  https://github.com/sannsyn/scotty-params-parser/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/scotty-params-parser.git+++library+  hs-source-dirs:+    library+  default-extensions:+    Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, 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:+    Scotty.QueryParser+  build-depends:+    --+    scotty >= 0.11 && < 0.12,+    --+    unordered-containers >= 0.2 && < 0.3,+    text == 1.*,+    --+    transformers >= 0.4 && < 0.6,+    success >= 0.2.6 && < 0.3,+    base-prelude >= 0.1.21 && < 0.2