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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0ec421c4e88d18d4fc0895107ce63e3d81ae6b4d
4
- data.tar.gz: 0a79a02b7197521c53fc52b4d8980981a1a2f1f6
2
+ SHA256:
3
+ metadata.gz: 541f00d959571fab29334ef1dbff8403564931e8023f7877c256f76edaa1c26b
4
+ data.tar.gz: 79ef800c5802e0539680880c09fa89519bc9f2f8b97dfff6270d68bc306b4cfd
5
5
  SHA512:
6
- metadata.gz: 82b6707f58b5f53abe9af0454d4ea4a03af8d254b5ce8ac8383e0e984b7e89ff116b18d4b8f022174420ded0f531b9e4ec0cfdd0d679e8c2b35540e0d4de937e
7
- data.tar.gz: b7ab5e90dda41a0a89f2ae1d11650555489ce2a77a6ea36751fc2c2e3c78fb9ae2eb65fdd3d85042853ec8b8b41dfcc2a27725864140ee69b1fad19a3e7f9fb9
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.0)
5
- httparty (~> 0.15.6)
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.15.6)
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 (10.5.0)
17
+ rake (12.3.3)
14
18
 
15
19
  PLATFORMS
16
- ruby
20
+ x86_64-darwin-19
17
21
 
18
22
  DEPENDENCIES
19
- bundler (~> 1.16)
20
- rake (~> 10.0)
23
+ bundler (~> 2.1, >= 2.1.0)
24
+ rake (~> 12.3, >= 12.3.3)
21
25
  statuspageio!
22
26
 
23
27
  BUNDLED WITH
24
- 1.16.0
28
+ 2.2.17
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Statuspageio
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/statuspageio`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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)
@@ -1,12 +1,17 @@
1
+ require 'httparty'
1
2
  require 'statuspageio/configuration'
2
- require 'statuspageio/request'
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
@@ -13,6 +13,11 @@ module Statuspageio
13
13
  get("/pages/#{self.page_id}/incidents")
14
14
  end
15
15
  end
16
+
17
+ def search_incidents(q)
18
+ return incidents if q.nil? || q.empty?
19
+ get("/pages/#{self.page_id}/incidents", { q: q })
20
+ end
16
21
  end
17
22
  end
18
23
  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
@@ -1,3 +1,3 @@
1
1
  module Statuspageio
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.6'
3
3
  end
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.15.6"
32
+ spec.add_dependency "httparty", "~> 0.17"
33
33
 
34
- spec.add_development_dependency "bundler", "~> 1.16"
35
- spec.add_development_dependency "rake", "~> 10.0"
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.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: 2019-01-07 00:00:00.000000000 Z
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.15.6
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.15.6
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.16'
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.16'
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: '10.0'
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: '10.0'
55
- description:
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/request.rb
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
- rubyforge_project:
97
- rubygems_version: 2.4.5.1
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: []
@@ -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