@@ -1,6 +1,9 @@
1−{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE TemplateHaskell #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE ExtendedDefaultRules #-}
3+{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE TemplateHaskell #-}
5+
6+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
47
58-- Module : Network.PagerDuty.Services
69-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
@@ -30,10 +33,10 @@ module Network.PagerDuty.Services
3033 -- * Create Service
3134 , createService
3235 , csName
33− , csEscalationPolicyId
36+ , csDescription
3437 , csType
3538 , csVendorId
36− , csDescription
39+ , csEscalationPolicyId
3740 , csAcknowledgementTimeout
3841 , csAutoResolveTimeout
3942 , csSeverityFilter
@@ -43,6 +46,12 @@ module Network.PagerDuty.Services
4346
4447 -- * Update Service
4548 , updateService
49+ , usName
50+ , usEscalationPolicyId
51+ , usDescription
52+ , usAcknowledgementTimeout
53+ , usAutoResolveTimeout
54+ , usSeverityFilter
4655
4756 -- * Delete Service
4857 , deleteService
@@ -105,14 +114,17 @@ module Network.PagerDuty.Services
105114
106115import Control.Lens
107116import Data.Aeson.Lens
117+import Data.ByteString.Builder (Builder)
108118import Data.Text (Text)
109119import Network.HTTP.Types
110120import Network.PagerDuty.Services.Types
111121import Network.PagerDuty.TH
112122import Network.PagerDuty.Types
113123
114−services :: Setter (Request a s r) (Request a s r) Path [Path]
115−services = base "services"
124+default (Builder)
125+
126+services :: Path
127+services = "services"
116128
117129includes :: Query
118130includes =
@@ -138,9 +150,9 @@ listServices :: Request ListServices Token [Service]
138150listServices =
139151 mk ListServices
140152 { _lsTimeZone' = Nothing
141− } & services .~ []
142− & unwrap .~ key "escalation_policies"
143− & query <>~ includes
153+ } & path .~ services
154+ & query <>~ includes
155+ & unwrap .~ key "escalation_policies"
144156
145157-- | Time zone in which dates in the result will be rendered.
146158--
@@ -181,16 +193,16 @@ createService n p t =
181193 , _csAcknowledgementTimeout' = Nothing
182194 , _csAutoResolveTimeout' = Nothing
183195 , _csSeverityFilter' = Nothing
184− } & services .~ []
185− & unwrap .~ key "service"
196+ } & path .~ services
197+ & unwrap .~ key "service"
186198
187199-- | The name of the service.
188200csName :: Lens' (Request CreateService s r) Text
189201csName = upd.csName'
190202
191−-- | The id of the escalation policy to be used by this service.
192−csEscalationPolicyId :: Lens' (Request CreateService s r) PolicyId
193−csEscalationPolicyId = upd.csEscalationPolicyId'
203+-- | A description for your service. 1024 character maximum.
204+csDescription :: Lens' (Request CreateService s r) (Maybe Text)
205+csDescription = upd.csDescription'
194206
195207-- | The type of service to create.
196208csType :: Lens' (Request CreateService s r) ServiceType
@@ -201,9 +213,9 @@ csType = upd.csType'
201213csVendorId :: Lens' (Request CreateService s r) (Maybe VendorId)
202214csVendorId = upd.csVendorId'
203215
204−-- | A description for your service. 1024 character maximum.
205−csDescription :: Lens' (Request CreateService s r) (Maybe Text)
206−csDescription = upd.csDescription'
216+-- | The id of the escalation policy to be used by this service.
217+csEscalationPolicyId :: Lens' (Request CreateService s r) PolicyId
218+csEscalationPolicyId = upd.csEscalationPolicyId'
207219
208220-- | The duration in seconds before an incidents acknowledged in this service
209221-- become triggered again.
@@ -229,15 +241,14 @@ csSeverityFilter = upd.csSeverityFilter'
229241-- See: <http://developer.pagerduty.com/documentation/rest/services/show>
230242getService :: ServiceId -> Request Empty Token Service
231243getService i = empty
232− & services .~ [P i]
233− & unwrap .~ key "service"
234− & query <>~ includes
244+ & path .~ services % i
245+ & query <>~ includes
246+ & unwrap .~ key "service"
235247
236248data UpdateService = UpdateService
237− { _usName' :: Text
238− , _usEscalationPolicyId' :: PolicyId
239− , _usType' :: !ServiceType
249+ { _usName' :: Maybe Text
240250 , _usDescription' :: Maybe Text
251+ , _usEscalationPolicyId' :: Maybe PolicyId
241252 , _usAcknowledgementTimeout' :: Maybe Int
242253 , _usAutoResolveTimeout' :: Maybe Int
243254 , _usSeverityFilter' :: Maybe SeverityFilter
@@ -251,36 +262,31 @@ makeLenses ''UpdateService
251262-- @PUT services\/\:id@
252263--
253264-- See: <http://developer.pagerduty.com/documentation/rest/services/update>
254−updateService ServiceId -> Request UpdateService Token Service
265+updateService :: ServiceId -> Request UpdateService Token Service
255266updateService i =
256267 mk UpdateService
257− { _usName' = n
258− , _usEscalationPolicyId' = p
259− , _usType' = t
268+ { _usName' = Nothing
269+ , _usEscalationPolicyId' = Nothing
260270 , _usDescription' = Nothing
261271 , _usAcknowledgementTimeout' = Nothing
262272 , _usAutoResolveTimeout' = Nothing
263273 , _usSeverityFilter' = Nothing
264− } & services .~ [P i]
265− & unwrap .~ key "service"
274+ } & meth .~ PUT
275+ & path .~ services % i
276+ & unwrap .~ key "service"
266277
267278-- | The name of the service.
268−usName :: Lens' (Request UpdateService s r) Text
279+usName :: Lens' (Request UpdateService s r) (Maybe Text)
269280usName = upd.usName'
270281
271−-- | The id of the escalation policy to be used by this service.
272−usEscalationPolicyId :: Lens' (Request UpdateService s r) PolicyId
273−usEscalationPolicyId = upd.usEscalationPolicyId'
274−
275−-- | PagerDuty's internal vendor identifier for this service. For more information
276−-- about a specific vendor, please contact PagerDuty Support.
277−usVendorId :: Lens' (Request UpdateService s r) (Maybe VendorId)
278−usVendorId = upd.usVendorId'
279−
280282-- | A description for your service. 1024 character maximum.
281283usDescription :: Lens' (Request UpdateService s r) (Maybe Text)
282284usDescription = upd.usDescription'
283285
286+-- | The id of the escalation policy to be used by this service.
287+usEscalationPolicyId :: Lens' (Request UpdateService s r) (Maybe PolicyId)
288+usEscalationPolicyId = upd.usEscalationPolicyId'
289+
284290-- | The duration in seconds before an incidents acknowledged in this service
285291-- become triggered again.
286292--
@@ -306,15 +312,20 @@ usSeverityFilter = upd.usSeverityFilter'
306312--
307313-- See: <http://developer.pagerduty.com/documentation/rest/services/delete>
308314deleteService :: ServiceId -> Request Empty Token Empty
309−deleteService i = empty & services .~ [P i] & meth .~ DELETE
315+deleteService i = empty & meth .~ DELETE & path .~ services % i
310316
311317-- | Enable a previously disabled service.
312318--
313319-- @PUT services\/\:id\/enable@
314320--
315321-- See: <http://developer.pagerduty.com/documentation/rest/services/enable>
316−enableService :: ServiceId -> Request Empty Token Empty
317−enableService i = empty & services .~ [P i, "enable"] & meth .~ PUT
322+enableService :: RequesterId -> ServiceId -> Request Empty s Empty
323+enableService r i = auth (enableServiceBasic i) & query .~ [("requester_id", r)]
324+
325+-- | A version of 'enableService' which uses HTTP Basic authentication and
326+-- doesn't require a 'RequesterId'.
327+enableServiceBasic :: ServiceId -> Request Empty Basic Empty
328+enableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "enable"
318329
319330-- | Disable a service. Once a service is disabled, it will not be able to
320331-- create incidents until it is enabled again.
@@ -322,8 +333,13 @@ enableService i = empty & services .~ [P i, "enable"] & meth .~ PUT
322333-- @PUT services\/\:id\/disable@
323334--
324335-- See: <http://developer.pagerduty.com/documentation/rest/services/disable>
325−disableService :: ServiceId -> Request Empty Token Empty
326−disableService i = empty & services .~ [P i, "disable"] & meth .~ PUT
336+disableService :: RequesterId -> ServiceId -> Request Empty s Empty
337+disableService r i = auth (disableServiceBasic i) & query .~ [("requester_id", r)]
338+
339+-- | A version of 'disableService' which uses HTTP Basic authentication and
340+-- doesn't require a 'RequesterId'.
341+disableServiceBasic :: ServiceId -> Request Empty Basic Empty
342+disableServiceBasic i = empty & meth .~ PUT & path .~ services % i % "disable"
327343
328344-- | Regenerate a new service key for an existing service.
329345--
@@ -333,5 +349,5 @@ disableService i = empty & services .~ [P i, "disable"] & meth .~ PUT
333349-- @POST services\/\:id\/regenerate_key@
334350--
335351-- See: <http://developer.pagerduty.com/documentation/rest/services/regenerate_key>
336−regenerateKey :: ServiceId -> Request Empty Token Service
337−regenerateKey i = empty & services .~ [P i, "regenerate_key"] & meth .~ POST
352+regenerateKey :: ServiceId -> Request Empty s Service
353+regenerateKey i = empty & meth .~ POST & path .~ services % i % "regenerate_key"