@@ -48,21 +48,111 @@
4848-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents>
4949module Network.PagerDuty.REST.Incidents
5050 (
51−
51+ -- * List Incidents
52+ ListIncidents
53+ , listIncidents
54+ , lsSince
55+ , lsUntil
56+ , lsDateRange
57+ , lsStatus
58+ , lsIncidentKey
59+ , lsService
60+ , lsAssignedToUser
61+ , lsTimeZone
62+ , lsSortBy
63+
64+ -- * Count Incidents
65+ , CountIncidents
66+ , countIncidents
67+ , cSince
68+ , cUntil
69+ , cDateRange
70+ , cStatus
71+ , cIncidentKey
72+ , cService
73+ , cAssignedToUser
74+
75+ -- * Get Incident
76+ , getIncident
77+
78+ -- * Update Incidents
79+ , UpdateIncidents
80+ , updateIncidents
81+ , updateIncidentsBasic
82+ , uiIncidents
83+
84+ -- * Resolve Incident
85+ , resolveIncident
86+ , resolveIncidentBasic
87+
88+ -- * Acknowledge Incident
89+ , acknowledgeIncident
90+ , acknowledgeIncidentBasic
91+
92+ -- * Reassign Incident
93+ , ReassignIncident
94+ , reassignIncident
95+ , riEscalationPolicy
96+ , riEscalationLevel
97+ , riAssignedToUser
98+
99+ -- * Types
100+ , Sort (..)
101+ , _Desc
102+ , _Asc
103+
104+ , Field (..)
105+
106+ , IncidentStatus (..)
107+ , UpdateStatus (..)
108+
109+ , UpdateIncident
110+ , iiId
111+ , iiStatus
112+ , iiEscalationLevel
113+ , iiEscalationPolicy
114+ , iiAssignedToUser
115+
116+ , UpdatedIncidents
117+ , uiId
118+ , uiStatus
119+ , uiIncidentNumber
120+ , uiUrl
121+ , uiError
122+
123+ , Assignee
124+ , aAt
125+ , aObject
126+
127+ , Incident
128+ , iIncidentNumber
129+ , iStatus
130+ , iCreatedOn
131+ , iHtmlUrl
132+ , iIncidentKey
133+ , iService
134+ , iEscalationPolicy
135+ , iAssignedTo
136+ , iAcknowledgers
137+ , iLastStatusChangeBy
138+ , iLastStatusChangeOn
139+ , iTriggerSummaryData
140+ , iTriggerDetailsHtmlUrl
52141 ) where
53142
54−import Control.Applicative hiding (empty)
55−import Control.Lens
56−import Data.Aeson
57−import Data.ByteString.Conversion (ToByteString(..))
58−import Data.Default
59−import Data.Monoid hiding (All)
60−import Data.Text (Text)
61−import Data.Time
62−import Network.HTTP.Types
63−import Network.PagerDuty.Query
64−import Network.PagerDuty.TH
65−import Network.PagerDuty.Types
143+import Control.Applicative hiding (empty)
144+import Control.Lens
145+import Data.Aeson
146+import Data.ByteString.Conversion (ToByteString(..), toByteString')
147+import Data.Default
148+import Data.Monoid hiding (All)
149+import Data.Text (Text)
150+import qualified Data.Text.Encoding as Text
151+import Data.Time
152+import Network.HTTP.Types
153+import Network.PagerDuty.Query
154+import Network.PagerDuty.TH
155+import Network.PagerDuty.Types
66156
67157default (Path)
68158
@@ -101,19 +191,28 @@ instance QueryValues Range where
101191 queryValues All = ["all"]
102192
103193data IncidentStatus
104− = Triggered
105− | Acknowledged
106− | Resolved
107− | Other Text
194+ = ITriggered
195+ | IAcknowledged
196+ | IResolved
197+ | IOther Text
108198 deriving (Eq, Show)
109199
110−deriveNullary ''IncidentStatus
111−
112200instance ToByteString IncidentStatus where
113− builder Triggered = "triggered"
114− builder Acknowledged = "acknowledged"
115− builder Resolved = "resolved"
116− builder (Other t) = builder t
201+ builder ITriggered = "triggered"
202+ builder IAcknowledged = "acknowledged"
203+ builder IResolved = "resolved"
204+ builder (IOther t) = builder t
205+
206+instance FromJSON IncidentStatus where
207+ parseJSON = withText "status" $ \t ->
208+ return $ case t of
209+ "triggered" -> ITriggered
210+ "acknowledged" -> IAcknowledged
211+ "resolved" -> IResolved
212+ _ -> IOther t
213+
214+instance ToJSON IncidentStatus where
215+ toJSON = String . Text.decodeUtf8 . toByteString'
117216
118217data Assignee = Assignee
119218 { _aAt :: Date
@@ -392,30 +491,148 @@ countIncidents =
392491 , _cAssignedToUser' = Nothing
393492 } & path .~ incidents % "count"
394493
494+
495+data UpdateStatus
496+ = UAcknowledged
497+ | UResolved
498+ deriving (Eq, Show)
499+
500+deriveNullary ''UpdateStatus
501+
502+data UpdateIncident = UpdateIncident
503+ { _iiId :: IncidentId
504+ , _iiStatus :: Maybe UpdateStatus
505+ , _iiEscalationLevel :: Maybe Int
506+ , _iiEscalationPolicy :: Maybe PolicyId
507+ , _iiAssignedToUser :: Maybe (CSV UserId)
508+ } deriving (Eq, Show)
509+
510+deriveJSON ''UpdateIncident
511+
512+-- | The id of the incident to update.
513+makeLens "_iiId" ''UpdateIncident
514+
515+-- | The new status of the incident.
516+makeLens "_iiStatus" ''UpdateIncident
517+
518+-- | Escalate incident to this level in the escalation policy.
519+makeLens "_iiEscalationLevel" ''UpdateIncident
520+
521+-- | Delegate this incident to the specified escalation policy id.
522+-- This restarts the incident's escalation following the new policy.
523+makeLens "_iiEscalationPolicy" ''UpdateIncident
524+
525+-- | List of user IDs to assign this incident to.
526+makeLens "_iiAssignedToUser" ''UpdateIncident
527+
528+data UpdatedIncidents = UpdatedIncidents
529+ { _uiId :: IncidentId
530+ , _uiStatus :: IncidentStatus
531+ , _uiIncidentNumber :: !Int
532+ , _uiUrl :: Text
533+ , _uiError :: Maybe Object
534+ } deriving (Eq, Show)
535+
536+deriveRecord ''UpdatedIncidents
537+
538+data UpdateIncidents = UpdateIncidents
539+ { _uiIncidents' :: [UpdateIncident]
540+ } deriving (Eq, Show)
541+
542+jsonRequest ''UpdateIncidents
543+
544+uiIncidents :: Lens' (Request UpdateIncidents s b) [UpdateIncident]
545+uiIncidents = upd.uiIncidents'
546+
395547-- | Acknowledge, resolve, escalate or reassign one or more incidents.
396548--
397549-- @PUT \/incidents@
398550--
399551-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/update>
400−updateIncidents = undefined
552+updateIncidents :: RequesterId -> Request UpdateIncidents s [UpdatedIncidents]
553+updateIncidents r = auth updateIncidentsBasic & query .~ [("requester_id", r)]
554+
555+-- | A version of 'updateIncidents' which uses HTTP Basic authentication and
556+-- doesn't require a 'RequesterId'.
557+updateIncidentsBasic :: Request UpdateIncidents Basic [UpdatedIncidents]
558+updateIncidentsBasic =
559+ mk UpdateIncidents
560+ { _uiIncidents' = []
561+ } & meth .~ PUT
562+ & path .~ incidents
401563
402564-- | Resolve an incident.
403565--
404566-- @PUT \/incidents\/\:id\/resolve@
405567--
406568-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/resolve>
407−resolveIncident = undefined
569+resolveIncident :: IncidentId
570+ -> RequesterId
571+ -> Request Empty s Empty
572+resolveIncident i r =
573+ auth (resolveIncidentBasic i) & query .~ [("requester_id", r)]
574+
575+-- | A version of 'resolveIncident' which uses HTTP Basic authentication and
576+-- doesn't require a 'RequesterId'.
577+resolveIncidentBasic :: IncidentId -> Request Empty s Empty
578+resolveIncidentBasic i = empty & meth .~ PUT & path .~ incidents % i % "resolve"
408579
409580-- | Acknowledge an incident.
410581--
411582-- @PUT \/incidents\/\:id\/acknowledge@
412583--
413584-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/acknowledge>
414−acknowledgeIncident = undefined
585+acknowledgeIncident :: IncidentId
586+ -> RequesterId
587+ -> Request Empty s Empty
588+acknowledgeIncident i r =
589+ auth (acknowledgeIncidentBasic i) & query .~ [("requester_id", r)]
590+
591+-- | A version of 'acknowledgeIncident' which uses HTTP Basic authentication and
592+-- doesn't require a 'RequesterId'.
593+acknowledgeIncidentBasic :: IncidentId -> Request Empty s Empty
594+acknowledgeIncidentBasic i =
595+ empty & meth .~ PUT & path .~ incidents % i % "acknowledge"
596+
597+data ReassignIncident = ReassignIncident
598+ { _riEscalationPolicy' :: Maybe PolicyId
599+ , _riEscalationLevel' :: Maybe Int
600+ , _riAssignedToUser' :: Maybe (CSV UserId)
601+ } deriving (Eq, Show)
602+
603+jsonRequest ''ReassignIncident
604+
605+-- | The ID of an escalation policy. Delegate the incident to this escalation
606+-- policy.
607+riEscalationPolicy :: Lens' (Request ReassignIncident s b) (Maybe PolicyId)
608+riEscalationPolicy = upd.riEscalationPolicy'
609+
610+-- | Escalate incident to this level in the escalation policy.
611+riEscalationLevel :: Lens' (Request ReassignIncident s b) (Maybe Int)
612+riEscalationLevel = upd.riEscalationLevel'
613+
614+-- | Comma separated list of user IDs to assign this incident to.
615+riAssignedToUser :: Lens' (Request ReassignIncident s b) (Maybe [UserId])
616+riAssignedToUser = upd.riAssignedToUser'.mapping _CSV
415617
416618-- | Reassign an incident.
417619--
418620-- @PUT \/incidents\/\:id\/reassign@
419621--
420622-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/reassign>
421−reassignIncident = undefined
623+reassignIncident :: IncidentId
624+ -> RequesterId
625+ -> Request ReassignIncident s Empty
626+reassignIncident i r =
627+ auth (reassignIncidentBasic i) & query .~ [("requester_id", r)]
628+
629+-- | A version of 'reassignIncident' which uses HTTP Basic authentication and
630+-- doesn't require a 'RequesterId'.
631+reassignIncidentBasic :: IncidentId -> Request ReassignIncident s Empty
632+reassignIncidentBasic i =
633+ mk ReassignIncident
634+ { _riEscalationPolicy' = Nothing
635+ , _riEscalationLevel' = Nothing
636+ , _riAssignedToUser' = Nothing
637+ } & meth .~ PUT
638+ & path .~ incidents % i % "reassign"