git.iko.soy/typeable/pagerduty
on develop help sign in
Updating Services API with correct body/query serialisation
bc04851Brendan Hay
pagerduty.cabal+6−6
@@ -30,17 +30,17 @@ library
30 ghc-options: -Wall
30 ghc-options: -Wall
31
31
32 exposed-modules:
32 exposed-modules:
33−-- Control.Monad.Trans.PagerDuty
33+ Control.Monad.Trans.PagerDuty
34− -- , Network.PagerDuty.Integration
34+ , Network.PagerDuty.Integration
35− -- , Network.PagerDuty.REST
35+ , Network.PagerDuty.REST
36−-- Network.PagerDuty.REST.Alerts
36+ , Network.PagerDuty.REST.Alerts
37 -- , Network.PagerDuty.REST.EscalationPolicies
37 -- , Network.PagerDuty.REST.EscalationPolicies
38 -- , Network.PagerDuty.REST.Incidents
38 -- , Network.PagerDuty.REST.Incidents
39− Network.PagerDuty.REST.LogEntries
39+ , Network.PagerDuty.REST.LogEntries
40 -- , Network.PagerDuty.REST.MaintenanceWindows
40 -- , Network.PagerDuty.REST.MaintenanceWindows
41 , Network.PagerDuty.REST.Reports
41 , Network.PagerDuty.REST.Reports
42 -- , Network.PagerDuty.REST.Schedules
42 -- , Network.PagerDuty.REST.Schedules
43− -- , Network.PagerDuty.REST.Services
43+ , Network.PagerDuty.REST.Services
44 -- , Network.PagerDuty.REST.Users
44 -- , Network.PagerDuty.REST.Users
45 -- , Network.PagerDuty.REST.Webhooks
45 -- , Network.PagerDuty.REST.Webhooks
46
46
src/Network/PagerDuty/REST/Alerts.hs+2−1
@@ -44,6 +44,7 @@ module Network.PagerDuty.REST.Alerts
44
44
45import Control.Lens
45import Control.Lens
46import Data.Aeson.Lens
46import Data.Aeson.Lens
47+import Data.Time
47import Network.PagerDuty.TH
48import Network.PagerDuty.TH
48import Network.PagerDuty.Types
49import Network.PagerDuty.Types
49
50
@@ -117,4 +118,4 @@ laFilter = upd.laFilter'
117--
118--
118-- Defaults to account time zone.
119-- Defaults to account time zone.
119laTimeZone :: Lens' (Request ListAlerts s r) (Maybe TimeZone)
120laTimeZone :: Lens' (Request ListAlerts s r) (Maybe TimeZone)
120−laTimeZone = upd.laTimeZone'._TZ
121+laTimeZone = upd.laTimeZone'.mapping _TZ
src/Network/PagerDuty/REST/Services.hs+64−64
@@ -2,6 +2,7 @@
2{-# LANGUAGE ExtendedDefaultRules #-}
2{-# LANGUAGE ExtendedDefaultRules #-}
3{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE TemplateHaskell #-}
4{-# LANGUAGE TemplateHaskell #-}
5+{-# LANGUAGE TypeFamilies #-}
5
6
6{-# OPTIONS_GHC -fno-warn-type-defaults #-}
7{-# OPTIONS_GHC -fno-warn-type-defaults #-}
7
8
@@ -139,8 +140,7 @@ data IncidentCounts = IncidentCounts
139 , _cntTotal :: !Int
140 , _cntTotal :: !Int
140 } deriving (Eq, Show)
141 } deriving (Eq, Show)
141
142
142−deriveJSON ''IncidentCounts
143−makeLenses ''IncidentCounts
143+deriveRecord ''IncidentCounts
144
144
145data EmailIncidentCreation
145data EmailIncidentCreation
146 = OnNewEmail
146 = OnNewEmail
@@ -151,7 +151,7 @@ data EmailIncidentCreation
151 -- ^ Open a new incident only if an open incident does not already exist.
151 -- ^ Open a new incident only if an open incident does not already exist.
152 deriving (Eq, Show)
152 deriving (Eq, Show)
153
153
154−deriveJSON ''EmailIncidentCreation
154+deriveNullary ''EmailIncidentCreation
155
155
156data EmailFilterMode
156data EmailFilterMode
157 = AllEmail
157 = AllEmail
@@ -162,7 +162,7 @@ data EmailFilterMode
162 -- ^ Accept email only if it matches ALL of the rules below
162 -- ^ Accept email only if it matches ALL of the rules below
163 deriving (Eq, Show)
163 deriving (Eq, Show)
164
164
165−deriveJSONWith hyphenated ''EmailFilterMode
165+deriveNullaryWith hyphenated ''EmailFilterMode
166
166
167data ServiceStatus
167data ServiceStatus
168 = Active
168 = Active
@@ -178,7 +178,7 @@ data ServiceStatus
178 -- ^ The service is disabled and will not have any new triggered incidents.
178 -- ^ The service is disabled and will not have any new triggered incidents.
179 deriving (Eq, Show)
179 deriving (Eq, Show)
180
180
181−deriveJSON ''ServiceStatus
181+deriveNullary ''ServiceStatus
182
182
183data ServiceType
183data ServiceType
184 = CloudKick
184 = CloudKick
@@ -191,15 +191,14 @@ data ServiceType
191 | SqlMonitor
191 | SqlMonitor
192 deriving (Eq, Show)
192 deriving (Eq, Show)
193
193
194−deriveJSON ''ServiceType
194+deriveNullary ''ServiceType
195
195
196data PolicyInfo = PolicyInfo
196data PolicyInfo = PolicyInfo
197 { _pinfoId :: PolicyId
197 { _pinfoId :: PolicyId
198 , _pinfoName :: Text
198 , _pinfoName :: Text
199 } deriving (Eq, Show)
199 } deriving (Eq, Show)
200
200
201−makeLenses ''PolicyInfo
202−deriveJSON ''PolicyInfo
201+deriveRecord ''PolicyInfo
203
202
204data MatchMode
203data MatchMode
205 = Always
204 = Always
@@ -207,7 +206,7 @@ data MatchMode
207 | NoMatch
206 | NoMatch
208 deriving (Eq, Show)
207 deriving (Eq, Show)
209
208
210−deriveJSONWith hyphenated ''MatchMode
209+deriveNullaryWith hyphenated ''MatchMode
211
210
212-- FIXME: Tighten up this type! Make the regex required for match/no-match.
211-- FIXME: Tighten up this type! Make the regex required for match/no-match.
213data EmailFilters = EmailFilters
212data EmailFilters = EmailFilters
@@ -271,7 +270,7 @@ data SeverityFilter
271 -- ^ SQL Monitor: Incidents are created for with high or medium severity
270 -- ^ SQL Monitor: Incidents are created for with high or medium severity
272 deriving (Eq, Show)
271 deriving (Eq, Show)
273
272
274−deriveJSONWith (dropped 3 underscored) ''SeverityFilter
273+deriveNullaryWith (dropped 3 underscored) ''SeverityFilter
275
274
276data Service = Service
275data Service = Service
277 { _svcId :: ServiceId
276 { _svcId :: ServiceId
@@ -321,13 +320,17 @@ makeLens "_svcAutoResolveTimeout" ''Service
321makeLens "_svcAcknowledgementTimeout" ''Service
320makeLens "_svcAcknowledgementTimeout" ''Service
322
321
323-- | The date/time when this service was created.
322-- | The date/time when this service was created.
324−makeLens "_svcCreatedAt" ''Service
323+svcCreatedAt :: Lens' Service UTCTime
324+svcCreatedAt = lens _svcCreatedAt (\s x -> s { _svcCreatedAt = x }) . _Date
325
325
326-- | The current state of the Service.
326-- | The current state of the Service.
327makeLens "_svcStatus" ''Service
327makeLens "_svcStatus" ''Service
328
328
329-- | The date/time when the most recent incident was created for this service.
329-- | The date/time when the most recent incident was created for this service.
330−makeLens "_svcLastIncidentTimestamp" ''Service
330+svcLastIncidentTimestamp :: Lens' Service (Maybe UTCTime)
331+svcLastIncidentTimestamp =
332+ lens _svcLastIncidentTimestamp
333+ (\s x -> s { _svcLastIncidentTimestamp = x }) . mapping _Date
331
334
332-- | If the service is a Generic Email service, this describes what kind of
335-- | If the service is a Generic Email service, this describes what kind of
333-- emails create an incident.
336-- emails create an incident.
@@ -360,8 +363,13 @@ newtype ListServices = ListServices
360
363
361instance Paginate ListServices
364instance Paginate ListServices
362
365
363−deriveJSON ''ListServices
366+deriveQuery ''ListServices
364−makeLenses ''ListServices
367+
368+-- | Time zone in which dates in the result will be rendered.
369+--
370+-- Defaults to account default time zone.
371+lsTimeZone :: Lens' (Request ListServices s r) (Maybe TimeZone)
372+lsTimeZone = upd.lsTimeZone'.mapping _TZ
365
373
366-- | List existing services.
374-- | List existing services.
367--
375--
@@ -376,12 +384,6 @@ listServices =
376 & query .~ includes
384 & query .~ includes
377 & unwrap .~ key "escalation_policies"
385 & unwrap .~ key "escalation_policies"
378
386
379−-- | Time zone in which dates in the result will be rendered.
380−--
381−-- Defaults to account default time zone.
382−lsTimeZone :: Lens' (Request ListServices s r) (Maybe TimeZone)
383−lsTimeZone = upd.lsTimeZone'._TZ
384−
385data CreateService = CreateService
387data CreateService = CreateService
386 { _csName' :: Text
388 { _csName' :: Text
387 , _csEscalationPolicyId' :: PolicyId
389 , _csEscalationPolicyId' :: PolicyId
@@ -393,30 +395,7 @@ data CreateService = CreateService
393 , _csSeverityFilter' :: Maybe SeverityFilter
395 , _csSeverityFilter' :: Maybe SeverityFilter
394 } deriving (Eq, Show)
396 } deriving (Eq, Show)
395
397
396−deriveJSON ''CreateService
397−makeLenses ''CreateService
398+deriveBody ''CreateService
398−
399−-- | Creates a new service.
400−--
401−-- @POST \/services@
402−--
403−-- See: <http://developer.pagerduty.com/documentation/rest/services/create>
404−createService :: Text
405− -> PolicyId
406− -> ServiceType
407− -> Request CreateService s Service
408−createService n p t =
409− mk CreateService
410− { _csName' = n
411− , _csEscalationPolicyId' = p
412− , _csType' = t
413− , _csVendorId' = Nothing
414− , _csDescription' = Nothing
415− , _csAcknowledgementTimeout' = Nothing
416− , _csAutoResolveTimeout' = Nothing
417− , _csSeverityFilter' = Nothing
418− } & path .~ services
419− & unwrap .~ key "service"
420
399
421-- | The name of the service.
400-- | The name of the service.
422csName :: Lens' (Request CreateService s r) Text
401csName :: Lens' (Request CreateService s r) Text
@@ -456,6 +435,28 @@ csAutoResolveTimeout = upd.csAutoResolveTimeout'
456csSeverityFilter :: Lens' (Request CreateService s r) (Maybe SeverityFilter)
435csSeverityFilter :: Lens' (Request CreateService s r) (Maybe SeverityFilter)
457csSeverityFilter = upd.csSeverityFilter'
436csSeverityFilter = upd.csSeverityFilter'
458
437
438+-- | Creates a new service.
439+--
440+-- @POST \/services@
441+--
442+-- See: <http://developer.pagerduty.com/documentation/rest/services/create>
443+createService :: Text
444+ -> PolicyId
445+ -> ServiceType
446+ -> Request CreateService s Service
447+createService n p t =
448+ mk CreateService
449+ { _csName' = n
450+ , _csEscalationPolicyId' = p
451+ , _csType' = t
452+ , _csVendorId' = Nothing
453+ , _csDescription' = Nothing
454+ , _csAcknowledgementTimeout' = Nothing
455+ , _csAutoResolveTimeout' = Nothing
456+ , _csSeverityFilter' = Nothing
457+ } & path .~ services
458+ & unwrap .~ key "service"
459+
459-- | Get details about an existing service.
460-- | Get details about an existing service.
460--
461--
461-- @GET services\/\:id@
462-- @GET services\/\:id@
@@ -476,26 +477,7 @@ data UpdateService = UpdateService
476 , _usSeverityFilter' :: Maybe SeverityFilter
477 , _usSeverityFilter' :: Maybe SeverityFilter
477 } deriving (Eq, Show)
478 } deriving (Eq, Show)
478
479
479−deriveJSON ''UpdateService
480−makeLenses ''UpdateService
480+deriveBody ''UpdateService
481−
482−-- | Update an existing service.
483−--
484−-- @PUT services\/\:id@
485−--
486−-- See: <http://developer.pagerduty.com/documentation/rest/services/update>
487−updateService :: ServiceId -> Request UpdateService s Service
488−updateService i =
489− mk UpdateService
490− { _usName' = Nothing
491− , _usEscalationPolicyId' = Nothing
492− , _usDescription' = Nothing
493− , _usAcknowledgementTimeout' = Nothing
494− , _usAutoResolveTimeout' = Nothing
495− , _usSeverityFilter' = Nothing
496− } & meth .~ PUT
497− & path .~ services % i
498− & unwrap .~ key "service"
499
481
500-- | The name of the service.
482-- | The name of the service.
501usName :: Lens' (Request UpdateService s r) (Maybe Text)
483usName :: Lens' (Request UpdateService s r) (Maybe Text)
@@ -526,6 +508,24 @@ usAutoResolveTimeout = upd.usAutoResolveTimeout'
526usSeverityFilter :: Lens' (Request UpdateService s r) (Maybe SeverityFilter)
508usSeverityFilter :: Lens' (Request UpdateService s r) (Maybe SeverityFilter)
527usSeverityFilter = upd.usSeverityFilter'
509usSeverityFilter = upd.usSeverityFilter'
528
510
511+-- | Update an existing service.
512+--
513+-- @PUT services\/\:id@
514+--
515+-- See: <http://developer.pagerduty.com/documentation/rest/services/update>
516+updateService :: ServiceId -> Request UpdateService s Service
517+updateService i =
518+ mk UpdateService
519+ { _usName' = Nothing
520+ , _usEscalationPolicyId' = Nothing
521+ , _usDescription' = Nothing
522+ , _usAcknowledgementTimeout' = Nothing
523+ , _usAutoResolveTimeout' = Nothing
524+ , _usSeverityFilter' = Nothing
525+ } & meth .~ PUT
526+ & path .~ services % i
527+ & unwrap .~ key "service"
528+
529-- | Delete an existing service. Once the service is deleted, it will not be
529-- | Delete an existing service. Once the service is deleted, it will not be
530-- accessible from the web UI and new incidents won't be able to be created
530-- accessible from the web UI and new incidents won't be able to be created
531-- for this service.
531-- for this service.
src/Network/PagerDuty/TH.hs+6−2
@@ -14,6 +14,7 @@ module Network.PagerDuty.TH
14 (
14 (
15 -- * Compound expressions
15 -- * Compound expressions
16 deriveNullary
16 deriveNullary
17+ , deriveNullaryWith
17 , deriveRecord
18 , deriveRecord
18 , deriveQuery
19 , deriveQuery
19 , deriveBody
20 , deriveBody
@@ -49,8 +50,11 @@ import Network.PagerDuty.Generics
49import Network.PagerDuty.Options
50import Network.PagerDuty.Options
50
51
51deriveNullary :: Name -> Q [Dec]
52deriveNullary :: Name -> Q [Dec]
53+deriveNullary = deriveNullaryWith underscored
54+
55+deriveNullaryWith :: Options -> Name -> Q [Dec]
52−deriveNullary n = concat <$> sequence
56+deriveNullaryWith o n = concat <$> sequence
53− [ deriveJSON n
57+ [ deriveJSONWith o n
54 , [d|instance QueryValueLike $(conT n) where toQueryValue = value . toJSON|]
58 , [d|instance QueryValueLike $(conT n) where toQueryValue = value . toJSON|]
55 ]
59 ]
56
60