git.iko.soy/typeable/pagerduty
on develop help sign in
Adding Notes REST API
commit37d618dfd0c4e9e7de7580f75d2aeb40c17e95d3 authorBrendan Hay <brendan.g.hay@gmail.com> dateTue 7 Oct 2014, 15:37 (12 years ago) parenta06b1fe
4 files changed+91−7
pagerduty.cabal+2−2 src/Network/PagerDuty/REST.hs+2 src/Network/PagerDuty/REST/Incidents/Notes.hs+85−4 src/Network/PagerDuty/Types.hs+2−1
pagerduty.cabal+2−2
@@ -38,8 +38,8 @@ library
3838 -- , Network.PagerDuty.REST.EscalationPolicies
3939-- , Network.PagerDuty.REST.EscalationPolicies.EscalationRules
4040-- , Network.PagerDuty.REST.EscalationPolicies.OnCall
41− , Network.PagerDuty.REST.Incidents
42− , Network.PagerDuty.REST.Incidents.Notes
41+ -- , Network.PagerDuty.REST.Incidents
42+ -- , Network.PagerDuty.REST.Incidents.Notes
4343 -- , Network.PagerDuty.REST.LogEntries
4444 -- , Network.PagerDuty.REST.MaintenanceWindows
4545 -- , Network.PagerDuty.REST.Reports
src/Network/PagerDuty/REST.hs+2
@@ -39,6 +39,8 @@ import Network.PagerDuty.Types
3939
4040-- FIXME: verify correct actions are all paginated
4141
42+-- FIXME: Ensure requesterid parameter is always first
43+
4244send :: (MonadIO m, FromJSON b)
4345 => Auth s
4446 -> SubDomain
src/Network/PagerDuty/REST/Incidents/Notes.hs+85−4
@@ -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.Incidents.Notes
58-- Copyright : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
@@ -16,12 +19,90 @@
1619-- /See:/ <http://developer.pagerduty.com/documentation/rest/incidents/notes>
1720module Network.PagerDuty.REST.Incidents.Notes
1821 (
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
1937 ) where
2038
21−import Control.Lens
22−import Data.Monoid
39+import Control.Lens hiding ((.=))
40+import Data.Aeson
2341import Data.Text (Text)
2442import Data.Time
2543import Network.HTTP.Types
44+import Network.PagerDuty.REST.Users
2645import Network.PagerDuty.TH
2746import 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
399399
400400type AlertId = Id "alert"
401401type EmailFilterId = Id "email-filter"
402+type IncidentId = Id "incident"
402403type LogEntryId = Id "log-entry"
404+type NoteId = Id "note"
403405type OverrideId = Id "schedule-override"
404406type PolicyId = Id "escalation-policy"
405407type RequesterId = Id "requester"
@@ -409,7 +411,6 @@ type ServiceId = Id "service"
409411type UserId = Id "user"
410412type VendorId = Id "vendor"
411413type WindowId = Id "maintenance-window"
412−type IncidentId = Id "incident"
413414
414415data Empty = Empty
415416