@@ -1,5 +1,8 @@
1+{-# LANGUAGE ExtendedDefaultRules #-}
1−{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE TemplateHaskell #-}
3+{-# LANGUAGE TemplateHaskell #-}
5+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
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
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
50+notes :: IncidentId -> Path
51+notes i = "incidents" % i % "notes"
55+ , _nCreatedAt :: Date
58+ } deriving (Eq, Show)
62+makeLens "_nId" ''Note
63+makeLens "_nUser" ''Note
64+makeLens "_nContent" ''Note
66+nCreatedAt :: Lens' Note UTCTime
67+nCreatedAt = lens _nCreatedAt (\n x -> n { _nCreatedAt = x }) . _D
69+-- | List existing notes for the specified incident.
71+-- @GET \/incidents\/\:incident_id\/notes@
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
77+newtype CreateNote = CreateNote
78+ { _cnContent' :: Maybe Text
79+ } deriving (Eq, Show)
81+makeLenses ''CreateNote
83+instance ToJSON CreateNote where
84+ toJSON cn = object ["note" .= object ["content" .= _cnContent' cn]]
86+instance QueryLike CreateNote where
89+-- | The note content.
90+cnContent :: Lens' (Request CreateNote s b) (Maybe Text)
91+cnContent = upd.cnContent'
93+-- | Create a new note for the specified incident.
95+-- @POST \/incidents\/\:incident_id\/notes@
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)]
101+-- | A version of 'createNote' which uses HTTP Basic authentication and
102+-- doesn't require a 'RequesterId'.
103+createNoteBasic :: IncidentId -> Request CreateNote s Note
106+ { _cnContent' = Nothing