@@ -2,7 +2,6 @@
2{-# LANGUAGE ExtendedDefaultRules #-}
2{-# LANGUAGE ExtendedDefaultRules #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5−{-# LANGUAGE LambdaCase #-}
6{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE TemplateHaskell #-}
6{-# LANGUAGE TemplateHaskell #-}
8{-# LANGUAGE TypeFamilies #-}
7{-# LANGUAGE TypeFamilies #-}
@@ -10,7 +9,7 @@
10{-# OPTIONS_GHC -fno-warn-type-defaults #-}
9{-# OPTIONS_GHC -fno-warn-type-defaults #-}
12-- Module : Network.PagerDuty.REST.Incidents
11-- Module : Network.PagerDuty.REST.Incidents
13−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
12+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
14-- License : This Source Code Form is subject to the terms of
13-- License : This Source Code Form is subject to the terms of
15-- the Mozilla Public License, v. 2.0.
14-- the Mozilla Public License, v. 2.0.
16-- A copy of the MPL can be found in the LICENSE file or
15-- A copy of the MPL can be found in the LICENSE file or
@@ -125,25 +124,35 @@ module Network.PagerDuty.REST.Incidents
126 , aObject
125 , aObject
129 , Incident
127 , Incident
137+ , iLastStatusChangeBy
138+ , iLastStatusChangeOn
139+ , iTriggerSummaryData
140+ , iTriggerDetailsHtmlUrl
132−import Control.Applicative hiding (empty)
143+import Control.Applicative hiding (empty)
133−import Control.Lens hiding (Empty)
144+import Control.Lens
134import Data.Aeson
145import Data.Aeson
135−import Data.ByteString.Conversion (ToByteString (..),
146+import Data.ByteString.Conversion (ToByteString(..), toByteString')
137−import Data.Default.Class
147+import Data.Default
139−import Data.Monoid hiding (All)
148+import Data.Monoid hiding (All)
140−import Data.Text (Text)
149+import Data.Text (Text)
141−import qualified Data.Text.Encoding as Text
150+import qualified Data.Text.Encoding as Text
142import Data.Time
151import Data.Time
143import Network.HTTP.Types
152import Network.HTTP.Types
144−import Network.PagerDuty.Internal.Query
153+import Network.PagerDuty.Query
145−import Network.PagerDuty.Internal.TH
154+import Network.PagerDuty.TH
146−import Network.PagerDuty.Internal.Types
155+import Network.PagerDuty.Types
148default (Path)
157default (Path)
@@ -189,18 +198,18 @@ data IncidentStatus
189 deriving (Eq, Show)
198 deriving (Eq, Show)
191instance ToByteString IncidentStatus where
200instance ToByteString IncidentStatus where
193− ITriggered -> "triggered"
201+ builder ITriggered = "triggered"
194− IAcknowledged -> "acknowledged"
202+ builder IAcknowledged = "acknowledged"
195− IResolved -> "resolved"
203+ builder IResolved = "resolved"
196− IOther t -> builder t
204+ builder (IOther t) = builder t
198instance FromJSON IncidentStatus where
206instance FromJSON IncidentStatus where
199− parseJSON = withText "status" $ pure . \case
207+ parseJSON = withText "status" $ \t ->
200− "triggered" -> ITriggered
209+ "triggered" -> ITriggered
201− "acknowledged" -> IAcknowledged
210+ "acknowledged" -> IAcknowledged
202− "resolved" -> IResolved
211+ "resolved" -> IResolved
203− t -> IOther t
212+ _ -> IOther t
205instance ToJSON IncidentStatus where
214instance ToJSON IncidentStatus where
206 toJSON = String . Text.decodeUtf8 . toByteString'
215 toJSON = String . Text.decodeUtf8 . toByteString'
@@ -213,104 +222,76 @@ data Assignee = Assignee
213deriveRecord ''Assignee
222deriveRecord ''Assignee
215data Incident = Incident
224data Incident = Incident
216− { _iIncidentNumber' :: !Int
225+ { _iIncidentNumber :: !Int
217− , _iStatus' :: !IncidentStatus
226+ , _iStatus :: !IncidentStatus
218− , _iCreatedOn' :: Date
227+ , _iCreatedOn :: Date
219− , _iHtmlUrl' :: Text
228+ , _iHtmlUrl :: Text
220− , _iIncidentKey' :: Maybe IncidentKey
229+ , _iIncidentKey :: Maybe IncidentKey
221− , _iService' :: Object
230+ , _iService :: Object
222− , _iEscalationPolicy' :: Maybe Object
231+ , _iEscalationPolicy :: Maybe Object
223− , _iAssignedTo' :: [Assignee]
232+ , _iAssignedTo :: [Assignee]
224− , _iAcknowledgers' :: [Assignee]
233+ , _iAcknowledgers :: [Assignee]
225− , _iLastStatusChangeBy' :: Maybe Assignee
234+ , _iLastStatusChangeBy :: Maybe Assignee
226− , _iLastStatusChangeOn' :: Maybe Date
235+ , _iLastStatusChangeOn :: Maybe Date
227− , _iTriggerSummaryData' :: Object
236+ , _iTriggerSummaryData :: Object
228− , _iTriggerDetailsHtmlUrl' :: Text
237+ , _iTriggerDetailsHtmlUrl :: Text
229 } deriving (Eq, Show)
238 } deriving (Eq, Show)
231−deriveRecord ''Incident
240+deriveJSON ''Incident
233−class HasIncident a where
234− incident :: Lens' a Incident
236− -- | The number of the incident. This is unique across your account.
242+-- | The number of the incident. This is unique across your account.
237− iIncidentNumber :: Lens' a Int
243+makeLens "_iIncidentNumber" ''Incident
239− -- | The current status of the incident. Valid statuses are:
245+-- | The current status of the incident. Valid statuses are:
240− iStatus :: Lens' a IncidentStatus
246+makeLens "_iStatus" ''Incident
242− -- | The date/time the incident was triggered.
248+-- | The date/time the incident was triggered.
243− iCreatedOn :: Lens' a UTCTime
249+iCreatedOn :: Lens' Incident UTCTime
244−
250+iCreatedOn = lens _iCreatedOn (\i x -> i { _iCreatedOn = x }) . _D
245− -- | The PagerDuty website URL where the incident can be viewed and further
252+-- | The PagerDuty website URL where the incident can be viewed and further
246− -- actions taken. This is not the resource URL.
253+-- actions taken. This is not the resource URL.
247− iHtmlUrl :: Lens' a Text
254+makeLens "_iHtmlUrl" ''Incident
249− -- | The incident's de-duplication key. See the PagerDuty Integration API
256+-- | The incident's de-duplication key. See the PagerDuty Integration API docs
250− -- docs for further details.
257+-- for further details.
251− iIncidentKey :: Lens' a (Maybe IncidentKey)
258+makeLens "_iIncidentKey" ''Incident
253− -- | The PagerDuty service that the incident belongs to. The service will
260+-- | The PagerDuty service that the incident belongs to. The service will
254− -- contain fields of its own.
261+-- contain fields of its own.
255− iService :: Lens' a Object
262+makeLens "_iService" ''Incident
257− -- | The escalation policy that the incident belongs to. The policy will
264+-- | The escalation policy that the incident belongs to. The policy will
258− -- contain fields of its own.
265+-- contain fields of its own.
259− iEscalationPolicy :: Lens' a (Maybe Object)
266+makeLens "_iEscalationPolicy" ''Incident
261− -- | The list of assignments of the incident. An assignment is an object
268+-- | The list of assignments of the incident. An assignment is an object
262− -- containing the assigned user as well as the date/time the incident was
269+-- containing the assigned user as well as the date/time the incident was assigned
263− -- assigned to that user. The user will contain fields of its own.
270+-- to that user. The user will contain fields of its own. This list is empty if
264− -- This list is empty if the status of the incident is resolved.
271+-- the status of the incident is resolved.
265− iAssignedTo :: Lens' a [Assignee]
272+makeLens "_iAssignedTo" ''Incident
267− -- | The list of acknowledgements of the incident. An acknowledgement is an
274+-- | The list of acknowledgements of the incident. An acknowledgement is an
268− -- object containing the acknowleding object (either a user or the
275+-- object containing the acknowleding object (either a user or the integration
269− -- integration API) as well as the date/time the incident was acknowledged.
276+-- API) as well as the date/time the incident was acknowledged. This field is only
270− -- This field is only present if the status of the incident is acknowledged.
277+-- present if the status of the incident is acknowledged. This field is sorted in
271− -- This field is sorted in ascending order by acknowledgement time.
278+-- ascending order by acknowledgement time.
272− iAcknowledgers :: Lens' a [Assignee]
279+makeLens "_iAcknowledgers" ''Incident
274− -- | The user who is responsible for the incident's last status change. If
281+-- | The user who is responsible for the incident's last status change. If the incident is in the acknowledged or resolved status, this will be the user that took the first acknowledged or resolved action. If the incident was automatically resolved (say through the Event Integration API), or if the incident is in the triggered state, this will be null. User fields are the same as in the assignedToUser field above.
275− -- the incident is in the acknowledged or resolved status, this will be the user
282+makeLens "_iLastStatusChangeBy" ''Incident
276− -- that took the first acknowledged or resolved action. If the incident was
283+
277− -- automatically resolved (say through the Event Integration API), or if the
278− -- incident is in the triggered state, this will be null. User fields are the
279− -- same as in the assignedToUser field above.
280− iLastStatusChangeBy :: Lens' a (Maybe Assignee)
282− -- | The date/time the incident's status last changed.
284+-- | The date/time the incident's status last changed.
283− iLastStatusChangeOn :: Lens' a (Maybe UTCTime)
285+iLastStatusChangeOn :: Lens' Incident (Maybe UTCTime)
284−
286+iLastStatusChangeOn =
285− -- | Some condensed information regarding the initial event that triggered
287+ lens _iLastStatusChangeOn (\i x -> i { _iLastStatusChangeOn = x })
286− -- this incident. This data will be a set of key/value pairs that vary depending
288+ . mapping _D
287− -- on what sort of event triggered the incident (email, Event API request,
289+
288− -- etc). For instance, if an email triggered the incident, then the
290+-- | Some condensed information regarding the initial event that triggered this incident. This data will be a set of key/value pairs that vary depending on what sort of event triggered the incident (email, Event API request, etc). For instance, if an email triggered the incident, then the triggerSummaryData will likely contain a subject. There are no guarantees on the full presence of this data for every incident.
289− -- triggerSummaryData will likely contain a subject. There are no guarantees
291+makeLens "_iTriggerSummaryData" ''Incident
290− -- o nthe full presence of this data for every incident.
292+
291− iTriggerSummaryData :: Lens' a Object
293− -- | The PagerDuty website URL where the full details regarding the initial
293+-- | The PagerDuty website URL where the full details regarding the initial event that triggered this incident can be found. (This is not the resource URL.)
294− -- event that triggered this incident can be found. (This is not the resource
294+makeLens "_iTriggerDetailsHtmlUrl" ''Incident
296− iTriggerDetailsHtmlUrl :: Lens' a Text
298− iIncidentNumber = incident.iIncidentNumber'
299− iStatus = incident.iStatus'
300− iCreatedOn = incident.iCreatedOn'._D
301− iHtmlUrl = incident.iHtmlUrl'
302− iIncidentKey = incident.iIncidentKey'
303− iService = incident.iService'
304− iEscalationPolicy = incident.iEscalationPolicy'
305− iAssignedTo = incident.iAssignedTo'
306− iAcknowledgers = incident.iAcknowledgers'
307− iLastStatusChangeBy = incident.iLastStatusChangeBy'
308− iLastStatusChangeOn = incident.iLastStatusChangeOn'.mapping _D
309− iTriggerSummaryData = incident.iTriggerSummaryData'
310− iTriggerDetailsHtmlUrl = incident.iTriggerDetailsHtmlUrl'
312−instance HasIncident Incident where
315data ListIncidents = ListIncidents
296data ListIncidents = ListIncidents
316 { _lsSince' :: Maybe Date
297 { _lsSince' :: Maybe Date
@@ -347,10 +328,13 @@ lsUntil = upd.lsUntil'.mapping _D
347-- | When set, the since and until parameters and defaults are
328-- | When set, the since and until parameters and defaults are
348-- ignored. Use this to get all incidents since the account was created.
329-- ignored. Use this to get all incidents since the account was created.
349lsDateRange :: Lens' (Request ListIncidents s b) Bool
330lsDateRange :: Lens' (Request ListIncidents s b) Bool
350−lsDateRange = upd.lens get_ (flip set_)
331+lsDateRange = upd . lens get' set'
352− get_ = (Just All ==) . view lsDateRange'
333+ get' x
353− set_ x = lsDateRange' .~ listToMaybe [All | x]
334+ | Just All <- _lsDateRange' x = True
337+ set' l x = l { _lsDateRange' = if x then Just All else Nothing }
355-- | Returns only the incidents currently in the passed status(es).
339-- | Returns only the incidents currently in the passed status(es).
356lsStatus :: Lens' (Request ListIncidents s b) (Maybe [IncidentStatus])
340lsStatus :: Lens' (Request ListIncidents s b) (Maybe [IncidentStatus])
@@ -437,12 +421,12 @@ cSince = upd.cSince'.mapping _D
438-- | The end of the date range over which you want to search.
422-- | The end of the date range over which you want to search.
440−-- /Note:/ If you leave off either since or until, a 30 day default range is
424+-- /Note: If you leave off either since or until, a 30 day default range is
441-- applied to your open ended range. Not including the since parameter will set
425-- applied to your open ended range. Not including the since parameter will set
442−-- the date range to until @-30@ days. Likewise, if you leave off until,
426+-- the date range to until - 30 days. Likewise, if you leave off until,
443−-- it is set to since @+30@ days.
427+-- it is set to since + 30 days.
445−-- /Default:/ The last 30 days if you leave off both. The size of the date
429+-- Defaults to the last 30 days if you leave off both. The size of the date
446-- range must be less than 180 days.
430-- range must be less than 180 days.
447cUntil :: Lens' (Request CountIncidents s b) (Maybe UTCTime)
431cUntil :: Lens' (Request CountIncidents s b) (Maybe UTCTime)
448cUntil = upd.cUntil'.mapping _D
432cUntil = upd.cUntil'.mapping _D
@@ -450,10 +434,13 @@ cUntil = upd.cUntil'.mapping _D
450-- | When set, the since and until parameters and defaults are
434-- | When set, the since and until parameters and defaults are
451-- ignored. Use this to get all counts since the account was created.
435-- ignored. Use this to get all counts since the account was created.
452cDateRange :: Lens' (Request CountIncidents s b) Bool
436cDateRange :: Lens' (Request CountIncidents s b) Bool
453−cDateRange = upd.lens get_ (flip set_)
437+cDateRange = upd . lens get' set'
455− get_ = (Just All ==) . view cDateRange'
439+ get' x
456− set_ x = cDateRange' .~ listToMaybe [All | x]
440+ | Just All <- _cDateRange' x = True
443+ set' l x = l { _cDateRange' = if x then Just All else Nothing }
458-- | Only counts the incidents currently in the passed status(es).
445-- | Only counts the incidents currently in the passed status(es).
459cStatus :: Lens' (Request CountIncidents s b) (Maybe [IncidentStatus])
446cStatus :: Lens' (Request CountIncidents s b) (Maybe [IncidentStatus])
@@ -516,7 +503,7 @@ data UpdateIncident = UpdateIncident
516 { _iiId :: IncidentId
503 { _iiId :: IncidentId
517 , _iiStatus :: Maybe UpdateStatus
504 , _iiStatus :: Maybe UpdateStatus
518 , _iiEscalationLevel :: Maybe Int
505 , _iiEscalationLevel :: Maybe Int
519− , _iiEscalationPolicy :: Maybe EscalationPolicyId
506+ , _iiEscalationPolicy :: Maybe PolicyId
520 , _iiAssignedToUser :: Maybe (CSV UserId)
507 , _iiAssignedToUser :: Maybe (CSV UserId)
521 } deriving (Eq, Show)
508 } deriving (Eq, Show)
@@ -567,7 +554,7 @@ updateIncidents r = auth updateIncidentsBasic & query .~ [("requester_id", r)]
568-- | A version of 'updateIncidents' which uses HTTP Basic authentication and
555-- | A version of 'updateIncidents' which uses HTTP Basic authentication and
569-- doesn't require a 'RequesterId'.
556-- doesn't require a 'RequesterId'.
570−updateIncidentsBasic :: Request UpdateIncidents 'Basic [UpdatedIncidents]
557+updateIncidentsBasic :: Request UpdateIncidents Basic [UpdatedIncidents]
571updateIncidentsBasic =
558updateIncidentsBasic =
572 mk UpdateIncidents
559 mk UpdateIncidents
573 { _uiIncidents' = []
560 { _uiIncidents' = []
@@ -608,7 +595,7 @@ acknowledgeIncidentBasic i =
608 empty & meth .~ PUT & path .~ incidents % i % "acknowledge"
595 empty & meth .~ PUT & path .~ incidents % i % "acknowledge"
610data ReassignIncident = ReassignIncident
597data ReassignIncident = ReassignIncident
611− { _riEscalationPolicy' :: Maybe EscalationPolicyId
598+ { _riEscalationPolicy' :: Maybe PolicyId
612 , _riEscalationLevel' :: Maybe Int
599 , _riEscalationLevel' :: Maybe Int
613 , _riAssignedToUser' :: Maybe (CSV UserId)
600 , _riAssignedToUser' :: Maybe (CSV UserId)
614 } deriving (Eq, Show)
601 } deriving (Eq, Show)
@@ -617,7 +604,7 @@ jsonRequest ''ReassignIncident
618-- | The ID of an escalation policy. Delegate the incident to this escalation
605-- | The ID of an escalation policy. Delegate the incident to this escalation
619-- policy.
606-- policy.
620−riEscalationPolicy :: Lens' (Request ReassignIncident s b) (Maybe EscalationPolicyId)
607+riEscalationPolicy :: Lens' (Request ReassignIncident s b) (Maybe PolicyId)
621riEscalationPolicy = upd.riEscalationPolicy'
608riEscalationPolicy = upd.riEscalationPolicy'
623-- | Escalate incident to this level in the escalation policy.
610-- | Escalate incident to this level in the escalation policy.