@@ -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