spage 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54883813e4806e59ff2641b139408d512d21bc30c873b1a01c401541849cf49b
4
- data.tar.gz: a7388e1c8b05ea32342411a7d62ef4fcb821606e8b3194dd1f42ac6e92dbc901
3
+ metadata.gz: 35eb8fd43c5337e98c631c59eb397344965292b8a31b41e374f892e9ef78b5ad
4
+ data.tar.gz: 789bb45f03127d6ffeda448880b9adf7a16f94511a49325c1ca9765c7ed2d9d9
5
5
  SHA512:
6
- metadata.gz: b85f98b5d7aca797bb91e43ffb071c5c2e9c39cd8c1511c9e206d707cf11f56651ea54f8dccf9b3f0e1cc00c9666f8cf4a81d351ef2b5fcaac2929c8de56057e
7
- data.tar.gz: 4a005cd7b9e291b83a9a15fe8cabadb663e48282ab2571a172e46f3e998c83e52934db68f8a504692de130c6e4a0fd5d1a6a480d57a834fc09173273ff00260d
6
+ metadata.gz: c55f9a3bfa318905236d38dd8eac141f78302a87d40686875921664183b72330126985af57ff66bbc7377f7c804b7a201dd877f3a09f5733c08fcd2d17284b25
7
+ data.tar.gz: a56f9e1c53e87c1ed3bee822e194d760e319eb6f7d4a78b53da341adadf2305aff2c4687949f1b7af3b7261bb6dd999626c531382081f5c31fd16fd6caee00ba
data/.gitignore CHANGED
@@ -8,6 +8,6 @@
8
8
  /tmp/
9
9
 
10
10
  Gemfile.lock
11
-
11
+ *.gem
12
12
  # rspec failure tracking
13
13
  .rspec_status
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## [v0.2.0](https://github.com/nulty/spage/tree/v0.2.0) (2020-11-01)
4
+
5
+ - Add CRUD Component API features
6
+
7
+
8
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
9
+ ## [v0.1.0](https://github.com/nulty/spage/tree/v0.1.0) (2020-10-20)
10
+
11
+ [Full Changelog](https://github.com/nulty/spage/compare/a0bab1b42c6762ceaaa448a100763ca57d5f3449...v0.1.0)
12
+
13
+ **Merged pull requests:**
14
+
15
+ - Rename project to Spage [\#1](https://github.com/nulty/spage/pull/1) ([nulty](https://github.com/nulty))
16
+
17
+
18
+
19
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Spage
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/spage`. To experiment with that code,
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Spage is a Ruby client for integrating Statuspage.io into your ruby app. The idea is for it to be more than just a set of http requests to the server. It tries to model the data on the server for you so you don't have to.
6
4
 
7
5
  ## Installation
8
6
 
@@ -38,12 +36,11 @@ Spage.configure do |config|
38
36
  end
39
37
  ```
40
38
 
41
-
42
39
  ### Client
43
40
 
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
41
+ `Spage::Api::Page.new.all` returns all the pages for your account
42
+ `Spage::Api::Page.new.find(id)` returns a single page
43
+ `Spage::Api::Page.new.update(id, page)` updates the page
47
44
 
48
45
 
49
46
  ## Development
@@ -58,14 +55,16 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/nulty/
58
55
 
59
56
  ### Testing
60
57
 
61
- The test suite should run normally. If the recorded API requests need to be updated, set an environment variable for the API key
58
+ The test suite should run normally. If the recorded API requests need to be updated, set an environment variable for the API key and pass the `record: :all` to the use_cassette function you want to re-record.
62
59
 
63
- `STATUSPAGE_API_KEY=your-api-key bundle exec rspec`
60
+ `VCR=1 STATUSPAGE_API_KEY=your-api-key bundle exec rspec`
64
61
 
65
62
  ## Roadmap
66
63
 
67
64
  - Add a logger with null logging
68
65
  - Add url_encoded body option to configuration
66
+ - Validations on the resources
67
+ - Respect HTTP caching like [`faraday/http_cache`](https://github.com/sourcelevel/faraday-http-cache)
69
68
 
70
69
  ## License
71
70
 
@@ -16,15 +16,18 @@ module Spage
16
16
  autoload :Api, 'spage/api'
17
17
  autoload :Page, 'spage/resources/page'
18
18
  autoload :Incident, 'spage/resources/incident'
19
+ autoload :Component, 'spage/resources/component'
19
20
 
20
21
  module Api
21
22
  autoload :Page, 'spage/api/page'
22
23
  autoload :Incident, 'spage/api/incident'
24
+ autoload :Component, 'spage/api/component'
23
25
  end
24
26
 
25
27
  module Serializers
26
28
  autoload :Page, 'spage/serializers/page'
27
29
  autoload :Incident, 'spage/serializers/incident'
30
+ autoload :Component, 'spage/serializers/component'
28
31
  end
29
32
 
30
33
  def self.config
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spage
4
+ # Api Module
5
+ #
6
+ module Api
7
+ # Component resources in the statuspage.io API
8
+ #
9
+ class Component
10
+ include Api
11
+
12
+ def all(page_id:)
13
+ response = client.get("pages/#{page_id}/components")
14
+
15
+ handle_response(response) do
16
+ response.body.map do |component|
17
+ Spage::Component.new(component)
18
+ end
19
+ end
20
+ end
21
+
22
+ def find(page_id:, id:)
23
+ response = client.get("pages/#{page_id}/components", id)
24
+
25
+ handle_response(response) do
26
+ Spage::Component.new(response.body)
27
+ end
28
+ end
29
+
30
+ def create(component, page_id:)
31
+ json = Spage::Serializers::Component.new(component,
32
+ update: true).to_json
33
+ response = client.post("pages/#{page_id}/components", json)
34
+
35
+ handle_response(response) do
36
+ Spage::Component.new(response.body)
37
+ end
38
+ end
39
+
40
+ def update(component, page_id:, id:)
41
+ json = Spage::Serializers::Component.new(component,
42
+ update: true).to_json
43
+ response = client.put("pages/#{page_id}/components", id, json)
44
+
45
+ handle_response(response) do
46
+ Spage::Component.new(response.body)
47
+ end
48
+ end
49
+
50
+ def delete(page_id:, id:)
51
+ response = client.delete("pages/#{page_id}/components", id)
52
+
53
+ handle_response(response) do
54
+ true
55
+ end
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def handle_response(response)
62
+ case response
63
+ when Net::HTTPSuccess
64
+ yield
65
+ when Net::HTTPUnauthorized
66
+ raise(Error, 'Unauthorized: wrong API Key')
67
+ else
68
+ # Net::HTTPBadRequest, Net::HTTPUnprocessableEntity, Net::HTTPForbidden
69
+ raise(Error, response.body)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -29,6 +29,26 @@ module Spage
29
29
  end
30
30
  end
31
31
 
32
+ def scheduled(page_id:)
33
+ response = client.get("pages/#{page_id}/incidents/scheduled")
34
+
35
+ handle_response(response) do
36
+ response.body.map do |incident|
37
+ Spage::Incident.new(incident)
38
+ end
39
+ end
40
+ end
41
+
42
+ def active_maintenance(page_id:)
43
+ response = client.get("pages/#{page_id}/incidents/active_maintenance")
44
+
45
+ handle_response(response) do
46
+ response.body.map do |incident|
47
+ Spage::Incident.new(incident)
48
+ end
49
+ end
50
+ end
51
+
32
52
  def find(page_id:, id:)
33
53
  response = client.get("pages/#{page_id}/incidents", id)
34
54
 
@@ -39,7 +59,7 @@ module Spage
39
59
 
40
60
  def create(incident, page_id:)
41
61
  json = Spage::Serializers::Incident.new(incident,
42
- update: true).to_json
62
+ update: true).to_json
43
63
 
44
64
  response = client.post("pages/#{page_id}/incidents", json)
45
65
 
@@ -50,13 +70,21 @@ module Spage
50
70
 
51
71
  def update(incident, page_id:, id:)
52
72
  json = Spage::Serializers::Incident.new(incident,
53
- update: true).to_json
73
+ update: true).to_json
54
74
  response = client.put("pages/#{page_id}/incidents", id, json)
55
75
 
56
76
  handle_response(response) do
57
77
  Spage::Incident.new(response.body)
58
78
  end
59
79
  end
80
+
81
+ def delete(page_id:, id:)
82
+ response = client.delete("pages/#{page_id}/incidents", id)
83
+
84
+ handle_response(response) do
85
+ Spage::Incident.new(response.body)
86
+ end
87
+ end
60
88
  end
61
89
 
62
90
  private
@@ -23,10 +23,14 @@ module Spage
23
23
  end
24
24
 
25
25
  def post(resource, body)
26
- make_request(Net::HTTP::Post, resource, id = nil, body)
26
+ make_request(Net::HTTP::Post, resource, nil, body)
27
27
  end
28
28
 
29
- # rubocop: disable Metrics/MethodLength
29
+ def delete(resource, id)
30
+ make_request(Net::HTTP::Delete, resource, id)
31
+ end
32
+
33
+ # rubocop: disable Metrics/MethodLength, Metrics/AbcSize
30
34
  def make_request(http_method, resource, id, body = nil)
31
35
  path = [@api_version, resource, id].compact.join('/')
32
36
  uri = URI::HTTP.build(host: BASE_URL, path: "/#{path}")
@@ -40,13 +44,13 @@ module Spage
40
44
  res = Net::HTTP.start(uri.hostname, use_ssl: true) do |http|
41
45
  response = http.request(request)
42
46
 
43
- response.body = JSON.parse(response.body)
47
+ response.body = JSON.parse(response.body) if response.body
44
48
  response
45
49
  end
46
50
 
47
51
  yield(res) if block_given?
48
52
  res
49
53
  end
50
- # rubocop: enable Metrics/MethodLength
54
+ # rubocop: enable Metrics/MethodLength, Metrics/AbcSize
51
55
  end
52
56
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spage
4
+ # Page resource in statuspage.io
5
+ #
6
+ class Component
7
+ # rubocop: disable Metrics/MethodLength, Metrics/AbcSize
8
+ def initialize(attrs)
9
+ @id = attrs['id']
10
+ @page_id = attrs['page_id']
11
+ @created_at = attrs['created_at']
12
+ @updated_at = attrs['updated_at']
13
+ @group = attrs['group']
14
+ @position = attrs['position']
15
+ @automation_email = attrs['automation_email']
16
+
17
+ # Updatable properties
18
+ @description = attrs['description']
19
+ @status = attrs['status']
20
+ @name = attrs['name']
21
+ @only_show_if_degraded = attrs['only_show_if_degraded']
22
+ @group_id = attrs['group_id']
23
+ @showcase = attrs['showcase']
24
+ end
25
+ # rubocop: enable Metrics/MethodLength, Metrics/AbcSize
26
+
27
+ # rubocop: disable Layout/LineLength
28
+ attr_reader :id, :page_id, :created_at, :updated_at, :group, :position, :automation_email
29
+
30
+ attr_accessor :description, :status, :name, :only_show_if_degraded, :group_id, :showcase
31
+ # rubocop: enable Layout/LineLength
32
+
33
+ private
34
+
35
+ def date_parse(str)
36
+ return str if str.nil?
37
+ return str if str.is_a?(DateTime)
38
+
39
+ DateTime.parse(str)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spage
4
+ module Serializers
5
+ # Serializer for the Component resource
6
+ #
7
+ class Component
8
+ def initialize(component, update: false)
9
+ @component = component
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
+ 'component' => Hash[
24
+ @ivars.map do |name|
25
+ [name[1..-1], @component.instance_variable_get(name)]
26
+ end
27
+ ]
28
+ }
29
+ end
30
+
31
+ private
32
+
33
+ def ivars(update)
34
+ if update
35
+ @component.instance_variables.select do |name|
36
+ processed_name = name[1..-1]
37
+ update_attrs.include?(processed_name) &&
38
+ !@component.send(processed_name).nil?
39
+ end
40
+ else
41
+ @component.instance_variables
42
+ end
43
+ end
44
+
45
+ def update_attrs
46
+ %w[
47
+ description
48
+ status
49
+ name
50
+ only_show_if_degraded
51
+ group_id
52
+ showcase
53
+ ]
54
+ end
55
+ end
56
+ end
57
+ end
@@ -34,7 +34,8 @@ module Spage
34
34
  if update
35
35
  @incident.instance_variables.select do |name|
36
36
  processed_name = name[1..-1]
37
- update_attrs.include?(processed_name) && !@incident.send(processed_name).nil?
37
+ update_attrs.include?(processed_name) &&
38
+ !@incident.send(processed_name).nil?
38
39
  end
39
40
  else
40
41
  @incident.instance_variables
@@ -1,3 +1,3 @@
1
1
  module Spage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,33 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/spage/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
4
- spec.name = "spage"
6
+ spec.name = 'spage'
5
7
  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")
8
+ spec.authors = ['Iain McNulty']
9
+ spec.email = ['iain@inulty.com']
14
10
 
15
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
11
+ spec.summary = 'Ruby client for using the statuspage.io API'
12
+ spec.description = 'Ruby client for making requests the statuspage.io API'
13
+ spec.homepage = 'https://github.com/nulty/spage'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
16
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"
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
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)/}) }
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ f.match(%r{^(test|spec|features)/})
24
+ end
25
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"
26
+ spec.require_paths = ['lib']
32
27
 
28
+ spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'simplecov'
30
+ spec.add_development_dependency 'vcr'
31
+ spec.add_development_dependency 'webmock'
33
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iain McNulty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-20 00:00:00.000000000 Z
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: vcr
28
+ name: simplecov
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: webmock
42
+ name: vcr
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: simplecov
56
+ name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: Ruby client for making requests the Spage API
69
+ description: Ruby client for making requests the statuspage.io API
70
70
  email:
71
71
  - iain@inulty.com
72
72
  executables: []
@@ -77,8 +77,8 @@ files:
77
77
  - ".rspec"
78
78
  - ".rubocop.yml"
79
79
  - ".travis.yml"
80
+ - CHANGELOG.md
80
81
  - Gemfile
81
- - Gemfile.lock
82
82
  - LICENSE.txt
83
83
  - README.md
84
84
  - Rakefile
@@ -86,12 +86,15 @@ files:
86
86
  - bin/setup
87
87
  - lib/spage.rb
88
88
  - lib/spage/api.rb
89
+ - lib/spage/api/component.rb
89
90
  - lib/spage/api/incident.rb
90
91
  - lib/spage/api/page.rb
91
92
  - lib/spage/client.rb
92
93
  - lib/spage/config.rb
94
+ - lib/spage/resources/component.rb
93
95
  - lib/spage/resources/incident.rb
94
96
  - lib/spage/resources/page.rb
97
+ - lib/spage/serializers/component.rb
95
98
  - lib/spage/serializers/incident.rb
96
99
  - lib/spage/serializers/page.rb
97
100
  - lib/spage/version.rb
@@ -121,5 +124,5 @@ requirements: []
121
124
  rubygems_version: 3.0.3
122
125
  signing_key:
123
126
  specification_version: 4
124
- summary: Ruby Client for using the Spage API
127
+ summary: Ruby client for using the statuspage.io API
125
128
  test_files: []