statuspageio 0.1.4 → 0.1.5
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/lib/statuspageio.rb +1 -4
- data/lib/statuspageio/client.rb +11 -5
- data/lib/statuspageio/client/subscriber.rb +52 -0
- data/lib/statuspageio/response_error.rb +0 -6
- data/lib/statuspageio/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c94e53b439a9509a7bb2d66d4935f6d7fc4264155ef471de82cb36660a226715
|
4
|
+
data.tar.gz: 39b2b3672117b309391f9cb1cb3bc6d4edb4a4836f288ab7b527572014967b69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fa4e7c17f275c7d40e7064109b662534fc3460450d2e351b1154cdd1254dce9ec54c8a42395031211c46aafa109e7de9652e3ed484c293d3373ab2ff60be26f
|
7
|
+
data.tar.gz: 0dc970cf730beabc42b60455850ceec989b2a1d1d47eeac9411b4b84d751f6892ae71e69d442ad3e81092ff17056dcd8d78511b509e0df4d2b44635af714b535
|
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
@@ -5,10 +5,13 @@ require 'statuspageio/response_error'
|
|
5
5
|
module Statuspageio
|
6
6
|
class Client
|
7
7
|
include HTTParty
|
8
|
-
base_uri 'api.statuspage.io/v1'
|
8
|
+
base_uri 'https://api.statuspage.io/v1'
|
9
9
|
|
10
10
|
require 'statuspageio/client/incident'
|
11
|
+
require 'statuspageio/client/subscriber'
|
12
|
+
|
11
13
|
include Statuspageio::Client::Incident
|
14
|
+
include Statuspageio::Client::Subscriber
|
12
15
|
|
13
16
|
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
14
17
|
|
@@ -31,7 +34,7 @@ module Statuspageio
|
|
31
34
|
if response.class == HTTParty::Response
|
32
35
|
raise ResponseError, response
|
33
36
|
end
|
34
|
-
raise StandardError,
|
37
|
+
raise StandardError, 'Unknown error'
|
35
38
|
end
|
36
39
|
|
37
40
|
def delete(path)
|
@@ -43,17 +46,20 @@ module Statuspageio
|
|
43
46
|
end
|
44
47
|
|
45
48
|
def post(path, data = {})
|
46
|
-
self.class.handle_response(self.class.post("#{path}.json", data, headers: headers))
|
49
|
+
self.class.handle_response(self.class.post("#{path}.json", body: data.to_json, headers: headers))
|
47
50
|
end
|
48
51
|
|
49
52
|
def put(path, data = {})
|
50
|
-
self.class.handle_response(self.class.put("#{path}.json", data, headers: headers))
|
53
|
+
self.class.handle_response(self.class.put("#{path}.json", body: data.to_json, headers: headers))
|
51
54
|
end
|
52
55
|
|
53
56
|
private
|
54
57
|
|
55
58
|
def headers
|
56
|
-
{
|
59
|
+
{
|
60
|
+
'Authorization' => "OAuth #{self.api_key}",
|
61
|
+
'Content-Type' => 'application/json'
|
62
|
+
}
|
57
63
|
end
|
58
64
|
end
|
59
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
|
@@ -1,11 +1,8 @@
|
|
1
1
|
module Statuspageio
|
2
|
-
# Error raised on a bad response
|
3
2
|
class ResponseError < StandardError
|
4
3
|
|
5
4
|
attr_reader :response, :code, :errors
|
6
5
|
|
7
|
-
# @param [HTTParty::Response] res
|
8
|
-
# @return [CloudApp::ResponseError]
|
9
6
|
def initialize(res)
|
10
7
|
@response = res.response
|
11
8
|
@code = res.code
|
@@ -16,9 +13,6 @@ module Statuspageio
|
|
16
13
|
end
|
17
14
|
end
|
18
15
|
|
19
|
-
# Returns error code and message
|
20
|
-
#
|
21
|
-
# @return [String]
|
22
16
|
def to_s
|
23
17
|
"#{code.to_s} #{response.msg}".strip
|
24
18
|
end
|
data/lib/statuspageio/version.rb
CHANGED
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Nixon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/statuspageio.rb
|
71
71
|
- lib/statuspageio/client.rb
|
72
72
|
- lib/statuspageio/client/incident.rb
|
73
|
+
- lib/statuspageio/client/subscriber.rb
|
73
74
|
- lib/statuspageio/configuration.rb
|
74
75
|
- lib/statuspageio/response_error.rb
|
75
76
|
- lib/statuspageio/version.rb
|
@@ -93,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
94
|
- !ruby/object:Gem::Version
|
94
95
|
version: '0'
|
95
96
|
requirements: []
|
96
|
-
|
97
|
-
rubygems_version: 2.4.5.1
|
97
|
+
rubygems_version: 3.0.3
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: Ruby API wrapper for Statuspage.io.
|