packages feed

cayley-client 0.1.1.0 → 0.1.2.0

raw patch · 4 files changed

+65/−33 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Database.Cayley.Client: Quad :: Text -> Text -> Text -> Maybe Text -> Quad
+ Database.Cayley.Client: data Quad
+ Database.Cayley.Client: label :: Quad -> Maybe Text
+ Database.Cayley.Client: object :: Quad -> Text
+ Database.Cayley.Client: predicate :: Quad -> Text
+ Database.Cayley.Client: subject :: Quad -> Text

Files

Database/Cayley/Client.hs view
@@ -1,14 +1,18 @@ {-# LANGUAGE OverloadedStrings #-} -module Database.Cayley.Client-    ( defaultCayleyConfig+module Database.Cayley.Client (+    -- * Connect & query+      defaultCayleyConfig     , connectCayley     , query+    -- * REST API operations+    , Quad (..)     , writeQuad     , deleteQuad     , writeQuads     , deleteQuads     , writeNQuadFile+    -- * Helper function     , successfulResults     ) where  @@ -48,23 +52,26 @@     doQuery m q = do         c <- ask         r <- apiRequest-                 m ("http://" ++ serverName c ++ "/api/v" ++-                    show (apiVersion c) ++ "/query/"+                 m ("http://"+                    ++ serverName c+                    ++ "/api/v"+                    ++ show (apiVersion c)+                    ++ "/query/"                     ++ show (queryLang c))                  (serverPort c) (RequestBodyBS q)-        case r of+        return $ case r of             Just a  ->                 case a ^? key "result" of-                    Just v  -> return $ Right v+                    Just v  -> Right v                     Nothing ->                       case a ^? key "error" of                           Just e  ->                               case A.fromJSON e of-                                  A.Success s -> return $ Left s-                                  A.Error e   -> return $ Left e-                          Nothing -> return $+                                  A.Success s -> Left s+                                  A.Error e   -> Left e+                          Nothing ->                               Left "No JSON response from Cayley"-            Nothing -> return $ Left "Can't get any response from Cayley"+            Nothing -> Left "Can't get any response from Cayley"  -- | Write a 'Quad' with the given subject, predicate, object and optional -- label. Throw result or extract amount of query 'successfulResults'@@ -85,10 +92,10 @@ -- | Delete the 'Quad' defined by the given subject, predicate, object -- and optional label. deleteQuad :: CayleyConnection-           -> T.Text-           -> T.Text-           -> T.Text-           -> Maybe T.Text+           -> T.Text             -- ^ Subject node+           -> T.Text             -- ^ Predicate node+           -> T.Text             -- ^ Object node+           -> Maybe T.Text       -- ^ Label node            -> IO (Maybe A.Value) deleteQuad c s p o l =     deleteQuads c [Quad { subject = s, predicate = p, object = o, label = l }]@@ -101,8 +108,10 @@     write m qs = do         c <- ask         apiRequest-            m ("http://" ++ serverName c-               ++ "/api/v" ++ show (apiVersion c)+            m ("http://"+               ++ serverName c+               ++ "/api/v"+               ++ show (apiVersion c)                ++ "/write")             (serverPort c) (toRequestBody qs) @@ -114,8 +123,10 @@     delete m qs = do         c <- ask         apiRequest-            m ("http://" ++ serverName c-               ++ "/api/v" ++ show (apiVersion c)+            m ("http://"+               ++ serverName c+               ++ "/api/v"+               ++ show (apiVersion c)                ++ "/delete")             (serverPort c)             (toRequestBody qs)@@ -126,21 +137,20 @@   where     writenq m p = do         c <- ask-        r <- parseUrl ("http://" ++ serverName c-                       ++ "/api/v" ++ show (apiVersion c)+        r <- parseUrl ("http://"+                       ++ serverName c+                       ++ "/api/v"+                       ++ show (apiVersion c)                        ++ "/write/file/nquad")                  >>= \r -> return r { port = serverPort c}         t <- liftIO $                  try $                     flip httpLbs m                         =<< formDataBody [partFileSource "NQuadFile" p] r-        case t of-            Right r -> return $ A.decode $ responseBody r-            Left e  ->-                return $-                    Just $-                        A.object-                            ["error" A..= T.pack (show (e :: SomeException))]+        return $ case t of+            Right r -> A.decode $ responseBody r+            Left e  -> Just $+                A.object ["error" A..= T.pack (show (e :: SomeException))]  -- | Get amount of successful results from a write/delete 'Quad'(s) -- operation.@@ -157,8 +167,9 @@                     case A.fromJSON v of                         A.Success s ->                             case AT.parse getAmount s of-                               AT.Done "" a -> Right a-                               _ -> Left "Can't get amount of successful results"+                                AT.Done "" a -> Right a+                                _            ->+                                    Left "Can't get amount of successful results"                         A.Error e -> Left e                 Nothing ->                     case a ^? key "error" of
Database/Cayley/Internal.hs view
@@ -12,7 +12,11 @@  import Database.Cayley.Types -apiRequest :: Manager -> String -> Int -> RequestBody -> ReaderT CayleyConfig IO (Maybe A.Value)+apiRequest :: Manager+              -> String+              -> Int+              -> RequestBody+              -> ReaderT CayleyConfig IO (Maybe A.Value) apiRequest m u p b = do     r <- parseUrl u >>= \c ->              return c { method = "POST", port = p, requestBody = b }
Database/Cayley/Types.hs view
@@ -41,7 +41,24 @@     , predicate :: T.Text       -- ^ Predicate node     , object    :: T.Text       -- ^ Object node     , label     :: Maybe T.Text -- ^ Label node-    } deriving (Eq,Show)+    }++instance Show Quad where+    show (Quad s p o (Just l)) = T.unpack s+                                 ++ " "+                                 ++ T.unpack p+                                 ++ " "+                                 ++ T.unpack o+                                 ++ " ("+                                 ++ T.unpack l+                                 ++ ")"+    show (Quad s p o Nothing)  = T.unpack s+                                 ++ " "+                                 ++ T.unpack p+                                 ++ " "+                                 ++ T.unpack o+instance Eq Quad where+    Quad s p o _ == Quad s' p' o' _ = s == s' && p == p' && o == o'  instance A.ToJSON Quad where     toJSON (Quad subject predicate object label) =
cayley-client.cabal view
@@ -1,7 +1,7 @@ name:                cayley-client-version:             0.1.1.0+version:             0.1.2.0 stability:           Experimental-synopsis:            An Haskell client for Cayley graph database+synopsis:            A Haskell client for Cayley graph database description:         cayley-client implements the RESTful API of the Cayley database graph. homepage:            https://github.com/MichelBoucey/cayley-client license:             BSD3