1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE OverloadedStrings #-}
4 {-# LANGUAGE TypeOperators #-}
5 module Gargantext.API.Orchestrator.Scrapy.Schedule where
9 import qualified Data.HashMap.Strict as H
10 import Data.Text (Text)
13 import Servant.Job.Utils (jsonOptions)
15 import Web.FormUrlEncoded hiding (parseMaybe)
17 data Schedule = Schedule
20 , s_setting :: ![Text]
21 , s_jobid :: !(Maybe Text)
22 , s_version :: !(Maybe Text)
23 , s_extra :: ![(Text,[Text])]
27 data ScheduleResponse = ScheduleResponse
33 instance FromJSON ScheduleResponse where
34 parseJSON = genericParseJSON (jsonOptions "r_")
36 instance ToForm Schedule where
39 [("project", [s_project s])
40 ,("spider", [s_spider s])
41 ,("setting", s_setting s)
42 ,("jobid", s_jobid s ^.. _Just)
43 ,("_version", s_version s ^.. _Just)
47 "schedule.json" :> ReqBody '[FormUrlEncoded] Schedule
48 :> Post '[JSON] ScheduleResponse
50 scrapyAPI :: Proxy Scrapy
53 scrapySchedule :: Schedule -> ClientM ScheduleResponse
54 scrapySchedule = client scrapyAPI