uptimerobot 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uptimerobot.rb +1 -0
- data/lib/uptimerobot/client.rb +29 -6
- data/lib/uptimerobot/version.rb +1 -1
- data/spec/uptimerobot_spec.rb +44 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b141a6405dfeb49f0e3207f558eb80655890c2a9
|
4
|
+
data.tar.gz: 668131150b4b46e6729d8b61665f3868d1bd6f19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a99db16eb179856b27273531dd742e13074b09959df945fd7228daa5e2cbd62be93d66bd7328910a07ee2a665f4b8795ca4fb12c786f36afd71109d63b6f645
|
7
|
+
data.tar.gz: 2cd2b99dbadc341804dcc32b9ed6e7ca7bd00f148932936b79e71bd9e4dfb0def4d863202e1023e55e2b440642911b46c98ce35bdfe282f58bede2879f26ab35
|
data/lib/uptimerobot.rb
CHANGED
data/lib/uptimerobot/client.rb
CHANGED
@@ -18,11 +18,20 @@ class UptimeRobot::Client
|
|
18
18
|
Faraday::Adapter::Test
|
19
19
|
]
|
20
20
|
|
21
|
+
OPTIONS = [
|
22
|
+
:apiKey,
|
23
|
+
:raise_no_monitors_error,
|
24
|
+
:skip_unescape_monitor
|
25
|
+
]
|
26
|
+
|
21
27
|
def initialize(options)
|
22
|
-
@
|
23
|
-
|
28
|
+
@options = {}
|
29
|
+
|
30
|
+
OPTIONS.each do |key|
|
31
|
+
@options[key] = options.delete(key)
|
32
|
+
end
|
24
33
|
|
25
|
-
raise ArgumentError, ':apiKey is required' unless @apiKey
|
34
|
+
raise ArgumentError, ':apiKey is required' unless @options[:apiKey]
|
26
35
|
|
27
36
|
options[:url] ||= ENDPOINT
|
28
37
|
|
@@ -60,7 +69,7 @@ class UptimeRobot::Client
|
|
60
69
|
|
61
70
|
def request(method_name, params = {})
|
62
71
|
params.update(
|
63
|
-
:apiKey => @apiKey,
|
72
|
+
:apiKey => @options[:apiKey],
|
64
73
|
:format => 'json',
|
65
74
|
:noJsonCallback => 1
|
66
75
|
)
|
@@ -72,10 +81,19 @@ class UptimeRobot::Client
|
|
72
81
|
end
|
73
82
|
|
74
83
|
json = response.body
|
84
|
+
validate_response!(json)
|
85
|
+
|
86
|
+
if method_name == :getMonitors and not @options[:skip_unescape_monitor]
|
87
|
+
unescape_monitor!(json)
|
88
|
+
end
|
75
89
|
|
90
|
+
json
|
91
|
+
end
|
92
|
+
|
93
|
+
def validate_response!(json)
|
76
94
|
if json['stat'] != 'ok'
|
77
95
|
if json['id'] == '212'
|
78
|
-
if @raise_no_monitors_error
|
96
|
+
if @options[:raise_no_monitors_error]
|
79
97
|
raise UptimeRobot::Error.new(json)
|
80
98
|
else
|
81
99
|
json.update(
|
@@ -87,7 +105,12 @@ class UptimeRobot::Client
|
|
87
105
|
raise UptimeRobot::Error.new(json)
|
88
106
|
end
|
89
107
|
end
|
108
|
+
end
|
90
109
|
|
91
|
-
|
110
|
+
def unescape_monitor!(json)
|
111
|
+
json['monitors']['monitor'].each do |monitor|
|
112
|
+
friendlyname = monitor['friendlyname']
|
113
|
+
monitor['friendlyname'] = CGI.unescapeHTML(friendlyname)
|
114
|
+
end
|
92
115
|
end
|
93
116
|
end
|
data/lib/uptimerobot/version.rb
CHANGED
data/spec/uptimerobot_spec.rb
CHANGED
@@ -113,6 +113,50 @@ describe UptimeRobot::Client do
|
|
113
113
|
|
114
114
|
expect(client.getMonitors(params)).to eq response
|
115
115
|
end
|
116
|
+
|
117
|
+
context 'when include escaped string' do
|
118
|
+
let(:escaped_string) do
|
119
|
+
'http monitor (basic auth)'
|
120
|
+
end
|
121
|
+
|
122
|
+
let(:unescaped_string) do
|
123
|
+
'http monitor (basic auth)'
|
124
|
+
end
|
125
|
+
|
126
|
+
let(:response_with_escaped_string) do
|
127
|
+
res = response.dup
|
128
|
+
res['monitors']['monitor'][0]['friendlyname'] = escaped_string
|
129
|
+
res
|
130
|
+
end
|
131
|
+
|
132
|
+
let(:response_with_unescaped_string) do
|
133
|
+
res = response.dup
|
134
|
+
res['monitors']['monitor'][0]['friendlyname'] = unescaped_string
|
135
|
+
res
|
136
|
+
end
|
137
|
+
|
138
|
+
it do
|
139
|
+
client = uptime_robot do |stub|
|
140
|
+
stub.get('getMonitors') do |env|
|
141
|
+
expect(env.params).to eq DEFAULT_PARAMS.merge(stringify_hash(params))
|
142
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response_with_escaped_string)]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
expect(client.getMonitors(params)).to eq response_with_unescaped_string
|
147
|
+
end
|
148
|
+
|
149
|
+
it do
|
150
|
+
client = uptime_robot(:skip_unescape_monitor => true) do |stub|
|
151
|
+
stub.get('getMonitors') do |env|
|
152
|
+
expect(env.params).to eq DEFAULT_PARAMS.merge(stringify_hash(params))
|
153
|
+
[200, {'Content-Type' => 'json'}, JSON.dump(response_with_escaped_string)]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
expect(client.getMonitors(params)).to eq response_with_escaped_string
|
158
|
+
end
|
159
|
+
end
|
116
160
|
end
|
117
161
|
|
118
162
|
describe '#newMonitor' do
|