@@ -1,5 +1,8 @@
1+{-# LANGUAGE ExtendedDefaultRules #-}
1−{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE TemplateHaskell #-}
3+{-# LANGUAGE TemplateHaskell #-}
5+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
4-- Module : Network.PagerDuty.REST.Users.NotificationRules
7-- Module : Network.PagerDuty.REST.Users.NotificationRules
5-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
8-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
@@ -20,50 +23,142 @@
20-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules>
23-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules>
21module Network.PagerDuty.REST.Users.NotificationRules
24module Network.PagerDuty.REST.Users.NotificationRules
32+ , crStartDelayInMinutes
41+ , urStartDelayInMinutes
50+ , rStartDelayInMinutes
25import Control.Lens
54import Control.Lens
26−import Data.Monoid
55+import Data.Aeson.Lens
27−import Data.Text (Text)
29import Network.HTTP.Types
56import Network.HTTP.Types
57+import Network.PagerDuty.REST.Users.ContactMethods
30import Network.PagerDuty.TH
58import Network.PagerDuty.TH
31import Network.PagerDuty.Types
59import Network.PagerDuty.Types
33−users :: Path
61+default (Path)
63+rules :: UserId -> Path
64+rules u = "users" % u % "notification_rules"
67+ { _rId :: NotificationRuleId
68+ , _rStartDelayInMinutes :: !Int
69+ , _rContactMethod :: Contact
70+ } deriving (Eq, Show)
75+instance HasContact Rule where
76+ contact = rContactMethod
36-- | List existing notification rules for the specified user.
78-- | List existing notification rules for the specified user.
38-- @GET \/users\/\:user_id\/notification_rules@
80-- @GET \/users\/\:user_id\/notification_rules@
40-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/list>
82-- /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
43-- | Get details for a notification rule.
86-- | Get details for a notification rule.
45-- @GET \/users\/\:user_id\/notification_rules\/\:id@
88-- @GET \/users\/\:user_id\/notification_rules\/\:id@
47-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/show>
90-- /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
94+data CreateRule = CreateRule
95+ { _crStartDelayInMinutes' :: !Int
96+ , _crContactMethodId' :: ContactId
97+ } deriving (Eq, Show)
99+jsonRequest ''CreateRule
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
104+crStartDelayInMinutes :: Lens' (Request CreateRule s b) Int
105+crStartDelayInMinutes = upd.crStartDelayInMinutes'
107+-- | The id of the contact method.
108+crContactMethodId :: Lens' (Request CreateRule s b) ContactId
109+crContactMethodId = upd.crContactMethodId'
50-- | Create a new notification rule for the specified user.
111-- | Create a new notification rule for the specified user.
52-- @POST \/users\/\:user_id\/notification_rules@
113-- @POST \/users\/\:user_id\/notification_rules@
54-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/create>
115-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/create>
55−createNotificationRule
116+createRule :: UserId -> ContactId -> Int -> Request CreateRule s Rule
119+ { _crStartDelayInMinutes' = n
120+ , _crContactMethodId' = c
123+ & unwrap .~ key "notification_rule"
125+data UpdateRule = UpdateRule
126+ { _urStartDelayInMinutes' :: Maybe Int
127+ , _urContactMethodId' :: Maybe ContactId
128+ } deriving (Eq, Show)
130+jsonRequest ''UpdateRule
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
135+urStartDelayInMinutes :: Lens' (Request UpdateRule s b) (Maybe Int)
136+urStartDelayInMinutes = upd.urStartDelayInMinutes'
138+-- | The id of the contact method.
139+urContactMethodId :: Lens' (Request UpdateRule s b) (Maybe ContactId)
140+urContactMethodId = upd.urContactMethodId'
57-- | Update an existing notification rule.
142-- | Update an existing notification rule.
59-- @PUT \/users\/\:user_id\/notification_rules\/\:id@
144-- @PUT \/users\/\:user_id\/notification_rules\/\:id@
61-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/update>
146-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/update>
62−updateNotificationRule
147+updateRule :: UserId -> NotificationRuleId -> Request UpdateRule s Rule
150+ { _urStartDelayInMinutes' = Nothing
151+ , _urContactMethodId' = Nothing
153+ & path .~ rules u % r
154+ & unwrap .~ key "notification_rule"
64-- | Remove a notification rule.
156-- | Remove a notification rule.
66-- @DELETE \/users\/\:user_id\/notification_rules\/\:id@
158-- @DELETE \/users\/\:user_id\/notification_rules\/\:id@
68-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules/delete>
160-- /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