@@ -0,0 +1,651 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE ExtendedDefaultRules #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5+{-# LANGUAGE LambdaCase #-}
6+{-# LANGUAGE OverloadedStrings #-}
7+{-# LANGUAGE TemplateHaskell #-}
8+{-# LANGUAGE TypeFamilies #-}
9+
10+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
11+
12+-- Module : Network.PagerDuty.REST.Incidents
13+-- Copyright : (c) 2013-2015 Brendan Hay <brendan.g.hay@gmail.com>
14+-- License : This Source Code Form is subject to the terms of
15+-- the Mozilla Public License, v. 2.0.
16+-- A copy of the MPL can be found in the LICENSE file or
17+-- you can obtain it at http://mozilla.org/MPL/2.0/.
18+-- Maintainer : Brendan Hay <brendan.g.hay@gmail.com>
19+-- Stability : experimental
20+-- Portability : non-portable (GHC extensions)
21+
22+-- | PagerDuty receives updates (called events) from monitoring systems through
23+-- services (like Nagios, email or generic API calls). Upon receiving an event,
24+-- active services will create a new incident and begin escalating it as
25+-- defined by the service's escalation policy. Events can be de-duplicated into
26+-- existing incidents based on service de-duplication rules to prevent you from
27+-- being overwhelmed by event storms.
28+--
29+-- An incident can be open, acknowledged or resolved. Whenever an incident is
30+-- created, it is assigned to a user (according to the escalation process, as
31+-- described by escalation rules and schedules). The assigned user has a chance
32+-- to either acknowledge that he is working on it, or to resolve it.
33+--
34+-- Resolving an incident closes it, whereas acknowledging it halts the
35+-- escalation process. If the incident is not resolved by the service's
36+-- incident ack timeout it continues up the escalation chain.
37+--
38+-- When an incident is triggered or when it is escalated it creates alerts
39+-- (also known as notifications). Alerts are messages containing the details of
40+-- the incident, and can be sent through SMS, email and phone calls.
41+--
42+-- 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
44+-- since, until or dateRange parameters.
45+--
46+-- Note: that to create an incident you need to trigger it through the
47+-- "Network.PagerDuty.Integration" API.
48+--
49+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents>
50+module Network.PagerDuty.REST.Incidents
51+ (
52+ -- * List Incidents
53+ ListIncidents
54+ , listIncidents
55+ , lsSince
56+ , lsUntil
57+ , lsDateRange
58+ , lsStatus
59+ , lsIncidentKey
60+ , lsService
61+ , lsAssignedToUser
62+ , lsTimeZone
63+ , lsSortBy
64+
65+ -- * Count Incidents
66+ , CountIncidents
67+ , countIncidents
68+ , cSince
69+ , cUntil
70+ , cDateRange
71+ , cStatus
72+ , cIncidentKey
73+ , cService
74+ , cAssignedToUser
75+
76+ -- * Get Incident
77+ , getIncident
78+
79+ -- * Update Incidents
80+ , UpdateIncidents
81+ , updateIncidents
82+ , updateIncidentsBasic
83+ , uiIncidents
84+
85+ -- * Resolve Incident
86+ , resolveIncident
87+ , resolveIncidentBasic
88+
89+ -- * Acknowledge Incident
90+ , acknowledgeIncident
91+ , acknowledgeIncidentBasic
92+
93+ -- * Reassign Incident
94+ , ReassignIncident
95+ , reassignIncident
96+ , riEscalationPolicy
97+ , riEscalationLevel
98+ , riAssignedToUser
99+
100+ -- * Types
101+ , Sort (..)
102+ , _Desc
103+ , _Asc
104+
105+ , Field (..)
106+
107+ , IncidentStatus (..)
108+ , UpdateStatus (..)
109+
110+ , UpdateIncident
111+ , iiId
112+ , iiStatus
113+ , iiEscalationLevel
114+ , iiEscalationPolicy
115+ , iiAssignedToUser
116+
117+ , UpdatedIncidents
118+ , uiId
119+ , uiStatus
120+ , uiIncidentNumber
121+ , uiUrl
122+ , uiError
123+
124+ , Assignee
125+ , aAt
126+ , aObject
127+
128+ , HasIncident (..)
129+ , Incident
130+ ) where
131+
132+import Control.Applicative hiding (empty)
133+import Control.Lens hiding (Empty)
134+import Data.Aeson
135+import Data.ByteString.Conversion (ToByteString (..),
136+ toByteString')
137+import Data.Default.Class
138+import Data.Maybe
139+import Data.Monoid hiding (All)
140+import Data.Text (Text)
141+import qualified Data.Text.Encoding as Text
142+import Data.Time
143+import Network.HTTP.Types
144+import Network.PagerDuty.Internal.Query
145+import Network.PagerDuty.Internal.TH
146+import Network.PagerDuty.Internal.Types
147+
148+default (Path)
149+
150+incidents :: Path
151+incidents = "incidents"
152+
153+data Sort a
154+ = Desc a
155+ | Asc a
156+ deriving (Eq, Show)
157+
158+makePrisms ''Sort
159+
160+data Field
161+ = IncidentNumber
162+ -- ^ The number of your incident.
163+ | CreatedOn
164+ -- ^ The date/time the incident was triggered.
165+ | ResolvedOn
166+ -- ^ The date/time the incident was resolved.
167+ deriving (Eq, Show)
168+
169+instance QueryValues (Sort Field) where
170+ queryValues s = case s of
171+ Desc f -> ["desc:" <> field f]
172+ Asc f -> ["asc:" <> field f]
173+ where
174+ field IncidentNumber = "incidentNumber"
175+ field CreatedOn = "createdOn"
176+ field ResolvedOn = "resolvedOn"
177+
178+data Range = All
179+ deriving (Eq, Show)
180+
181+instance QueryValues Range where
182+ queryValues All = ["all"]
183+
184+data IncidentStatus
185+ = ITriggered
186+ | IAcknowledged
187+ | IResolved
188+ | IOther Text
189+ deriving (Eq, Show)
190+
191+instance ToByteString IncidentStatus where
192+ builder = \case
193+ ITriggered -> "triggered"
194+ IAcknowledged -> "acknowledged"
195+ IResolved -> "resolved"
196+ IOther t -> builder t
197+
198+instance FromJSON IncidentStatus where
199+ parseJSON = withText "status" $ pure . \case
200+ "triggered" -> ITriggered
201+ "acknowledged" -> IAcknowledged
202+ "resolved" -> IResolved
203+ t -> IOther t
204+
205+instance ToJSON IncidentStatus where
206+ toJSON = String . Text.decodeUtf8 . toByteString'
207+
208+data Assignee = Assignee
209+ { _aAt :: Date
210+ , _aObject :: Object
211+ } deriving (Eq, Show)
212+
213+deriveRecord ''Assignee
214+
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)
230+
231+deriveRecord ''Incident
232+
233+class HasIncident a where
234+ incident :: Lens' a Incident
235+
236+ -- | The number of the incident. This is unique across your account.
237+ iIncidentNumber :: Lens' a Int
238+
239+ -- | The current status of the incident. Valid statuses are:
240+ iStatus :: Lens' a IncidentStatus
241+
242+ -- | The date/time the incident was triggered.
243+ iCreatedOn :: Lens' a UTCTime
244+
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
248+
249+ -- | The incident's de-duplication key. See the PagerDuty Integration API
250+ -- docs for further details.
251+ iIncidentKey :: Lens' a (Maybe IncidentKey)
252+
253+ -- | The PagerDuty service that the incident belongs to. The service will
254+ -- contain fields of its own.
255+ iService :: Lens' a Object
256+
257+ -- | The escalation policy that the incident belongs to. The policy will
258+ -- contain fields of its own.
259+ iEscalationPolicy :: Lens' a (Maybe Object)
260+
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]
266+
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]
273+
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)
281+
282+ -- | The date/time the incident's status last changed.
283+ iLastStatusChangeOn :: Lens' a (Maybe UTCTime)
284+
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
292+
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
295+ -- URL.)
296+ iTriggerDetailsHtmlUrl :: Lens' a Text
297+
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'
311+
312+instance HasIncident Incident where
313+ incident = id
314+
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)
326+
327+queryRequest ''ListIncidents
328+
329+instance Paginate ListIncidents
330+
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
334+
335+-- | The end of the date range over which you want to search.
336+--
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.
341+--
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
346+
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_)
351+ where
352+ get_ = (Just All ==) . view lsDateRange'
353+ set_ x = lsDateRange' .~ listToMaybe [All | x]
354+
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
358+
359+-- | Returns only the incidents with the passed de-duplication key.
360+--
361+-- /See:/ "Network.PagerDuty.Integration"
362+lsIncidentKey :: Lens' (Request ListIncidents s b) (Maybe IncidentKey)
363+lsIncidentKey = upd.lsIncidentKey'
364+
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
369+
370+-- | Returns only the incidents currently assigned to the passed user(s). This
371+-- expects one or more user IDs.
372+--
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
378+
379+-- | Time zone in which dates in the result will be rendered.
380+--
381+-- /Default:/ 'UTC'.
382+lsTimeZone :: Lens' (Request ListIncidents s b) TimeZone
383+lsTimeZone = upd.lsTimeZone'._TZ
384+
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'
389+
390+-- | The PagerDuty incidents query API can be used to query current and
391+-- historical PagerDuty incidents over a date range, letting you build custom
392+-- dashboards or incident reports. The API allows for searching for incidents
393+-- with multiple filters or query parameters, various sorts, and also supports
394+-- the pagination of results.
395+--
396+-- @GET \/incidents@
397+--
398+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/list>
399+listIncidents :: Request ListIncidents s [Incident]
400+listIncidents =
401+ mk ListIncidents
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
412+
413+-- | Get detailed information about an incident. Accepts either an incident id,
414+-- or an incident number.
415+--
416+-- @GET \/incidents\/\:id@
417+--
418+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/show>
419+getIncident :: IncidentId -> Request Empty s Incident
420+getIncident i = empty & path .~ incidents % i
421+
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)
431+
432+queryRequest ''CountIncidents
433+
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
437+
438+-- | The end of the date range over which you want to search.
439+--
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.
444+--
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
449+
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_)
454+ where
455+ get_ = (Just All ==) . view cDateRange'
456+ set_ x = cDateRange' .~ listToMaybe [All | x]
457+
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
461+
462+-- | Returns only the incidents with the passed de-duplication key.
463+--
464+-- /See:/ "Network.PagerDuty.Integration"
465+cIncidentKey :: Lens' (Request CountIncidents s b) (Maybe IncidentKey)
466+cIncidentKey = upd.cIncidentKey'
467+
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
472+
473+-- | Only counts the incidents currently assigned to the passed user(s).
474+-- This is expecting one or more user IDs.
475+--
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
481+
482+newtype Count = Count Int
483+ deriving (Eq, Ord, Show, Bounded, Enum, Num, Integral, Real)
484+
485+instance FromJSON Count where
486+ parseJSON = withObject "count" $ \o -> Count <$> o .: "total"
487+
488+-- | 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
490+-- actual incident details.
491+--
492+-- @GET \/incidents\/count@
493+--
494+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/count>
495+countIncidents :: Request CountIncidents s Count
496+countIncidents =
497+ mk CountIncidents
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"
506+
507+
508+data UpdateStatus
509+ = UAcknowledged
510+ | UResolved
511+ deriving (Eq, Show)
512+
513+deriveNullary ''UpdateStatus
514+
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)
522+
523+deriveJSON ''UpdateIncident
524+
525+-- | The id of the incident to update.
526+makeLens "_iiId" ''UpdateIncident
527+
528+-- | The new status of the incident.
529+makeLens "_iiStatus" ''UpdateIncident
530+
531+-- | Escalate incident to this level in the escalation policy.
532+makeLens "_iiEscalationLevel" ''UpdateIncident
533+
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
537+
538+-- | List of user IDs to assign this incident to.
539+makeLens "_iiAssignedToUser" ''UpdateIncident
540+
541+data UpdatedIncidents = UpdatedIncidents
542+ { _uiId :: IncidentId
543+ , _uiStatus :: IncidentStatus
544+ , _uiIncidentNumber :: !Int
545+ , _uiUrl :: Text
546+ , _uiError :: Maybe Object
547+ } deriving (Eq, Show)
548+
549+deriveRecord ''UpdatedIncidents
550+
551+data UpdateIncidents = UpdateIncidents
552+ { _uiIncidents' :: [UpdateIncident]
553+ } deriving (Eq, Show)
554+
555+jsonRequest ''UpdateIncidents
556+
557+uiIncidents :: Lens' (Request UpdateIncidents s b) [UpdateIncident]
558+uiIncidents = upd.uiIncidents'
559+
560+-- | Acknowledge, resolve, escalate or reassign one or more incidents.
561+--
562+-- @PUT \/incidents@
563+--
564+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/update>
565+updateIncidents :: RequesterId -> Request UpdateIncidents s [UpdatedIncidents]
566+updateIncidents r = auth updateIncidentsBasic & query .~ [("requester_id", r)]
567+
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 =
572+ mk UpdateIncidents
573+ { _uiIncidents' = []
574+ } & meth .~ PUT
575+ & path .~ incidents
576+
577+-- | Resolve an incident.
578+--
579+-- @PUT \/incidents\/\:id\/resolve@
580+--
581+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/resolve>
582+resolveIncident :: IncidentId
583+ -> RequesterId
584+ -> Request Empty s Empty
585+resolveIncident i r =
586+ auth (resolveIncidentBasic i) & query .~ [("requester_id", r)]
587+
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"
592+
593+-- | Acknowledge an incident.
594+--
595+-- @PUT \/incidents\/\:id\/acknowledge@
596+--
597+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/acknowledge>
598+acknowledgeIncident :: IncidentId
599+ -> RequesterId
600+ -> Request Empty s Empty
601+acknowledgeIncident i r =
602+ auth (acknowledgeIncidentBasic i) & query .~ [("requester_id", r)]
603+
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"
609+
610+data ReassignIncident = ReassignIncident
611+ { _riEscalationPolicy' :: Maybe EscalationPolicyId
612+ , _riEscalationLevel' :: Maybe Int
613+ , _riAssignedToUser' :: Maybe (CSV UserId)
614+ } deriving (Eq, Show)
615+
616+jsonRequest ''ReassignIncident
617+
618+-- | The ID of an escalation policy. Delegate the incident to this escalation
619+-- policy.
620+riEscalationPolicy :: Lens' (Request ReassignIncident s b) (Maybe EscalationPolicyId)
621+riEscalationPolicy = upd.riEscalationPolicy'
622+
623+-- | Escalate incident to this level in the escalation policy.
624+riEscalationLevel :: Lens' (Request ReassignIncident s b) (Maybe Int)
625+riEscalationLevel = upd.riEscalationLevel'
626+
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
630+
631+-- | Reassign an incident.
632+--
633+-- @PUT \/incidents\/\:id\/reassign@
634+--
635+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/reassign>
636+reassignIncident :: IncidentId
637+ -> RequesterId
638+ -> Request ReassignIncident s Empty
639+reassignIncident i r =
640+ auth (reassignIncidentBasic i) & query .~ [("requester_id", r)]
641+
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 =
646+ mk ReassignIncident
647+ { _riEscalationPolicy' = Nothing
648+ , _riEscalationLevel' = Nothing
649+ , _riAssignedToUser' = Nothing
650+ } & meth .~ PUT
651+ & path .~ incidents % i % "reassign"