]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-client/Script.hs
[BIN] gargantext-client config for stack
[gargantext.git] / bin / gargantext-client / Script.hs
1 module Script (script) where
2
3 import Auth
4 import Control.Monad.IO.Class
5 import Core
6 import Gargantext.API.Client
7 import Options
8 import Prelude
9 import Servant.Client
10 import Tracking
11
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.
16 --
17 -- Don't forget to pass @--user@ and @--pass@ if you're using 'withAuthToken'.
18 script :: ClientOpts -> ClientM ()
19 script opts = do
20 -- we start by asking the backend for its version
21 ver <- getBackendVersion
22 liftIO . putStrLn $ "Backend version: " ++ show ver
23
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
29 steps <-
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"]
34 [ ("get roots", do
35 roots <- getRoots tok
36 liftIO . putStrLn $ "roots: " ++ show roots
37 )
38 , ("get user node detail", do
39 userNodeDetail <- getNode tok userNode
40 liftIO . putStrLn $ "user node details: " ++ show userNodeDetail
41 )
42 ]
43 -- we pretty print the values we sampled for all metrics and the
44 -- results of all the steps
45 whenVerbose opts (ppTracked steps)