@@ -1,5 +1,7 @@
1+{-# LANGUAGE DataKinds #-}
12{-# LANGUAGE OverloadedStrings #-}
23{-# LANGUAGE TemplateHaskell #-}
4+{-# LANGUAGE TypeFamilies #-}
35
46-- Module : Network.PagerDuty.REST.MaintenanceWindows
57-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
@@ -15,8 +17,271 @@
1517-- during which no incidents will be created.
1618module Network.PagerDuty.REST.MaintenanceWindows
1719 (
20+ -- * List Windows
21+ ListWindows
22+ , listWindows
23+ , lwQuery
24+ , lwServiceIds
25+ , lwFilter
1826
27+ , ListwindowsResponse
28+ , lwMatenanceWindows
29+ , lwCounts
30+
31+ -- * Create Window
32+ , CreateWindow
33+ , createWindow
34+ , createWindowBasic
35+ , cwStartTime
36+ , cwEndTime
37+ , cwDescription
38+ , cwServiceIds
39+
40+ -- * Get Window
41+ , getWindow
42+
43+ -- * Update Window
44+ , UpdateWindow
45+ , updateWindow
46+ , uwStartTime
47+ , uwEndTime
48+ , uwDescription
49+ , uwServiceIds
50+
51+ -- * Delete Window
52+ , deleteWindow
53+
54+ -- * Types
55+ , ServiceInfo
56+ , siId
57+ , siName
58+ , siUrl
59+
60+ , Counts
61+ , cOngoing
62+ , cFuture
63+ , cPast
64+ , cAll
65+
66+ , MaintenanceWindow
67+ , mwSequenceNumber
68+ , mwStartTime
69+ , mwEndTime
70+ , mwDescription
71+ , mwCreatedBy
72+ , mwServices
1973 ) where
2074
21−maintenance :: Path
22−maintenance = "maintenance_windows"
75+import Control.Lens
76+import Data.Monoid
77+import Data.Text (Text)
78+import Data.Time
79+import Network.HTTP.Types
80+import Network.PagerDuty.REST.Users (User)
81+import Network.PagerDuty.TH
82+import Network.PagerDuty.Types
83+
84+windows :: Path
85+windows = "maintenance_windows"
86+
87+data ServiceInfo = ServiceInfo
88+ { _siId :: ServiceId
89+ , _siName :: Text
90+ , _siUrl :: Text
91+ } deriving (Eq, Show)
92+
93+deriveRecord ''ServiceInfo
94+
95+data MaintenanceWindow = MaintenanceWindow
96+ { _mwSequenceNumber :: !Int
97+ , _mwStartTime :: Date
98+ , _mwEndTime :: Date
99+ , _mwDescription :: Maybe Text
100+ , _mwCreatedBy :: User
101+ , _mwServices :: [ServiceInfo]
102+ } deriving (Eq, Show)
103+
104+deriveRecord ''MaintenanceWindow
105+
106+data ListWindows = ListWindows
107+ { _lwQuery' :: Maybe Text
108+ , _lwServiceIds' :: List ServiceId
109+ , _lwFilter' :: Maybe Text
110+ }
111+
112+deriveQuery ''ListWindows
113+
114+-- | Filters the results, showing only the maintenance windows whose
115+-- descriptions contain the query.
116+lwQuery :: Lens' (Request ListWindows s b) (Maybe Text)
117+lwQuery = upd.lwQuery'
118+
119+-- | An array of service IDs, specifying services whose maintenance
120+-- windows shall be returned.
121+lwServiceIds :: Lens' (Request ListWindows s b) [ServiceId]
122+lwServiceIds = upd.lwServiceIds'._L
123+
124+-- | Only return maintenance windows that are of this type. Possible values
125+-- are past, future, ongoing. If this parameter is omitted, all maintenance
126+-- windows will be returned.
127+lwFilter :: Lens' (Request ListWindows s b) (Maybe Text)
128+lwFilter = upd.lwFilter'
129+
130+data Counts = Counts
131+ { _cOngoing :: !Int
132+ , _cFuture :: !Int
133+ , _cPast :: !Int
134+ , _cAll :: !Int
135+ } deriving (Eq, Show)
136+
137+deriveRecord ''Counts
138+
139+data ListWindowsResponse = ListWindowsResponse
140+ { _lwMaintenanceWindows :: [MaintenanceWindow]
141+ , _lwCounts :: Counts
142+ } deriving (Eq, Show)
143+
144+deriveRecord ''ListWindowsResponse
145+
146+-- | List existing maintenance windows, optionally filtered by service,
147+-- or whether they are from the past, present or future.
148+--
149+-- @GET maintenance_windows@
150+--
151+-- See: <http://developer.pagerduty.com/documentation/rest/maintenance_windows/list>
152+listWindows :: Request ListWindows s ListWindowsResponse
153+listWindows =
154+ mk ListWindows
155+ { _lwQuery' = Nothing
156+ , _lwServiceIds' = mempty
157+ , _lwFilter' = Nothing
158+ } & path .~ windows
159+
160+data CreateWindow' = CreateWindow'
161+ { _cwStartTime' :: Date
162+ , _cwEndTime' :: Date
163+ , _cwDescription' :: Maybe Text
164+ , _cwServiceIds' :: [ServiceId] -- ^ List1
165+ } deriving (Eq, Show)
166+
167+deriveRecord ''CreateWindow'
168+
169+data CreateWindow = CreateWindow
170+ { _cwRequesterId' :: Maybe RequesterId
171+ , _cwMaintenanceWindow' :: CreateWindow'
172+ } deriving (Eq, Show)
173+
174+deriveBody ''CreateWindow
175+
176+-- | This maintenance window's start time. This is when the services will stop
177+-- creating incidents. If this date is in the past, it will be updated to be the
178+-- current time.
179+cwStartTime :: Lens' (Request CreateWindow s b) UTCTime
180+cwStartTime = upd.cwMaintenanceWindow'.cwStartTime'._D
181+
182+-- | This maintenance window's end time. This is when the services will start
183+-- creating incidents again. This date must be in the future and after the
184+-- start_time.
185+cwEndTime :: Lens' (Request CreateWindow s b) UTCTime
186+cwEndTime = upd.cwMaintenanceWindow'.cwEndTime'._D
187+
188+-- | A description for this maintenance window.
189+cwDescription :: Lens' (Request CreateWindow s b) (Maybe Text)
190+cwDescription = upd.cwMaintenanceWindow'.cwDescription'
191+
192+-- | The ids of the services that are affected by this maintenance window.
193+cwServiceIds :: Lens' (Request CreateWindow s b) [ServiceId]
194+cwServiceIds = upd.cwMaintenanceWindow'.cwServiceIds'
195+
196+-- | Create a new maintenance window for the specified services. No new
197+-- incidents will be created for a service that is currently in maintenance.
198+--
199+-- @POST maintenance_windows@
200+--
201+-- See: <http://developer.pagerduty.com/documentation/rest/maintenance_windows/create>
202+createWindow :: RequesterId
203+ -> UTCTime -- ^ 'cwStartTime'
204+ -> UTCTime -- ^ 'cwEndTime'
205+ -> [ServiceId] -- ^ 'cwServiceIds'
206+ -> Request CreateWindow s MaintenanceWindow
207+createWindow r s e xs =
208+ auth (createWindowBasic s e xs) & upd.cwRequesterId' ?~ r
209+
210+-- | A version of 'createWindow' which uses HTTP Basic authentication and
211+-- doesn't require a 'RequesterId'.
212+createWindowBasic :: UTCTime -- ^ 'cwStartTime'
213+ -> UTCTime -- ^ 'cwEndTime'
214+ -> [ServiceId] -- ^ 'cwServiceIds'
215+ -> Request CreateWindow Basic MaintenanceWindow
216+createWindowBasic s e xs =
217+ mk CreateWindow
218+ { _cwRequesterId' = Nothing
219+ , _cwMaintenanceWindow' = CreateWindow'
220+ { _cwStartTime' = D s
221+ , _cwEndTime' = D e
222+ , _cwDescription' = Nothing
223+ , _cwServiceIds' = xs
224+ }
225+ } & meth .~ POST
226+ & path .~ windows
227+
228+-- | Get details about an existing maintenance window.
229+--
230+-- @GET maintenance_windows/:id@
231+--
232+-- See: <http://developer.pagerduty.com/documentation/rest/maintenance_windows/show>
233+getWindow :: WindowId -> Request Empty s MaintenanceWindow
234+getWindow w = empty & path .~ windows % w
235+
236+data UpdateWindow = UpdateWindow
237+ { _uwStartTime' :: Maybe Date
238+ , _uwEndTime' :: Maybe Date
239+ , _uwDescription' :: Maybe Text
240+ , _uwServiceIds' :: Maybe [ServiceId]
241+ } deriving (Eq, Show)
242+
243+deriveBody ''UpdateWindow
244+
245+-- | The maintenance window's start time. Can only be updated on future
246+-- maintenance windows. If the start_time is set to a date in the past, it will be
247+-- updated to the current date.
248+uwStartTime :: Lens' (Request UpdateWindow s b) (Maybe Date)
249+uwStartTime = upd.uwStartTime'
250+
251+-- | The maintenance window's end time. Can only be updated on ongoing and
252+-- future maintenance windows, and cannot be set to a value before start_time.
253+uwEndTime :: Lens' (Request UpdateWindow s b) (Maybe Date)
254+uwEndTime = upd.uwEndTime'
255+
256+-- | Description for this maintenance window. Can only be updated on ongoing
257+-- and future maintenance windows.
258+uwDescription :: Lens' (Request UpdateWindow s b) (Maybe Text)
259+uwDescription = upd.uwDescription'
260+
261+-- | Services that are affected by this maintenance window. Can only be updated
262+-- on future maintenance windows.
263+uwServiceIds :: Lens' (Request UpdateWindow s b) (Maybe [ServiceId])
264+uwServiceIds = upd.uwServiceIds'
265+
266+-- | Update an existing maintenance window.
267+--
268+-- @PUT maintenance_windows/:id@
269+--
270+-- See: <http://developer.pagerduty.com/documentation/rest/maintenance_windows/update>
271+updateWindow :: WindowId -> Request UpdateWindow s MaintenanceWindow
272+updateWindow w =
273+ mk UpdateWindow
274+ { _uwStartTime' = Nothing
275+ , _uwEndTime' = Nothing
276+ , _uwDescription' = Nothing
277+ , _uwServiceIds' = Nothing
278+ } & meth .~ PUT
279+ & path .~ windows % w
280+
281+-- | Cancel or delete an existing maintenance window.
282+--
283+-- @DELETE maintenance_windows/:id@
284+--
285+-- See: <http://developer.pagerduty.com/documentation/rest/maintenance_windows/delete>
286+deleteWindow :: WindowId -> Request Empty s Empty
287+deleteWindow w = empty & meth .~ DELETE & path .~ windows % w