git.iko.soy/typeable/pagerduty
on develop help sign in
Adding EmailFilters REST API
commitc346e35cba6fbc76a4cc19b931eb7a9e59272a43 authorBrendan Hay <brendan.g.hay@gmail.com> dateTue 7 Oct 2014, 07:48 (12 years ago) parent4d55af3
17 files changed+250−85
pagerduty.cabal+3−3 src/Network/PagerDuty/REST/EscalationPolicies/EscalationRules.hs+2 src/Network/PagerDuty/REST/EscalationPolicies/OnCall.hs+30−5 src/Network/PagerDuty/REST/Incidents.hs+2 src/Network/PagerDuty/REST/Incidents/Notes.hs+2 src/Network/PagerDuty/REST/LogEntries.hs+2 src/Network/PagerDuty/REST/MaintenanceWindows.hs+2 src/Network/PagerDuty/REST/Reports.hs+2 src/Network/PagerDuty/REST/Schedules.hs+2 src/Network/PagerDuty/REST/Schedules/Overrides.hs+2 src/Network/PagerDuty/REST/Services.hs−67 src/Network/PagerDuty/REST/Services/EmailFilters.hs+157−5 src/Network/PagerDuty/REST/Users.hs+36−5 src/Network/PagerDuty/REST/Users/ContactMethods.hs+2 src/Network/PagerDuty/REST/Users/NotificationRules.hs+2 src/Network/PagerDuty/REST/Users/OnCall.hs+2 src/Network/PagerDuty/REST/Webhooks.hs+2
pagerduty.cabal+3−3
@@ -36,15 +36,15 @@ library
3636 -- , Network.PagerDuty.REST
3737 -- , Network.PagerDuty.REST.Alerts
3838 -- , Network.PagerDuty.REST.EscalationPolicies
39− , Network.PagerDuty.REST.EscalationPolicies.EscalationRules
40− , Network.PagerDuty.REST.EscalationPolicies.OnCall
39+-- , Network.PagerDuty.REST.EscalationPolicies.EscalationRules
40+-- , Network.PagerDuty.REST.EscalationPolicies.OnCall
4141 , Network.PagerDuty.REST.Incidents
4242 , Network.PagerDuty.REST.Incidents.Notes
4343 -- , Network.PagerDuty.REST.LogEntries
4444 -- , Network.PagerDuty.REST.MaintenanceWindows
4545 -- , Network.PagerDuty.REST.Reports
4646 -- , Network.PagerDuty.REST.Schedules
47− , Network.PagerDuty.REST.Schedules.Overrides
47+-- , Network.PagerDuty.REST.Schedules.Overrides
4848 -- , Network.PagerDuty.REST.Services
4949 , Network.PagerDuty.REST.Services.EmailFilters
5050 , Network.PagerDuty.REST.Users
src/Network/PagerDuty/REST/EscalationPolicies/EscalationRules.hs+2
@@ -17,6 +17,8 @@
1717
1818-- | This API lets you access and manipulate escalation rules of an existing
1919-- escalation policy.
20+--
21+-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/escalation_rules>
2022module Network.PagerDuty.REST.EscalationPolicies.EscalationRules
2123 (
2224 -- * List Rules
src/Network/PagerDuty/REST/EscalationPolicies/OnCall.hs+30−5
@@ -11,12 +11,11 @@
1111-- Stability : experimental
1212-- Portability : non-portable (GHC extensions)
1313
14−-- | List all the existing escalation policies with currently on-call users.
15−--
16−-- If the start and end of an on-call object are null, then the user is always
17−-- on-call for an escalation policy level.
14+-- | List escalation policies for currently on-call users.
1815module Network.PagerDuty.REST.EscalationPolicies.OnCall
19− (
16+ ( ListOnCallPolicies
17+ , listOnCallPolicies
18+ , locpQuery
2019 ) where
2120
2221import Control.Lens
@@ -26,3 +25,29 @@ import Data.Time
2625import Network.HTTP.Types
2726import Network.PagerDuty.TH
2827import Network.PagerDuty.Types
28+
29+newtype ListOnCallPolicies = ListOnCallPolicies
30+ { _locpQuery :: Maybe Text
31+ } deriving (Eq, Show)
32+
33+queryRequest ''ListOnCallPolicies
34+
35+instance Paginate ListOnCallPolicies
36+
37+-- | Filters the result, showing only the escalation policies whose names match
38+-- the query.
39+makeLens "_locpQuery" ''ListOnCallPolicies
40+
41+-- | List all the existing escalation policies with currently on-call users.
42+--
43+-- If the start and end of an on-call object are null, then the user is always
44+-- on-call for an escalation policy level.
45+--
46+-- @GET \/escalation_policies\/on_call@
47+--
48+-- /See:/ <http://developer.pagerduty.com/documentation/rest/escalation_policies/on_call>
49+listOnCallPolicies :: Request ListOnCallPolicies s [Policy]
50+listOnCallPolicies =
51+ mk ListOnCallPolicies
52+ { _locpQuery = Nothing
53+ } & path .~ "policies"
src/Network/PagerDuty/REST/Incidents.hs+2
@@ -37,6 +37,8 @@
3737--
3838-- Note: that to create an incident you need to trigger it through the
3939-- "Network.PagerDuty.Integration" API.
40+--
41+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents>
4042module Network.PagerDuty.REST.Incidents
4143 (
4244
src/Network/PagerDuty/REST/Incidents/Notes.hs+2
@@ -12,6 +12,8 @@
1212-- Portability : non-portable (GHC extensions)
1313
1414-- | The Incident Notes API allows you to add notes to a specified incident.
15+--
16+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/notes>
1517module Network.PagerDuty.REST.Incidents.Notes
1618 (
1719 ) where
src/Network/PagerDuty/REST/LogEntries.hs+2
@@ -20,6 +20,8 @@
2020-- incidents. Log entry data includes details about the event(s) that triggered
2121-- the incident, who was notified and when, how they were notified, and who
2222-- acknowledged or resolved it, amongst a few other things.
23+--
24+-- /See:/ <http://developer.pagerduty.com/documentation/rest/log_entries>
2325module Network.PagerDuty.REST.LogEntries
2426 (
2527 -- * List Logs
src/Network/PagerDuty/REST/MaintenanceWindows.hs+2
@@ -15,6 +15,8 @@
1515
1616-- | Maintenance windows allow you to schedule service maintenance periods,
1717-- during which no incidents will be created.
18+--
19+-- /See:/ <http://developer.pagerduty.com/documentation/rest/maintenance_windows>
1820module Network.PagerDuty.REST.MaintenanceWindows
1921 (
2022 -- * List Windows
src/Network/PagerDuty/REST/Reports.hs+2
@@ -18,6 +18,8 @@
1818
1919-- | Access high level reports about alerts and incidents.
2020-- Useful for creating graphs.
21+--
22+-- /See:/ <http://developer.pagerduty.com/documentation/rest/reports>
2123module Network.PagerDuty.REST.Reports
2224 (
2325 -- * Alerts Per Time
src/Network/PagerDuty/REST/Schedules.hs+2
@@ -20,6 +20,8 @@
2020-- a user is on-call he is eligible to receive alerts from incidents.
2121--
2222-- This API allows users to manipulate on-call schedules.
23+--
24+-- /See:/ <http://developer.pagerduty.com/documentation/rest/schedules/overrides>
2325module Network.PagerDuty.REST.Schedules
2426 (
2527 -- * List Schedules
src/Network/PagerDuty/REST/Schedules/Overrides.hs+2
@@ -19,6 +19,8 @@
1919-- | Schedule overrides are custom, non-recurring exceptions to your regular
2020-- on-call schedules. Use them when your team members go on vacation, swap shifts,
2121-- or when you simply cannot achieve your normal scheduling with recurring layers.
22+--
23+-- /See:/ <http://developer.pagerduty.com/documentation/rest/schedules>
2224module Network.PagerDuty.REST.Schedules.Overrides
2325 (
2426 -- * List Overrides
src/Network/PagerDuty/REST/Services.hs−67
@@ -72,7 +72,6 @@ module Network.PagerDuty.REST.Services
7272 -- * Types
7373 , EmailFilterMode (..)
7474 , EmailIncidentCreation (..)
75− , MatchMode (..)
7675 , ServiceStatus (..)
7776 , ServiceType (..)
7877 , SeverityFilter (..)
@@ -83,15 +82,6 @@ module Network.PagerDuty.REST.Services
8382 , cntResolved
8483 , cntTotal
8584
86− , EmailFilters (..)
87− , efsId
88− , efsSubjectMode
89− , efsSubjectRegex
90− , efsBodyMode
91− , efsBodyRegex
92− , efsFromEmailMode
93− , efsFromEmailRegex
94−
9585 , PolicyInfo
9686 , pinfoId
9787 , pinfoName
@@ -203,63 +193,6 @@ data PolicyInfo = PolicyInfo
203193
204194deriveRecord ''PolicyInfo
205195
206−data MatchMode
207− = Always
208− | Match
209− | NoMatch
210− deriving (Eq, Show)
211−
212−deriveNullaryWith hyphenated ''MatchMode
213−
214−-- FIXME: Tighten up this type! Make the regex required for match/no-match.
215−data EmailFilters = EmailFilters
216− { _efsId :: EmailFilterId
217− , _efsSubjectMode :: Maybe MatchMode
218− , _efsSubjectRegex :: Maybe Text
219− , _efsBodyMode :: Maybe MatchMode
220− , _efsBodyRegex :: Maybe Text
221− , _efsFromEmailMode :: Maybe MatchMode
222− , _efsFromEmailRegex :: Maybe Text
223− } deriving (Eq, Show)
224−
225−deriveJSON ''EmailFilters
226−
227−-- | The email filter ID.
228−makeLens "_efsId" ''EmailFilters
229−
230−-- | One of always, match, no-match, which, respectively, means to not filter
231−-- the email trigger by subject, filter it if the email subject matches the
232−-- given regex, or filter if it doesn't match the given regex.
233−--
234−-- /Default:/ always.
235−makeLens "_efsSubjectMode" ''EmailFilters
236−
237−-- | The regex to be used when subject_mode is match or no-match.
238−-- It is a required parameter on such cases.
239−makeLens "_efsSubjectRegex" ''EmailFilters
240−
241−-- | One of always, match, no-match, which, respectively, means to not filter
242−-- the email trigger by body, filter it if the body email matches the given regex,
243−-- or filter if it doesn't match the given regex.
244−--
245−-- /Default:/ always.
246−makeLens "_efsBodyMode" ''EmailFilters
247−
248−-- | The regex to be used when body_mode is match or no-match.
249−-- It is a required parameter on such cases.
250−makeLens "_efsBodyRegex" ''EmailFilters
251−
252−-- | One of always, match, no-match, which, respectively, means to not filter
253−-- the email trigger by its from address, filter it if the email from address
254−-- matches the given regex, or filter if it doesn't match the given regex.
255−--
256−-- /Default:/ always.
257−makeLens "_efsFromEmailMode" ''EmailFilters
258−
259−-- | The regex to be used when from_email_mode is match or no-match.
260−-- It is a required parameter on such cases.
261−makeLens "_efsFromEmailRegex" ''EmailFilters
262−
263196data SeverityFilter
264197 = SevCritical
265198 -- ^ Incidents are created when an alarm enters the Critical state.
src/Network/PagerDuty/REST/Services/EmailFilters.hs+157−5
@@ -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.Services.EmailFilters
58-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
@@ -15,15 +18,164 @@
1518-- subject and from address. It only applies to generic_email kind of
1619-- Services. The way multiple filters are combined depends on the
1720-- email_filter_mode attribute of the service.
21+--
22+-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/email_filters>
1823module Network.PagerDuty.REST.Services.EmailFilters
1924 (
25+ -- * Create Email Filter
26+ createEmailFilter
27+
28+ -- * Update Email Filter
29+ , updateEmailFilter
30+
31+ -- * Delete Email Filter
32+ , deleteEmailFilter
33+
34+ -- * Types
35+ , MatchMode (..)
36+ , HasEmailFilterInfo (..)
37+ , EmailFilterInfo
38+ , EmailFilter
39+ , efId
2040 ) where
2141
22−import Control.Lens
42+import Control.Applicative hiding (empty)
43+import Control.Lens hiding ((.=))
44+import Data.Aeson
45+import Data.ByteString.Builder (Builder)
46+import Data.Default
2347import Data.Monoid
24−import Data.Text (Text)
25−import Data.Time
48+import Data.Text (Text)
2649import Network.HTTP.Types
2750import Network.PagerDuty.TH
2851import Network.PagerDuty.Types
2952
53+default (Builder)
54+
55+filters :: ServiceId -> Path
56+filters s = "services" % s % "email_filters"
57+
58+data MatchMode
59+ = Always
60+ | Match
61+ | NoMatch
62+ deriving (Eq, Show)
63+
64+deriveNullaryWith hyphenated ''MatchMode
65+
66+-- FIXME: Tighten up this type! Make the regex required for match/no-match and
67+-- encode the conditional invariants.
68+data EmailFilterInfo = EmailFilterInfo
69+ { _efSubjectMode' :: Maybe MatchMode
70+ , _efSubjectRegex' :: Maybe Text
71+ , _efBodyMode' :: Maybe MatchMode
72+ , _efBodyRegex' :: Maybe Text
73+ , _efFromEmailMode' :: Maybe MatchMode
74+ , _efFromEmailRegex' :: Maybe Text
75+ } deriving (Eq, Show)
76+
77+deriveRecord ''EmailFilterInfo
78+
79+instance Default EmailFilterInfo where
80+ def = EmailFilterInfo Nothing Nothing Nothing Nothing Nothing Nothing
81+
82+instance QueryLike EmailFilterInfo where
83+ toQuery = const []
84+
85+class HasEmailFilterInfo a where
86+ emailFilterInfo :: Lens' a EmailFilterInfo
87+
88+ -- | One of always, match, no-match, which, respectively, means to not
89+ -- filter the email trigger by subject, filter it if the email subject
90+ -- matches the given regex, or filter if it doesn't match the given regex.
91+ --
92+ -- /Default:/ always.
93+ efSubjectMode :: Lens' a (Maybe MatchMode)
94+
95+ -- | The regex to be used when subject_mode is match or no-match.
96+ -- It is a required parameter on such cases.
97+ efSubjectRegex :: Lens' a (Maybe Text)
98+
99+ -- | One of always, match, no-match, which, respectively, means to not filter
100+ -- the email trigger by body, filter it if the body email matches the given
101+ -- regex, or filter if it doesn't match the given regex.
102+ --
103+ -- /Default:/ always.
104+ efBodyMode :: Lens' a (Maybe MatchMode)
105+
106+ -- | The regex to be used when body_mode is match or no-match.
107+ -- It is a required parameter on such cases.
108+ efBodyRegex :: Lens' a (Maybe Text)
109+
110+ -- | One of always, match, no-match, which, respectively, means to not filter
111+ -- the email trigger by its from address, filter it if the email from address
112+ -- matches the given regex, or filter if it doesn't match the given regex.
113+ --
114+ -- /Default:/ always.
115+ efFromEmailMode :: Lens' a (Maybe MatchMode)
116+
117+ -- | The regex to be used when from_email_mode is match or no-match.
118+ -- It is a required parameter on such cases.
119+ efFromEmailRegex :: Lens' a (Maybe Text)
120+
121+ efSubjectMode = emailFilterInfo.efSubjectMode'
122+ efSubjectRegex = emailFilterInfo.efSubjectRegex'
123+ efBodyMode = emailFilterInfo.efBodyMode'
124+ efBodyRegex = emailFilterInfo.efBodyRegex'
125+ efFromEmailMode = emailFilterInfo.efFromEmailMode'
126+ efFromEmailRegex = emailFilterInfo.efFromEmailRegex'
127+
128+instance (QueryLike a, ToJSON a, HasEmailFilterInfo a)
129+ => HasEmailFilterInfo (Request a s b) where
130+ emailFilterInfo = upd.emailFilterInfo
131+
132+instance HasEmailFilterInfo EmailFilterInfo where
133+ emailFilterInfo = id
134+
135+data EmailFilter = EmailFilter
136+ { _efId :: EmailFilterId
137+ , _efInfo :: EmailFilterInfo
138+ } deriving (Eq, Show)
139+
140+instance FromJSON EmailFilter where
141+ parseJSON = withObject "email_filter" $ \o ->
142+ EmailFilter <$> parseJSON (Object o)
143+ <*> o .: "id"
144+
145+instance ToJSON EmailFilter where
146+ toJSON e = Object (x <> y)
147+ where
148+ Object x = toJSON (_efInfo e)
149+ Object y = object ["id" .= _efId e]
150+
151+instance HasEmailFilterInfo EmailFilter where
152+ emailFilterInfo = lens _efInfo (\e x -> e { _efInfo = x })
153+
154+-- | The email filter ID.
155+makeLens "_efId" ''EmailFilter
156+
157+-- | Create a new Email Filter for the specified service.
158+--
159+-- @POST \/services\/\:service_id\/email_filters@
160+--
161+-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/email_filters/create>
162+createEmailFilter :: ServiceId -> Request EmailFilterInfo s EmailFilter
163+createEmailFilter s = mk def & meth .~ POST & path .~ filters s
164+
165+-- | Update an existing Email Filter.
166+--
167+-- @PUT \/services\/\:service_id\/email_filters\/\:id@
168+--
169+-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/email_filters/update>
170+updateEmailFilter :: ServiceId
171+ -> EmailFilterId
172+ -> Request EmailFilterInfo s Empty
173+updateEmailFilter s e = mk def & meth .~ PUT & path .~ filters s % e
174+
175+-- | Delete an existing Email Filter.
176+--
177+-- @DELETE \/services\/\:service_id\/email_filters\/\:id@
178+--
179+-- /See:/ <http://developer.pagerduty.com/documentation/rest/services/email_filters/delete>
180+deleteEmailFilter :: ServiceId -> EmailFilterId -> Request Empty s Empty
181+deleteEmailFilter s e = empty & meth .~ DELETE & path .~ filters s % e
src/Network/PagerDuty/REST/Users.hs+36−5
@@ -14,6 +14,8 @@
1414-- | Access and manipulate user data for your PagerDuty account. When a user is
1515-- shown inlined in other resources, a deleted user will have its @html_url@ attribute
1616-- set to null.
17+--
18+-- /See:/ <http://developer.pagerduty.com/documentation/rest/users>
1719module Network.PagerDuty.REST.Users
1820 (
1921
@@ -27,9 +29,11 @@ module Network.PagerDuty.REST.Users
2729 , uInvitationSent
2830 ) where
2931
30−import Control.Lens
32+import Control.Applicative hiding (empty)
33+import Control.Lens hiding ((.=))
34+import Data.Aeson
3135import Data.Monoid
32−import Data.Text (Text)
36+import Data.Text (Text)
3337import Data.Time
3438import Network.HTTP.Types
3539import Network.PagerDuty.TH
@@ -53,12 +57,16 @@ class HasUserInfo a where
5357
5458 -- | The id of the user.
5559 uId :: Lens' a UserId
60+
5661 -- | The name of the user.
5762 uName :: Lens' a Text
63+
5864 -- | The user's email address.
5965 uEmail :: Lens' a Address
66+
6067 -- | The color used to represent the user in schedules.
6168 uColor :: Lens' a Text
69+
6270 -- | The user's personal time zone.
6371 uTimeZone :: Lens' a (Maybe TimeZone)
6472
@@ -68,21 +76,44 @@ class HasUserInfo a where
6876 uColor = userInfo.uColor'
6977 uTimeZone = userInfo.uTimeZone'.mapping _TZ
7078
79+instance (QueryLike a, ToJSON a, HasUserInfo a)
80+ => HasUserInfo (Request a s b) where
81+ userInfo = upd.userInfo
82+
7183instance HasUserInfo UserInfo where
7284 userInfo = id
7385
7486data User = User
75− { _uInfo' :: UserInfo
87+ { _uInfo :: UserInfo
7688 , _uRole :: Text
7789 , _uAvatarUrl :: Text
7890 , _uUrl :: Text
7991 , _uInvitationSent' :: !Bool'
8092 } deriving (Eq, Show)
8193
82−deriveRecord ''User
94+makeLenses ''User
95+
96+instance FromJSON User where
97+ parseJSON = withObject "user" $ \o ->
98+ User <$> parseJSON (Object o)
99+ <*> o .: "role"
100+ <*> o .: "avatar_url"
101+ <*> o .: "url"
102+ <*> o .: "invitation_sent"
103+
104+instance ToJSON User where
105+ toJSON u = Object (x <> y)
106+ where
107+ Object x = toJSON (_uInfo u)
108+ Object y = object
109+ [ "role" .= _uRole u
110+ , "avatar_url" .= _uAvatarUrl u
111+ , "url" .= _uUrl u
112+ , "invitation_sent" .= _uInvitationSent' u
113+ ]
83114
84115instance HasUserInfo User where
85− userInfo = uInfo'
116+ userInfo = uInfo
86117
87118uInvitationSent :: Lens' User Bool
88119uInvitationSent = uInvitationSent'._B
src/Network/PagerDuty/REST/Users/ContactMethods.hs+2
@@ -16,6 +16,8 @@
1616-- the user.
1717--
1818-- Access and manipulate the contact methods for a user.
19+--
20+-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/contact_methods>
1921module Network.PagerDuty.REST.Users.ContactMethods
2022 (
2123 ) where
src/Network/PagerDuty/REST/Users/NotificationRules.hs+2
@@ -16,6 +16,8 @@
1616-- long after the incident to do so.
1717--
1818-- Access and manipulate the notification rules for a user.
19+--
20+-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/notification_rules>
1921module Network.PagerDuty.REST.Users.NotificationRules
2022 (
2123 ) where
src/Network/PagerDuty/REST/Users/OnCall.hs+2
@@ -16,6 +16,8 @@
1616--
1717-- If the start and end of an on-call object are null, then the user is always
1818-- on-call for an escalation policy level.
19+--
20+-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/on_call>
1921module Network.PagerDuty.REST.Users.OnCall
2022 (
2123 ) where
src/Network/PagerDuty/REST/Webhooks.hs+2
@@ -21,6 +21,8 @@
2121-- certain interesting changes to an incident's state will cause other types of
2222-- incident webhook messages to be sent: Generally, any change to the @status@ or
2323-- @assigned_to_user@ of an incident will cause an outgoing message to be sent.
24+--
25+-- /See:/ <http://developer.pagerduty.com/documentation/rest/webhooks>
2426module Network.PagerDuty.REST.Webhooks
2527 (
2628