git.iko.soy/typeable/pagerduty
on develop help sign in
Manually making a classy instance for Incident to share with Webhook module
commit0f15bad583e9e6ccba0250823bf10d40b728155d authorBrendan Hay <brendan.g.hay@gmail.com> dateThu 23 Oct 2014, 19:55 (12 years ago) parentc5c4b4a
6 files changed+116−102
pagerduty.cabal+14−14 src/Network/PagerDuty/REST/EscalationPolicies/EscalationRules.hs−1 src/Network/PagerDuty/REST/Incidents.hs+97−81 src/Network/PagerDuty/REST/Reports.hs−1 src/Network/PagerDuty/REST/Schedules.hs+2−2 src/Network/PagerDuty/REST/Webhooks.hs+3−3
pagerduty.cabal+14−14
@@ -32,21 +32,21 @@ library
3232
3333 exposed-modules:
3434 Control.Monad.Trans.PagerDuty
35− -- , Network.PagerDuty.Integration
36− -- , Network.PagerDuty.REST
37− -- , Network.PagerDuty.REST.Alerts
38− -- , Network.PagerDuty.REST.EscalationPolicies
39−-- , Network.PagerDuty.REST.EscalationPolicies.EscalationRules
35+ , Network.PagerDuty.Integration
36+ , Network.PagerDuty.REST
37+ , Network.PagerDuty.REST.Alerts
38+ , Network.PagerDuty.REST.EscalationPolicies
39+ , Network.PagerDuty.REST.EscalationPolicies.EscalationRules
4040 , Network.PagerDuty.REST.Incidents
41− -- , Network.PagerDuty.REST.Incidents.Notes
42− -- , Network.PagerDuty.REST.LogEntries
43− -- , Network.PagerDuty.REST.MaintenanceWindows
44− -- , Network.PagerDuty.REST.Reports
45− -- , Network.PagerDuty.REST.Schedules
46−-- , Network.PagerDuty.REST.Schedules.Overrides
47− -- , Network.PagerDuty.REST.Services
48−-- , Network.PagerDuty.REST.Services.EmailFilters
49−-- , Network.PagerDuty.REST.Users
41+ , Network.PagerDuty.REST.Incidents.Notes
42+ , Network.PagerDuty.REST.LogEntries
43+ , Network.PagerDuty.REST.MaintenanceWindows
44+ , Network.PagerDuty.REST.Reports
45+ , Network.PagerDuty.REST.Schedules
46+ , Network.PagerDuty.REST.Schedules.Overrides
47+ , Network.PagerDuty.REST.Services
48+ , Network.PagerDuty.REST.Services.EmailFilters
49+ , Network.PagerDuty.REST.Users
5050 , Network.PagerDuty.REST.Users.ContactMethods
5151 , Network.PagerDuty.REST.Users.NotificationRules
5252 , Network.PagerDuty.REST.Webhooks
src/Network/PagerDuty/REST/EscalationPolicies/EscalationRules.hs−1
@@ -67,7 +67,6 @@ module Network.PagerDuty.REST.EscalationPolicies.EscalationRules
6767import Control.Applicative ((<$>))
6868import Control.Lens hiding ((.=))
6969import Data.Aeson
70−import Data.ByteString.Builder (Builder)
7170import qualified Data.HashMap.Strict as Map
7271import Data.Text (Text)
7372import Network.HTTP.Types
src/Network/PagerDuty/REST/Incidents.hs+97−81
@@ -125,20 +125,8 @@ module Network.PagerDuty.REST.Incidents
125125 , aAt
126126 , aObject
127127
128+ , HasIncident (..)
128129 , Incident
129− , iIncidentNumber
130− , iStatus
131− , iCreatedOn
132− , iHtmlUrl
133− , iIncidentKey
134− , iService
135− , iEscalationPolicy
136− , iAssignedTo
137− , iAcknowledgers
138− , iLastStatusChangeBy
139− , iLastStatusChangeOn
140− , iTriggerSummaryData
141− , iTriggerDetailsHtmlUrl
142130 ) where
143131
144132import Control.Applicative hiding (empty)
@@ -223,76 +211,104 @@ data Assignee = Assignee
223211deriveRecord ''Assignee
224212
225213data Incident = Incident
226− { _iIncidentNumber :: !Int
227− , _iStatus :: !IncidentStatus
228− , _iCreatedOn :: Date
229− , _iHtmlUrl :: Text
230− , _iIncidentKey :: Maybe IncidentKey
231− , _iService :: Object
232− , _iEscalationPolicy :: Maybe Object
233− , _iAssignedTo :: [Assignee]
234− , _iAcknowledgers :: [Assignee]
235− , _iLastStatusChangeBy :: Maybe Assignee
236− , _iLastStatusChangeOn :: Maybe Date
237− , _iTriggerSummaryData :: Object
238− , _iTriggerDetailsHtmlUrl :: Text
214+ { _iIncidentNumber' :: !Int
215+ , _iStatus' :: !IncidentStatus
216+ , _iCreatedOn' :: Date
217+ , _iHtmlUrl' :: Text
218+ , _iIncidentKey' :: Maybe IncidentKey
219+ , _iService' :: Object
220+ , _iEscalationPolicy' :: Maybe Object
221+ , _iAssignedTo' :: [Assignee]
222+ , _iAcknowledgers' :: [Assignee]
223+ , _iLastStatusChangeBy' :: Maybe Assignee
224+ , _iLastStatusChangeOn' :: Maybe Date
225+ , _iTriggerSummaryData' :: Object
226+ , _iTriggerDetailsHtmlUrl' :: Text
239227 } deriving (Eq, Show)
240228
241−deriveJSON ''Incident
242−
243−-- | The number of the incident. This is unique across your account.
244−makeLens "_iIncidentNumber" ''Incident
245−
246−-- | The current status of the incident. Valid statuses are:
247−makeLens "_iStatus" ''Incident
248−
249−-- | The date/time the incident was triggered.
250−iCreatedOn :: Lens' Incident UTCTime
251−iCreatedOn = lens _iCreatedOn (\i x -> i { _iCreatedOn = x }) . _D
252−
253−-- | The PagerDuty website URL where the incident can be viewed and further
254−-- actions taken. This is not the resource URL.
255−makeLens "_iHtmlUrl" ''Incident
256−
257−-- | The incident's de-duplication key. See the PagerDuty Integration API docs
258−-- for further details.
259−makeLens "_iIncidentKey" ''Incident
260−
261−-- | The PagerDuty service that the incident belongs to. The service will
262−-- contain fields of its own.
263−makeLens "_iService" ''Incident
264−
265−-- | The escalation policy that the incident belongs to. The policy will
266−-- contain fields of its own.
267−makeLens "_iEscalationPolicy" ''Incident
268−
269−-- | The list of assignments of the incident. An assignment is an object
270−-- containing the assigned user as well as the date/time the incident was assigned
271−-- to that user. The user will contain fields of its own. This list is empty if
272−-- the status of the incident is resolved.
273−makeLens "_iAssignedTo" ''Incident
274−
275−-- | The list of acknowledgements of the incident. An acknowledgement is an
276−-- object containing the acknowleding object (either a user or the integration
277−-- API) as well as the date/time the incident was acknowledged. This field is only
278−-- present if the status of the incident is acknowledged. This field is sorted in
279−-- ascending order by acknowledgement time.
280−makeLens "_iAcknowledgers" ''Incident
281−
282−-- | 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.
283−makeLens "_iLastStatusChangeBy" ''Incident
284−
285−-- | The date/time the incident's status last changed.
286−iLastStatusChangeOn :: Lens' Incident (Maybe UTCTime)
287−iLastStatusChangeOn =
288− lens _iLastStatusChangeOn (\i x -> i { _iLastStatusChangeOn = x })
289− . mapping _D
290−
291−-- | 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.
292−makeLens "_iTriggerSummaryData" ''Incident
293−
294−-- | 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.)
295−makeLens "_iTriggerDetailsHtmlUrl" ''Incident
229+deriveRecord ''Incident
230+
231+class HasIncident a where
232+ incident :: Lens' a Incident
233+
234+ -- | The number of the incident. This is unique across your account.
235+ iIncidentNumber :: Lens' a Int
236+
237+ -- | The current status of the incident. Valid statuses are:
238+ iStatus :: Lens' a IncidentStatus
239+
240+ -- | The date/time the incident was triggered.
241+ iCreatedOn :: Lens' a UTCTime
242+
243+ -- | The PagerDuty website URL where the incident can be viewed and further
244+ -- actions taken. This is not the resource URL.
245+ iHtmlUrl :: Lens' a Text
246+
247+ -- | The incident's de-duplication key. See the PagerDuty Integration API
248+ -- docs for further details.
249+ iIncidentKey :: Lens' a (Maybe IncidentKey)
250+
251+ -- | The PagerDuty service that the incident belongs to. The service will
252+ -- contain fields of its own.
253+ iService :: Lens' a Object
254+
255+ -- | The escalation policy that the incident belongs to. The policy will
256+ -- contain fields of its own.
257+ iEscalationPolicy :: Lens' a (Maybe Object)
258+
259+ -- | The list of assignments of the incident. An assignment is an object
260+ -- containing the assigned user as well as the date/time the incident was
261+ -- assigned to that user. The user will contain fields of its own.
262+ -- This list is empty if the status of the incident is resolved.
263+ iAssignedTo :: Lens' a [Assignee]
264+
265+ -- | The list of acknowledgements of the incident. An acknowledgement is an
266+ -- object containing the acknowleding object (either a user or the
267+ -- integration API) as well as the date/time the incident was acknowledged.
268+ -- This field is only present if the status of the incident is acknowledged.
269+ -- This field is sorted in ascending order by acknowledgement time.
270+ iAcknowledgers :: Lens' a [Assignee]
271+
272+ -- | The user who is responsible for the incident's last status change. If
273+ -- the incident is in the acknowledged or resolved status, this will be the user
274+ -- that took the first acknowledged or resolved action. If the incident was
275+ -- automatically resolved (say through the Event Integration API), or if the
276+ -- incident is in the triggered state, this will be null. User fields are the
277+ -- same as in the assignedToUser field above.
278+ iLastStatusChangeBy :: Lens' a (Maybe Assignee)
279+
280+ -- | The date/time the incident's status last changed.
281+ iLastStatusChangeOn :: Lens' a (Maybe UTCTime)
282+
283+ -- | Some condensed information regarding the initial event that triggered
284+ -- this incident. This data will be a set of key/value pairs that vary depending
285+ -- on what sort of event triggered the incident (email, Event API request,
286+ -- etc). For instance, if an email triggered the incident, then the
287+ -- triggerSummaryData will likely contain a subject. There are no guarantees
288+ -- o nthe full presence of this data for every incident.
289+ iTriggerSummaryData :: Lens' a Object
290+
291+ -- | The PagerDuty website URL where the full details regarding the initial
292+ -- event that triggered this incident can be found. (This is not the resource
293+ -- URL.)
294+ iTriggerDetailsHtmlUrl :: Lens' a Text
295+
296+ iIncidentNumber = incident.iIncidentNumber'
297+ iStatus = incident.iStatus'
298+ iCreatedOn = incident.iCreatedOn'._D
299+ iHtmlUrl = incident.iHtmlUrl'
300+ iIncidentKey = incident.iIncidentKey'
301+ iService = incident.iService'
302+ iEscalationPolicy = incident.iEscalationPolicy'
303+ iAssignedTo = incident.iAssignedTo'
304+ iAcknowledgers = incident.iAcknowledgers'
305+ iLastStatusChangeBy = incident.iLastStatusChangeBy'
306+ iLastStatusChangeOn = incident.iLastStatusChangeOn'.mapping _D
307+ iTriggerSummaryData = incident.iTriggerSummaryData'
308+ iTriggerDetailsHtmlUrl = incident.iTriggerDetailsHtmlUrl'
309+
310+instance HasIncident Incident where
311+ incident = id
296312
297313data ListIncidents = ListIncidents
298314 { _lsSince' :: Maybe Date
src/Network/PagerDuty/REST/Reports.hs−1
@@ -60,7 +60,6 @@ module Network.PagerDuty.REST.Reports
6060
6161import Control.Lens
6262import Data.Aeson.Lens
63−import Data.ByteString.Builder (Builder)
6463import Data.Time
6564import Network.PagerDuty.TH
6665import Network.PagerDuty.Types
src/Network/PagerDuty/REST/Schedules.hs+2−2
@@ -226,7 +226,7 @@ data ScheduleInfo = ScheduleInfo
226226 , _siName' :: Text
227227 , _siTimeZone' :: TZ
228228 , _siToday' :: Date
229− , _siEscalationPolicies' :: [PolicyId]
229+ , _siEscalationPolicies' :: [EscalationPolicyId]
230230 } deriving (Eq, Show)
231231
232232deriveRecord ''ScheduleInfo
@@ -243,7 +243,7 @@ class HasScheduleInfo a where
243243 -- | The current day in the schedule's time zone.
244244 sToday :: Lens' a UTCTime
245245 -- | An list of all the escalation policies that uses this schedule.
246− sEscalationPolicies :: Lens' a [PolicyId]
246+ sEscalationPolicies :: Lens' a [EscalationPolicyId]
247247
248248 sId = scheduleInfo.siId'
249249 sName = scheduleInfo.siName'
src/Network/PagerDuty/REST/Webhooks.hs+3−3
@@ -101,6 +101,9 @@ data Webhook = Webhook
101101
102102deriveJSON ''Webhook
103103
104+instance HasIncident Webhook where
105+ incident = lens _wData (\s x -> s { _wData = x })
106+
104107-- | Uniquely identifies this outgoing webhook message; can be used for
105108-- idempotency when processing the messages.
106109makeLens "_wId" ''Webhook
@@ -111,6 +114,3 @@ makeLens "_wType" ''Webhook
111114-- | The date/time when the incident changed state.
112115wCreatedOn :: Lens' Webhook UTCTime
113116wCreatedOn = lens _wCreatedOn (\i x -> i { _wCreatedOn = x }) . _D
114−
115−-- | The incident details at the time of the state change.
116−makeLens "_wData" ''Webhook