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