]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/Orchestrator/Scrapy/Schedule.hs
[FIX] removing template haskell
[gargantext.git] / src / Gargantext / API / Admin / Orchestrator / Scrapy / Schedule.hs
1 {-|
2 Module : Gargantext.API.Admin.Orchestartor.Scrapy.Schedule
3 Description : Server API Auth Module
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE DataKinds #-}
13 {-# LANGUAGE DeriveGeneric #-}
14 {-# LANGUAGE OverloadedStrings #-}
15 {-# LANGUAGE TypeOperators #-}
16
17 module Gargantext.API.Admin.Orchestrator.Scrapy.Schedule
18 where
19
20 import Control.Lens
21 import Data.Aeson
22 import Data.Text (Text)
23 import GHC.Generics
24 import Servant
25 import Servant.Client
26 import Servant.Job.Utils (jsonOptions)
27 import Web.FormUrlEncoded hiding (parseMaybe)
28 import qualified Data.HashMap.Strict as H
29
30 ------------------------------------------------------------------------
31
32 data Schedule = Schedule
33 { s_project :: !Text
34 , s_spider :: !Text
35 , s_setting :: ![Text]
36 , s_jobid :: !(Maybe Text)
37 , s_version :: !(Maybe Text)
38 , s_extra :: ![(Text,[Text])]
39 }
40 deriving (Generic)
41
42 data ScheduleResponse = ScheduleResponse
43 { r_status :: !Text
44 , r_jobid :: !Text
45 }
46 deriving (Generic)
47
48 instance FromJSON ScheduleResponse where
49 parseJSON = genericParseJSON (jsonOptions "r_")
50
51 instance ToForm Schedule where
52 toForm s =
53 Form . H.fromList $
54 [("project", [s_project s])
55 ,("spider", [s_spider s])
56 ,("setting", s_setting s)
57 ,("jobid", s_jobid s ^.. _Just)
58 ,("_version", s_version s ^.. _Just)
59 ] ++ s_extra s
60
61 type Scrapy =
62 "schedule.json" :> ReqBody '[FormUrlEncoded] Schedule
63 :> Post '[JSON] ScheduleResponse
64
65 scrapyAPI :: Proxy Scrapy
66 scrapyAPI = Proxy
67
68 scrapySchedule :: Schedule -> ClientM ScheduleResponse
69 scrapySchedule = client scrapyAPI