]> average.org Git - pdns-pipe-nmc.git/commitdiff
wip handling response
authorEugene Crosser <crosser@average.org>
Thu, 27 Mar 2014 15:48:29 +0000 (19:48 +0400)
committerEugene Crosser <crosser@average.org>
Thu, 27 Mar 2014 15:48:29 +0000 (19:48 +0400)
Data/JsonRpcClient.hs
pdns-pipe-nmc.hs

index 573e94df14529337d3d04b4cf44eb9a508a85978..6038695359b83a0131d96bf0219a13a976e043ce 100644 (file)
@@ -46,9 +46,9 @@ data JsonRpcError = JsonRpcError { jrpcErrCode    :: Int
                                  } deriving (Show)
 instance FromJSON JsonRpcError where
   parseJSON (Object o) = JsonRpcError
-                                <$> o .: "code"
-                                <*> o .: "error"
-                                <*> o .: "data"
+                                <$> o .:  "code"
+                                <*> o .:  "message"
+                                <*> o .:? "data"
   parseJSON x = return $ JsonRpcError
                                 (-32600)
                                 "Unparseable error object"
@@ -60,9 +60,9 @@ data JsonRpcResponse = JsonRpcResponse { jrpcRspResult :: Maybe Value
                                        } deriving (Show)
 instance FromJSON JsonRpcResponse where
   parseJSON (Object o) = JsonRpcResponse
-                                <$> o .: "result"
-                                <*> o .: "error"
-                                <*> o .: "id"
+                                <$> o .:? "result"
+                                <*> o .:  "error"
+                                <*> o .:  "id"
   parseJSON x = return $ JsonRpcResponse
                                 Nothing
                                 (JsonRpcError
index 3d1e46d112705132f8d4ed2934ef20aa6ea69c4e..079e3b9cd9ab4014cb85016cc4d2892f78a94b3f 100644 (file)
@@ -47,12 +47,14 @@ qReq cf q = applyBasicAuth (pack (rpcuser cf)) (pack (rpcpassword cf))
                 , method         = "PUT"
                 , requestHeaders = [ (hAccept,      "application/json")
                                    , (hContentType, "application/json")
+                                   , (hConnection,  "Keep-Alive")
                                    ]
                 , requestBody    = RequestBodyLBS $ encode $
                                    JsonRpcRequest JsonRpcV1
                                                   "name_show"
                                                   [q]
                                                   (String "pdns-nmc")
+                , checkStatus    = \_ _ _ -> Nothing
                 }
 
 -- NMC interface
@@ -167,8 +169,17 @@ main = do
 
   mgr <- newManager def
 
-  print $ qReq cfg "d/dot-bit"
-  rsp <- runResourceT $ httpLbs (qReq cfg "d/dot-bit") mgr
+  print $ qReq cfg "d/nosuchdomain"
+  rsp <- runResourceT $ httpLbs (qReq cfg "d/nosuchdomain") mgr
+  print $ (statusCode . responseStatus) rsp
+  putStrLn "===== complete response is:"
   print rsp
+  let rbody = responseBody rsp
+  putStrLn "===== response body is:"
+  print rbody
+  let result = parseJsonRpc rbody :: Either JsonRpcError NmcRes
+  putStrLn "===== parsed response is:"
+  print result
+--  print $ parseJsonRpc (responseBody rsp)
 
   --forever $ getLine >>= (pdnsOut uri) . (pdnsParse ver)