spage 0.1.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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +24 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/bin/console +20 -0
- data/bin/setup +8 -0
- data/lib/spage.rb +38 -0
- data/lib/spage/api.rb +11 -0
- data/lib/spage/api/incident.rb +76 -0
- data/lib/spage/api/page.rb +53 -0
- data/lib/spage/client.rb +52 -0
- data/lib/spage/config.rb +21 -0
- data/lib/spage/resources/incident.rb +69 -0
- data/lib/spage/resources/page.rb +71 -0
- data/lib/spage/serializers/incident.rb +76 -0
- data/lib/spage/serializers/page.rb +79 -0
- data/lib/spage/version.rb +3 -0
- data/spage.gemspec +33 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 54883813e4806e59ff2641b139408d512d21bc30c873b1a01c401541849cf49b
|
4
|
+
data.tar.gz: a7388e1c8b05ea32342411a7d62ef4fcb821606e8b3194dd1f42ac6e92dbc901
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b85f98b5d7aca797bb91e43ffb071c5c2e9c39cd8c1511c9e206d707cf11f56651ea54f8dccf9b3f0e1cc00c9666f8cf4a81d351ef2b5fcaac2929c8de56057e
|
7
|
+
data.tar.gz: 4a005cd7b9e291b83a9a15fe8cabadb663e48282ab2571a172e46f3e998c83e52934db68f8a504692de130c6e4a0fd5d1a6a480d57a834fc09173273ff00260d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Style/SymbolArray:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
# Want to be able to assign config
|
5
|
+
# without using =
|
6
|
+
Style/TrivialAccessors:
|
7
|
+
Exclude:
|
8
|
+
- 'lib/status_page/config.rb'
|
9
|
+
|
10
|
+
# Don't need to create frozen string const in specs
|
11
|
+
Style/FrozenStringLiteralComment:
|
12
|
+
Exclude:
|
13
|
+
- 'spec/**/*'
|
14
|
+
Metrics/BlockLength:
|
15
|
+
Exclude:
|
16
|
+
- 'spec/**/*'
|
17
|
+
|
18
|
+
Layout/MultilineMethodCallIndentation:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
# allow "expect { \n ..}"
|
22
|
+
Style/BlockDelimiters:
|
23
|
+
Exclude:
|
24
|
+
- 'spec/**/*'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Iain McNulty
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Spage
|
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/spage`. To experiment with that code,
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'spage'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install spage
|
22
|
+
|
23
|
+
|
24
|
+
## Official Docs
|
25
|
+
|
26
|
+
[StatusPage API documentation](https://developer.statuspage.io/)
|
27
|
+
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Configuration
|
32
|
+
Configure the client with your API key
|
33
|
+
You can put this in an initailizer in Rails
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
Spage.configure do |config|
|
37
|
+
config.api_key(YOUR_API_KEY)
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
### Client
|
43
|
+
|
44
|
+
`Spage::Api::Page.all` returns all the pages for your account
|
45
|
+
`Spage::Api::Page.find(id)` returns a single page
|
46
|
+
`Spage::Api::Page.update(id, page)` updates the page
|
47
|
+
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
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).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nulty/spage.
|
58
|
+
|
59
|
+
### Testing
|
60
|
+
|
61
|
+
The test suite should run normally. If the recorded API requests need to be updated, set an environment variable for the API key
|
62
|
+
|
63
|
+
`STATUSPAGE_API_KEY=your-api-key bundle exec rspec`
|
64
|
+
|
65
|
+
## Roadmap
|
66
|
+
|
67
|
+
- Add a logger with null logging
|
68
|
+
- Add url_encoded body option to configuration
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'spage'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require 'pry'
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
begin
|
15
|
+
require 'pry'
|
16
|
+
Pry.start
|
17
|
+
rescue LoadError
|
18
|
+
require 'irb'
|
19
|
+
IRB.start(__FILE__)
|
20
|
+
end
|
data/bin/setup
ADDED
data/lib/spage.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path('./lib')
|
4
|
+
|
5
|
+
require 'json'
|
6
|
+
require 'time'
|
7
|
+
|
8
|
+
require 'spage/version'
|
9
|
+
require 'spage/client'
|
10
|
+
require 'spage/config'
|
11
|
+
|
12
|
+
# Base module for the Spage Client
|
13
|
+
module Spage
|
14
|
+
class Error < StandardError; end
|
15
|
+
|
16
|
+
autoload :Api, 'spage/api'
|
17
|
+
autoload :Page, 'spage/resources/page'
|
18
|
+
autoload :Incident, 'spage/resources/incident'
|
19
|
+
|
20
|
+
module Api
|
21
|
+
autoload :Page, 'spage/api/page'
|
22
|
+
autoload :Incident, 'spage/api/incident'
|
23
|
+
end
|
24
|
+
|
25
|
+
module Serializers
|
26
|
+
autoload :Page, 'spage/serializers/page'
|
27
|
+
autoload :Incident, 'spage/serializers/incident'
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.config
|
31
|
+
@config ||= Config.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.configure
|
35
|
+
yield(config)
|
36
|
+
config
|
37
|
+
end
|
38
|
+
end
|
data/lib/spage/api.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spage
|
4
|
+
# Api Module
|
5
|
+
#
|
6
|
+
module Api
|
7
|
+
# Incident resources in the statuspage.io API
|
8
|
+
#
|
9
|
+
class Incident
|
10
|
+
include Api
|
11
|
+
|
12
|
+
def all(page_id:)
|
13
|
+
response = client.get("pages/#{page_id}/incidents")
|
14
|
+
|
15
|
+
handle_response(response) do
|
16
|
+
response.body.map do |incident|
|
17
|
+
Spage::Incident.new(incident)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def unresolved(page_id:)
|
23
|
+
response = client.get("pages/#{page_id}/incidents/unresolved")
|
24
|
+
|
25
|
+
handle_response(response) do
|
26
|
+
response.body.map do |incident|
|
27
|
+
Spage::Incident.new(incident)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def find(page_id:, id:)
|
33
|
+
response = client.get("pages/#{page_id}/incidents", id)
|
34
|
+
|
35
|
+
handle_response(response) do
|
36
|
+
Spage::Incident.new(response.body)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def create(incident, page_id:)
|
41
|
+
json = Spage::Serializers::Incident.new(incident,
|
42
|
+
update: true).to_json
|
43
|
+
|
44
|
+
response = client.post("pages/#{page_id}/incidents", json)
|
45
|
+
|
46
|
+
handle_response(response) do
|
47
|
+
Spage::Incident.new(response.body)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def update(incident, page_id:, id:)
|
52
|
+
json = Spage::Serializers::Incident.new(incident,
|
53
|
+
update: true).to_json
|
54
|
+
response = client.put("pages/#{page_id}/incidents", id, json)
|
55
|
+
|
56
|
+
handle_response(response) do
|
57
|
+
Spage::Incident.new(response.body)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def handle_response(response)
|
65
|
+
case response
|
66
|
+
when Net::HTTPSuccess
|
67
|
+
yield
|
68
|
+
when Net::HTTPUnauthorized
|
69
|
+
raise(Error, 'Unauthorized: wrong API Key')
|
70
|
+
else
|
71
|
+
# Net::HTTPBadRequest, Net::HTTPUnprocessableEntity, Net::HTTPForbidden
|
72
|
+
raise(Error, response.body)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spage
|
4
|
+
# Api Module
|
5
|
+
#
|
6
|
+
module Api
|
7
|
+
# Page resources in the statuspage.io API
|
8
|
+
#
|
9
|
+
class Page
|
10
|
+
include Api
|
11
|
+
|
12
|
+
def all
|
13
|
+
response = client.get(:pages)
|
14
|
+
|
15
|
+
handle_response(response) do
|
16
|
+
response.body.map do |page|
|
17
|
+
Spage::Page.new(page)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def find(id)
|
23
|
+
response = client.get(:pages, id)
|
24
|
+
|
25
|
+
handle_response(response) do
|
26
|
+
Spage::Page.new(response.body)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def update(id, page)
|
31
|
+
json = Spage::Serializers::Page.new(page, update: true).to_json
|
32
|
+
response = client.put(:pages, id, json)
|
33
|
+
|
34
|
+
handle_response(response) do
|
35
|
+
Spage::Page.new(response.body)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def handle_response(response)
|
43
|
+
case response
|
44
|
+
when Net::HTTPSuccess
|
45
|
+
yield
|
46
|
+
when Net::HTTPUnauthorized
|
47
|
+
raise(Error, 'Unauthorized: wrong API Key')
|
48
|
+
when Net::HTTPBadRequest
|
49
|
+
raise(Error, response.body)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/spage/client.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
BASE_URL = 'api.statuspage.io'
|
7
|
+
|
8
|
+
module Spage
|
9
|
+
# HTTP client for making requests to statuspage.io
|
10
|
+
#
|
11
|
+
class Client
|
12
|
+
def initialize
|
13
|
+
@api_key = Spage.config.api_key
|
14
|
+
@api_version = Spage.config.api_version
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(resource, id = nil)
|
18
|
+
make_request(Net::HTTP::Get, resource, id)
|
19
|
+
end
|
20
|
+
|
21
|
+
def put(resource, id, body)
|
22
|
+
make_request(Net::HTTP::Put, resource, id, body)
|
23
|
+
end
|
24
|
+
|
25
|
+
def post(resource, body)
|
26
|
+
make_request(Net::HTTP::Post, resource, id = nil, body)
|
27
|
+
end
|
28
|
+
|
29
|
+
# rubocop: disable Metrics/MethodLength
|
30
|
+
def make_request(http_method, resource, id, body = nil)
|
31
|
+
path = [@api_version, resource, id].compact.join('/')
|
32
|
+
uri = URI::HTTP.build(host: BASE_URL, path: "/#{path}")
|
33
|
+
|
34
|
+
request = http_method.new(uri)
|
35
|
+
request.add_field('Authorization', "OAuth #{@api_key}")
|
36
|
+
request.add_field('Content-Type', 'application/json')
|
37
|
+
|
38
|
+
request.body = body if request.request_body_permitted?
|
39
|
+
|
40
|
+
res = Net::HTTP.start(uri.hostname, use_ssl: true) do |http|
|
41
|
+
response = http.request(request)
|
42
|
+
|
43
|
+
response.body = JSON.parse(response.body)
|
44
|
+
response
|
45
|
+
end
|
46
|
+
|
47
|
+
yield(res) if block_given?
|
48
|
+
res
|
49
|
+
end
|
50
|
+
# rubocop: enable Metrics/MethodLength
|
51
|
+
end
|
52
|
+
end
|
data/lib/spage/config.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spage
|
4
|
+
# Global Configuration for the Spage Client
|
5
|
+
#
|
6
|
+
class Config
|
7
|
+
def initialize
|
8
|
+
@api_endpoint = 'https://api.statuspage.io'
|
9
|
+
@api_version = 'v1'
|
10
|
+
@api_key = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def api_key(api_key = nil)
|
14
|
+
(api_key && @api_key = api_key) || @api_key
|
15
|
+
end
|
16
|
+
|
17
|
+
def api_version(api_version = nil)
|
18
|
+
(api_version && @api_version = api_version) || @api_version
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spage
|
4
|
+
# Page resource in statuspage.io
|
5
|
+
#
|
6
|
+
class Incident
|
7
|
+
# rubocop: disable Metrics/MethodLength, Metrics/AbcSize, Layout/LineLength
|
8
|
+
def initialize(attrs)
|
9
|
+
@id = attrs['id']
|
10
|
+
@components = attrs['components'] # Array of Component
|
11
|
+
@impact = attrs['impact']
|
12
|
+
@impact_override = attrs['impact_override']
|
13
|
+
@incident_updates = attrs['incident_updates'] # Array of IncidentUpdate
|
14
|
+
@metadata = attrs['metadata'] # Hash of values
|
15
|
+
@name = attrs['name']
|
16
|
+
@page_id = attrs['page_id']
|
17
|
+
@postmortem_body = attrs['postmortem_body']
|
18
|
+
@postmortem_body_last_updated_at = attrs['postmortem_body_last_updated_at']
|
19
|
+
@postmortem_ignored = attrs['postmortem_ignored']
|
20
|
+
@postmortem_notified_subscribers = attrs['postmortem_notified_subscribers']
|
21
|
+
@postmortem_notified_twitter = attrs['postmortem_notified_twitter']
|
22
|
+
@postmortem_published_at = attrs['postmortem_published_at']
|
23
|
+
@scheduled_auto_completed = attrs['scheduled_auto_completed']
|
24
|
+
@scheduled_auto_in_progress = attrs['scheduled_auto_in_progress']
|
25
|
+
@scheduled_for = attrs['scheduled_for']
|
26
|
+
@scheduled_remind_prior = attrs['scheduled_remind_prior']
|
27
|
+
@scheduled_reminded_at = date_parse(attrs['scheduled_reminded_at'])
|
28
|
+
@scheduled_until = attrs['scheduled_until']
|
29
|
+
@shortlink = attrs['shortlink']
|
30
|
+
@status = attrs['status']
|
31
|
+
@monitoring_at = date_parse(attrs['monitoring_at'])
|
32
|
+
@resolved_at = date_parse(attrs['resolved_at'])
|
33
|
+
@created_at = date_parse(attrs['created_at'])
|
34
|
+
@updated_at = date_parse(attrs['updated_at'])
|
35
|
+
|
36
|
+
# vars only used to update/create incident
|
37
|
+
@deliver_notifications = attrs['deliver_notifications']
|
38
|
+
@auto_transition_deliver_notifications_at_end = attrs['auto_transition_deliver_notifications_at_end']
|
39
|
+
@auto_transition_deliver_notifications_at_start = attrs['auto_transition_deliver_notifications_at_start']
|
40
|
+
@auto_transition_to_maintenance_state = attrs['auto_transition_to_maintenance_state']
|
41
|
+
@auto_transition_to_operational_state = attrs['auto_transition_to_operational_state']
|
42
|
+
@auto_tweet_at_beginning = attrs['auto_tweet_at_beginning']
|
43
|
+
@auto_tweet_on_completion = attrs['auto_tweet_on_completion']
|
44
|
+
@auto_tweet_on_creation = attrs['auto_tweet_on_creation']
|
45
|
+
@auto_tweet_one_hour_before = attrs['auto_tweet_one_hour_before']
|
46
|
+
@backfill_date = attrs['backfill_date']
|
47
|
+
@backfilled = attrs['backfilled']
|
48
|
+
@body = attrs['body']
|
49
|
+
@component_ids = attrs['component_ids']
|
50
|
+
@scheduled_auto_transition = attrs['scheduled_auto_transition']
|
51
|
+
end
|
52
|
+
# rubocop: enable Metrics/MethodLength, Metrics/AbcSize, Layout/LineLength
|
53
|
+
|
54
|
+
# rubocop: disable Layout/LineLength
|
55
|
+
attr_reader :id, :created_at, :impact, :incident_updates, :monitoring_at, :page_id, :postmortem_body, :postmortem_body_last_updated_at, :postmortem_ignored, :postmortem_notified_subscribers, :postmortem_notified_twitter, :postmortem_published_at, :resolved_at, :shortlink, :updated_at
|
56
|
+
|
57
|
+
attr_accessor :name, :status, :impact_override, :scheduled_for, :scheduled_until, :scheduled_remind_prior, :scheduled_auto_in_progress, :scheduled_auto_completed, :metadata, :deliver_notifications, :auto_transition_deliver_notifications_at_end, :auto_transition_deliver_notifications_at_start, :auto_transition_to_maintenance_state, :auto_transition_to_operational_state, :auto_tweet_at_beginning, :auto_tweet_on_completion, :auto_tweet_on_creation, :auto_tweet_one_hour_before, :backfill_date, :backfilled, :body, :components, :component_ids, :scheduled_auto_transition
|
58
|
+
# rubocop: enable Layout/LineLength
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def date_parse(str)
|
63
|
+
return str if str.nil?
|
64
|
+
return str if str.is_a?(DateTime)
|
65
|
+
|
66
|
+
DateTime.parse(str)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spage
|
4
|
+
# Page resource in statuspage.io
|
5
|
+
#
|
6
|
+
class Page
|
7
|
+
# rubocop: disable Metrics/MethodLength, Metrics/AbcSize
|
8
|
+
def initialize(attrs)
|
9
|
+
@id = attrs['id']
|
10
|
+
@created_at = date_parse(attrs['created_at'])
|
11
|
+
@updated_at = date_parse(attrs['updated_at'])
|
12
|
+
@name = attrs['name']
|
13
|
+
@page_description = attrs['page_description']
|
14
|
+
@headline = attrs['headline']
|
15
|
+
@branding = attrs['branding']
|
16
|
+
@subdomain = attrs['subdomain']
|
17
|
+
@domain = attrs['domain']
|
18
|
+
@url = attrs['url']
|
19
|
+
@support_url = attrs['support_url']
|
20
|
+
@hidden_from_search = attrs['hidden_from_search']
|
21
|
+
@allow_page_subscribers = attrs['allow_page_subscribers']
|
22
|
+
@allow_incident_subscribers = attrs['allow_incident_subscribers']
|
23
|
+
@allow_email_subscribers = attrs['allow_email_subscribers']
|
24
|
+
@allow_sms_subscribers = attrs['allow_sms_subscribers']
|
25
|
+
@allow_rss_atom_feeds = attrs['allow_rss_atom_feeds']
|
26
|
+
@allow_webhook_subscribers = attrs['allow_webhook_subscribers']
|
27
|
+
@notifications_from_email = attrs['notifications_from_email']
|
28
|
+
@notifications_email_footer = attrs['notifications_email_footer']
|
29
|
+
@activity_score = attrs['activity_score']
|
30
|
+
@twitter_username = attrs['twitter_username']
|
31
|
+
@viewers_must_be_team_members = attrs['viewers_must_be_team_members']
|
32
|
+
@ip_restrictions = attrs['ip_restrictions']
|
33
|
+
@city = attrs['city']
|
34
|
+
@state = attrs['state']
|
35
|
+
@country = attrs['country']
|
36
|
+
@time_zone = attrs['time_zone']
|
37
|
+
@css_body_background_color = attrs['css_body_background_color']
|
38
|
+
@css_font_color = attrs['css_font_color']
|
39
|
+
@css_light_font_color = attrs['css_light_font_color']
|
40
|
+
@css_greens = attrs['css_greens']
|
41
|
+
@css_yellows = attrs['css_yellows']
|
42
|
+
@css_oranges = attrs['css_oranges']
|
43
|
+
@css_blues = attrs['css_blues']
|
44
|
+
@css_reds = attrs['css_reds']
|
45
|
+
@css_border_color = attrs['css_border_color']
|
46
|
+
@css_graph_color = attrs['css_graph_color']
|
47
|
+
@css_link_color = attrs['css_link_color']
|
48
|
+
@css_no_data = attrs['css_no_data']
|
49
|
+
@favicon_logo = attrs['favicon_logo']
|
50
|
+
@transactional_logo = attrs['transactional_logo']
|
51
|
+
@hero_cover = attrs['hero_cover']
|
52
|
+
@email_logo = attrs['email_logo']
|
53
|
+
@twitter_logo = attrs['twitter_logo']
|
54
|
+
end
|
55
|
+
# rubocop: enable Metrics/MethodLength, Metrics/AbcSize
|
56
|
+
|
57
|
+
# rubocop: disable Layout/LineLength
|
58
|
+
attr_reader :id, :created_at, :updated_at, :page_description, :headline, :support_url, :activity_score, :twitter_username, :ip_restrictions, :city, :state, :country, :favicon_logo, :transactional_logo, :hero_cover, :email_logo, :twitter_logo
|
59
|
+
|
60
|
+
attr_accessor :name, :domain, :subdomain, :url, :branding, :css_body_background_color, :css_font_color, :css_light_font_color, :css_greens, :css_yellows, :css_oranges, :css_reds, :css_blues, :css_border_color, :css_graph_color, :css_link_color, :css_no_data, :hidden_from_search, :viewers_must_be_team_members, :allow_page_subscribers, :allow_incident_subscribers, :allow_email_subscribers, :allow_sms_subscribers, :allow_rss_atom_feeds, :allow_webhook_subscribers, :notifications_from_email, :time_zone, :notifications_email_footer
|
61
|
+
|
62
|
+
# rubocop: enable Layout/LineLength
|
63
|
+
|
64
|
+
def date_parse(str)
|
65
|
+
return str if str.nil?
|
66
|
+
return str if str.is_a?(DateTime)
|
67
|
+
|
68
|
+
DateTime.parse(str)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spage
|
4
|
+
module Serializers
|
5
|
+
# Serializer for the Page resource
|
6
|
+
#
|
7
|
+
class Incident
|
8
|
+
def initialize(incident, update: false)
|
9
|
+
@incident = incident
|
10
|
+
@ivars = ivars(update)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_json(obj = nil)
|
14
|
+
as_json.to_json(obj)
|
15
|
+
end
|
16
|
+
|
17
|
+
def as_json
|
18
|
+
to_hash
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
{
|
23
|
+
'incident' => Hash[
|
24
|
+
@ivars.map do |name|
|
25
|
+
[name[1..-1], @incident.instance_variable_get(name)]
|
26
|
+
end
|
27
|
+
]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def ivars(update)
|
34
|
+
if update
|
35
|
+
@incident.instance_variables.select do |name|
|
36
|
+
processed_name = name[1..-1]
|
37
|
+
update_attrs.include?(processed_name) && !@incident.send(processed_name).nil?
|
38
|
+
end
|
39
|
+
else
|
40
|
+
@incident.instance_variables
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# rubocop: disable Metrics/MethodLength
|
45
|
+
def update_attrs
|
46
|
+
%w[
|
47
|
+
name
|
48
|
+
status
|
49
|
+
impact_override
|
50
|
+
scheduled_for
|
51
|
+
scheduled_until
|
52
|
+
scheduled_remind_prior
|
53
|
+
scheduled_auto_in_progress
|
54
|
+
scheduled_auto_completed
|
55
|
+
metadata
|
56
|
+
deliver_notifications
|
57
|
+
auto_transition_deliver_notifications_at_end
|
58
|
+
auto_transition_deliver_notifications_at_start
|
59
|
+
auto_transition_to_maintenance_state
|
60
|
+
auto_transition_to_operational_state
|
61
|
+
auto_tweet_at_beginning
|
62
|
+
auto_tweet_on_completion
|
63
|
+
auto_tweet_on_creation
|
64
|
+
auto_tweet_one_hour_before
|
65
|
+
backfill_date
|
66
|
+
backfilled
|
67
|
+
body
|
68
|
+
components
|
69
|
+
component_ids
|
70
|
+
scheduled_auto_transition
|
71
|
+
]
|
72
|
+
end
|
73
|
+
# rubocop: enable Metrics/MethodLength
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spage
|
4
|
+
module Serializers
|
5
|
+
# Serializer for the Page resource
|
6
|
+
#
|
7
|
+
class Page
|
8
|
+
def initialize(page, update: false)
|
9
|
+
@page = page
|
10
|
+
@ivars = ivars(update)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_json(obj = nil)
|
14
|
+
as_json.to_json(obj)
|
15
|
+
end
|
16
|
+
|
17
|
+
def as_json
|
18
|
+
to_hash
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
{
|
23
|
+
'page' => Hash[
|
24
|
+
@ivars.map do |name|
|
25
|
+
[name[1..-1], @page.instance_variable_get(name)]
|
26
|
+
end
|
27
|
+
]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def ivars(update)
|
34
|
+
if update
|
35
|
+
@page.instance_variables.select do |name|
|
36
|
+
update_attrs.include?(name[1..-1])
|
37
|
+
end
|
38
|
+
else
|
39
|
+
@page.instance_variables
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# rubocop: disable Metrics/MethodLength
|
44
|
+
def update_attrs
|
45
|
+
%w[
|
46
|
+
name
|
47
|
+
domain
|
48
|
+
subdomain
|
49
|
+
url
|
50
|
+
branding
|
51
|
+
css_body_background_color
|
52
|
+
css_font_color
|
53
|
+
css_light_font_color
|
54
|
+
css_greens
|
55
|
+
css_yellows
|
56
|
+
css_oranges
|
57
|
+
css_reds
|
58
|
+
css_blues
|
59
|
+
css_border_color
|
60
|
+
css_graph_color
|
61
|
+
css_link_color
|
62
|
+
css_no_data
|
63
|
+
hidden_from_search
|
64
|
+
viewers_must_be_team_members
|
65
|
+
allow_page_subscribers
|
66
|
+
allow_incident_subscribers
|
67
|
+
allow_email_subscribers
|
68
|
+
allow_sms_subscribers
|
69
|
+
allow_rss_atom_feeds
|
70
|
+
allow_webhook_subscribers
|
71
|
+
notifications_from_email
|
72
|
+
time_zone
|
73
|
+
notifications_email_footer
|
74
|
+
]
|
75
|
+
end
|
76
|
+
# rubocop: enable Metrics/MethodLength
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/spage.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'lib/spage/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "spage"
|
5
|
+
spec.version = Spage::VERSION
|
6
|
+
spec.authors = ["Iain McNulty"]
|
7
|
+
spec.email = ["iain@inulty.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Ruby Client for using the Spage API}
|
10
|
+
spec.description = %q{Ruby client for making requests the Spage API}
|
11
|
+
spec.homepage = "https://github.com/nulty/spage"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
14
|
+
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/nulty/spage"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/nulty/spage/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
spec.add_development_dependency "vcr"
|
30
|
+
spec.add_development_dependency "webmock"
|
31
|
+
spec.add_development_dependency "simplecov"
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Iain McNulty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: vcr
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Ruby client for making requests the Spage API
|
70
|
+
email:
|
71
|
+
- iain@inulty.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/spage.rb
|
88
|
+
- lib/spage/api.rb
|
89
|
+
- lib/spage/api/incident.rb
|
90
|
+
- lib/spage/api/page.rb
|
91
|
+
- lib/spage/client.rb
|
92
|
+
- lib/spage/config.rb
|
93
|
+
- lib/spage/resources/incident.rb
|
94
|
+
- lib/spage/resources/page.rb
|
95
|
+
- lib/spage/serializers/incident.rb
|
96
|
+
- lib/spage/serializers/page.rb
|
97
|
+
- lib/spage/version.rb
|
98
|
+
- spage.gemspec
|
99
|
+
homepage: https://github.com/nulty/spage
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata:
|
103
|
+
homepage_uri: https://github.com/nulty/spage
|
104
|
+
source_code_uri: https://github.com/nulty/spage
|
105
|
+
changelog_uri: https://github.com/nulty/spage/CHANGELOG.md
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 2.5.0
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubygems_version: 3.0.3
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Ruby Client for using the Spage API
|
125
|
+
test_files: []
|