git.iko.soy/typeable/pagerduty
on develop help sign in
Adding Notes REST API
37d618dBrendan Hay
pagerduty.cabal+2−2
@@ -38,8 +38,8 @@ library
38 -- , Network.PagerDuty.REST.EscalationPolicies
38 -- , Network.PagerDuty.REST.EscalationPolicies
39-- , Network.PagerDuty.REST.EscalationPolicies.EscalationRules
39-- , Network.PagerDuty.REST.EscalationPolicies.EscalationRules
40-- , Network.PagerDuty.REST.EscalationPolicies.OnCall
40-- , Network.PagerDuty.REST.EscalationPolicies.OnCall
41− , Network.PagerDuty.REST.Incidents
41+ -- , Network.PagerDuty.REST.Incidents
42− , Network.PagerDuty.REST.Incidents.Notes
42+ -- , Network.PagerDuty.REST.Incidents.Notes
43 -- , Network.PagerDuty.REST.LogEntries
43 -- , Network.PagerDuty.REST.LogEntries
44 -- , Network.PagerDuty.REST.MaintenanceWindows
44 -- , Network.PagerDuty.REST.MaintenanceWindows
45 -- , Network.PagerDuty.REST.Reports
45 -- , Network.PagerDuty.REST.Reports
src/Network/PagerDuty/REST.hs+2
@@ -39,6 +39,8 @@ import Network.PagerDuty.Types
39
39
40-- FIXME: verify correct actions are all paginated
40-- FIXME: verify correct actions are all paginated
41
41
42+-- FIXME: Ensure requesterid parameter is always first
43+
42send :: (MonadIO m, FromJSON b)
44send :: (MonadIO m, FromJSON b)
43 => Auth s
45 => Auth s
44 -> SubDomain
46 -> SubDomain
src/Network/PagerDuty/REST/Incidents/Notes.hs+85−4
@@ -1,5 +1,8 @@
1+{-# LANGUAGE ExtendedDefaultRules #-}
1−{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE TemplateHaskell #-}
3+{-# LANGUAGE TemplateHaskell #-}
4+
5+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
3
6
4-- Module : Network.PagerDuty.REST.Incidents.Notes
7-- Module : Network.PagerDuty.REST.Incidents.Notes
5-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
8-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
@@ -16,12 +19,90 @@
16-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/notes>
19-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/notes>
17module Network.PagerDuty.REST.Incidents.Notes
20module Network.PagerDuty.REST.Incidents.Notes
18 (
21 (
22+ -- * List Notes
23+ listNotes
24+
25+ -- * Create Note
26+ , CreateNote
27+ , createNote
28+ , createNoteBasic
29+ , cnContent
30+
31+ -- * Types
32+ , Note
33+ , nId
34+ , nCreatedAt
35+ , nUser
36+ , nContent
19 ) where
37 ) where
20
38
21−import Control.Lens
39+import Control.Lens hiding ((.=))
22−import Data.Monoid
40+import Data.Aeson
23import Data.Text (Text)
41import Data.Text (Text)
24import Data.Time
42import Data.Time
25import Network.HTTP.Types
43import Network.HTTP.Types
44+import Network.PagerDuty.REST.Users
26import Network.PagerDuty.TH
45import Network.PagerDuty.TH
27import Network.PagerDuty.Types
46import Network.PagerDuty.Types
47+
48+default (Path)
49+
50+notes :: IncidentId -> Path
51+notes i = "incidents" % i % "notes"
52+
53+data Note = Note
54+ { _nId :: NoteId
55+ , _nCreatedAt :: Date
56+ , _nUser :: User
57+ , _nContent :: Text
58+ } deriving (Eq, Show)
59+
60+deriveJSON ''Note
61+
62+makeLens "_nId" ''Note
63+makeLens "_nUser" ''Note
64+makeLens "_nContent" ''Note
65+
66+nCreatedAt :: Lens' Note UTCTime
67+nCreatedAt = lens _nCreatedAt (\n x -> n { _nCreatedAt = x }) . _D
68+
69+-- | List existing notes for the specified incident.
70+--
71+-- @GET \/incidents\/\:incident_id\/notes@
72+--
73+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/notes/create>
74+listNotes :: IncidentId -> Request Empty s [Note]
75+listNotes i = empty & path .~ notes i
76+
77+newtype CreateNote = CreateNote
78+ { _cnContent' :: Maybe Text
79+ } deriving (Eq, Show)
80+
81+makeLenses ''CreateNote
82+
83+instance ToJSON CreateNote where
84+ toJSON cn = object ["note" .= object ["content" .= _cnContent' cn]]
85+
86+instance QueryLike CreateNote where
87+ toQuery = const []
88+
89+-- | The note content.
90+cnContent :: Lens' (Request CreateNote s b) (Maybe Text)
91+cnContent = upd.cnContent'
92+
93+-- | Create a new note for the specified incident.
94+--
95+-- @POST \/incidents\/\:incident_id\/notes@
96+--
97+-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/notes/create>
98+createNote :: IncidentId -> RequesterId -> Request CreateNote s Note
99+createNote i r = auth (createNoteBasic i) & query .~ [("requester_id", r)]
100+
101+-- | A version of 'createNote' which uses HTTP Basic authentication and
102+-- doesn't require a 'RequesterId'.
103+createNoteBasic :: IncidentId -> Request CreateNote s Note
104+createNoteBasic i =
105+ mk CreateNote
106+ { _cnContent' = Nothing
107+ } & meth .~ POST
108+ & path .~ notes i
src/Network/PagerDuty/Types.hs+2−1
@@ -399,7 +399,9 @@ instance QueryValueLike (Id a) where
399
399
400type AlertId = Id "alert"
400type AlertId = Id "alert"
401type EmailFilterId = Id "email-filter"
401type EmailFilterId = Id "email-filter"
402+type IncidentId = Id "incident"
402type LogEntryId = Id "log-entry"
403type LogEntryId = Id "log-entry"
404+type NoteId = Id "note"
403type OverrideId = Id "schedule-override"
405type OverrideId = Id "schedule-override"
404type PolicyId = Id "escalation-policy"
406type PolicyId = Id "escalation-policy"
405type RequesterId = Id "requester"
407type RequesterId = Id "requester"
@@ -409,7 +411,6 @@ type ServiceId = Id "service"
409type UserId = Id "user"
411type UserId = Id "user"
410type VendorId = Id "vendor"
412type VendorId = Id "vendor"
411type WindowId = Id "maintenance-window"
413type WindowId = Id "maintenance-window"
412−type IncidentId = Id "incident"
413
414
414data Empty = Empty
415data Empty = Empty
415
416