@@ -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