statusio 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 877f843331586d5fd846c23feac7b26210a9cca2
4
+ data.tar.gz: 8b68a7615090aface50e0de3d1af31601355cd00
5
+ SHA512:
6
+ metadata.gz: f5bda2f3b2d0fa0c8b9e45a3f2b4e37d0adb973c87c4d8a185503046bbdc7ecfdc346cac45a399f073d576d5dc3ced77bcf9d20561c068d82859dab449375f8d
7
+ data.tar.gz: 616f8780ae19780b8c1e1ef361551a3bf23774ef4eeaa2aaad04d36118088d69d48bd5fdec0f150946482b5c0978ce936a46fc79617f735a988f172325e80a5c
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-2
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rbconfig'
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rest-client'
6
+
7
+ group :test do
8
+ gem 'rspec'
9
+ gem 'rake'
10
+ gem 'win32console' if (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
11
+ gem 'httparty'
12
+ end
13
+
14
+ # Specify your gem's dependencies in statusio.gemspec
15
+ gemspec
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Statusio::Rb
2
+
3
+ Ruby library wrapper for Status.io
4
+
5
+ [![Travis CI](https://travis-ci.org/statusio/statusio-ruby.svg)](https://travis-ci.org/statusio/statusio-ruby)
6
+
7
+ Ruby library wrapper for Status.io - A Complete Status Platform - Status pages, incident tracking, subscriber notifications and more
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'statusio'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install statusio
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ # Sign up an account and get your api_id, api_key from developer tab
29
+ statusioclient = StatusioClient.new(api_key, api_id)
30
+ ```
31
+
32
+ To work with component method
33
+
34
+ To work with maintenance methods
35
+
36
+ To work with subscriber methods
37
+
38
+ To work with metric methods
39
+
40
+ Please refer to Status.io API v2 for more details.
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/statusio-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
51
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.test_files = FileList['spec/*_spec.rb']
6
+ t.verbose = false
7
+ end
8
+
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "statusio/rb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/statusio.rb ADDED
@@ -0,0 +1,581 @@
1
+ require 'rubygems' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby' && RUBY_VERSION < '1.9'
2
+ require 'statusio/rb/version'
3
+ require 'rest-client'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ class StatusioClient
8
+ STATUS_OPERATIONAL = 100
9
+ STATUS_DEGRADED_PERFORMANCE = 300
10
+ STATUS_PARTIAL_SERVICE_DISRUPTION = 400
11
+ STATUS_SERVICE_DISRUPTION = 500
12
+ STATUS_SECURITY_EVENT = 600
13
+
14
+ STATE_INVESTIGATING = 100
15
+ STATE_IDENTIFIED = 200
16
+ STATE_MONITORING = 300
17
+
18
+ NOTIFY_EMAIL = 1
19
+ NOTIFY_SMS = 2
20
+ NOTIFY_WEBHOOK = 4
21
+ NOTIFY_SOCIAL = 8
22
+ NOTIFY_IRC = 16
23
+ NOTIFY_HIPCHAT = 32
24
+ NOTIFY_SLACK = 64
25
+
26
+ def initialize(api_key, api_id)
27
+ @api_key = api_key
28
+ @api_id = api_id
29
+
30
+ @url = 'https://api.status.io/v2/'
31
+
32
+ @headers = {
33
+ 'x-api-id' => @api_id,
34
+ 'x-api-key' => @api_key,
35
+ 'Content-Type' => 'application/json',
36
+ 'Accept' => 'application/json'
37
+ }
38
+ end
39
+
40
+ private
41
+
42
+ def get_notify(notifications)
43
+ notify = {
44
+ 'notify_email' => '0',
45
+ 'notify_sms' => '0',
46
+ 'notify_webhook' => '0',
47
+ 'social' => '0',
48
+ 'irc' => '0',
49
+ 'hipchat' => '0',
50
+ 'slack' => '0'
51
+ }
52
+
53
+ if notifications & NOTIFY_EMAIL == NOTIFY_EMAIL
54
+ notify['notify_email'] = '1'
55
+ end
56
+
57
+ if notifications & NOTIFY_SMS == NOTIFY_SMS
58
+ notify['notify_sms'] = '1'
59
+ end
60
+
61
+ if notifications & NOTIFY_WEBHOOK == NOTIFY_WEBHOOK
62
+ notify['notify_webhook'] = '1'
63
+ end
64
+
65
+ if notifications & NOTIFY_SOCIAL == NOTIFY_SOCIAL
66
+ notify['social'] = '1'
67
+ end
68
+
69
+ if notifications & NOTIFY_IRC == NOTIFY_IRC
70
+ notify['irc'] = '1'
71
+ end
72
+
73
+ if notifications & NOTIFY_HIPCHAT == NOTIFY_HIPCHAT
74
+ notify['hipchat'] = '1'
75
+ end
76
+
77
+ if notifications & NOTIFY_SLACK == NOTIFY_SLACK
78
+ notify['slack'] = '1'
79
+ end
80
+
81
+ return notify
82
+ end
83
+
84
+ public
85
+
86
+ ##
87
+ # List all components.
88
+ #
89
+ # @param statuspage_id(string) Status page ID
90
+ # @return object
91
+
92
+ def component_list(statuspage_id)
93
+ response = RestClient::Request.execute(
94
+ :method => :get,
95
+ :url => @url + 'component/list/' + statuspage_id,
96
+ :headers => @headers)
97
+
98
+ if response.code == 200
99
+ return JSON.parse(response.body)
100
+ end
101
+ end
102
+
103
+ ##
104
+ # Update the status of a component on the fly without creating an incident or maintenance.
105
+ #
106
+ # @param statuspage_id(string) string Status page ID
107
+ # @param components(array) ID of each affected component
108
+ # @param containers(array) ID of each affected container
109
+ # @param details(string) A brief message describing this update
110
+ # @param current_status(int) Any numeric status code.
111
+ # @return object
112
+
113
+ def component_status_update(statuspage_id, components, containers, details, current_status)
114
+ data = {
115
+ 'statuspage_id' => statuspage_id,
116
+ 'components' => components,
117
+ 'containers' => containers,
118
+ 'details' => details,
119
+ 'current_status' => current_status
120
+ }
121
+
122
+ response = RestClient.post(@url + 'component/status/update', data, @headers)
123
+
124
+ if response.code == 200
125
+ return JSON.parse(response.body)
126
+ end
127
+ end
128
+
129
+ # INCIDENT
130
+
131
+ ##
132
+ # List all active and resolved incidents.
133
+ #
134
+ # @param statuspage_id(string) Status page ID
135
+ # @return object
136
+
137
+ def incident_list(statuspage_id)
138
+ response = RestClient::Request.execute(
139
+ :method => :get,
140
+ :url => @url + 'incident/list/' + statuspage_id,
141
+ :headers => @headers)
142
+
143
+ if response.code == 200
144
+ return JSON.parse(response.body)
145
+ end
146
+ end
147
+
148
+
149
+ ##
150
+ # Display incident message.
151
+ #
152
+ # @param statuspage_id(string) Status page ID
153
+ # @param message_id(string) Message ID
154
+ # @return object
155
+
156
+ def incident_message(statuspage_id, message_id)
157
+ response = RestClient::Request.execute(
158
+ :method => :get,
159
+ :url => @url + 'incident/message/' + statuspage_id + '/' + message_id,
160
+ :headers => @headers
161
+ )
162
+
163
+ if response.code == 200
164
+ return JSON.parse(response.body)
165
+ end
166
+ end
167
+
168
+ ##
169
+ # Create a new incident.
170
+ #
171
+ # @param statuspage_id(string) Status page ID
172
+ # @param incident_name(string) A descriptive title for the incident
173
+ # @param incident_details(string) Message describing this incident
174
+ # @param components(array) ID of each affected component
175
+ # @param containers(array) ID of each affected container
176
+ # @param current_status(int) The status of the components and containers affected by this incident (StatusioClient::STATUS_#).
177
+ # @param current_state(int) The state of this incident (StatusioClient::STATE_#).
178
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
179
+ # @param all_infrastructure_affected(int) Affect all components and containers (default = 0)
180
+ # @return object
181
+
182
+ def incident_create(statuspage_id, incident_name, incident_details, components, containers, current_status, current_state, notifications = 0, all_infrastructure_affected = 0)
183
+ data = get_notify(notifications)
184
+ data['statuspage_id'] = statuspage_id
185
+ data['incident_name'] = incident_name
186
+ data['incident_details'] = incident_details
187
+ data['components'] = components
188
+ data['containers'] = containers
189
+ data['current_status'] = current_status
190
+ data['current_state'] = current_state
191
+ data['all_infrastructure_affected'] = all_infrastructure_affected
192
+
193
+ response = RestClient.post(@url + 'incident/create', data, @headers)
194
+ if (response.code == 200)
195
+ return JSON.parse(response.body)
196
+ end
197
+ end
198
+
199
+ ##
200
+ # Update an existing incident
201
+ #
202
+ # @param statuspage_id(string) Status page ID
203
+ # @param incident_id(string) Incident ID
204
+ # @param incident_details(string) Message describing this incident
205
+ # @param current_status(int) The status of the components and containers affected by this incident (StatusioClient::STATUS_#).
206
+ # @param current_state(int) The state of this incident (StatusioClient::STATE_#).
207
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
208
+ # @return object
209
+
210
+ def incident_update(statuspage_id, incident_id, incident_details, current_status, current_state, notifications = 0)
211
+ data = get_notify(notifications)
212
+ data['statuspage_id'] = statuspage_id
213
+ data['incident_id'] = incident_id
214
+ data['incident_details'] = incident_details
215
+ data['current_status'] = current_status
216
+ data['current_state'] = current_state
217
+
218
+ response = RestClient.post(@url + 'incident/update', data, @headers)
219
+ if (response.code == 200)
220
+ return JSON.parse(response.body)
221
+ end
222
+ end
223
+
224
+ ##
225
+ # Resolve an existing incident. The incident will be shown in the history instead of on the main page.
226
+ #
227
+ # @param statuspage_id(string) Status page ID
228
+ # @param incident_id(string) Incident ID
229
+ # @param incident_details(string) Message describing this incident
230
+ # @param current_status(int) The status of the components and containers affected by this incident (StatusioClient::STATUS_#).
231
+ # @param current_state(int) The state of this incident (StatusioClient::STATE_#).
232
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
233
+ # @return object
234
+
235
+ def incident_resolve(statuspage_id, incident_id, incident_details, current_status, current_state, notifications = 0)
236
+ data = get_notify(notifications)
237
+ data['statuspage_id'] = statuspage_id
238
+ data['incident_id'] = incident_id
239
+ data['incident_details'] = incident_details
240
+ data['current_status'] = current_status
241
+ data['current_state'] =current_state
242
+
243
+ response = RestClient.post(@url + 'incident/resolve', data, @headers)
244
+ if (response.code == 200)
245
+ return JSON.parse(response.body)
246
+ end
247
+ end
248
+
249
+ ##
250
+ # Delete an existing incident. The incident will be deleted forever and cannot be recovered.
251
+ #
252
+ # @param statuspage_id(string) Status page ID
253
+ # @param incident_id(string) Incident ID
254
+ # @return object
255
+
256
+ def incident_delete(statuspage_id, incident_id)
257
+ data = {}
258
+ data['statuspage_id'] = statuspage_id
259
+ data['incident_id'] = incident_id
260
+
261
+ response = RestClient.post(@url + 'incident/delete', data, @headers)
262
+ if (response.code == 200)
263
+ return JSON.parse(response.body)
264
+ end
265
+ end
266
+
267
+ # MAINTENANCE
268
+
269
+ ##
270
+ # List all active, resolved and upcoming maintenances
271
+ #
272
+ # @param statuspage_id(string) Status page ID
273
+ # @return object
274
+ #/
275
+
276
+ def maintenance_list(statuspage_id)
277
+ response = RestClient::Request.execute(
278
+ :method => :get,
279
+ :url => @url + 'maintenance/list/' + statuspage_id,
280
+ :headers => @headers
281
+ )
282
+
283
+ if response.code == 200
284
+ return JSON.parse(response.body)
285
+ end
286
+ end
287
+
288
+ ##
289
+ # Display maintenance message
290
+ #
291
+ # @param statuspage_id(string) Status page ID
292
+ # @param message_id(string) Message ID
293
+ # @return object
294
+
295
+ def maintenance_message(statuspage_id, message_id)
296
+ response = RestClient::Request.execute(
297
+ :method => :get,
298
+ :url => @url + 'maintenance/message/' + statuspage_id + '/' + message_id,
299
+ :headers => @headers
300
+ )
301
+
302
+ if response.code == 200
303
+ return JSON.parse(response.body)
304
+ end
305
+ end
306
+
307
+ ##
308
+ # Schedule a new maintenance
309
+ #
310
+ # @param statuspage_id(string) Status page ID
311
+ # @param maintenance_name(string) A descriptive title for this maintenance
312
+ # @param maintenance_details(string) Message describing this maintenance
313
+ # @param components(array) ID of each affected component
314
+ # @param containers(array) ID of each affected container
315
+ # @param date_planned_start(string) Date maintenance is expected to start
316
+ # @param time_planned_start(string) Time maintenance is expected to start
317
+ # @param date_planned_end(string) Date maintenance is expected to end
318
+ # @param time_planned_end(string) Time maintenance is expected to end
319
+ # @param automation(int) Automatically start and end the maintenance (default = 0)
320
+ # @param all_infrastructure_affected(int) Affect all components and containers (default = 0)
321
+ # @param maintenance_notify_now(int) Notify subscribers now (1 = Send notification)
322
+ # @param maintenance_notify_1_hr(int) Notify subscribers 1 hour before scheduled maintenance start time (1 = Send notification)
323
+ # @param maintenance_notify_24_hr(int) Notify subscribers 24 hours before scheduled maintenance start time (1 = Send notification)
324
+ # @param maintenance_notify_72_hr(int) Notify subscribers 72 hours before scheduled maintenance start time (1 = Send notification)
325
+ # @return object
326
+
327
+ def maintenance_schedule(statuspage_id, maintenance_name, maintenance_details, components, containers,
328
+ date_planned_start, time_planned_start, date_planned_end, time_planned_end,
329
+ automation = 0, all_infrastructure_affected = 0,
330
+ maintenance_notify_now = 0, maintenance_notify_1_hr = 0,
331
+ maintenance_notify_24_hr = 0, maintenance_notify_72_hr = 0)
332
+ data = {}
333
+ data['statuspage_id'] = statuspage_id
334
+ data['maintenance_name'] = maintenance_name
335
+ data['maintenance_details'] = maintenance_details
336
+ data['components'] = components
337
+ data['containers'] = containers
338
+ data['all_infrastructure_affected'] = all_infrastructure_affected
339
+ data['date_planned_start'] = date_planned_start
340
+ data['time_planned_start'] = time_planned_start
341
+ data['date_planned_end'] = date_planned_end
342
+ data['time_planned_end'] = time_planned_end
343
+ data['automation'] = automation
344
+ data['maintenance_notify_now'] = maintenance_notify_now
345
+ data['maintenance_notify_1_hr'] = maintenance_notify_1_hr
346
+ data['maintenance_notify_24_hr'] = maintenance_notify_24_hr
347
+ data['maintenance_notify_72_hr'] = maintenance_notify_72_hr
348
+
349
+ response = RestClient.post(@url + 'maintenance/schedule', data, @headers)
350
+ if (response.code == 200)
351
+ return JSON.parse(response.body)
352
+ end
353
+ end
354
+
355
+ ##
356
+ # Begin a scheduled maintenance now
357
+ #
358
+ # @param statuspage_id(string) Status page ID
359
+ # @param maintenance_id(string) Maintenance ID
360
+ # @param maintenance_details(string) Message describing this maintenance update
361
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
362
+ # @return object
363
+
364
+ def maintenance_start(statuspage_id, maintenance_id, maintenance_details, notifications = 0)
365
+ data = get_notify(notifications)
366
+ data['statuspage_id'] = statuspage_id
367
+ data['maintenance_id'] = maintenance_id
368
+ data['maintenance_details'] = maintenance_details
369
+
370
+ response = RestClient.post(@url + 'maintenance/start', data, @headers)
371
+ if (response.code == 200)
372
+ return JSON.parse(response.body)
373
+ end
374
+ end
375
+
376
+ ##
377
+ # Update an active maintenance
378
+ #
379
+ # @param statuspage_id(string) Status page ID
380
+ # @param maintenance_id(string) Maintenance ID
381
+ # @param maintenance_details(string) Message describing this maintenance
382
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
383
+ # @return object
384
+
385
+ def maintenance_update(statuspage_id, maintenance_id, maintenance_details, notifications = 0)
386
+ data = get_notify(notifications)
387
+ data['statuspage_id'] = statuspage_id
388
+ data['maintenance_id'] = maintenance_id
389
+ data['maintenance_details'] = maintenance_details
390
+
391
+ response = RestClient.post(@url + 'maintenance/update', data, @headers)
392
+ if (response.code == 200)
393
+ return JSON.parse(response.body)
394
+ end
395
+ end
396
+
397
+ ##
398
+ # Close an active maintenance. The maintenance will be moved to the history.
399
+ #
400
+ # @param statuspage_id(string) Status page ID
401
+ # @param maintenance_id(string) Maintenance ID
402
+ # @param maintenance_details(string) Message describing this maintenance
403
+ # @param notifications(int) Bitmasked notifications (StatusioClient::NOTIFY_#). To use multiple just add them up (ie StatusioClient::NOTIFY_SMS + StatusioClient::NOTIFY_SLACK).
404
+ # @return object
405
+
406
+ def maintenance_finish(statuspage_id, maintenance_id, maintenance_details, notifications = 0)
407
+ data = get_notify(notifications)
408
+ data['statuspage_id'] = statuspage_id
409
+ data['maintenance_id'] = maintenance_id
410
+ data['maintenance_details'] = maintenance_details
411
+
412
+ response = RestClient.post(@url + 'maintenance/finish', data, @headers)
413
+ if (response.code == 200)
414
+ return JSON.parse(response.body)
415
+ end
416
+ end
417
+
418
+ ##
419
+ # Delete an existing maintenance. The maintenance will be deleted forever and cannot be recovered.
420
+ #
421
+ # @param statuspage_id(string) Status page ID
422
+ # @param maintenance_id(string) Maintenance ID
423
+ # @return object
424
+ #/
425
+ def maintenance_delete(statuspage_id, maintenance_id)
426
+ data = {}
427
+ data['statuspage_id'] = statuspage_id
428
+ data['maintenance_id'] = maintenance_id
429
+
430
+ response = RestClient.post(@url + 'maintenance/delete', data, @headers)
431
+ if (response.code == 200)
432
+ return JSON.parse(response.body)
433
+ end
434
+ end
435
+
436
+ # METRIC
437
+
438
+ ##
439
+ # Update custom metric data
440
+ #
441
+ # @param statuspage_id(string) Status page ID
442
+ # @param metric_id(string) Metric ID
443
+ # @param day_avg(float) Average value for past 24 hours
444
+ # @param day_start(int) UNIX timestamp for start of metric timeframe
445
+ # @param day_dates(array) An array of timestamps for the past 24 hours (2014-03-28T05:43:00+00:00)
446
+ # @param day_values(array) An array of values matching the timestamps (Must be 24 values)
447
+ # @param week_avg(float) Average value for past 7 days
448
+ # @param week_start(int) UNIX timestamp for start of metric timeframe
449
+ # @param week_dates(array) An array of timestamps for the past 7 days (2014-03-28T05:43:00+00:00)
450
+ # @param week_values(array) An array of values matching the timestamps (Must be 7 values)
451
+ # @param month_avg(float) Average value for past 30 days
452
+ # @param month_start(int) UNIX timestamp for start of metric timeframe
453
+ # @param month_dates(array) An array of timestamps for the past 30 days (2014-03-28T05:43:00+00:00)
454
+ # @param month_values(array) An array of values matching the timestamps (Must be 30 values)
455
+ # @return object
456
+
457
+ def metric_update(statuspage_id, metric_id, day_avg, day_start, day_dates, day_values,
458
+ week_avg, week_start, week_dates, week_values,
459
+ month_avg, month_start, month_dates, month_values)
460
+ data = {}
461
+ data['statuspage_id'] = statuspage_id
462
+ data['metric_id'] = metric_id
463
+ data['day_avg'] = day_avg
464
+ data['day_start'] = day_start
465
+ data['day_dates'] = day_dates
466
+ data['day_values'] = day_values
467
+ data['week_avg'] = week_avg
468
+ data['week_start'] = week_start
469
+ data['week_dates'] = week_dates
470
+ data['week_values'] =week_values
471
+ data['month_avg'] = month_avg
472
+ data['month_start'] = month_start
473
+ data['month_dates'] = month_dates
474
+ data['month_values'] = month_values
475
+
476
+ response = RestClient.post(@url + 'metric/update', data, @headers)
477
+ if (response.code == 200)
478
+ return JSON.parse(response.body)
479
+ end
480
+ end
481
+
482
+ # STATUS
483
+
484
+ ##
485
+ # Show the summary status for all components and containers
486
+ #
487
+ # @param statuspage_id(string) Status page ID
488
+ # @return object
489
+
490
+ def status_summary(statuspage_id)
491
+ response = RestClient::Request.execute(
492
+ :method => :get,
493
+ :url => @url + 'status/summary/' + statuspage_id,
494
+ :headers => @headers
495
+ )
496
+
497
+ if response.code == 200
498
+ return JSON.parse(response.body)
499
+ end
500
+ end
501
+
502
+ # SUBSCRIBER
503
+
504
+ ##
505
+ # List all subscribers
506
+ #
507
+ # @param statuspage_id(string) Status page ID
508
+ # @return object
509
+
510
+ def subscriber_list(statuspage_id)
511
+ response = RestClient::Request.execute(
512
+ :method => :get,
513
+ :url => @url + 'subscriber/list/' + statuspage_id,
514
+ :headers => @headers
515
+ )
516
+
517
+ if response.code == 200
518
+ return JSON.parse(response.body)
519
+ end
520
+ end
521
+
522
+ ##
523
+ # Add a new subscriber
524
+ #
525
+ # @param statuspage_id(string) Status page ID
526
+ # @param method(string) Communication method of subscriber. Valid methods are `email`, `sms` or `webhook`
527
+ # @param address(string) Subscriber address (SMS number must include country code ie. +1)
528
+ # @param silent(int) Supress the welcome message (1 = Do not send notification)
529
+ # @param granular(string) List of component_container combos
530
+ # @return object
531
+
532
+ def subscriber_add(statuspage_id, method, address, silent = 1, granular = '')
533
+ data = {}
534
+ data['statuspage_id'] = statuspage_id
535
+ data['method'] = method
536
+ data['address'] = address
537
+ data['silent'] = silent
538
+ data['granular'] = granular
539
+
540
+ response = RestClient.post(@url + 'subscriber/add', data, @headers)
541
+ if (response.code == 200)
542
+ return JSON.parse(response.body)
543
+ end
544
+ end
545
+
546
+ ##
547
+ # Update existing subscriber
548
+ #
549
+ # @param statuspage_id(string) Status page ID
550
+ # @param subscriber_id(string) Subscriber ID
551
+ # @param address(string) Subscriber address (SMS number must include country code ie. +1)
552
+ # @param granular(string) List of component_container combos
553
+ # @return object
554
+
555
+ def subscriber_update(statuspage_id, subscriber_id, address, granular = '')
556
+ data = {}
557
+ data['statuspage_id'] = statuspage_id
558
+ data['subscriber_id'] = subscriber_id
559
+ data['address'] = address
560
+ data['granular'] = granular
561
+
562
+ response = RestClient.patch(@url + 'subscriber/update', data, @headers)
563
+ if (response.code == 200)
564
+ return JSON.parse(response.body)
565
+ end
566
+ end
567
+
568
+ ##
569
+ # Delete subscriber
570
+ #
571
+ # @param statuspage_id(string) Status page ID
572
+ # @param subscriber_id(string) Subscriber ID
573
+ # @return object
574
+
575
+ def subscriber_remove(statuspage_id, subscriber_id)
576
+ response = RestClient.delete(@url + 'subscriber/remove/' + statuspage_id + '/' + subscriber_id, @headers)
577
+ if (response.code == 200)
578
+ return JSON.parse(response.body)
579
+ end
580
+ end
581
+ end
@@ -0,0 +1,3 @@
1
+ class StatusioClient
2
+ VERSION = '0.2.0'
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statusio/rb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'statusio'
8
+ spec.version = StatusioClient::VERSION
9
+ spec.authors = ['Status.io']
10
+ spec.email = ['hello@status.io']
11
+
12
+ spec.summary = 'Ruby library wrapper for Status.io'
13
+ spec.description = 'Ruby library wrapper for Status.io - A Complete Status Platform - Status pages, incident tracking, subscriber notifications and more'
14
+ spec.homepage = 'https://status.io'
15
+
16
+ =begin
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'TODO: Set to \'http://mygemserver.com\''
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+ =end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statusio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Status.io
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby library wrapper for Status.io - A Complete Status Platform - Status
14
+ pages, incident tracking, subscriber notifications and more
15
+ email:
16
+ - hello@status.io
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rspec
23
+ - .travis.yml
24
+ - Gemfile
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - lib/statusio.rb
30
+ - lib/statusio/rb/version.rb
31
+ - statusio-rb.gemspec
32
+ homepage: https://status.io
33
+ licenses: []
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.0.14
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Ruby library wrapper for Status.io
55
+ test_files: []