packages feed

collection-json (empty) → 0.1.0.0

raw patch · 5 files changed

+239/−0 lines, 5 filesdep +aesondep +basedep +bytestringsetup-changed

Dependencies added: aeson, base, bytestring, text

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 Daniel Choi++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.
+ README.md view
@@ -0,0 +1,8 @@+# collection-json++A Haskell supporting library for the Collection+JSON media type.++In progess.+++See <http://amundsen.com/media-types/collection/> for information about this media type.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Text/JSON/CollectionJSON/Types.hs view
@@ -0,0 +1,181 @@+{-# LANGUAGE OverloadedStrings, RecordWildCards #-} +module Text.JSON.CollectionJSON.Types where+import Data.Aeson hiding (Error)+import Data.Text (Text)+import Control.Applicative++data Collection = Collection {+    cVersion :: Text+  , cHref :: Text+  , cLinks :: [Link]+  , cItems :: [Item]+  , cQueries :: [Query]+  , cTemplate :: Maybe Template+  , cError :: Maybe Error+  } deriving Show++data Error = Error {+    eTitle :: Text+  , eCode :: Maybe Text+  , eMessage :: Maybe Text+  } deriving Show++{- Each has five possible properties: href (REQUIRED), rel (REQURIED), name (OPTIONAL), render (OPTIONAL), and prompt, (OPTIONAL).+-}++data Link = Link {+    lHref :: Text+  , lRel :: Text+  , lName :: Maybe Text+  , lRender :: Maybe Text+  , lPrompt :: Maybe Text+  } deriving Show+  +{- The queries array SHOULD contain one or more anonymous objects. Each object composed of five possible properties: href (REQUIRED), rel (REQUIRED), name (OPTIONAL), prompt (OPTIONAL), and a data array (OPTIONAL). -}++data Query = Query {+    qHref :: Text+  , qRel :: Text+  , qName :: Maybe Text+  , qPrompt :: Maybe Text+  , qData :: [Data]+  } deriving Show++{- The data array SHOULD contain one or more anonymous objects. Each +object MAY have any of three possible properties: name (REQUIRED), value+(OPTIONAL), and prompt (OPTIONAL). -}++data Data = Data { +    dName :: Text+  , dValue :: Maybe Text+  , dPrompt :: Maybe Text+  } deriving Show++{- Each element in the items array SHOULD contain an href property. The+href property MUST contain a URI. This URI MAY be used to retrieve a+Collection+JSON document representing the associated item. It MAY be used+to edit or delete the associated item. See Reading and Writing Data for+details.++The items array MAY have a data array child property.++The items array MAY have a links array child property.+-}++data Item = Item {+    iHref :: Text+  , iData :: [Data]+  , iLinks :: [Link]+  } deriving Show++{- The template object SHOULD have a data array child property. -}+++data Template = Template {+    tData :: [Data]+  } deriving Show+ +------------------------------------------------------------------------+-- FromJSON instances++instance FromJSON Template where+    parseJSON (Object v) = Template <$> v .: "data" ++instance FromJSON Item where+    parseJSON (Object v) = Item +        <$> v .: "href" +        <*> v .:? "data" .!= [] +        <*> v .:? "links" .!= []++instance FromJSON Data where+    parseJSON (Object v) = Data+        <$> v .: "name"+        <*> v .:? "value"+        <*> v .:? "prompt"++instance FromJSON Query where+    parseJSON (Object v) = Query+        <$> v .: "href"+        <*> v .: "rel"+        <*> v .:? "name"+        <*> v .:? "prompt"+        <*> v .:? "data" .!= []++instance FromJSON Link where+    parseJSON (Object v) = Link+        <$> v .: "href"+        <*> v .: "rel"+        <*> v .:? "name"+        <*> v .:? "render"+        <*> v .:? "prompt"++instance FromJSON Error where+    parseJSON (Object v) = Error+        <$> v .: "title"+        <*> v .:? "code"+        <*> v .:? "message"++instance FromJSON Collection where+    parseJSON (Object v) = Collection +        <$> v .: "version" +        <*> v .: "href" +        <*> v .:? "links" .!= []+        <*> v .:? "items" .!= []+        <*> v .:? "queries" .!= []+        <*> v .:? "template" +        <*> v .:? "error" ++------------------------------------------------------------------------++instance ToJSON Template where+    toJSON Template{..} = object [ "data" .= tData ]++instance ToJSON Item where+    toJSON Item{..} = object [ +        "href" .= iHref+      , "data" .= iData+      , "links" .= iLinks+      ]++instance ToJSON Data where+    toJSON Data{..} = object [ +        "name" .= dName+      , "data" .= dValue+      , "prompt" .= dPrompt+      ]++instance ToJSON Query where+    toJSON Query{..} = object [ +        "href" .= qHref+      , "rel" .= qRel+      , "name" .= qName+      , "prompt" .= qPrompt+      , "data" .= qData+      ]++instance ToJSON Link where+    toJSON Link{..} = object [ +        "href" .= lHref+      , "rel" .= lRel+      , "name" .= lName+      , "render" .= lRender+      , "prompt" .= lPrompt+      ]++instance ToJSON Error where+    toJSON Error{..} = object [ +        "title" .= eTitle+      , "code" .= eCode+      , "message" .= eMessage+      ]++instance ToJSON Collection where+    toJSON Collection{..} = object [ +        "version" .= cVersion+      , "href" .= cHref+      , "links" .= cLinks+      , "items" .= cItems+      , "queries" .= cQueries+      , "template" .= cTemplate+      , "error" .= cError+      ]
+ collection-json.cabal view
@@ -0,0 +1,28 @@+-- Initial collection-json.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                collection-json+version:             0.1.0.0+synopsis:            Collection+JSON hypermedia type tools+homepage:            https://github.com/danchoi/collection-json.hs+description:         Collection+JSON hypermedia type tools+license:             MIT+license-file:        LICENSE+author:              Daniel Choi+maintainer:          dhchoi@gmail.com+copyright:           2015 Daniel Choi+category:            Web+build-type:          Simple+-- extra-source-files:  +cabal-version:       >=1.10++library+  exposed-modules:     Text.JSON.CollectionJSON.Types+  -- other-modules:       +  -- other-extensions:    +  build-depends:       base >=4.6 && <4.8+                     , aeson >= 0.8+                     , text+                     , bytestring+  -- hs-source-dirs:      +  default-language:    Haskell2010