uptimerobot 0.1.3 → 0.1.4

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: b2dd9afefcc2700e84aee76b59b8eff83f6b4189
4
- data.tar.gz: 759431d88327f91c1a390f3befa84f71e9d67ab5
3
+ metadata.gz: b141a6405dfeb49f0e3207f558eb80655890c2a9
4
+ data.tar.gz: 668131150b4b46e6729d8b61665f3868d1bd6f19
5
5
  SHA512:
6
- metadata.gz: 58f973019110873771c81b56930fd33f88ba38c90f37ce0f12871827b36119a6dffc00af77d7b6e820da30f3209d20dcf12f9781586856501bfe1cadca551e81
7
- data.tar.gz: 6318681db5a9db150551477735b3724c7089618f827f8153eaa88daf8081dd6ee07d9956a469bc65707057243bf2110e106234d36043c15c486367c395d77795
6
+ metadata.gz: 6a99db16eb179856b27273531dd742e13074b09959df945fd7228daa5e2cbd62be93d66bd7328910a07ee2a665f4b8795ca4fb12c786f36afd71109d63b6f645
7
+ data.tar.gz: 2cd2b99dbadc341804dcc32b9ed6e7ca7bd00f148932936b79e71bd9e4dfb0def4d863202e1023e55e2b440642911b46c98ce35bdfe282f58bede2879f26ab35
data/lib/uptimerobot.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'cgi'
1
2
  require 'json'
2
3
 
3
4
  require 'faraday'
@@ -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
- @apiKey = options.delete(:apiKey)
23
- @raise_no_monitors_error = !!options.delete(:raise_no_monitors_error)
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
- json
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
@@ -1,3 +1,3 @@
1
1
  module UptimeRobot
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uptimerobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara