@@ -1,16 +1,8 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE ExtendedDefaultRules #-}
3−{-# LANGUAGE FlexibleInstances #-}
4−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5−{-# LANGUAGE LambdaCase #-}
6−{-# LANGUAGE OverloadedStrings #-}
1+{-# LANGUAGE OverloadedStrings #-}
7−{-# LANGUAGE TemplateHaskell #-}
2+{-# LANGUAGE TemplateHaskell #-}
8−{-# LANGUAGE TypeFamilies #-}
10−{-# OPTIONS_GHC -fno-warn-type-defaults #-}
12-- Module : Network.PagerDuty.REST.Incidents
4-- Module : Network.PagerDuty.REST.Incidents
13−-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
5+-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
14-- License : This Source Code Form is subject to the terms of
6-- License : This Source Code Form is subject to the terms of
15-- the Mozilla Public License, v. 2.0.
7-- the Mozilla Public License, v. 2.0.
16-- A copy of the MPL can be found in the LICENSE file or
8-- A copy of the MPL can be found in the LICENSE file or
@@ -41,352 +33,18 @@
42-- Incidents and Incident Counts from the last 30 days are returned by
34-- Incidents and Incident Counts from the last 30 days are returned by
43-- default. To change this default date range, see the documentation for the
35-- default. To change this default date range, see the documentation for the
44−-- since, until or dateRange parameters.
36+-- since, until or date_range parameters.
46-- Note: that to create an incident you need to trigger it through the
38-- Note: that to create an incident you need to trigger it through the
47-- "Network.PagerDuty.Integration" API.
39-- "Network.PagerDuty.Integration" API.
49−-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents>
50module Network.PagerDuty.REST.Incidents
40module Network.PagerDuty.REST.Incidents
79− -- * Update Incidents
82− , updateIncidentsBasic
85− -- * Resolve Incident
87− , resolveIncidentBasic
89− -- * Acknowledge Incident
90− , acknowledgeIncident
91− , acknowledgeIncidentBasic
93− -- * Reassign Incident
107− , IncidentStatus (..)
114− , iiEscalationPolicy
132−import Control.Applicative hiding (empty)
133−import Control.Lens hiding (Empty)
135−import Data.ByteString.Conversion (ToByteString (..),
137−import Data.Default.Class
139−import Data.Monoid hiding (All)
140−import Data.Text (Text)
141−import qualified Data.Text.Encoding as Text
143−import Network.HTTP.Types
144−import Network.PagerDuty.Internal.Query
145−import Network.PagerDuty.Internal.TH
146−import Network.PagerDuty.Internal.Types
150incidents :: Path
45incidents :: Path
151incidents = "incidents"
46incidents = "incidents"
162− -- ^ The number of your incident.
164− -- ^ The date/time the incident was triggered.
166− -- ^ The date/time the incident was resolved.
169−instance QueryValues (Sort Field) where
170− queryValues s = case s of
171− Desc f -> ["desc:" <> field f]
172− Asc f -> ["asc:" <> field f]
174− field IncidentNumber = "incidentNumber"
175− field CreatedOn = "createdOn"
176− field ResolvedOn = "resolvedOn"
181−instance QueryValues Range where
182− queryValues All = ["all"]
191−instance ToByteString IncidentStatus where
193− ITriggered -> "triggered"
194− IAcknowledged -> "acknowledged"
195− IResolved -> "resolved"
196− IOther t -> builder t
198−instance FromJSON IncidentStatus where
199− parseJSON = withText "status" $ pure . \case
200− "triggered" -> ITriggered
201− "acknowledged" -> IAcknowledged
202− "resolved" -> IResolved
205−instance ToJSON IncidentStatus where
206− toJSON = String . Text.decodeUtf8 . toByteString'
208−data Assignee = Assignee
210− , _aObject :: Object
211− } deriving (Eq, Show)
213−deriveRecord ''Assignee
215−data Incident = Incident
216− { _iIncidentNumber' :: !Int
217− , _iStatus' :: !IncidentStatus
218− , _iCreatedOn' :: Date
219− , _iHtmlUrl' :: Text
220− , _iIncidentKey' :: Maybe IncidentKey
221− , _iService' :: Object
222− , _iEscalationPolicy' :: Maybe Object
223− , _iAssignedTo' :: [Assignee]
224− , _iAcknowledgers' :: [Assignee]
225− , _iLastStatusChangeBy' :: Maybe Assignee
226− , _iLastStatusChangeOn' :: Maybe Date
227− , _iTriggerSummaryData' :: Object
228− , _iTriggerDetailsHtmlUrl' :: Text
229− } deriving (Eq, Show)
231−deriveRecord ''Incident
233−class HasIncident a where
234− incident :: Lens' a Incident
236− -- | The number of the incident. This is unique across your account.
237− iIncidentNumber :: Lens' a Int
239− -- | The current status of the incident. Valid statuses are:
240− iStatus :: Lens' a IncidentStatus
242− -- | The date/time the incident was triggered.
243− iCreatedOn :: Lens' a UTCTime
245− -- | The PagerDuty website URL where the incident can be viewed and further
246− -- actions taken. This is not the resource URL.
247− iHtmlUrl :: Lens' a Text
249− -- | The incident's de-duplication key. See the PagerDuty Integration API
250− -- docs for further details.
251− iIncidentKey :: Lens' a (Maybe IncidentKey)
253− -- | The PagerDuty service that the incident belongs to. The service will
254− -- contain fields of its own.
255− iService :: Lens' a Object
257− -- | The escalation policy that the incident belongs to. The policy will
258− -- contain fields of its own.
259− iEscalationPolicy :: Lens' a (Maybe Object)
261− -- | 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
263− -- assigned to that user. The user will contain fields of its own.
264− -- This list is empty if the status of the incident is resolved.
265− iAssignedTo :: Lens' a [Assignee]
267− -- | The list of acknowledgements of the incident. An acknowledgement is an
268− -- object containing the acknowleding object (either a user or the
269− -- integration API) as well as the date/time the incident was acknowledged.
270− -- This field is only present if the status of the incident is acknowledged.
271− -- This field is sorted in ascending order by acknowledgement time.
272− iAcknowledgers :: Lens' a [Assignee]
274− -- | The user who is responsible for the incident's last status change. If
275− -- the incident is in the acknowledged or resolved status, this will be the user
276− -- that took the first acknowledged or resolved action. If the incident was
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.
283− iLastStatusChangeOn :: Lens' a (Maybe UTCTime)
285− -- | Some condensed information regarding the initial event that triggered
286− -- this incident. This data will be a set of key/value pairs that vary depending
287− -- on what sort of event triggered the incident (email, Event API request,
288− -- etc). For instance, if an email triggered the incident, then the
289− -- triggerSummaryData will likely contain a subject. There are no guarantees
290− -- o nthe full presence of this data for every incident.
291− iTriggerSummaryData :: Lens' a Object
293− -- | The PagerDuty website URL where the full details regarding the initial
294− -- event that triggered this incident can be found. (This is not the resource
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
315−data ListIncidents = ListIncidents
316− { _lsSince' :: Maybe Date
317− , _lsUntil' :: Maybe Date
318− , _lsDateRange' :: Maybe Range
319− , _lsStatus' :: Maybe (CSV IncidentStatus)
320− , _lsIncidentKey' :: Maybe IncidentKey
321− , _lsService' :: Maybe (CSV ServiceId)
322− , _lsAssignedToUser' :: Maybe (CSV UserId)
323− , _lsTimeZone' :: !TZ
324− , _lsSortBy' :: Maybe (Sort Field)
325− } deriving (Eq, Show)
327−queryRequest ''ListIncidents
329−instance Paginate ListIncidents
331−-- | The start of the date range over which you want to search.
332−lsSince :: Lens' (Request ListIncidents s b) (Maybe UTCTime)
333−lsSince = upd.lsSince'.mapping _D
335−-- | The end of the date range over which you want to search.
337−-- /Note: If you leave off either since or until, a 30 day default range is
338−-- applied to your open ended range. Not including the since parameter will set
339−-- the date range to until - 30 days. Likewise, if you leave off until,
340−-- it is set to since + 30 days.
342−-- Defaults to the last 30 days if you leave off both. The size of the date
343−-- range must be less than 180 days.
344−lsUntil :: Lens' (Request ListIncidents s b) (Maybe UTCTime)
345−lsUntil = upd.lsUntil'.mapping _D
347−-- | When set, the since and until parameters and defaults are
348−-- ignored. Use this to get all incidents since the account was created.
349−lsDateRange :: Lens' (Request ListIncidents s b) Bool
350−lsDateRange = upd.lens get_ (flip set_)
352− get_ = (Just All ==) . view lsDateRange'
353− set_ x = lsDateRange' .~ listToMaybe [All | x]
355−-- | Returns only the incidents currently in the passed status(es).
356−lsStatus :: Lens' (Request ListIncidents s b) (Maybe [IncidentStatus])
357−lsStatus = upd.lsStatus'.mapping _CSV
359−-- | Returns only the incidents with the passed de-duplication key.
361−-- /See:/ "Network.PagerDuty.Integration"
362−lsIncidentKey :: Lens' (Request ListIncidents s b) (Maybe IncidentKey)
363−lsIncidentKey = upd.lsIncidentKey'
365−-- | Returns only the incidents associated with the passed service(s). This
366−-- expects one or more service IDs.
367−lsService :: Lens' (Request ListIncidents s b) (Maybe [ServiceId])
368−lsService = upd.lsService'.mapping _CSV
370−-- | Returns only the incidents currently assigned to the passed user(s). This
371−-- expects one or more user IDs.
373−-- /Note:/ When using the assignedToUser filter, you will only receive
374−-- incidents with statuses of triggered or acknowledged. This is because resolved
375−-- incidents are not assigned to any user.
376−lsAssignedToUser :: Lens' (Request ListIncidents s b) (Maybe [UserId])
377−lsAssignedToUser = upd.lsAssignedToUser'.mapping _CSV
379−-- | Time zone in which dates in the result will be rendered.
382−lsTimeZone :: Lens' (Request ListIncidents s b) TimeZone
383−lsTimeZone = upd.lsTimeZone'._TZ
385−-- | Used to specify both the field you wish to sort the results on, as well as
386−-- the direction (ascending/descending) of the results.
387−lsSortBy :: Lens' (Request ListIncidents s b) (Maybe (Sort Field))
388−lsSortBy = upd.lsSortBy'
390-- | The PagerDuty incidents query API can be used to query current and
48-- | The PagerDuty incidents query API can be used to query current and
391-- historical PagerDuty incidents over a date range, letting you build custom
49-- historical PagerDuty incidents over a date range, letting you build custom
392-- dashboards or incident reports. The API allows for searching for incidents
50-- dashboards or incident reports. The API allows for searching for incidents
@@ -395,95 +53,16 @@ lsSortBy = upd.lsSortBy'
396-- @GET \/incidents@
54-- @GET \/incidents@
398−-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/list>
56+-- See: <http://developer.pagerduty.com/documentation/rest/incidents/list>
399−listIncidents :: Request ListIncidents s [Incident]
57+listIncidents = undefined
402− { _lsSince' = Nothing
403− , _lsUntil' = Nothing
404− , _lsDateRange' = Nothing
405− , _lsStatus' = Nothing
406− , _lsIncidentKey' = Nothing
407− , _lsService' = Nothing
408− , _lsAssignedToUser' = Nothing
409− , _lsTimeZone' = def
410− , _lsSortBy' = Nothing
411− } & path .~ incidents
413-- | Get detailed information about an incident. Accepts either an incident id,
59-- | Get detailed information about an incident. Accepts either an incident id,
414-- or an incident number.
60-- or an incident number.
416-- @GET \/incidents\/\:id@
62-- @GET \/incidents\/\:id@
418−-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/show>
64+-- See: <http://developer.pagerduty.com/documentation/rest/incidents/show>
419−getIncident :: IncidentId -> Request Empty s Incident
65+getIncident = undefined
420−getIncident i = empty & path .~ incidents % i
422−data CountIncidents = CountIncidents
423− { _cSince' :: Maybe Date
424− , _cUntil' :: Maybe Date
425− , _cDateRange' :: Maybe Range
426− , _cStatus' :: Maybe (CSV IncidentStatus)
427− , _cIncidentKey' :: Maybe IncidentKey
428− , _cService' :: Maybe (CSV ServiceId)
429− , _cAssignedToUser' :: Maybe (CSV UserId)
430− } deriving (Eq, Show)
432−queryRequest ''CountIncidents
434−-- | The start of the date range over which you want to search.
435−cSince :: Lens' (Request CountIncidents s b) (Maybe UTCTime)
436−cSince = upd.cSince'.mapping _D
438−-- | 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
441−-- 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,
443−-- it is set to since @+30@ days.
445−-- /Default:/ The last 30 days if you leave off both. The size of the date
446−-- range must be less than 180 days.
447−cUntil :: Lens' (Request CountIncidents s b) (Maybe UTCTime)
448−cUntil = upd.cUntil'.mapping _D
450−-- | When set, the since and until parameters and defaults are
451−-- ignored. Use this to get all counts since the account was created.
452−cDateRange :: Lens' (Request CountIncidents s b) Bool
453−cDateRange = upd.lens get_ (flip set_)
455− get_ = (Just All ==) . view cDateRange'
456− set_ x = cDateRange' .~ listToMaybe [All | x]
458−-- | Only counts the incidents currently in the passed status(es).
459−cStatus :: Lens' (Request CountIncidents s b) (Maybe [IncidentStatus])
460−cStatus = upd.cStatus'.mapping _CSV
462−-- | Returns only the incidents with the passed de-duplication key.
464−-- /See:/ "Network.PagerDuty.Integration"
465−cIncidentKey :: Lens' (Request CountIncidents s b) (Maybe IncidentKey)
466−cIncidentKey = upd.cIncidentKey'
468−-- | Only counts the incidents associated with the passed service(s).
469−-- This is expecting one or more service IDs.
470−cService :: Lens' (Request CountIncidents s b) (Maybe [ServiceId]) -- list1
471−cService = upd.cService'.mapping _CSV
473−-- | Only counts the incidents currently assigned to the passed user(s).
474−-- This is expecting one or more user IDs.
476−-- /Note:/ When using the assigned_to_user filter, you will only count
477−-- incidents with statuses of triggered or acknowledged. This is because resolved
478−-- incidents are not assigned to any user.
479−cAssignedToUser :: Lens' (Request CountIncidents s b) (Maybe [UserId]) -- list1
480−cAssignedToUser = upd.cAssignedToUser'.mapping _CSV
482−newtype Count = Count Int
483− deriving (Eq, Ord, Show, Bounded, Enum, Num, Integral, Real)
485−instance FromJSON Count where
486− parseJSON = withObject "count" $ \o -> Count <$> o .: "total"
488-- | Use this query if you are simply looking for the count of incidents that
67-- | Use this query if you are simply looking for the count of incidents that
489-- match a given query. This should be used if you don't need access to the
68-- match a given query. This should be used if you don't need access to the
@@ -491,161 +70,33 @@ instance FromJSON Count where
492-- @GET \/incidents\/count@
71-- @GET \/incidents\/count@
494−-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/count>
73+-- See: <http://developer.pagerduty.com/documentation/rest/incidents/count>
495−countIncidents :: Request CountIncidents s Count
74+countIncidents = undefined
498− { _cSince' = Nothing
499− , _cUntil' = Nothing
500− , _cDateRange' = Nothing
501− , _cStatus' = Nothing
502− , _cIncidentKey' = Nothing
503− , _cService' = Nothing
504− , _cAssignedToUser' = Nothing
505− } & path .~ incidents % "count"
513−deriveNullary ''UpdateStatus
515−data UpdateIncident = UpdateIncident
516− { _iiId :: IncidentId
517− , _iiStatus :: Maybe UpdateStatus
518− , _iiEscalationLevel :: Maybe Int
519− , _iiEscalationPolicy :: Maybe EscalationPolicyId
520− , _iiAssignedToUser :: Maybe (CSV UserId)
521− } deriving (Eq, Show)
523−deriveJSON ''UpdateIncident
525−-- | The id of the incident to update.
526−makeLens "_iiId" ''UpdateIncident
528−-- | The new status of the incident.
529−makeLens "_iiStatus" ''UpdateIncident
531−-- | Escalate incident to this level in the escalation policy.
532−makeLens "_iiEscalationLevel" ''UpdateIncident
534−-- | Delegate this incident to the specified escalation policy id.
535−-- This restarts the incident's escalation following the new policy.
536−makeLens "_iiEscalationPolicy" ''UpdateIncident
538−-- | List of user IDs to assign this incident to.
539−makeLens "_iiAssignedToUser" ''UpdateIncident
541−data UpdatedIncidents = UpdatedIncidents
542− { _uiId :: IncidentId
543− , _uiStatus :: IncidentStatus
544− , _uiIncidentNumber :: !Int
546− , _uiError :: Maybe Object
547− } deriving (Eq, Show)
549−deriveRecord ''UpdatedIncidents
551−data UpdateIncidents = UpdateIncidents
552− { _uiIncidents' :: [UpdateIncident]
553− } deriving (Eq, Show)
555−jsonRequest ''UpdateIncidents
557−uiIncidents :: Lens' (Request UpdateIncidents s b) [UpdateIncident]
558−uiIncidents = upd.uiIncidents'
560-- | Acknowledge, resolve, escalate or reassign one or more incidents.
76-- | Acknowledge, resolve, escalate or reassign one or more incidents.
562-- @PUT \/incidents@
78-- @PUT \/incidents@
564−-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/update>
80+-- See: <http://developer.pagerduty.com/documentation/rest/incidents/update>
565−updateIncidents :: RequesterId -> Request UpdateIncidents s [UpdatedIncidents]
81+updateIncidents = undefined
566−updateIncidents r = auth updateIncidentsBasic & query .~ [("requester_id", r)]
568−-- | A version of 'updateIncidents' which uses HTTP Basic authentication and
569−-- doesn't require a 'RequesterId'.
570−updateIncidentsBasic :: Request UpdateIncidents 'Basic [UpdatedIncidents]
571−updateIncidentsBasic =
573− { _uiIncidents' = []
577-- | Resolve an incident.
83-- | Resolve an incident.
579-- @PUT \/incidents\/\:id\/resolve@
85-- @PUT \/incidents\/\:id\/resolve@
581−-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/resolve>
87+-- See: <http://developer.pagerduty.com/documentation/rest/incidents/resolve>
582−resolveIncident :: IncidentId
88+resolveIncident = undefined
584− -> Request Empty s Empty
585−resolveIncident i r =
586− auth (resolveIncidentBasic i) & query .~ [("requester_id", r)]
588−-- | A version of 'resolveIncident' which uses HTTP Basic authentication and
589−-- doesn't require a 'RequesterId'.
590−resolveIncidentBasic :: IncidentId -> Request Empty s Empty
591−resolveIncidentBasic i = empty & meth .~ PUT & path .~ incidents % i % "resolve"
593-- | Acknowledge an incident.
90-- | Acknowledge an incident.
595-- @PUT \/incidents\/\:id\/acknowledge@
92-- @PUT \/incidents\/\:id\/acknowledge@
597−-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/acknowledge>
94+-- See: <http://developer.pagerduty.com/documentation/rest/incidents/acknowledge>
598−acknowledgeIncident :: IncidentId
95+acknowledgeIncident = undefined
600− -> Request Empty s Empty
601−acknowledgeIncident i r =
602− auth (acknowledgeIncidentBasic i) & query .~ [("requester_id", r)]
604−-- | A version of 'acknowledgeIncident' which uses HTTP Basic authentication and
605−-- doesn't require a 'RequesterId'.
606−acknowledgeIncidentBasic :: IncidentId -> Request Empty s Empty
607−acknowledgeIncidentBasic i =
608− empty & meth .~ PUT & path .~ incidents % i % "acknowledge"
610−data ReassignIncident = ReassignIncident
611− { _riEscalationPolicy' :: Maybe EscalationPolicyId
612− , _riEscalationLevel' :: Maybe Int
613− , _riAssignedToUser' :: Maybe (CSV UserId)
614− } deriving (Eq, Show)
616−jsonRequest ''ReassignIncident
618−-- | The ID of an escalation policy. Delegate the incident to this escalation
620−riEscalationPolicy :: Lens' (Request ReassignIncident s b) (Maybe EscalationPolicyId)
621−riEscalationPolicy = upd.riEscalationPolicy'
623−-- | Escalate incident to this level in the escalation policy.
624−riEscalationLevel :: Lens' (Request ReassignIncident s b) (Maybe Int)
625−riEscalationLevel = upd.riEscalationLevel'
627−-- | Comma separated list of user IDs to assign this incident to.
628−riAssignedToUser :: Lens' (Request ReassignIncident s b) (Maybe [UserId])
629−riAssignedToUser = upd.riAssignedToUser'.mapping _CSV
631-- | Reassign an incident.
97-- | Reassign an incident.
633-- @PUT \/incidents\/\:id\/reassign@
99-- @PUT \/incidents\/\:id\/reassign@
635−-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/reassign>
101+-- See: <http://developer.pagerduty.com/documentation/rest/incidents/reassign>
636−reassignIncident :: IncidentId
102+reassignIncident = undefined
638− -> Request ReassignIncident s Empty
639−reassignIncident i r =
640− auth (reassignIncidentBasic i) & query .~ [("requester_id", r)]
642−-- | A version of 'reassignIncident' which uses HTTP Basic authentication and
643−-- doesn't require a 'RequesterId'.
644−reassignIncidentBasic :: IncidentId -> Request ReassignIncident s Empty
645−reassignIncidentBasic i =
647− { _riEscalationPolicy' = Nothing
648− , _riEscalationLevel' = Nothing
649− , _riAssignedToUser' = Nothing
651− & path .~ incidents % i % "reassign"