statuspageio 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 0ec421c4e88d18d4fc0895107ce63e3d81ae6b4d
4
- data.tar.gz: 0a79a02b7197521c53fc52b4d8980981a1a2f1f6
3
+ metadata.gz: 0caf8c784355d8fc2004397fe2139773a2d9aef7
4
+ data.tar.gz: 2edf2c57f1ccc345f4aca38b9e2a500ed47efcb2
5
5
  SHA512:
6
- metadata.gz: 82b6707f58b5f53abe9af0454d4ea4a03af8d254b5ce8ac8383e0e984b7e89ff116b18d4b8f022174420ded0f531b9e4ec0cfdd0d679e8c2b35540e0d4de937e
7
- data.tar.gz: b7ab5e90dda41a0a89f2ae1d11650555489ce2a77a6ea36751fc2c2e3c78fb9ae2eb65fdd3d85042853ec8b8b41dfcc2a27725864140ee69b1fad19a3e7f9fb9
6
+ metadata.gz: c84864826dea97ead1b424a414682ed89aa2afca35bc57f637d6fc0762c21e60a83b1ff6e75171e8dd7e8a5f61e69d2cf7ffc63feb43ad29fd3a4e9fdc01833c
7
+ data.tar.gz: dbed2abf04dd767beeed0943b03b63d963e6ecba5b778b184f4263864238de1cca1d2f3c5892ff3728b4448251b599cb0ef2ca29899978d8e093801f5f116a0f
@@ -1,11 +1,13 @@
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
6
- require 'statuspageio/client/incident'
7
+ include HTTParty
8
+ base_uri 'api.statuspage.io/v1'
7
9
 
8
- include Statuspageio::Request
10
+ require 'statuspageio/client/incident'
9
11
  include Statuspageio::Client::Incident
10
12
 
11
13
  attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
@@ -16,5 +18,42 @@ module Statuspageio
16
18
  send("#{key}=", options[key])
17
19
  end
18
20
  end
21
+
22
+ def self.handle_response(response)
23
+ if response.success?
24
+ JSON.parse(response.body)
25
+ else
26
+ bad_response(response)
27
+ end
28
+ end
29
+
30
+ def self.bad_response(response)
31
+ if response.class == HTTParty::Response
32
+ raise ResponseError, response
33
+ end
34
+ raise StandardError, "Unknown error"
35
+ end
36
+
37
+ def delete(path)
38
+ self.class.handle_response(self.class.delete("#{path}.json", headers: headers))
39
+ end
40
+
41
+ def get(path)
42
+ self.class.handle_response(self.class.get("#{path}.json", headers: headers))
43
+ end
44
+
45
+ def post(path, data = {})
46
+ self.class.handle_response(self.class.post("#{path}.json", data, headers: headers))
47
+ end
48
+
49
+ def put(path, data = {})
50
+ self.class.handle_response(self.class.put("#{path}.json", data, headers: headers))
51
+ end
52
+
53
+ private
54
+
55
+ def headers
56
+ { 'Authorization' => "OAuth #{self.api_key}" }
57
+ end
19
58
  end
20
59
  end
@@ -0,0 +1,41 @@
1
+ module Statuspageio
2
+ # Error raised on a bad response
3
+ class ResponseError < StandardError
4
+
5
+ attr_reader :response, :code, :errors
6
+
7
+ # @param [HTTParty::Response] res
8
+ # @return [CloudApp::ResponseError]
9
+ def initialize(res)
10
+ @response = res.response
11
+ @code = res.code
12
+ begin
13
+ @errors = parse_errors(res.parsed_response)
14
+ rescue JSON::ParserError
15
+ @errors = [res.response.body]
16
+ end
17
+ end
18
+
19
+ # Returns error code and message
20
+ #
21
+ # @return [String]
22
+ def to_s
23
+ "#{code.to_s} #{response.msg}".strip
24
+ end
25
+
26
+ private
27
+
28
+ def parse_errors(errors)
29
+ return case errors
30
+ when Hash
31
+ errors.collect{|k,v| "#{k}: #{v}"}
32
+ when String
33
+ [errors]
34
+ when Array
35
+ errors
36
+ else
37
+ []
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Statuspageio
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  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.2
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-01-07 00:00:00.000000000 Z
11
+ date: 2019-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -71,7 +71,7 @@ files:
71
71
  - lib/statuspageio/client.rb
72
72
  - lib/statuspageio/client/incident.rb
73
73
  - lib/statuspageio/configuration.rb
74
- - lib/statuspageio/request.rb
74
+ - lib/statuspageio/response_error.rb
75
75
  - lib/statuspageio/version.rb
76
76
  - statuspageio.gemspec
77
77
  homepage: https://github.com/dasnixon/statuspageio
@@ -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