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 +4 -4
- data/lib/statuspageio/client.rb +42 -3
- data/lib/statuspageio/response_error.rb +41 -0
- data/lib/statuspageio/version.rb +1 -1
- metadata +3 -3
- data/lib/statuspageio/request.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0caf8c784355d8fc2004397fe2139773a2d9aef7
|
4
|
+
data.tar.gz: 2edf2c57f1ccc345f4aca38b9e2a500ed47efcb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c84864826dea97ead1b424a414682ed89aa2afca35bc57f637d6fc0762c21e60a83b1ff6e75171e8dd7e8a5f61e69d2cf7ffc63feb43ad29fd3a4e9fdc01833c
|
7
|
+
data.tar.gz: dbed2abf04dd767beeed0943b03b63d963e6ecba5b778b184f4263864238de1cca1d2f3c5892ff3728b4448251b599cb0ef2ca29899978d8e093801f5f116a0f
|
data/lib/statuspageio/client.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
require 'httparty'
|
1
2
|
require 'statuspageio/configuration'
|
2
|
-
require 'statuspageio/
|
3
|
+
require 'statuspageio/response_error'
|
3
4
|
|
4
5
|
module Statuspageio
|
5
6
|
class Client
|
6
|
-
|
7
|
+
include HTTParty
|
8
|
+
base_uri 'api.statuspage.io/v1'
|
7
9
|
|
8
|
-
|
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
|
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.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-
|
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/
|
74
|
+
- lib/statuspageio/response_error.rb
|
75
75
|
- lib/statuspageio/version.rb
|
76
76
|
- statuspageio.gemspec
|
77
77
|
homepage: https://github.com/dasnixon/statuspageio
|
data/lib/statuspageio/request.rb
DELETED
@@ -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
|