@@ -20,11 +20,50 @@
2020-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/contact_methods>
2121module Network.PagerDuty.REST.Users.ContactMethods
2222 (
23+ -- * List Contacts
24+ listContacts
25+
26+ -- * Create Contact
27+ , CreateContact
28+ , createContact
29+ , ccType
30+ , ccAddress
31+ , ccCountryCode
32+ , ccLabel
33+ , ccSendShortEmail
34+
35+ -- * Get Contact
36+ , getContact
37+
38+ -- * Update Contact
39+ , UpdateContact
40+ , updateContact
41+ , ucAddress
42+ , ucCountryCode
43+ , ucLabel
44+ , ucSendShortEmail
45+
46+ -- * Delete Contact
47+ , deleteContact
48+
49+ -- * Types
50+ , ContactType (..)
51+
52+ , Contact
53+ , cId
54+ , cUserId
55+ , cLabel
56+ , cAddress
57+ , cType
58+ , cCountryCode
59+ , cSendShortEmail
60+ , cBlacklisted
2361 ) where
2462
2563import Control.Lens
64+import Data.Aeson.Lens
2665import Data.Monoid
27−import Data.Text (Text)
66+import Data.Text (Text)
2867import Data.Time
2968import Network.HTTP.Types
3069import Network.PagerDuty.TH
@@ -33,16 +72,6 @@ import Network.PagerDuty.Types
3372contacts :: UserId -> Path
3473contacts u = "users" % u % "contact_methods"
3574
36−data Contact = Contact
37− { _cId :: ContactId
38− , _cUserId :: UserId
39− , _cLabel :: Text
40− , _cAddress :: Address
41− , _cType :: ContactType
42− , _cSendShortEmail :: Maybe Bool'
43− , _cBlacklisted :: Maybe Bool'
44− } deriving (Eq, Show)
45−
4675data ContactType
4776 = SMS
4877 | Phone
@@ -51,27 +80,76 @@ data ContactType
5180
5281deriveNullary ''ContactType
5382
54−Name Type Required Description
55−type String Yes The type of the contact method. One of SMS, email or phone.
56−address String Yes The id of the contact method. For SMS and phone it is the number, and for email it is the email address.
57−country_code Integer No The number code for your country. Not used for email. Defaults to 1.
58−label String No A human friendly label for the contact method. (ie: "Home Phone", "Work Email", etc.) Defaults to the type of the contact method and the address (with country code for phone numbers).
59−send_short_email Boolean No Send an abbreviated email message instead of the standard email output. Useful for email-to-SMS gateways and email based pagers. Only valid for email contact methods. Defaults to false.
83+data Contact = Contact
84+ { _cId :: ContactId
85+ , _cUserId :: UserId
86+ , _cLabel :: Text
87+ , _cAddress :: Address
88+ , _cType :: !ContactType
89+ , _cCountryCode :: Maybe Int
90+ , _cSendShortEmail :: Maybe Bool'
91+ , _cBlacklisted :: Maybe Bool'
92+ } deriving (Eq, Show)
6093
94+deriveRecord ''Contact
6195
6296-- | List existing contact methods for the specified user.
6397--
6498-- @GET \/users\/\:user_id\/contact_methods@
6599--
66100-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/contact_methods/list>
67−listContacts
101+listContacts :: UserId -> Request Empty s [Contact]
102+listContacts u = empty & path .~ contacts u
68103
69104-- | Get details for a contact method.
70105--
71106-- @GET \/users\/\:user_id\/contact_methods\/\:id@
72107--
73108-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/contact_methods/show>
74−getContact
109+getContact :: UserId -> ContactId -> Request Empty s Contact
110+getContact u c = empty & path .~ contacts u % c
111+
112+data CreateContact = CreateContact
113+ { _ccType' :: !ContactType
114+ , _ccAddress' :: Address
115+ , _ccCountryCode' :: Maybe Int
116+ , _ccLabel' :: Maybe Text
117+ , _ccSendShortEmail' :: Maybe Bool'
118+ } deriving (Eq, Show)
119+
120+jsonRequest ''CreateContact
121+
122+-- | The type of the contact method.
123+ccType :: Lens' (Request CreateContact s b) ContactType
124+ccType = upd.ccType'
125+
126+-- | The id of the contact method. For 'SMS' and 'Phone' it is the number, and for
127+-- 'Email' it is the email address.
128+ccAddress :: Lens' (Request CreateContact s b) Address
129+ccAddress = upd.ccAddress'
130+
131+-- | The number code for your country. Not used for 'Email'.
132+--
133+-- /Default:/ 1
134+ccCountryCode :: Lens' (Request CreateContact s b) (Maybe Int)
135+ccCountryCode = upd.ccCountryCode'
136+
137+-- | A human friendly label for the contact method.
138+--
139+-- /Example:/ "Home Phone", "Work Email", etc.
140+--
141+-- /Default:/ The type of the contact method and the address (with country code
142+-- for phone numbers).
143+ccLabel :: Lens' (Request CreateContact s b) (Maybe Text)
144+ccLabel = upd.ccLabel'
145+
146+-- | Send an abbreviated email message instead of the standard email
147+-- output. Useful for email-to-SMS gateways and email based pagers. Only valid for
148+-- 'Email' contact methods.
149+--
150+-- /Default:/ false.
151+ccSendShortEmail :: Lens' (Request CreateContact s b) (Maybe Bool)
152+ccSendShortEmail = upd.ccSendShortEmail'.mapping _B
75153
76154-- | Create a new contact method for a given user. A contact method can be one
77155-- of the following types: SMS, email, and phone. push_notification contact
@@ -83,18 +161,78 @@ getContact
83161-- /Note:/ The contact info must be unique.
84162--
85163-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/contact_methods/create>
86−createContact
164+createContact :: UserId
165+ -> ContactType
166+ -> Address
167+ -> Request CreateContact s Contact
168+createContact u t a =
169+ mk CreateContact
170+ { _ccType' = t
171+ , _ccAddress' = a
172+ , _ccCountryCode' = Nothing
173+ , _ccLabel' = Nothing
174+ , _ccSendShortEmail' = Nothing
175+ } & meth .~ POST
176+ & path .~ contacts u
177+ & unwrap .~ key "contact_method"
178+
179+data UpdateContact = UpdateContact
180+ { _ucAddress' :: Maybe Address
181+ , _ucCountryCode' :: Maybe Int
182+ , _ucLabel' :: Maybe Text
183+ , _ucSendShortEmail' :: Maybe Bool'
184+ } deriving (Eq, Show)
185+
186+jsonRequest ''UpdateContact
187+
188+-- | The id of the contact method. For 'SMS' and 'Phone' it is the number, and for
189+-- 'Email' it is the email address.
190+ucAddress :: Lens' (Request UpdateContact s b) (Maybe Address)
191+ucAddress = upd.ucAddress'
192+
193+-- | The number code for your country. Not used for 'Email'.
194+--
195+-- /Default:/ 1
196+ucCountryCode :: Lens' (Request UpdateContact s b) (Maybe Int)
197+ucCountryCode = upd.ucCountryCode'
198+
199+-- | A human friendly label for the contact method.
200+--
201+-- /Example:/ "Home Phone", "Work Email", etc.
202+--
203+-- /Default:/ The type of the contact method and the address (with country code
204+-- for phone numbers).
205+ucLabel :: Lens' (Request UpdateContact s b) (Maybe Text)
206+ucLabel = upd.ucLabel'
207+
208+-- | Send an abbreviated email message instead of the standard email
209+-- output. Useful for email-to-SMS gateways and email based pagers. Only valid for
210+-- 'Email' contact methods.
211+--
212+-- /Default:/ false.
213+ucSendShortEmail :: Lens' (Request UpdateContact s b) (Maybe Bool)
214+ucSendShortEmail = upd.ucSendShortEmail'.mapping _B
87215
88216-- | Update an existing contact method of a given user. Note that you cannot change the type of an existing method.
89217--
90218-- @PUT \/users\/\:user_id\/contact_methods\/\:id@
91219--
92220-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/contact_methods/update>
93−updateContact
221+updateContact :: UserId -> ContactId -> Request UpdateContact s Contact
222+updateContact u c =
223+ mk UpdateContact
224+ { _ucAddress' = Nothing
225+ , _ucCountryCode' = Nothing
226+ , _ucLabel' = Nothing
227+ , _ucSendShortEmail' = Nothing
228+ } & meth .~ PUT
229+ & path .~ contacts u % c
230+ & unwrap .~ key "contact_method"
94231
95232-- | Remove a contact method and any corresponding notification rules.
96233--
97234-- @DELETE \/users\/\:user_id\/contact_methods\/\:id@
98235--
99236-- /See:/ <http://developer.pagerduty.com/documentation/rest/users/contact_methods/delete>
100−deleteContact
237+deleteContact :: UserId -> ContactId -> Request Empty s Empty
238+deleteContact u c = empty & meth .~ DELETE & path .~ contacts u % c