pagerduty-sdk 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ class Notes
2
+ include Virtus.model
3
+
4
+ attribute :notes, Array[Note]
5
+ end
6
+
7
+
@@ -26,24 +26,25 @@ class Pagerduty
26
26
  #end
27
27
 
28
28
  def log_entries(options={})
29
- LogEntries.new(JSON.parse(curl({
29
+ LogEntries.new(curl({
30
30
  uri: "https://#@@subdomain.pagerduty.com/api/v1/users/#{self.id}/log_entries",
31
31
  params: options,
32
32
  method: 'GET'
33
- }).body))
33
+ }))
34
34
  end
35
35
 
36
36
  def delete
37
37
  res = curl({
38
38
  uri: "https://#@@subdomain.pagerduty.com/api/v1/users/#{self.id}",
39
- method: 'DELETE'
39
+ method: 'DELETE',
40
+ raw_response: true
40
41
  })
41
42
 
42
43
  res.code == '204' ? "Successfully deleted User #{self.id}" : JSON.parse(response.body)
43
44
  end
44
45
 
45
46
  def save
46
- saved_user = User.new(JSON.parse(curl({
47
+ saved_user = User.new(curl({
47
48
  uri: "https://#@@subdomain.pagerduty.com/api/v1/users/#{self.id}",
48
49
  data: {
49
50
  role: self.role,
@@ -52,7 +53,7 @@ class Pagerduty
52
53
  time_zone: self.time_zone
53
54
  },
54
55
  method: 'PUT'
55
- }).body)['user'])
56
+ })['user'])
56
57
 
57
58
  self.role = saved_user.role
58
59
  self.name = saved_user.name
@@ -1,6 +1,8 @@
1
1
 
2
2
  class Pagerduty
3
3
 
4
+ include Pagerduty::Core
5
+
4
6
  attr_reader :token
5
7
  attr_reader :subdomain
6
8
 
@@ -9,83 +11,49 @@ class Pagerduty
9
11
  @@subdomain = options[:subdomain]
10
12
  end
11
13
 
12
- ###################################################################################
13
- # def curl
14
- #
15
- # Purpose: Performs a CURL request
16
- #
17
- # Params: options<~Hash> - The options Hash to send
18
- # uri<~String> - The URI to curl
19
- # ssl<~Boolean><Optional> - Whether or not to use SSL
20
- # port<~Integer><Optional> - The port number to connect to
21
- # params<~Hash><Optional> - The params to send in the curl request
22
- # headers<~Hash><Optional> - The headers to send in the curl request
23
- # method<~String> - The HTTP method to perform
24
- # basic_auth<~Hash><Optional>
25
- # user<~String> - Basic auth user
26
- # password<~String> - Basic auth password
27
- #
28
- # Returns: <String>
29
- ###################################################################################
30
- def curl(options)
31
-
32
- curl_request = {
33
- ssl: true,
34
- port: 443,
35
- headers: {
36
- "Content-Type" => "application/json",
37
- "Authorization" => "Token token=#@@token",
38
- },
39
- }
40
-
41
- options.merge! curl_request
42
-
43
- url = URI.parse(options[:uri])
44
-
45
- if options[:params]
46
- parameters = options[:params].map { |k,v| "#{k}=#{v}" }.join("&")
47
- url += "?#{parameters}"
48
- end
49
-
50
- http = Net::HTTP.new(url.host, 443)
51
- http.use_ssl = true
52
-
53
- request = case options[:method]
54
- when 'DELETE'
55
- Net::HTTP::Delete.new(url)
56
- when 'GET'
57
- Net::HTTP::Get.new(url)
58
- when 'POST'
59
- Net::HTTP::Post.new(url)
60
- when 'PUT'
61
- Net::HTTP::Put.new(url)
62
- end
63
-
64
- if options.has_key?(:data)
65
- request.set_form_data(options[:data])
66
- end
67
-
68
- if options.has_key?(:basic_auth)
69
- request.basic_auth options[:basic_auth][:user], options[:basic_auth][:password]
70
- end
71
-
72
- request.body = options[:body]
73
-
74
- options[:headers].each { |key,val| request.add_field(key,val) }
75
-
76
- if options[:method] == 'POST'
77
- http.post(url.path,options[:data].to_json,options[:headers])
78
- elsif options[:method] == 'PUT'
79
- http.put(url.path,options[:data].to_json,options[:headers])
80
- else
81
- http.request(request)
82
- end
83
- end
84
14
 
15
+ # Check a Hash object for expected keys
16
+ #
17
+ # ==== Parameters
18
+ # * 'keys'<~Array><~Object> - An array of objects expected to be found as keys in the supplied Hash
19
+ # * 'options'<~Hash> - The Hash to perform the check on
20
+ #
21
+ # ==== Returns
22
+ # * Boolean
23
+ #
85
24
  def has_requirements?(keys,options)
86
25
  (keys - options.keys).empty?
87
26
  end
88
27
 
28
+
29
+ # List existing alerts for a given time range, optionally filtered by type (SMS, Email, Phone, or Push)
30
+ #
31
+ # ==== Parameters
32
+ # * params<~Hash>
33
+ # * 'since'<~String>: The start of the date range over which you want to search. The time element is optional.
34
+ # * 'until'<~String>: The end of the date range over which you want to search. This should be in the same format as since. The size of the date range must be less than 3 months.
35
+ # * 'filter'<~String>: Returns only the alerts of the said types. Can be one of SMS, Email, Phone, or Push.
36
+ # * 'time_zone'<~TimeZone>: Time zone in which dates in the result will be rendered. Defaults to account time zone.
37
+ #
38
+ # ==== Returns
39
+ # * 'alerts'<~Array><~Alerts>
40
+ # * 'id'<~String>
41
+ # * 'type'<~String>
42
+ # * 'started_at'<~String>
43
+ # * 'user'<~Pagerduty::User>
44
+ # * 'id'<~String>
45
+ # * 'name'<~String>
46
+ # * 'email'<~String>
47
+ # * 'time_zone'<~String>
48
+ # * 'color'<~String>
49
+ # * 'avatar_url'<~String>
50
+ # * 'user_url'<~String>
51
+ # * 'invitation_sent'<~Boolean>
52
+ # * 'marketing'<~String>
53
+ # * 'marketing_opt_out'<~String>
54
+ # * 'type'<~String>
55
+ #
56
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/alerts/list]
89
57
  def alerts(options={})
90
58
 
91
59
  unless has_requirements? [:since, :until], options
@@ -94,26 +62,106 @@ class Pagerduty
94
62
  return
95
63
  end
96
64
 
97
- JSON.parse(curl({
65
+ Alerts.new(curl({
98
66
  uri: "https://#@@subdomain.pagerduty.com/api/v1/alerts",
99
67
  params: options,
100
68
  method: 'GET'
101
- }).body)['alerts'].inject([]) { |alerts, alert|
102
- alerts << Alert.new(alert)
103
- }
104
-
69
+ }))
105
70
  end
106
71
 
72
+ # List all the existing escalation policies.
73
+ #
74
+ # ==== Parameters
75
+ # * params<~Hash>
76
+ # * 'query'<~String> - Filters the result, showing only the escalation policies whose names match the query.
77
+ # * 'include'<~Array> - An array of extra data to include with the escalation policies.
78
+ #
79
+ # ==== Returns
80
+ # * <~Array>
81
+ # * <~EscalationPolicy>
82
+ # * 'id'<~String> - Id of request
83
+ # * 'name'<~String> - The policy name
84
+ # * 'escalation_rules'<~Array><~EscalationRule>
85
+ # * 'escalation_delay_in_minutes'<~Integer> - The escalation delay in minutes
86
+ # * 'rule_object'<~RuleObject>:
87
+ # * 'id'<~String> - The id of the rule object
88
+ # * 'name'<~String> - The name of the rule
89
+ # * 'type'<~String> - The type of rule
90
+ # * 'email'<~String> - The email address associated with the rule
91
+ # * 'time_zone'<~String> - The time zone for the rule
92
+ # * 'color'<~String> - The display color of the rule
93
+ # * 'services'<~Array><~EscalationService>:
94
+ # * 'id'<~String> -
95
+ # * 'name'<~String> -
96
+ # * 'service_url'<~String> -
97
+ # * 'service_key'<~String> -
98
+ # * 'auto_resolve_timeout'<~String> -
99
+ # * 'acknowledgement_timeout'<~String> -
100
+ # * 'created_at'<~String> -
101
+ # * 'deleted_at'<~String> -
102
+ # * 'status'<~String> -
103
+ # * 'last_incident_timestamp'<~String> -
104
+ # * 'email_incident_creation'<~String> -
105
+ # * 'incident_counts'<~String> -
106
+ # * 'email_filter_mode'<~String> -
107
+ # * 'type'<~String> -
108
+ # * 'num_loops'<~Integer> - The number of times to loop the incident
109
+ # * 'limit'<~Integer>
110
+ # * 'offset'<~Integer>
111
+ # * 'total'<~Integer>
112
+ #
113
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/escalation_policies/list]
107
114
  def escalation_policies(options={})
108
- JSON.parse(curl({
115
+ curl({
109
116
  uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies",
110
117
  params: { 'query' => options[:query] },
111
118
  method: 'GET'
112
- }).body)['escalation_policies'].inject([]) { |policies, policy|
119
+ })['escalation_policies'].inject([]) { |policies, policy|
113
120
  policies << EscalationPolicy.new(policy)
114
121
  }
115
122
  end
116
123
 
124
+ # Creates a new escalation policy. There must be at least one existing
125
+ # escalation rule added to create a new escalation policy
126
+ #
127
+ # ==== Parameters
128
+ # * params<~Hash>
129
+ # * 'name'<~String> - The desired name for the escalation policy
130
+ # * 'repeat_enabled'<~Boolean> - Whether or not to allow this policy to repeat its escalation rules after the last rule is finished. Defaults to false.
131
+ # * 'num_loops'<~Integer> - The number of times to loop over the set of rules in this escalation policy.
132
+ # * 'escalation_rules'<~Array> - The escalation rules for this policy. The ordering and available parameters are found under the Escalation Rules API. There must be at least one rule to create a new escalation policy.
133
+ #
134
+ # ==== Returns
135
+ # * response<~EscalationPolicy>:
136
+ # * 'id'<~String> - Id of request
137
+ # * 'name'<~String> - The policy name
138
+ # * 'escalation_rules'<~Array><~EscalationRule>
139
+ # * 'escalation_delay_in_minutes'<~Integer> - The escalation delay in minutes
140
+ # * 'rule_object'<~RuleObject>:
141
+ # * 'id'<~String> - The id of the rule object
142
+ # * 'name'<~String> - The name of the rule
143
+ # * 'type'<~String> - The type of rule
144
+ # * 'email'<~String> - The email address associated with the rule
145
+ # * 'time_zone'<~String> - The time zone for the rule
146
+ # * 'color'<~String> - The display color of the rule
147
+ # * 'services'<~Array><~EscalationService>:
148
+ # * 'id'<~String> -
149
+ # * 'name'<~String> -
150
+ # * 'service_url'<~String> -
151
+ # * 'service_key'<~String> -
152
+ # * 'auto_resolve_timeout'<~String> -
153
+ # * 'acknowledgement_timeout'<~String> -
154
+ # * 'created_at'<~String> -
155
+ # * 'deleted_at'<~String> -
156
+ # * 'status'<~String> -
157
+ # * 'last_incident_timestamp'<~String> -
158
+ # * 'email_incident_creation'<~String> -
159
+ # * 'incident_counts'<~String> -
160
+ # * 'email_filter_mode'<~String> -
161
+ # * 'type'<~String> -
162
+ # * 'num_loops'<~Integer> - The number of times to loop the incident
163
+ #
164
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/escalation_policies/create]
117
165
  def create_escalation_policy(options={})
118
166
 
119
167
  if options[:escalation_rules]
@@ -122,45 +170,121 @@ class Pagerduty
122
170
  }
123
171
  end
124
172
 
125
- EscalationPolicy.new(JSON.parse(curl({
173
+ EscalationPolicy.new(curl({
126
174
  uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies",
127
175
  data: options,
128
176
  method: 'POST'
129
- }).body)['escalation_policy'])
177
+ })['escalation_policy'])
130
178
 
131
179
  end
132
180
 
181
+ # Get information about an existing escalation policy and its rules
182
+ #
183
+ # ==== Parameters
184
+ #
185
+ # * params<~Hash>
186
+ # * 'id'<~String>: The id of the escalation policy
187
+ #
188
+ # ==== Returns
189
+ # * response<Array><~Pagerduty::EscalationPolicy>:
190
+ # * 'id'<~String> - Id of request
191
+ # * 'name'<~String> - The name of the policy
192
+ # * 'description'<~String> - Policy description
193
+ # * 'escalation_rules'<~Array><~RuleObject>:
194
+ # * 'id'<~String> - The id of the rule object
195
+ # * 'name'<~String> - The name of the rule
196
+ # * 'type'<~String> - The type of rule
197
+ # * 'email'<~String> - The email address associated with the rule
198
+ # * 'time_zone'<~String> - The time zone for the rule
199
+ # * 'color'<~String> - The display color of the rule
200
+ # * 'services'<~Array><~EscalationService>:
201
+ # * 'id'<~String> -
202
+ # * 'name'<~String> -
203
+ # * 'service_url'<~String> -
204
+ # * 'service_key'<~String> -
205
+ # * 'auto_resolve_timeout'<~String> -
206
+ # * 'acknowledgement_timeout'<~String> -
207
+ # * 'created_at'<~String> -
208
+ # * 'deleted_at'<~String> -
209
+ # * 'status'<~String> -
210
+ # * 'last_incident_timestamp'<~String> -
211
+ # * 'email_incident_creation'<~String> -
212
+ # * 'incident_counts'<~String> -
213
+ # * 'email_filter_mode'<~String> -
214
+ # * 'type'<~String> -
215
+ # * 'num_loops'<~Integer> - The number of times to loop the incident
216
+ #
217
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/escalation_policies/show]
133
218
  def get_escalation_policy(options={})
134
- EscalationPolicy.new(JSON.parse(curl({
219
+ EscalationPolicy.new(curl({
135
220
  uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies/#{options[:id]}",
136
221
  method: 'GET'
137
- }).body)['escalation_policy'])
222
+ })['escalation_policy'])
138
223
  end
139
224
 
225
+ # List all the escalation rules for an existing escalation policy
226
+ #
227
+ # ==== Parameters
228
+ #
229
+ # * params<~Hash>
230
+ # * 'escalation_policy_id'<~String>: The id of the escalation policy
231
+ #
232
+ # ==== Returns
233
+ # * response<Array><~Pagerduty::EscalationRule>:
234
+ # * 'id'<~String> - Id of request
235
+ # * 'escalation_delay_in_minutes'<~Integer> - The escalation delay in minutes
236
+ # * <~RuleObject>:
237
+ # * 'id'<~String> - The id of the rule object
238
+ # * 'name'<~String> - The name of the rule
239
+ # * 'type'<~String> - The type of rule
240
+ # * 'email'<~String> - The email address associated with the rule
241
+ # * 'time_zone'<~String> - The time zone for the rule
242
+ # * 'color'<~String> - The display color of the rule
243
+ #
244
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/escalation_policies/escalation_rules/list]
140
245
  def escalation_rules(options)
141
- JSON.parse(curl({
246
+ curl({
142
247
  uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies/#{options[:escalation_policy_id]}/escalation_rules",
143
248
  params: { 'query' => options[:query] },
144
249
  method: 'GET'
145
- }).body)['escalation_rules'].inject([]) { |rules, rule|
250
+ })['escalation_rules'].inject([]) { |rules, rule|
146
251
  rules << EscalationRule.new(rule)
147
252
  }
148
253
  end
149
254
 
255
+ # Show the escalation rule for an existing escalation policy
256
+ #
257
+ # ==== Parameters
258
+ # * params<~Hash>
259
+ # * 'escalation_policy_id'<~String>: The id of the escalation policy the rule resides in
260
+ # * 'rule_id'<~String>: The id of the rule to retrieve
261
+ #
262
+ # ==== Returns
263
+ # * response<~Pagerduty::EscalationRule>:
264
+ # * 'id'<~String> - Id of request
265
+ # * 'escalation_delay_in_minutes'<~Integer> - The escalation delay in minutes
266
+ # * <~RuleObject>:
267
+ # * 'id'<~String> - The id of the rule object
268
+ # * 'name'<~String> - The name of the rule
269
+ # * 'type'<~String> - The type of rule
270
+ # * 'email'<~String> - The email address associated with the rule
271
+ # * 'time_zone'<~String> - The time zone for the rule
272
+ # * 'color'<~String> - The display color of the rule
273
+ #
274
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/escalation_policies/escalation_rules/show]
150
275
  def get_escalation_rule(options={})
151
- JSON.parse(curl({
276
+ EscalationRule.new(curl({
152
277
  uri: "https://#@@subdomain.pagerduty.com/api/v1/escalation_policies/#{options[:escalation_policy_id]}/escalation_rules/#{options[:rule_id]}",
153
278
  method: 'GET'
154
- }).body)
279
+ })['escalation_rule'])
155
280
  end
156
281
 
157
282
  # Retrieve all incidents
158
283
  #
159
284
  # ==== Parameters
160
- #
161
285
  # * params<~Hash>
162
- # * 'since'<~String>: The start of the date range over which to search
163
- # * 'until'<~String>: The end of the date range over which to search
286
+ # * 'since'<~String>: The start of the date range over which you want to search. The time element is optional.
287
+ # * 'until'<~String>: The end of the date range over which you want to search. This should be in the same format as since. The size of the date range must be less than 3 months.
164
288
  # * 'date_range'<~String>: When set to 'all' the 'since' and 'until' params are ignored. Use this to get all incidents since the account was created
165
289
  # * 'fields'<~String>: Used to restrict the properties of each incident returned to a set of pre-defined fields. If omitted, returned incidents have all fields present. See below for a list of possible fields.
166
290
  # * 'status'<~String>: Returns only the incidents currently in the passed status(es). Valid status options are triggered, acknowledged, and resolved. More status codes may be introduced in the future.
@@ -204,163 +328,788 @@ class Pagerduty
204
328
  #
205
329
  # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/incidents/list]
206
330
  def incidents(options={})
207
- JSON.parse(curl({
331
+
332
+ Pagerduty::Incidents.new(curl({
208
333
  uri: "https://#@@subdomain.pagerduty.com/api/v1/incidents",
209
334
  params: {
210
335
  since: options[:since] || (Time.now - 1.day).strftime("%Y-%m-%d"),
211
336
  :until => options[:until] || (Time.now + 1.day).strftime("%Y-%m-%d"),
212
337
  },
213
338
  method: 'GET'
214
- }).body)['incidents'].inject([]) { |incidents, incident|
215
- incidents << Incident.new(incident)
216
- }
339
+ }))
217
340
  end
218
341
 
342
+
343
+ # Show detailed information about an incident. Accepts either an incident id, or an incident number
344
+ #
345
+ # ==== Parameters
346
+ # options<~Hash>
347
+ # * 'id'<~String> - The incident id or incident number to look for
348
+ #
349
+ # ==== Returns
350
+ # * <~Pagerduty::Incident>:
351
+ # * 'id'<~String> - Id of request
352
+ # * 'incident_number'<~String>:
353
+ # * 'created_on'<~String>:
354
+ # * 'status'<~String>:
355
+ # * 'html_url'<~String>:
356
+ # * 'incident_key'<~String>:
357
+ # * 'service'<~Pagerduty::Service>
358
+ # * 'id'<~String>:
359
+ # * 'name'<~String>:
360
+ # * 'html_url'<~String>:
361
+ # * 'deleted_at'<~String>:
362
+ # * 'escalation_policy'<~String>:
363
+ # * 'assigned_to_user'<~String>:
364
+ # * 'trigger_summary_data'<~String>:
365
+ # * 'trigger_details_html_url'<~String>:
366
+ # * 'trigger_type'<~String>:
367
+ # * 'last_status_change_on'<~String>:
368
+ # * 'last_status_change_by'<~Pagerduty::User>:
369
+ # * 'id'<~String>:
370
+ # * 'name'<~String>:
371
+ # * 'email'<~String>:
372
+ # * 'html_url'<~String>:
373
+ # * 'number_of_escalations'<~Integer>:
374
+ # * 'resolved_by_user'<~Pagerduty::ResolvedByUser>:
375
+ # * 'id'<~String>:
376
+ # * 'name'<~String>:
377
+ # * 'email'<~String>:
378
+ # * 'html_url'<~String>:
379
+ #
380
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/incidents/show]
219
381
  def get_incident(options={})
220
- incidents.detect { |incident| incident.id == options[:id] } || 'No results'
382
+ incidents.incidents.detect { |incident|
383
+ incident.id == options[:id] || incident.incident_number == options[:id]
384
+ } || 'No results'
221
385
  end
222
386
 
387
+ # Use this query if you are simply looking for the count of incidents that match a given query. This should be used if you don't need access to the actual incident details.
388
+ #
389
+ # ==== Parameters
390
+ # * options<~Hash>:
391
+ # * 'since'<~String> - The start of the date range over which you want to search. The time element is optional.
392
+ # * 'until'<~String> - The end of the date range over which you want to search. This should be in the same format as since. The size of the date range must be less than 3 months.
393
+ # * 'date_range'<~String> - When set to all, the since and until parameters and defaults are ignored. Use this to get all counts since the account was created.
394
+ # * 'status'<~String> - Only counts the incidents currently in the passed status(es). Valid status options are triggered, acknowledged, and resolved. More status codes may be introduced in the future.
395
+ # * 'incident_key'<~String> - Only counts the incidents with the passed de-duplication key. See the PagerDuty Integration API docs for further details.
396
+ # * 'service'<~String> - Only counts the incidents associated with the passed service(s). This is expecting one or more service IDs. Separate multiple ids by a comma.
397
+ # * 'assigned_to_user'<~String> - Only counts the incidents currently assigned to the passed user(s). This is expecting one or more user IDs. Note: When using the assigned_to_user filter, you will only count incidents with statuses of triggered or acknowledged. This is because resolved incidents are not assigned to any user. Separate multiple ids by a comma.
398
+ #
399
+ # ==== Returns
400
+ # <~Hash>
401
+ # * 'total'<~Integer>
402
+ #
403
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/incidents/count]
223
404
  def get_incident_counts(options={})
224
- JSON.parse(curl({
405
+ curl({
225
406
  uri: "https://#@@subdomain.pagerduty.com/api/v1/incidents/count",
226
407
  params: options,
227
408
  method: 'GET',
228
- }).body)
409
+ })
229
410
  end
230
411
 
412
+ # List users of your PagerDuty account, optionally filtered by a search query.
413
+ #
414
+ # ==== Parameters
415
+ # * options<~Hash>:
416
+ # * 'query'<~String> - Filters the result, showing only the users whose names or email addresses match the query
417
+ # * 'include'<~Array> - Array of additional details to include. This API accepts contact_methods, and notification_rules
418
+ #
419
+ # ==== Returns
420
+ # * <~Users>
421
+ # * 'users'<~Array>:
422
+ # * 'user'<~Pagerduty::User>:
423
+ # * 'id'<~String>
424
+ # * 'name'<~String>
425
+ # * 'email'<~String>
426
+ # * 'time_zone'<~String>
427
+ # * 'color'<~String>
428
+ # * 'role'<~String>
429
+ # * 'avatar_url'<~String>
430
+ # * 'user_url'<~String>
431
+ # * 'invitation_sent'<~Boolean>
432
+ # * 'marketing'<~String>
433
+ # * 'marketing_opt_out'<~String>
434
+ # * 'type'<~String>
435
+ # * 'active_account_users'<~Integer>
436
+ # * 'limit'<~Integer>
437
+ # * 'offset'<~Integer>
438
+ # * 'total'<~Integer>
439
+ #
440
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/users/list]
231
441
  def get_users(options={})
232
- Users.new(JSON.parse(curl({
442
+ Users.new(curl({
233
443
  uri: "https://#@@subdomain.pagerduty.com/api/v1/users",
234
- params: { query: options[:query] },
444
+ params: options,
235
445
  method: 'GET'
236
- }).body))
446
+ }))
237
447
  end
238
448
 
449
+ # Get information about an existing user.
450
+ #
451
+ # ==== Parameters
452
+ # * options<~Hash>:
453
+ # * 'id'<~String> - The ID of the user to retrieve
454
+ #
455
+ # ==== Returns
456
+ # * 'user'<~User>:
457
+ # * 'time_zone'<~String>
458
+ # * 'color'<~String>
459
+ # * 'email'<~String>
460
+ # * 'avatar_url'<~String>
461
+ # * 'user_url'<~String>
462
+ # * 'invitation_sent'<~Boolean>
463
+ # * 'role'<~String>
464
+ # * 'name'<~String>
465
+ # * 'id'<~String>
466
+ #
467
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/users/show]
239
468
  def get_user(options={})
240
469
  get_users.users.detect { |user| user.id == options[:id] }
241
470
  end
242
471
 
472
+ # Create a new user for your account. An invite email will be sent asking the user to choose a password
473
+ #
474
+ # ==== Parameters
475
+ # * options<~Hash>:
476
+ # * 'role'<~String> - The user's role. This can either be admin or user and defaults to user if not specificed
477
+ # * 'name'<~String> - The name of the user
478
+ # * 'email'<~String> - The email of the user. The newly created user will receive an email asking to confirm the subscription
479
+ # * 'time_zone'<~String> - The time zone the user is in. If not specified, the time zone of the account making the API call will be used
480
+ # * 'requester_id'<~String> - The user id of the user creating the user. This is only needed if you are using token based authentication
481
+ #
482
+ # ==== Returns
483
+ # * 'user'<~User>
484
+ # * 'time_zone'<~String>
485
+ # * 'color'<~String>
486
+ # * 'email'<~String>
487
+ # * 'avatar_url'<~String>
488
+ # * 'user_url'<~String>
489
+ # * 'invitation_sent'<~String>
490
+ # * 'role'<~String>
491
+ # * 'name'<~String>
492
+ # * 'id'<~String>
493
+ #
494
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/users/create]
243
495
  def create_user(options={})
244
- User.new(JSON.parse(curl({
496
+ User.new(curl({
245
497
  uri: "https://#@@subdomain.pagerduty.com/api/v1/users",
246
498
  data: options,
247
499
  method: 'POST'
248
- }).body)['user'])
500
+ })['user'])
249
501
  end
250
502
 
503
+ # List existing notes for the specified incident.
504
+ #
505
+ # ==== Parameters
506
+ # * options<~Hash>:
507
+ # * 'id' - The id of the incident to retrieve notes from
508
+ #
509
+ # ==== Returns
510
+ # * <~Notes>:
511
+ # * 'notes'<~Array>:
512
+ # * ~<Note>:
513
+ # * 'id' -
514
+ # * 'user'<~Pagerduty::User>:
515
+ # * 'id'<~String>
516
+ # * 'name'<~String>
517
+ # * 'email'<~String>
518
+ # * 'time_zone'<~String>
519
+ # * 'color'<~String>
520
+ # * 'role'<~String>
521
+ # * 'avatar_url'<~String>
522
+ # * 'user_url'<~String>
523
+ # * 'invitation_sent'<~Boolean>
524
+ # * 'marketing'<~String>
525
+ # * 'marketing_opt_out'<~String>
526
+ # * 'type'<~String>
527
+ # * 'content'<~String> -
528
+ # * 'created_at'<~String> -
529
+ #
530
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/incidents/notes/list]
251
531
  def notes(id)
252
- JSON.parse(curl({
532
+ Notes.new(curl({
253
533
  uri: "https://#@@subdomain.pagerduty.com/api/v1/incidents/#{id}/notes",
254
534
  method: 'GET'
255
- }).body)['notes'].inject([]) { |notes, note|
256
- notes << Note.new(note)
257
- }
535
+ }))
258
536
  end
259
537
 
538
+
539
+ # List all incident log entries across the entire account
540
+ #
541
+ # ==== Parameters
542
+ # * options<~Hash>:
543
+ # * 'time_zone'<~String> -
544
+ # * 'since'<~String> - The start of the date range over which you want to search. The time element is optional.
545
+ # * 'until'<~String> - The end of the date range over which you want to search. This should be in the same format as since. The size of the date range must be less than 3 months.
546
+ # * 'is_overview'<~Boolean> -
547
+ # * 'until'<~Array> - The end of the date range over which you want to search. This should be in the same format as since. The size of the date range must be less than 3 months.
548
+ # * 'include'<~Array> - The end of the date range over which you want to search. This should be in the same format as since. The size of the date range must be less than 3 months.
549
+ #
550
+ # ==== Returns
551
+ # * 'log_entries'<~Array>:
552
+ # * <~Pagerduty::LogEntry>:
553
+ # * 'id'<~String> -
554
+ # * 'type'<~String> -
555
+ # * 'created_at'<~String> -
556
+ # * 'note'<~String> -
557
+ # * 'agent'<~Pagerduty::User>
558
+ # * 'id'<~String>
559
+ # * 'name'<~String>
560
+ # * 'email'<~String>
561
+ # * 'time_zone'<~String>
562
+ # * 'color'<~String>
563
+ # * 'role'<~String>
564
+ # * 'avatar_url'<~String>
565
+ # * 'user_url'<~String>
566
+ # * 'invitation_sent'<~Boolean>
567
+ # * 'marketing'<~String>
568
+ # * 'marketing_opt_out'<~String>
569
+ # * 'type'<~String>
570
+ # * 'user'<~Pagerduty::User>
571
+ # * 'id'<~String>
572
+ # * 'name'<~String>
573
+ # * 'email'<~String>
574
+ # * 'time_zone'<~String>
575
+ # * 'color'<~String>
576
+ # * 'role'<~String>
577
+ # * 'avatar_url'<~String>
578
+ # * 'user_url'<~String>
579
+ # * 'invitation_sent'<~Boolean>
580
+ # * 'marketing'<~String>
581
+ # * 'marketing_opt_out'<~String>
582
+ # * 'type'<~String>
583
+ # * 'channel'<~Hash>
584
+ # * 'type'
585
+ # * 'limit'<~Integer> -
586
+ # * 'offset'<~Integer> -
587
+ # * 'total'<~Integer> -
588
+ #
589
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/log_entries/list]
260
590
  def get_log_entries(options={})
261
- LogEntries.new(JSON.parse(curl({
591
+ LogEntries.new(curl({
262
592
  uri: "https://#@@subdomain.pagerduty.com/api/v1/log_entries",
263
593
  params: options,
264
594
  method: 'GET'
265
- }).body))
595
+ }))
266
596
  end
267
597
 
598
+ # Get details for a specific incident log entry. This method provides additional information you can use to get at raw event data
599
+ #
600
+ # ==== Parameters
601
+ # * options<~Hash>
602
+ # * 'time_zone'<~TimeZone> -
603
+ # * 'include'<~Array> -
604
+ #
605
+ # ==== Returns
606
+ # * 'log_entry'<~LogEntry>
607
+ # * 'id'<~String>
608
+ # * 'type'<~String>
609
+ # * 'created_at'<~String>
610
+ # * 'agent'<~Pagerduty::User>
611
+ # * 'id'<~String>
612
+ # * 'name'<~String>
613
+ # * 'email'<~String>
614
+ # * 'time_zone'<~String>
615
+ # * 'color'<~String>
616
+ # * 'role'<~String>
617
+ # * 'avatar_url'<~String>
618
+ # * 'user_url'<~String>
619
+ # * 'invitation_sent'<~Boolean>
620
+ # * 'marketing'<~String>
621
+ # * 'marketing_opt_out'<~String>
622
+ # * 'type'<~String>
623
+ # * 'user'<~Pagerduty::User>
624
+ # * 'id'<~String>
625
+ # * 'name'<~String>
626
+ # * 'email'<~String>
627
+ # * 'time_zone'<~String>
628
+ # * 'color'<~String>
629
+ # * 'role'<~String>
630
+ # * 'avatar_url'<~String>
631
+ # * 'user_url'<~String>
632
+ # * 'invitation_sent'<~Boolean>
633
+ # * 'marketing'<~String>
634
+ # * 'marketing_opt_out'<~String>
635
+ # * 'type'<~String>
636
+ # * 'channel'<~Hash>
637
+ # * 'summary'<~String>
638
+ # * 'type'<~String>
639
+ #
640
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/log_entries/show]
268
641
  def get_log_entry(options={})
269
- LogEntry.new(JSON.parse(curl({
642
+ LogEntry.new(curl({
270
643
  uri: "https://#@@subdomain.pagerduty.com/api/v1/log_entries/#{options[:id]}",
271
644
  params: options,
272
645
  method: 'GET'
273
- }).body)['log_entry'])
646
+ })['log_entry'])
274
647
  end
275
648
 
649
+ # Get high level statistics about the number of alerts (SMSes, phone calls and emails) sent for the desired time period, summed daily, weekly or monthly.
650
+ #
651
+ # ==== Parameters
652
+ # * options<~Hash>:
653
+ # * 'since'<~String> - The start of the date range over which you want to search. The time element is optional.
654
+ # * 'until'<~String> - The end of the date range over which you want to search. This should be in the same format as since. The size of the date range must be less than 3 months.
655
+ # * 'rollup'<~String> - Possible values are daily, weekly or monthly. Specifies the bucket duration for each summation. Defaults to monthly. (Example: A time window of two years (based on since and until) with a rollup of monthly will result in 24 sets of data points being returned (one for each month in the span))
656
+ #
657
+ # ==== Returns
658
+ # * 'alerts'<~Array>
659
+ # * <~Pagerduty::Reports::Alert>:
660
+ # * 'number_of_alerts'<~Integer>
661
+ # * 'number_of_phone_alerts'<~Integer>
662
+ # * 'number_of_sms_alerts'<~Integer>
663
+ # * 'number_of_email_alerts'<~Integer>
664
+ # * 'start'<~String>
665
+ # * 'end'<~String>
666
+ # * 'total_number_of_alerts'<~Integer> -
667
+ # * 'total_number_of_phone_alerts'<~Integer> -
668
+ # * 'total_number_of_sms_alerts'<~Integer> -
669
+ # * 'total_number_of_email_alerts'<~Integer> -
670
+ # * 'total_number_of_billable_alerts'<~Integer> -
671
+ #
672
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/reports/alerts_per_time]
276
673
  def alerts_per_time(options={})
277
- Pagerduty::Reports::Alerts.new(JSON.parse(curl({
674
+ Pagerduty::Reports::Alerts.new(curl({
278
675
  uri: "https://#@@subdomain.pagerduty.com/api/v1/reports/alerts_per_time",
279
676
  params: options,
280
677
  method: 'GET'
281
- }).body))
678
+ }))
282
679
  end
283
680
 
681
+ # Get high level statistics about the number of incidents created for the desired time period, summed daily, weekly or monthly
682
+ #
683
+ # ==== Parameters
684
+ # * options<~Hash>:
685
+ # * 'since'<~String>: The start of the date range over which you want to search. The time element is optional.
686
+ # * 'until'<~String>: The end of the date range over which you want to search. This should be in the same format as since. The size of the date range must be less than 3 months.
687
+ # * 'rollup'<~String>: Possible values are daily, weekly or monthly. Specifies the bucket duration for each summation. Defaults to monthly. (Example: A time window of two years (based on since and until) with a rollup of monthly will result in 24 sets of data points being returned (one for each month in the span))
688
+ #
689
+ # ==== Returns
690
+ # * <~Pagerduty::Reports::Incidents>
691
+ # * 'incidents'<~Array>
692
+ # * <~Pagerduty::Reports::Incident>
693
+ # * 'number_of_incidents'<~Integer> -
694
+ # * 'start'<~String> -
695
+ # * 'end'<~String> -
696
+ #
697
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/reports/incidents_per_time]
284
698
  def incidents_per_time(options={})
285
- Pagerduty::Reports::Incidents.new(JSON.parse(curl({
699
+ Pagerduty::Reports::Incidents.new(curl({
286
700
  uri: "https://#@@subdomain.pagerduty.com/api/v1/reports/incidents_per_time/",
287
701
  params: options,
288
702
  method: 'GET'
289
- }).body))
703
+ }))
290
704
  end
291
705
 
706
+ # List existing maintenance windows, optionally filtered by service, or whether they are from the past, present or future
707
+ #
708
+ # ==== Parameters
709
+ # * options<~Hash>
710
+ # * 'query'<~String> - Filters the results, showing only the maintenance windows whose descriptions contain the query
711
+ # * 'service_ids'<~Array> - An array of service IDs, specifying services whose maintenance windows shall be returned
712
+ # * 'filter'<~String> - Only return maintenance windows that are of this type. Possible values are past, future, ongoing. If this parameter is omitted, all maintenance windows will be returned
713
+ #
714
+ # ==== Returns
715
+ # * <~Pagerduty::MaintenanceWindows>
716
+ # * 'maintenance_windows'<~Array>
717
+ # * <~Pagerduty::MaintenanceWindow>
718
+ # * 'id'<~String>
719
+ # * 'sequence_number'<~Integer>
720
+ # * 'start_time'<~String>
721
+ # * 'end_time'<~String>
722
+ # * 'description'<~String>
723
+ # * 'created_by'<~Pagerduty::User>
724
+ # * 'id'<~String>
725
+ # * 'name'<~String>
726
+ # * 'email'<~String>
727
+ # * 'time_zone'<~String>
728
+ # * 'color'<~String>
729
+ # * 'role'<~String>
730
+ # * 'avatar_url'<~String>
731
+ # * 'user_url'<~String>
732
+ # * 'invitation_sent'<~Boolean>
733
+ # * 'marketing'<~String>
734
+ # * 'marketing_opt_out'<~String>
735
+ # * 'type'<~String>
736
+ # * 'services'<~Array>
737
+ # * <~Service>
738
+ # * 'id'<~String>
739
+ # * 'name'<~String>
740
+ # * 'html_url'<~String>
741
+ # * 'delete_at'<~String>
742
+ # * 'service_ids'<~Array> - An array of strings of all the service IDs associated with the maintenance window
743
+ # * 'limit'<~Integer>
744
+ # * 'offset'<~Integer>
745
+ # * 'total'<~Integer>
746
+ # * 'query'<~Integer>
747
+ # * 'query'<~String>
748
+ # * 'counts'<~Pagerduty::MaintenanceWindow::Count>
749
+ # * 'ongoing'<~Integer>
750
+ # * 'future'<~Integer>
751
+ # * 'past'<~Integer>
752
+ # * 'all'<~Integer>
753
+ #
754
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/maintenance_windows/list]
292
755
  def get_maintenance_windows(options={})
293
- Pagerduty::MaintenanceWindows.new(JSON.parse(curl({
756
+ Pagerduty::MaintenanceWindows.new(curl({
294
757
  uri: "https://#@@subdomain.pagerduty.com/api/v1/maintenance_windows",
295
758
  params: options,
296
759
  method: 'GET'
297
- }).body))
760
+ }))
298
761
  end
299
762
 
763
+ # Get details about an existing maintenance window
764
+ #
765
+ # ==== Parameters
766
+ # * 'options'<~Hash>:
767
+ # * 'id'<~String> - The id of the maintenance window to retrieve
768
+ #
769
+ # ==== Returns
770
+ # * <~Pagerduty::MaintenanceWindow>
771
+ # * 'id'<~String>
772
+ # * 'sequence_number'<~Integer>
773
+ # * 'start_time'<~String>
774
+ # * 'end_time'<~String>
775
+ # * 'description'<~String>
776
+ # * 'created_by'<~Pagerduty::User>
777
+ # * 'id'<~String>
778
+ # * 'name'<~String>
779
+ # * 'email'<~String>
780
+ # * 'time_zone'<~String>
781
+ # * 'color'<~String>
782
+ # * 'role'<~String>
783
+ # * 'avatar_url'<~String>
784
+ # * 'user_url'<~String>
785
+ # * 'invitation_sent'<~Boolean>
786
+ # * 'marketing'<~String>
787
+ # * 'marketing_opt_out'<~String>
788
+ # * 'type'<~String>
789
+ # * 'services'<~Array>
790
+ # * <~Service>
791
+ # * 'id'<~String>
792
+ # * 'name'<~String>
793
+ # * 'html_url'<~String>
794
+ # * 'delete_at'<~String>
795
+ # * 'service_ids'<~Array> - An array of strings of all the service IDs associated with the maintenance window
796
+ #
797
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/maintenance_windows/show]
300
798
  def get_maintenance_window(options={})
301
- Pagerduty::MaintenanceWindow.new(JSON.parse(curl({
799
+ Pagerduty::MaintenanceWindow.new(curl({
302
800
  uri: "https://#@@subdomain.pagerduty.com/api/v1/maintenance_windows/#{options[:id]}",
303
801
  params: options,
304
802
  method: 'GET'
305
- }).body)['maintenance_window'])
803
+ })['maintenance_window'])
306
804
  end
307
805
 
806
+ # Create a new maintenance window for the specified services. No new incidents will be created for a service that is currently in maintenance
807
+ #
808
+ # ==== Parameters
809
+ # * 'options'<~Hash>
810
+ # * 'requester_id'<~String>
811
+ # * 'maintenance_window'<~Hash>
812
+ # * 'start_time'<~String>
813
+ # * 'end_time'<~String>
814
+ # * 'description'<~String>
815
+ # * 'service_ids'<~Array>
816
+ #
817
+ # ==== Returns
818
+ # * <~Pagerduty::MaintenanceWindow>
819
+ # * 'id'<~String>
820
+ # * 'sequence_number'<~Integer>
821
+ # * 'start_time'<~String>
822
+ # * 'end_time'<~String>
823
+ # * 'description'<~String>
824
+ # * 'created_by'<~Pagerduty::User>
825
+ # * 'id'<~String>
826
+ # * 'name'<~String>
827
+ # * 'email'<~String>
828
+ # * 'time_zone'<~String>
829
+ # * 'color'<~String>
830
+ # * 'role'<~String>
831
+ # * 'avatar_url'<~String>
832
+ # * 'user_url'<~String>
833
+ # * 'invitation_sent'<~Boolean>
834
+ # * 'marketing'<~String>
835
+ # * 'marketing_opt_out'<~String>
836
+ # * 'type'<~String>
837
+ # * 'services'<~Array>
838
+ # * <~Service>
839
+ # * 'id'<~String>
840
+ # * 'name'<~String>
841
+ # * 'html_url'<~String>
842
+ # * 'delete_at'<~String>
843
+ # * 'service_ids'<~Array> - An array of strings of all the service IDs associated with the maintenance window
844
+ #
845
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/maintenance_windows/create]
308
846
  def create_maintenance_window(options={})
309
- Pagerduty::MaintenanceWindow.new(JSON.parse(curl({
847
+ Pagerduty::MaintenanceWindow.new(curl({
310
848
  uri: "https://#@@subdomain.pagerduty.com/api/v1/maintenance_windows",
311
849
  data: options,
312
850
  method: 'POST'
313
- }).body)['maintenance_window'])
851
+ })['maintenance_window'])
314
852
  end
315
853
 
854
+ # List existing on-call schedules
855
+ #
856
+ # ==== Parameters
857
+ # * options<~Hash>:
858
+ # * 'query'<~String> - Filters the result, showing only the schedules whose name matches the query
859
+ # * 'requester_id'<~String> - The user id of the user making the request. This will be used to generate the calendar private urls. This is only needed if you are using token based authentication
860
+ #
861
+ # ==== Returns
862
+ # * <~Pagerduty::Schedules>
863
+ # * 'schedules'<~Array>
864
+ # * <~Pagerduty::Schedules::Schedule>
865
+ # * 'id'<~String>
866
+ # * 'name'<~String>
867
+ # * 'time_zone'<~String>
868
+ # * 'today'<~String>
869
+ # * 'escalation_policies'<~Array>
870
+ # * <~EscalationPolicy>
871
+ # * 'id'<~String>
872
+ # * 'name'<~String>
873
+ # * 'description'<~String>
874
+ # * 'escalation_rules'<~Array>
875
+ # * 'services'<~Set>
876
+ # * 'num_loops'<~Integer>
877
+ # * 'limit'<~Integer>
878
+ # * 'offset'<~Integer>
879
+ # * 'total'<~Integer>
880
+ #
881
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/schedules/list]
316
882
  def get_schedules(options={})
317
- Pagerduty::Schedules.new(JSON.parse(curl({
883
+ Pagerduty::Schedules.new(curl({
318
884
  uri: "https://#@@subdomain.pagerduty.com/api/v1/schedules",
319
885
  params: options,
320
886
  method: 'GET'
321
- }).body))
887
+ }))
322
888
  end
323
889
 
890
+ # Show detailed information about a schedule, including entries for each layer and sub-schedule
891
+ #
892
+ # ==== Parameters
893
+ # * options<~Hash>:
894
+ # * 'since'<~String> - The start of the date range over which you want to return on-call schedule entries and on-call schedule layers
895
+ # * 'until'<~String> - The end of the date range over which you want to return schedule entries and on-call schedule layers
896
+ # * 'time_zone'<~TimeZone> - Time zone in which dates in the result will be rendered. Defaults to account time zone
897
+ #
898
+ # ==== Returns
899
+ # * response<~ScheduleInfo>:
900
+ # * 'id'<~String>
901
+ # * 'name'<~String>
902
+ # * 'time_zone'<~String>
903
+ # * 'today'<~String>
904
+ # * 'escalation_policies'<~Array>:
905
+ # * <~EscalationPolicy>:
906
+ # * 'id'<~String>
907
+ # * 'name'<~String>
908
+ # * 'description'<~String>
909
+ # * 'escalation_rules'<~Array>
910
+ # * 'services'<~Set>
911
+ # * 'num_loops'<~Integer>
912
+ # * 'schedule_layers'<~Array>:
913
+ # * <~Pagerduty::Schedules::ScheduleLayer>:
914
+ # * 'name'<~String>
915
+ # * 'rendered_schedule_entries'<~Array>
916
+ # * 'id'<~String>
917
+ # * 'priority'<~Integer>
918
+ # * 'start'<~String>
919
+ # * 'end'<~String>
920
+ # * 'restriction_type'<~String>
921
+ # * 'rotation_virtual_start'<~String>
922
+ # * 'rotation_turn_length_seconds'<~Integer>
923
+ # * 'users'<~Array>
924
+ # * <~Pagerduty::Schedules::ScheduleLayer::User>:
925
+ # * 'member_order'<~Integer>
926
+ # * 'user'<~Pagerduty::User>:
927
+ # * 'id'<~String>
928
+ # * 'name'<~String>
929
+ # * 'email'<~String>
930
+ # * 'time_zone'<~String>
931
+ # * 'color'<~String>
932
+ # * 'role'<~String>
933
+ # * 'avatar_url'<~String>
934
+ # * 'user_url'<~String>
935
+ # * 'invitation_sent'<~Boolean>
936
+ # * 'marketing'<~String>
937
+ # * 'marketing_opt_out'<~String>
938
+ # * 'type'<~String>
939
+ # * 'restrictions'<~Array>
940
+ # * 'rendered_coverage_percentage'<~Float>
941
+ # * 'overrides_schedule'<~Pagerduty::Schedules::Override>:
942
+ # * 'name'<~String>
943
+ # * 'rendered_schedule_entries'<~Array>
944
+ # * 'final_schedule'<~Pagerduty::Schedules::FinalSchedule>:
945
+ # * 'name'<~String>
946
+ # * 'rendered_schedule_entries'<~Array>
947
+ # * 'rendered_coverage_percentage'<~Float>
948
+ #
949
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/schedules/show]
324
950
  def get_schedule(options={})
325
- Pagerduty::ScheduleInfo.new(JSON.parse(curl({
951
+ Pagerduty::ScheduleInfo.new(curl({
326
952
  uri: "https://#@@subdomain.pagerduty.com/api/v1/schedules/#{options[:id]}",
327
953
  params: options,
328
954
  method: 'GET'
329
- }).body)['schedule'])
955
+ })['schedule'])
330
956
  end
331
957
 
958
+ # List all the users on-call in a given schedule for a given time range.
959
+ #
960
+ # ==== Parameters
961
+ # * options<~Hash>:
962
+ # * 'since'<~String> - The start of the date range over which you want to return on-call users
963
+ # * 'until'<~String> - The end time of the date range over which you want to return on-call users
964
+ #
965
+ # ==== Returns
966
+ # * <~Array>:
967
+ # * <~Pagerduty::User>
968
+ # * 'id'<~String>
969
+ # * 'name'<~String>
970
+ # * 'email'<~String>
971
+ # * 'time_zone'<~String>
972
+ # * 'color'<~String>
973
+ # * 'role'<~String>
974
+ # * 'avatar_url'<~String>
975
+ # * 'user_url'<~String>
976
+ # * 'invitation_sent'<~Boolean>
977
+ # * 'marketing'<~String>
978
+ # * 'marketing_opt_out'<~String>
979
+ # * 'type'<~String>
980
+ #
981
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/schedules/users]
332
982
  def get_schedule_users(options={})
333
- JSON.parse(curl({
983
+ Users.new(curl({
334
984
  uri: "https://#@@subdomain.pagerduty.com/api/v1/schedules/#{options[:id]}/users",
335
985
  params: options,
336
986
  method: 'GET'
337
- }).body)['users'].inject([]) { |users, user|
338
- users << Pagerduty::User.new(user)
339
- }
987
+ })).users
340
988
  end
341
989
 
990
+ # List existing services
991
+ #
992
+ # ==== Parameters
993
+ # * options<~Hash>:
994
+ # * 'include'<~Array> - Include extra information in the response. Possible values are escalation_policy (for inline Escalation Policy) and email_filters (for inline Email Filters)
995
+ # * 'time_zone'<~TimeZone> - Time zone in which dates in the result will be rendered. Defaults to account default time zone
996
+ #
997
+ # ==== Returns
998
+ # * services<~Array>:
999
+ # * <~Pagerduty::Services::Objects::Service>:
1000
+ # * 'id'<~String>
1001
+ # * 'name'<~String>
1002
+ # * 'description'<~String>
1003
+ # * 'service_url'<~String>
1004
+ # * 'service_key'<~String>
1005
+ # * 'auto_resolve_timeout'<~Integer>
1006
+ # * 'acknowledgement_timeout'<~Integer>
1007
+ # * 'created_at'<~String>
1008
+ # * 'status'<~String>
1009
+ # * 'last_incident_timestamp'<~String>
1010
+ # * 'email_incident_creation'<~String>
1011
+ # * 'incident_counts'<~Hash>
1012
+ # * 'triggered'<~Integer>
1013
+ # * 'acknowledged'<~Integer>
1014
+ # * 'resolved'<~Integer>
1015
+ # * 'total'<~Integer>
1016
+ # * 'email_filter_mode'<~String>
1017
+ # * 'type'<~String>
1018
+ # * 'escalation_policy'<~String>
1019
+ # * 'email_filters'<~String> - An object containing inline Email Filters. Only present if email_filters is passed as an argument. Note that only generic_email services have Email Filters
1020
+ # * 'severity_filter'<~String> - Specifies what severity levels will create a new open incident
1021
+ #
1022
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/services/list]
342
1023
  def get_services(options={})
343
- Pagerduty::Services.new(JSON.parse(curl({
1024
+ Pagerduty::Services.new(curl({
344
1025
  uri: "https://#@@subdomain.pagerduty.com/api/v1/services",
345
1026
  params: options,
346
1027
  method: 'GET'
347
- }).body))
1028
+ }))
348
1029
  end
349
1030
 
1031
+ # Get details about an existing service
1032
+ #
1033
+ # ==== Parameters
1034
+ # * options<~Hash>:
1035
+ # * 'include'<~Array> - Include extra information in the response. Possible values are escalation_policy (for inline Escalation Policy) and email_filters (for inline Email Filters)
1036
+ #
1037
+ # ==== Returns
1038
+ # * <~Pagerduty::Services::Objects::Service>:
1039
+ # * 'id'<~String>
1040
+ # * 'name'<~String>
1041
+ # * 'description'<~String>
1042
+ # * 'service_url'<~String>
1043
+ # * 'service_key'<~String>
1044
+ # * 'auto_resolve_timeout'<~Integer>
1045
+ # * 'acknowledgement_timeout'<~Integer>
1046
+ # * 'created_at'<~String>
1047
+ # * 'status'<~String>
1048
+ # * 'last_incident_timestamp'<~String>
1049
+ # * 'email_incident_creation'<~String>
1050
+ # * 'incident_counts'<~Hash>
1051
+ # * 'triggered'<~Integer>
1052
+ # * 'acknowledged'<~Integer>
1053
+ # * 'resolved'<~Integer>
1054
+ # * 'total'<~Integer>
1055
+ # * 'email_filter_mode'<~String>
1056
+ # * 'type'<~String>
1057
+ # * 'escalation_policy'<~String>
1058
+ # * 'email_filters'<~String> - An object containing inline Email Filters. Only present if email_filters is passed as an argument. Note that only generic_email services have Email Filters
1059
+ # * 'severity_filter'<~String> - Specifies what severity levels will create a new open incident
1060
+ #
1061
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/services/show]
350
1062
  def get_service(options={})
351
- Pagerduty::Services::Objects::Service.new(JSON.parse(curl({
1063
+ Pagerduty::Services::Objects::Service.new(curl({
352
1064
  uri: "https://#@@subdomain.pagerduty.com/api/v1/services/#{options[:id]}",
353
1065
  params: options,
354
1066
  method: 'GET'
355
- }).body)['service'])
1067
+ })['service'])
356
1068
  end
357
1069
 
1070
+ # Create a new service
1071
+ #
1072
+ # ==== Parameters
1073
+ # * options<~Hash>:
1074
+ # * 'name'<~String> - The name of the service
1075
+ # * 'escalation_policy_id'<~String> - The id of the escalation policy to be used by this service
1076
+ # * 'type'<~String> - The type of service to create. Can be one of generic_email, generic_events_api, keynote, nagios, pingdom, server_density or sql_monitor
1077
+ # * 'description'<~String> - A description for your service. 1024 character maximum
1078
+ # * 'acknowledgement_timeout'<~Integer> - The duration in seconds before an incidents acknowledged in this service become triggered again. (Defaults to 30 minutes)
1079
+ # * 'auto_resolve_timeout'<~Integer> - The duration in seconds before a triggered incident auto-resolves itself. (Defaults to 4 hours)
1080
+ # * 'severity_filter'<~String> - Specifies what severity levels will create a new open incident
1081
+ #
1082
+ # ==== Returns
1083
+ # * <~Pagerduty::Services::Objects::Service>:
1084
+ # * 'id'<~String>
1085
+ # * 'name'<~String>
1086
+ # * 'description'<~String>
1087
+ # * 'service_url'<~String>
1088
+ # * 'service_key'<~String>
1089
+ # * 'auto_resolve_timeout'<~Integer>
1090
+ # * 'acknowledgement_timeout'<~Integer>
1091
+ # * 'created_at'<~String>
1092
+ # * 'status'<~String>
1093
+ # * 'last_incident_timestamp'<~String>
1094
+ # * 'email_incident_creation'<~String>
1095
+ # * 'incident_counts'<~Hash>
1096
+ # * 'triggered'<~Integer>
1097
+ # * 'acknowledged'<~Integer>
1098
+ # * 'resolved'<~Integer>
1099
+ # * 'total'<~Integer>
1100
+ # * 'email_filter_mode'<~String>
1101
+ # * 'type'<~String>
1102
+ # * 'escalation_policy'<~String>
1103
+ # * 'email_filters'<~String> - An object containing inline Email Filters. Only present if email_filters is passed as an argument. Note that only generic_email services have Email Filters
1104
+ # * 'severity_filter'<~String> - Specifies what severity levels will create a new open incident
1105
+ #
1106
+ # {Pagerduty API Reference}[http://developer.pagerduty.com/documentation/rest/services/create]
358
1107
  def create_service(options={})
359
- Pagerduty::Services::Objects::Service.new(JSON.parse(curl({
1108
+ Pagerduty::Services::Objects::Service.new(curl({
360
1109
  uri: "https://#@@subdomain.pagerduty.com/api/v1/services",
361
1110
  data: { service: options },
362
1111
  method: 'POST'
363
- }).body)['service'])
1112
+ })['service'])
364
1113
  end
365
1114
 
366
1115
  end