git.iko.soy/typeable/pagerduty
on develop help sign in
Adding Users/NotificationRules REST API
commit84700dd6de4765b2147cfec58eafd83eee8e4deb authorBrendan Hay <brendan.g.hay@gmail.com> dateThu 23 Oct 2014, 19:07 (12 years ago) parentd2b2dad
8 files changed+158−63
src/Network/PagerDuty/REST/EscalationPolicies.hs+5−5 src/Network/PagerDuty/REST/EscalationPolicies/EscalationRules.hs+10−8 src/Network/PagerDuty/REST/Incidents.hs+3−3 src/Network/PagerDuty/REST/Services.hs+6−6 src/Network/PagerDuty/REST/Users.hs+1−1 src/Network/PagerDuty/REST/Users/ContactMethods.hs+10−13 src/Network/PagerDuty/REST/Users/NotificationRules.hs+107−12 src/Network/PagerDuty/Types.hs+16−15
src/Network/PagerDuty/REST/EscalationPolicies.hs+5−5
@@ -76,7 +76,7 @@ policies :: Path
7676policies = "escalation_policies"
7777
7878data Policy = Policy
79− { _pId :: PolicyId
79+ { _pId :: EscalationPolicyId
8080 , _pName :: Text
8181 , _pNumLoops :: !Int
8282 , _pRules :: [Rule]
@@ -170,7 +170,7 @@ cpEscalationRules = upd.cpEscalationRules'
170170-- @POST \/escalation_policies@
171171--
172172-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/create>
173−createPolicy :: PolicyId
173+createPolicy :: EscalationPolicyId
174174 -> Text -- ^ 'creName'
175175 -> [Rule] -- ^ 'creEscalationRules'
176176 -> Request CreatePolicy s Policy
@@ -189,7 +189,7 @@ createPolicy i n rs =
189189-- @GET \/escalation_policies\/\:id@
190190--
191191-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/show>
192−getPolicy :: PolicyId -> Request Empty s Policy
192+getPolicy :: EscalationPolicyId -> Request Empty s Policy
193193getPolicy i = empty & path .~ policies % i & unwrap .~ key "escalation_policy"
194194
195195data UpdatePolicy = UpdatePolicy
@@ -223,7 +223,7 @@ upEscalationRules = upd.upEscalationRules'
223223-- @PUT \/escalation_policies\/\:id@
224224--
225225-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/update>
226−updatePolicy :: PolicyId -> Request UpdatePolicy s Policy
226+updatePolicy :: EscalationPolicyId -> Request UpdatePolicy s Policy
227227updatePolicy i =
228228 mk UpdatePolicy
229229 { _upName' = Nothing
@@ -240,5 +240,5 @@ updatePolicy i =
240240-- @DELETE \/escalation_policies\/\:id@
241241--
242242-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/delete>
243−deletePolicy :: PolicyId -> Request Empty s Empty
243+deletePolicy :: EscalationPolicyId -> Request Empty s Empty
244244deletePolicy i = empty & meth .~ DELETE & path .~ policies % i
src/Network/PagerDuty/REST/EscalationPolicies/EscalationRules.hs+10−8
@@ -77,7 +77,9 @@ import Network.PagerDuty.Types
7777
7878default (Path)
7979
80−rules :: PolicyId -> Path
80+-- FIXME: The lenses here need to operate over (Request x s b) using upd
81+
82+rules :: EscalationPolicyId -> Path
8183rules p = "escalation_policies" % p % "escalation_rules"
8284
8385data TargetType
@@ -137,7 +139,7 @@ instance ToJSON Target where
137139 TUser u -> ("user", toJSON u)
138140
139141data Rule = Rule
140− { _rId :: RuleId
142+ { _rId :: EscalationRuleId
141143 , _rEscalationDelayInMinutes :: !Int
142144 , _rTargets :: [Target]
143145 } deriving (Eq, Show)
@@ -158,7 +160,7 @@ makeLens "_rTargets" ''Rule
158160-- @GET \/escalation_policies\/\:escalation_policy_id\/escalation_rules@
159161--
160162-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/escalation_rules/list>
161−listRules :: PolicyId -> Request Empty s [Rule]
163+listRules :: EscalationPolicyId -> Request Empty s [Rule]
162164listRules p = empty & path .~ rules p
163165
164166-- | Show the escalation rule for an existing escalation policy.
@@ -166,7 +168,7 @@ listRules p = empty & path .~ rules p
166168-- @GET \/escalation_policies\/:escalation_policy_id\/escalation_rules\/\:id@
167169--
168170-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/escalation_rules/show>
169−getRule :: PolicyId -> RuleId -> Request Empty s Rule
171+getRule :: EscalationPolicyId -> EscalationRuleId -> Request Empty s Rule
170172getRule p r = empty & path .~ rules p % r
171173
172174data CreateRule = CreateRule
@@ -194,7 +196,7 @@ makeLens "_crTargets" ''CreateRule
194196-- @POST \/escalation_policies\/\:escalation_policy_id\/escalation_rules@
195197--
196198-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/escalation_rules/create>
197−createRule :: PolicyId
199+createRule :: EscalationPolicyId
198200 -> Int -- ^ 'crEscalationDelayInMinutes'
199201 -> [TargetId] -- ^ 'crTargets'
200202 -> Request CreateRule s Rule
@@ -225,7 +227,7 @@ makeLens "_urEscalationRules" ''UpdateRules
225227-- @PUT \/escalation_policies\/\:escalation_policy_id\/escalation_rules@
226228--
227229-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/escalation_rules/multi_update>
228−updateRules :: PolicyId
230+updateRules :: EscalationPolicyId
229231 -> [TargetId] -- ^ 'urEscalationRules'
230232 -> Request UpdateRules s [Rule]
231233updateRules p rs =
@@ -258,7 +260,7 @@ makeLens "_urTargets" ''UpdateRule
258260-- @PUT \/escalation_policies\/\:escalation_policy_id\/escalation_rules\/\:id@
259261--
260262-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/escalation_rules/update>
261−updateRule :: PolicyId -> RuleId -> Request UpdateRule s Rule
263+updateRule :: EscalationPolicyId -> EscalationRuleId -> Request UpdateRule s Rule
262264updateRule p r =
263265 mk UpdateRule
264266 { _urEscalationDelayInMinutes = Nothing
@@ -272,5 +274,5 @@ updateRule p r =
272274-- @DELETE \/escalation_policies\/\:escalation_policy_id\/escalation_rules\/\:id@
273275--
274276-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/escalation_rules/delete>
275−deleteRule :: PolicyId -> RuleId -> Request Empty s Empty
277+deleteRule :: EscalationPolicyId -> EscalationRuleId -> Request Empty s Empty
276278deleteRule p r = empty & meth .~ DELETE & path .~ rules p % r
src/Network/PagerDuty/REST/Incidents.hs+3−3
@@ -503,7 +503,7 @@ data UpdateIncident = UpdateIncident
503503 { _iiId :: IncidentId
504504 , _iiStatus :: Maybe UpdateStatus
505505 , _iiEscalationLevel :: Maybe Int
506− , _iiEscalationPolicy :: Maybe PolicyId
506+ , _iiEscalationPolicy :: Maybe EscalationPolicyId
507507 , _iiAssignedToUser :: Maybe (CSV UserId)
508508 } deriving (Eq, Show)
509509
@@ -595,7 +595,7 @@ acknowledgeIncidentBasic i =
595595 empty & meth .~ PUT & path .~ incidents % i % "acknowledge"
596596
597597data ReassignIncident = ReassignIncident
598− { _riEscalationPolicy' :: Maybe PolicyId
598+ { _riEscalationPolicy' :: Maybe EscalationPolicyId
599599 , _riEscalationLevel' :: Maybe Int
600600 , _riAssignedToUser' :: Maybe (CSV UserId)
601601 } deriving (Eq, Show)
@@ -604,7 +604,7 @@ jsonRequest ''ReassignIncident
604604
605605-- | The ID of an escalation policy. Delegate the incident to this escalation
606606-- policy.
607−riEscalationPolicy :: Lens' (Request ReassignIncident s b) (Maybe PolicyId)
607+riEscalationPolicy :: Lens' (Request ReassignIncident s b) (Maybe EscalationPolicyId)
608608riEscalationPolicy = upd.riEscalationPolicy'
609609
610610-- | Escalate incident to this level in the escalation policy.
src/Network/PagerDuty/REST/Services.hs+6−6
@@ -187,7 +187,7 @@ data ServiceType
187187deriveNullary ''ServiceType
188188
189189data PolicyInfo = PolicyInfo
190− { _pinfoId :: PolicyId
190+ { _pinfoId :: EscalationPolicyId
191191 , _pinfoName :: Text
192192 } deriving (Eq, Show)
193193
@@ -322,7 +322,7 @@ listServices =
322322
323323data CreateService = CreateService
324324 { _csName' :: Text
325− , _csEscalationPolicyId' :: PolicyId
325+ , _csEscalationPolicyId' :: EscalationPolicyId
326326 , _csType' :: !ServiceType
327327 , _csVendorId' :: Maybe VendorId
328328 , _csDescription' :: Maybe Text
@@ -351,7 +351,7 @@ csVendorId :: Lens' (Request CreateService s r) (Maybe VendorId)
351351csVendorId = upd.csVendorId'
352352
353353-- | The id of the escalation policy to be used by this service.
354−csEscalationPolicyId :: Lens' (Request CreateService s r) PolicyId
354+csEscalationPolicyId :: Lens' (Request CreateService s r) EscalationPolicyId
355355csEscalationPolicyId = upd.csEscalationPolicyId'
356356
357357-- | The duration in seconds before an incidents acknowledged in this service
@@ -377,7 +377,7 @@ csSeverityFilter = upd.csSeverityFilter'
377377--
378378-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/create>
379379createService :: Text
380− -> PolicyId
380+ -> EscalationPolicyId
381381 -> ServiceType
382382 -> Request CreateService s Service
383383createService n p t =
@@ -407,7 +407,7 @@ getService i = empty
407407data UpdateService = UpdateService
408408 { _usName' :: Maybe Text
409409 , _usDescription' :: Maybe Text
410− , _usEscalationPolicyId' :: Maybe PolicyId
410+ , _usEscalationPolicyId' :: Maybe EscalationPolicyId
411411 , _usAcknowledgementTimeout' :: Maybe Int
412412 , _usAutoResolveTimeout' :: Maybe Int
413413 , _usSeverityFilter' :: Maybe SeverityFilter
@@ -424,7 +424,7 @@ usDescription :: Lens' (Request UpdateService s r) (Maybe Text)
424424usDescription = upd.usDescription'
425425
426426-- | The id of the escalation policy to be used by this service.
427−usEscalationPolicyId :: Lens' (Request UpdateService s r) (Maybe PolicyId)
427+usEscalationPolicyId :: Lens' (Request UpdateService s r) (Maybe EscalationPolicyId)
428428usEscalationPolicyId = upd.usEscalationPolicyId'
429429
430430-- | The duration in seconds before an incidents acknowledged in this service
src/Network/PagerDuty/REST/Users.hs+1−1
@@ -144,7 +144,7 @@ instance HasUserInfo UserInfo where
144144 userInfo = id
145145
146146data PolicyInfo = PolicyInfo
147− { _piId :: PolicyId
147+ { _piId :: EscalationPolicyId
148148 , _piName :: Text
149149 } deriving (Eq, Show)
150150
src/Network/PagerDuty/REST/Users/ContactMethods.hs+10−13
@@ -1,5 +1,8 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE TemplateHaskell #-}
1+{-# LANGUAGE ExtendedDefaultRules #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE TemplateHaskell #-}
4+
5+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
36
47-- Module : Network.PagerDuty.REST.Users.ContactMethods
58-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
@@ -49,26 +52,19 @@ module Network.PagerDuty.REST.Users.ContactMethods
4952 -- * Types
5053 , ContactType (..)
5154
55+ , HasContact (..)
5256 , Contact
53− , cId
54− , cUserId
55− , cLabel
56− , cAddress
57− , cType
58− , cCountryCode
59− , cSendShortEmail
60− , cBlacklisted
6157 ) where
6258
6359import Control.Lens
6460import Data.Aeson.Lens
65−import Data.Monoid
6661import Data.Text (Text)
67−import Data.Time
6862import Network.HTTP.Types
6963import Network.PagerDuty.TH
7064import Network.PagerDuty.Types
7165
66+default (Path)
67+
7268contacts :: UserId -> Path
7369contacts u = "users" % u % "contact_methods"
7470
@@ -91,7 +87,8 @@ data Contact = Contact
9187 , _cBlacklisted :: Maybe Bool'
9288 } deriving (Eq, Show)
9389
94−deriveRecord ''Contact
90+deriveJSON ''Contact
91+makeClassy ''Contact
9592
9693-- | List existing contact methods for the specified user.
9794--
src/Network/PagerDuty/REST/Users/NotificationRules.hs+107−12
@@ -1,5 +1,8 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE TemplateHaskell #-}
1+{-# LANGUAGE ExtendedDefaultRules #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE TemplateHaskell #-}
4+
5+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
36
47-- Module : Network.PagerDuty.REST.Users.NotificationRules
58-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
@@ -20,50 +23,142 @@
2023-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules>
2124module Network.PagerDuty.REST.Users.NotificationRules
2225 (
26+ -- * List Rules
27+ listRules
28+
29+ -- * Create Rule
30+ , CreateRule
31+ , createRule
32+ , crStartDelayInMinutes
33+ , crContactMethodId
34+
35+ -- * Get Rule
36+ , getRule
37+
38+ -- * Update Rule
39+ , UpdateRule
40+ , updateRule
41+ , urStartDelayInMinutes
42+ , urContactMethodId
43+
44+ -- * Delete Rule
45+ , deleteRule
46+
47+ -- * Types
48+ , Rule
49+ , rId
50+ , rStartDelayInMinutes
51+ , rContactMethod
2352 ) where
2453
2554import Control.Lens
26−import Data.Monoid
27−import Data.Text (Text)
28−import Data.Time
55+import Data.Aeson.Lens
2956import Network.HTTP.Types
57+import Network.PagerDuty.REST.Users.ContactMethods
3058import Network.PagerDuty.TH
3159import Network.PagerDuty.Types
3260
33−users :: Path
34−users = "users"
61+default (Path)
62+
63+rules :: UserId -> Path
64+rules u = "users" % u % "notification_rules"
65+
66+data Rule = Rule
67+ { _rId :: NotificationRuleId
68+ , _rStartDelayInMinutes :: !Int
69+ , _rContactMethod :: Contact
70+ } deriving (Eq, Show)
71+
72+deriveJSON ''Rule
73+makeLenses ''Rule
74+
75+instance HasContact Rule where
76+ contact = rContactMethod
3577
3678-- | List existing notification rules for the specified user.
3779--
3880-- @GET \/users\/\:user_id\/notification_rules@
3981--
4082-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/list>
41−listNotificationRules
83+listRules :: UserId -> Request Empty s Rule
84+listRules u = empty & path .~ rules u
4285
4386-- | Get details for a notification rule.
4487--
4588-- @GET \/users\/\:user_id\/notification_rules\/\:id@
4689--
4790-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/show>
48−getNotificationRule
91+getRule :: UserId -> NotificationRuleId -> Request Empty s Rule
92+getRule u n = empty & path .~ rules u % n
93+
94+data CreateRule = CreateRule
95+ { _crStartDelayInMinutes' :: !Int
96+ , _crContactMethodId' :: ContactId
97+ } deriving (Eq, Show)
98+
99+jsonRequest ''CreateRule
100+
101+-- | Number of minutes it will take for the notification rule to be activated
102+-- (from the time the incident is assigned to the owning user) and an alert be
103+-- fired.
104+crStartDelayInMinutes :: Lens' (Request CreateRule s b) Int
105+crStartDelayInMinutes = upd.crStartDelayInMinutes'
106+
107+-- | The id of the contact method.
108+crContactMethodId :: Lens' (Request CreateRule s b) ContactId
109+crContactMethodId = upd.crContactMethodId'
49110
50111-- | Create a new notification rule for the specified user.
51112--
52113-- @POST \/users\/\:user_id\/notification_rules@
53114--
54115-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/create>
55−createNotificationRule
116+createRule :: UserId -> ContactId -> Int -> Request CreateRule s Rule
117+createRule u c n =
118+ mk CreateRule
119+ { _crStartDelayInMinutes' = n
120+ , _crContactMethodId' = c
121+ } & meth .~ POST
122+ & path .~ rules u
123+ & unwrap .~ key "notification_rule"
124+
125+data UpdateRule = UpdateRule
126+ { _urStartDelayInMinutes' :: Maybe Int
127+ , _urContactMethodId' :: Maybe ContactId
128+ } deriving (Eq, Show)
129+
130+jsonRequest ''UpdateRule
131+
132+-- | Number of minutes it will take for the notification rule to be activated
133+-- (from the time the incident is assigned to the owning user) and an alert be
134+-- fired.
135+urStartDelayInMinutes :: Lens' (Request UpdateRule s b) (Maybe Int)
136+urStartDelayInMinutes = upd.urStartDelayInMinutes'
137+
138+-- | The id of the contact method.
139+urContactMethodId :: Lens' (Request UpdateRule s b) (Maybe ContactId)
140+urContactMethodId = upd.urContactMethodId'
56141
57142-- | Update an existing notification rule.
58143--
59144-- @PUT \/users\/\:user_id\/notification_rules\/\:id@
60145--
61146-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/update>
62−updateNotificationRule
147+updateRule :: UserId -> NotificationRuleId -> Request UpdateRule s Rule
148+updateRule u r =
149+ mk UpdateRule
150+ { _urStartDelayInMinutes' = Nothing
151+ , _urContactMethodId' = Nothing
152+ } & meth .~ PUT
153+ & path .~ rules u % r
154+ & unwrap .~ key "notification_rule"
63155
64156-- | Remove a notification rule.
65157--
66158-- @DELETE \/users\/\:user_id\/notification_rules\/\:id@
67159--
68160-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/delete>
69−deleteNotificationRule
161+deleteRule :: UserId
162+ -> NotificationRuleId
163+ -> Request Empty s Empty
164+deleteRule u n = empty & meth .~ DELETE & path .~ rules u % n
src/Network/PagerDuty/Types.hs+16−15
@@ -397,21 +397,22 @@ instance QueryValues (Id a)
397397instance QueryValueLike (Id a) where
398398 toQueryValue = Just . toByteString'
399399
400−type AlertId = Id "alert"
401−type ContactId = Id "contact"
402−type EmailFilterId = Id "email-filter"
403−type IncidentId = Id "incident"
404−type LogEntryId = Id "log-entry"
405−type NoteId = Id "note"
406−type OverrideId = Id "schedule-override"
407−type PolicyId = Id "escalation-policy"
408−type RequesterId = Id "requester"
409−type RuleId = Id "rule"
410−type ScheduleId = Id "schedule"
411−type ServiceId = Id "service"
412−type UserId = Id "user"
413−type VendorId = Id "vendor"
414−type WindowId = Id "maintenance-window"
400+type AlertId = Id "alert"
401+type ContactId = Id "contact"
402+type EmailFilterId = Id "email-filter"
403+type EscalationPolicyId = Id "escalation-policy"
404+type EscalationRuleId = Id "escalation-rule"
405+type IncidentId = Id "incident"
406+type LogEntryId = Id "log-entry"
407+type NoteId = Id "note"
408+type NotificationRuleId = Id "notification-rule"
409+type OverrideId = Id "schedule-override"
410+type RequesterId = Id "requester"
411+type ScheduleId = Id "schedule"
412+type ServiceId = Id "service"
413+type UserId = Id "user"
414+type VendorId = Id "vendor"
415+type WindowId = Id "maintenance-window"
415416
416417data Empty = Empty
417418