statuspageio 0.1.1 → 0.1.6
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 +5 -5
- data/Gemfile.lock +12 -8
- data/README.md +18 -4
- data/lib/statuspageio.rb +1 -4
- data/lib/statuspageio/client.rb +47 -2
- data/lib/statuspageio/client/incident.rb +5 -0
- data/lib/statuspageio/client/subscriber.rb +52 -0
- data/lib/statuspageio/response_error.rb +35 -0
- data/lib/statuspageio/version.rb +1 -1
- data/statuspageio.gemspec +3 -3
- metadata +27 -15
- data/lib/statuspageio/request.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 541f00d959571fab29334ef1dbff8403564931e8023f7877c256f76edaa1c26b
|
4
|
+
data.tar.gz: 79ef800c5802e0539680880c09fa89519bc9f2f8b97dfff6270d68bc306b4cfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44ad4009dadceee1950526c5930c15b9f56a53d252fed9e967170e3979da8c4c27d6dc4ddcfa990950c0294b66832e094b328402fe221f973ce3885693abaf87
|
7
|
+
data.tar.gz: beb031e23a779106d81711afba0ef97adb4a9987668c31834107880d1eeb9a21013ddf641cd494cf1f95266c9a73191cce17bc5dae1ef62b2b3853660a9a737f
|
data/Gemfile.lock
CHANGED
@@ -1,24 +1,28 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
statuspageio (0.1.
|
5
|
-
httparty (~> 0.
|
4
|
+
statuspageio (0.1.5)
|
5
|
+
httparty (~> 0.17)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
httparty (0.
|
10
|
+
httparty (0.18.1)
|
11
|
+
mime-types (~> 3.0)
|
11
12
|
multi_xml (>= 0.5.2)
|
13
|
+
mime-types (3.3.1)
|
14
|
+
mime-types-data (~> 3.2015)
|
15
|
+
mime-types-data (3.2021.0225)
|
12
16
|
multi_xml (0.6.0)
|
13
|
-
rake (
|
17
|
+
rake (12.3.3)
|
14
18
|
|
15
19
|
PLATFORMS
|
16
|
-
|
20
|
+
x86_64-darwin-19
|
17
21
|
|
18
22
|
DEPENDENCIES
|
19
|
-
bundler (~> 1.
|
20
|
-
rake (~>
|
23
|
+
bundler (~> 2.1, >= 2.1.0)
|
24
|
+
rake (~> 12.3, >= 12.3.3)
|
21
25
|
statuspageio!
|
22
26
|
|
23
27
|
BUNDLED WITH
|
24
|
-
|
28
|
+
2.2.17
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Statuspageio
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Ruby gem for the [Statuspage REST API](https://developer.statuspage.io).
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,23 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
##### In plain Ruby
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = Statuspageio::Client.new(api_key: '<your_api_key>', page_id: '<your_page_id>')
|
27
|
+
client.incidents(:all) # get a list of all your incidents
|
28
|
+
```
|
29
|
+
|
30
|
+
##### In Rails you can configure using an initializer
|
31
|
+
|
32
|
+
`config/intializers/statuspage.rb`
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Statuspageio.configure do |config|
|
36
|
+
config.api_key = ENV['STATUSPAGE_API_KEY']
|
37
|
+
config.page_id = ENV['STATUSPAGE_PAGE_ID']
|
38
|
+
end
|
39
|
+
```
|
26
40
|
|
27
41
|
## Development
|
28
42
|
|
data/lib/statuspageio.rb
CHANGED
@@ -3,15 +3,12 @@ require 'statuspageio/configuration'
|
|
3
3
|
|
4
4
|
module Statuspageio
|
5
5
|
extend Configuration
|
6
|
+
|
6
7
|
class << self
|
7
|
-
# Alias for Statuspageio::Client.new
|
8
|
-
#
|
9
|
-
# @return [Statuspageio::Client]
|
10
8
|
def new(options = {})
|
11
9
|
Statuspageio::Client.new(options)
|
12
10
|
end
|
13
11
|
|
14
|
-
# Delegate to Gems::Client
|
15
12
|
def method_missing(method, *args, &block)
|
16
13
|
return super unless new.respond_to?(method)
|
17
14
|
new.send(method, *args, &block)
|
data/lib/statuspageio/client.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
+
require 'httparty'
|
1
2
|
require 'statuspageio/configuration'
|
2
|
-
require 'statuspageio/
|
3
|
+
require 'statuspageio/response_error'
|
3
4
|
|
4
5
|
module Statuspageio
|
5
6
|
class Client
|
7
|
+
include HTTParty
|
8
|
+
base_uri 'https://api.statuspage.io/v1'
|
9
|
+
|
6
10
|
require 'statuspageio/client/incident'
|
11
|
+
require 'statuspageio/client/subscriber'
|
7
12
|
|
8
|
-
include Statuspageio::Request
|
9
13
|
include Statuspageio::Client::Incident
|
14
|
+
include Statuspageio::Client::Subscriber
|
10
15
|
|
11
16
|
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
12
17
|
|
@@ -16,5 +21,45 @@ module Statuspageio
|
|
16
21
|
send("#{key}=", options[key])
|
17
22
|
end
|
18
23
|
end
|
24
|
+
|
25
|
+
def self.handle_response(response)
|
26
|
+
if response.success?
|
27
|
+
JSON.parse(response.body)
|
28
|
+
else
|
29
|
+
bad_response(response)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.bad_response(response)
|
34
|
+
if response.class == HTTParty::Response
|
35
|
+
raise ResponseError, response
|
36
|
+
end
|
37
|
+
raise StandardError, 'Unknown error'
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete(path)
|
41
|
+
self.class.handle_response(self.class.delete("#{path}.json", headers: headers))
|
42
|
+
end
|
43
|
+
|
44
|
+
def get(path, query = {})
|
45
|
+
self.class.handle_response(self.class.get("#{path}.json", query: query, headers: headers))
|
46
|
+
end
|
47
|
+
|
48
|
+
def post(path, data = {})
|
49
|
+
self.class.handle_response(self.class.post("#{path}.json", body: data.to_json, headers: headers))
|
50
|
+
end
|
51
|
+
|
52
|
+
def put(path, data = {})
|
53
|
+
self.class.handle_response(self.class.put("#{path}.json", body: data.to_json, headers: headers))
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def headers
|
59
|
+
{
|
60
|
+
'Authorization' => "OAuth #{self.api_key}",
|
61
|
+
'Content-Type' => 'application/json'
|
62
|
+
}
|
63
|
+
end
|
19
64
|
end
|
20
65
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Statuspageio
|
2
|
+
class Client
|
3
|
+
module Subscriber
|
4
|
+
SUBSCRIBER_OPTIONS = %i(
|
5
|
+
email
|
6
|
+
endpoint
|
7
|
+
phone_country
|
8
|
+
phone_number
|
9
|
+
skip_confirmation_notification
|
10
|
+
page_access_user
|
11
|
+
component_ids
|
12
|
+
)
|
13
|
+
|
14
|
+
def subscribers(incident_id: nil)
|
15
|
+
if incident_id
|
16
|
+
get("/pages/#{self.page_id}/incidents/#{incident_id}/subscribers")
|
17
|
+
else
|
18
|
+
get("/pages/#{self.page_id}/subscribers")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def search_subscribers(q)
|
23
|
+
return subscribers if q.nil? || q.empty?
|
24
|
+
get("/pages/#{self.page_id}/subscribers", { q: q })
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_subscriber(options)
|
28
|
+
create_options = options.dup.slice(*SUBSCRIBER_OPTIONS)
|
29
|
+
|
30
|
+
if valid_for_subscribing?(create_options)
|
31
|
+
post("/pages/#{self.page_id}/subscribers", { subscriber: create_options })
|
32
|
+
else
|
33
|
+
raise ArgumentError, 'An email address or phone number with the two digit country code is required'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete_subscriber(subscriber_id, incident_id: nil)
|
38
|
+
if incident_id
|
39
|
+
delete("/pages/#{self.page_id}/incidents/#{incident_id}/subscribers/#{subscriber_id}")
|
40
|
+
else
|
41
|
+
delete("/pages/#{self.page_id}/subscribers/#{subscriber_id}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def valid_for_subscribing?(options)
|
48
|
+
!(options[:email].empty? && (options[:phone_country].empty? || options[:phone_number].empty?))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Statuspageio
|
2
|
+
class ResponseError < StandardError
|
3
|
+
|
4
|
+
attr_reader :response, :code, :errors
|
5
|
+
|
6
|
+
def initialize(res)
|
7
|
+
@response = res.response
|
8
|
+
@code = res.code
|
9
|
+
begin
|
10
|
+
@errors = parse_errors(res.parsed_response)
|
11
|
+
rescue JSON::ParserError
|
12
|
+
@errors = [res.response.body]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"#{code.to_s} #{response.msg}".strip
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def parse_errors(errors)
|
23
|
+
return case errors
|
24
|
+
when Hash
|
25
|
+
errors.collect{|k,v| "#{k}: #{v}"}
|
26
|
+
when String
|
27
|
+
[errors]
|
28
|
+
when Array
|
29
|
+
errors
|
30
|
+
else
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/statuspageio/version.rb
CHANGED
data/statuspageio.gemspec
CHANGED
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
|
-
spec.add_dependency "httparty", "~> 0.
|
32
|
+
spec.add_dependency "httparty", "~> 0.17"
|
33
33
|
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
34
|
+
spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.0'
|
35
|
+
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
|
36
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statuspageio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Nixon
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -16,43 +16,55 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: '0.17'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: '0.17'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1
|
33
|
+
version: '2.1'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.1.0
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
41
|
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1
|
43
|
+
version: '2.1'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.1.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: rake
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '12.3'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 12.3.3
|
48
57
|
type: :development
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
52
61
|
- - "~>"
|
53
62
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
|
63
|
+
version: '12.3'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 12.3.3
|
67
|
+
description:
|
56
68
|
email:
|
57
69
|
- chris.d.nixon@gmail.com
|
58
70
|
executables: []
|
@@ -70,15 +82,16 @@ files:
|
|
70
82
|
- lib/statuspageio.rb
|
71
83
|
- lib/statuspageio/client.rb
|
72
84
|
- lib/statuspageio/client/incident.rb
|
85
|
+
- lib/statuspageio/client/subscriber.rb
|
73
86
|
- lib/statuspageio/configuration.rb
|
74
|
-
- lib/statuspageio/
|
87
|
+
- lib/statuspageio/response_error.rb
|
75
88
|
- lib/statuspageio/version.rb
|
76
89
|
- statuspageio.gemspec
|
77
90
|
homepage: https://github.com/dasnixon/statuspageio
|
78
91
|
licenses:
|
79
92
|
- MIT
|
80
93
|
metadata: {}
|
81
|
-
post_install_message:
|
94
|
+
post_install_message:
|
82
95
|
rdoc_options: []
|
83
96
|
require_paths:
|
84
97
|
- lib
|
@@ -93,9 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
106
|
- !ruby/object:Gem::Version
|
94
107
|
version: '0'
|
95
108
|
requirements: []
|
96
|
-
|
97
|
-
|
98
|
-
signing_key:
|
109
|
+
rubygems_version: 3.1.4
|
110
|
+
signing_key:
|
99
111
|
specification_version: 4
|
100
112
|
summary: Ruby API wrapper for Statuspage.io.
|
101
113
|
test_files: []
|
data/lib/statuspageio/request.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
|
3
|
-
module Statuspageio
|
4
|
-
module Request
|
5
|
-
include HTTParty
|
6
|
-
base_uri 'api.statuspage.io/v1'
|
7
|
-
|
8
|
-
def delete(path, data = {})
|
9
|
-
self.class.delete("#{path}.json", data, headers: headers)
|
10
|
-
end
|
11
|
-
|
12
|
-
def get(path, data = {})
|
13
|
-
self.class.get("#{path}.json", data, headers: headers)
|
14
|
-
end
|
15
|
-
|
16
|
-
def post(path, data = {})
|
17
|
-
self.class.post("#{path}.json", data, headers: headers)
|
18
|
-
end
|
19
|
-
|
20
|
-
def put(path, data = {})
|
21
|
-
self.class.put("#{path}.json", data, headers: headers)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def headers
|
27
|
-
{ Authorization: "OAuth #{self.api_key}" }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|