git.iko.soy/typeable/pagerduty
on develop help sign in
Adding Get and Update Service operations
commit0624660c46e33a2c076a92979bb768a4a90cfdee authorBrendan Hay <brendan.g.hay@gmail.com> dateTue 30 Sep 2014, 07:39 (12 years ago) parenta3e5bad
2 files changed+73−6
src/Network/PagerDuty/Services.hs+70−6 src/Network/PagerDuty/Types.hs+3
src/Network/PagerDuty/Services.hs+70−6
@@ -222,17 +222,81 @@ csAutoResolveTimeout = upd.csAutoResolveTimeout'
222222csSeverityFilter :: Lens' (Request CreateService s r) (Maybe SeverityFilter)
223223csSeverityFilter = upd.csSeverityFilter'
224224
225+-- | Get details about an existing service.
225226--
226227-- @GET services\/\:id@
227228--
228229-- See: <http://developer.pagerduty.com/documentation/rest/services/show>
229−getService = undefined
230+getService :: ServiceId -> Request Empty Token Service
231+getService i = empty
232+ & services .~ [P i]
233+ & unwrap .~ key "service"
234+ & query <>~ includes
235+
236+data UpdateService = UpdateService
237+ { _usName' :: Text
238+ , _usEscalationPolicyId' :: PolicyId
239+ , _usType' :: !ServiceType
240+ , _usDescription' :: Maybe Text
241+ , _usAcknowledgementTimeout' :: Maybe Int
242+ , _usAutoResolveTimeout' :: Maybe Int
243+ , _usSeverityFilter' :: Maybe SeverityFilter
244+ } deriving (Eq, Show)
245+
246+deriveJSON ''UpdateService
247+makeLenses ''UpdateService
230248
249+-- | Update an existing service.
231250--
232251-- @PUT services\/\:id@
233252--
234253-- See: <http://developer.pagerduty.com/documentation/rest/services/update>
235−updateService = undefined
254+updateService ServiceId -> Request UpdateService Token Service
255+updateService i =
256+ mk UpdateService
257+ { _usName' = n
258+ , _usEscalationPolicyId' = p
259+ , _usType' = t
260+ , _usDescription' = Nothing
261+ , _usAcknowledgementTimeout' = Nothing
262+ , _usAutoResolveTimeout' = Nothing
263+ , _usSeverityFilter' = Nothing
264+ } & services .~ [P i]
265+ & unwrap .~ key "service"
266+
267+-- | The name of the service.
268+usName :: Lens' (Request UpdateService s r) Text
269+usName = upd.usName'
270+
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+
280+-- | A description for your service. 1024 character maximum.
281+usDescription :: Lens' (Request UpdateService s r) (Maybe Text)
282+usDescription = upd.usDescription'
283+
284+-- | The duration in seconds before an incidents acknowledged in this service
285+-- become triggered again.
286+--
287+-- Defaults to 30 minutes.
288+usAcknowledgementTimeout :: Lens' (Request UpdateService s r) (Maybe Int)
289+usAcknowledgementTimeout = upd.usAcknowledgementTimeout'
290+
291+-- | The duration in seconds before a triggered incident auto-resolves itself.
292+--
293+-- Defaults to 4 hours.
294+usAutoResolveTimeout :: Lens' (Request UpdateService s r) (Maybe Int)
295+usAutoResolveTimeout = upd.usAutoResolveTimeout'
296+
297+-- | Specifies what severity levels will create a new open incident.
298+usSeverityFilter :: Lens' (Request UpdateService s r) (Maybe SeverityFilter)
299+usSeverityFilter = upd.usSeverityFilter'
236300
237301-- | Delete an existing service. Once the service is deleted, it will not be
238302-- accessible from the web UI and new incidents won't be able to be created
@@ -242,7 +306,7 @@ updateService = undefined
242306--
243307-- See: <http://developer.pagerduty.com/documentation/rest/services/delete>
244308deleteService :: ServiceId -> Request Empty Token Empty
245−deleteService i = mk Empty & services .~ [P i] & meth .~ DELETE
309+deleteService i = empty & services .~ [P i] & meth .~ DELETE
246310
247311-- | Enable a previously disabled service.
248312--
@@ -250,7 +314,7 @@ deleteService i = mk Empty & services .~ [P i] & meth .~ DELETE
250314--
251315-- See: <http://developer.pagerduty.com/documentation/rest/services/enable>
252316enableService :: ServiceId -> Request Empty Token Empty
253−enableService i = mk Empty & services .~ [P i, "enable"] & meth .~ PUT
317+enableService i = empty & services .~ [P i, "enable"] & meth .~ PUT
254318
255319-- | Disable a service. Once a service is disabled, it will not be able to
256320-- create incidents until it is enabled again.
@@ -259,7 +323,7 @@ enableService i = mk Empty & services .~ [P i, "enable"] & meth .~ PUT
259323--
260324-- See: <http://developer.pagerduty.com/documentation/rest/services/disable>
261325disableService :: ServiceId -> Request Empty Token Empty
262−disableService i = mk Empty & services .~ [P i, "disable"] & meth .~ PUT
326+disableService i = empty & services .~ [P i, "disable"] & meth .~ PUT
263327
264328-- | Regenerate a new service key for an existing service.
265329--
@@ -270,4 +334,4 @@ disableService i = mk Empty & services .~ [P i, "disable"] & meth .~ PUT
270334--
271335-- See: <http://developer.pagerduty.com/documentation/rest/services/regenerate_key>
272336regenerateKey :: ServiceId -> Request Empty Token Service
273−regenerateKey i = mk Empty & services .~ [P i, "regenerate_key"] & meth .~ POST
337+regenerateKey i = empty & services .~ [P i, "regenerate_key"] & meth .~ POST
src/Network/PagerDuty/Types.hs+3
@@ -236,6 +236,9 @@ type Unwrap = Getting (First Value) Value Value
236236mk :: ToJSON a => a -> Request a s r
237237mk x = Request x GET E mempty Nothing pure
238238
239+empty :: Request Empty s r
240+empty = mk Empty
241+
239242-- | Modify the request state.
240243upd :: ToJSON a => Lens' (Request a s r) a
241244upd = lens _rqPayload (\(Request _ m p q g u) x -> Request x m p q g u)