1 module Script (script) where
3 import Control.Monad.IO.Class
4 import Gargantext.API.Client
12 -- | An example script. Tweak, rebuild and re-run the executable to see the
13 -- effect of your changes. You can hit any gargantext endpoint in the body
14 -- of 'script' using the many (many!) client functions exposed by the
15 -- 'Gargantext.API.Client' module.
17 -- Don't forget to pass @--user@ and @--pass@ if you're using 'withAuthToken'.
18 script :: ClientOpts -> ClientM ()
20 -- we start by asking the backend for its version
21 ver <- getBackendVersion
22 liftIO . putStrLn $ "Backend version: " ++ show ver
24 -- next we authenticate using the credentials given on the command line
25 -- (through --user and --pass), erroring out loudly if the auth creds don't
26 -- go through, running the continuation otherwise.
27 withAuthToken opts $ \tok userNode -> do
28 liftIO . putStrLn $ "user node: " ++ show userNode
30 -- we run a few client computations while tracking some EKG metrics
31 -- (any RTS stats or routing-related data), which means that we sample the
32 -- metrics at the beginning, the end, and in between each pair of steps.
33 tracking opts ["rts.gc.bytes_allocated"]
36 liftIO . putStrLn $ "roots: " ++ show roots
38 , ("get user node detail", do
39 userNodeDetail <- getNode tok userNode
40 liftIO . putStrLn $ "user node details: " ++ show userNodeDetail
43 -- we pretty print the values we sampled for all metrics and the
44 -- results of all the steps
45 whenVerbose opts (ppTracked steps)