flapjack-diner 0.12 → 0.15

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.
data/.gitignore CHANGED
@@ -16,3 +16,6 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .DS_Store
19
+ .rbenv-version
20
+ .ruby-version
21
+ .rvmrc
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - 2.0.0
4
5
  script: "bundle exec rspec"
data/README.md CHANGED
@@ -524,9 +524,9 @@ Returns a boolean value representing the success or otherwise of the creation of
524
524
  Delete a scheduled maintenance period for a check on an entity:
525
525
 
526
526
  ```ruby
527
- # end_time (Time object, optional)
527
+ # start_time (Time object, required)
528
528
  Flapjack::Diner.delete_scheduled_maintenance!('example.com', 'ping',
529
- :end_time => Time.local(2012, 12, 01))
529
+ :start_time => Time.local(2012, 12, 01))
530
530
  ```
531
531
 
532
532
  Returns a boolean value representing the success or otherwise of the deletion of the scheduled maintenance periods by the server.
@@ -536,9 +536,9 @@ Returns a boolean value representing the success or otherwise of the deletion of
536
536
  Delete a scheduled maintenance period for all checks on some entities and specified checks on others.
537
537
 
538
538
  ```ruby
539
- # end_time (Time object, optional)
539
+ # start_time (Time object, required)
540
540
  Flapjack::Diner.bulk_delete_scheduled_maintenance!(:check => {'example.com' => ['ping', 'ssh']},
541
- :end_time => Time.local(2012, 12, 01))
541
+ :start_time => Time.local(2012, 12, 01))
542
542
  ```
543
543
 
544
544
  Returns a boolean value representing the success or otherwise of the deletion of the scheduled maintenance periods by the server.
@@ -31,9 +31,8 @@ module Flapjack
31
31
 
32
32
  def status(entity, options = {})
33
33
  check = options.delete(:check)
34
- args = options.merge( check ? {:check => {entity => check}} : {:entity => entity} )
35
- validate_bulk_params(args)
36
- perform_get('/status', args)
34
+ path = check.nil? ? "/status/#{escape(entity)}" : "/status/#{escape(entity)}/#{escape(check)}"
35
+ perform_get(path)
37
36
  end
38
37
 
39
38
  def bulk_status(options = {})
@@ -120,13 +119,13 @@ module Flapjack
120
119
 
121
120
  def scheduled_maintenances(entity, options = {})
122
121
  check = options.delete(:check)
123
- args = options.merge( check ? {:check => {entity => check}} : {:entity => entity} )
124
122
 
125
- validate_bulk_params(args) do
123
+ validate_params(options) do
126
124
  validate :query => [:start_time, :end_time], :as => :time
127
125
  end
128
126
 
129
- perform_get('/scheduled_maintenances', args)
127
+ ec_path = entity_check_path(entity, check)
128
+ perform_get("/scheduled_maintenances/#{ec_path}", options)
130
129
  end
131
130
 
132
131
  def bulk_scheduled_maintenances(options = {})
@@ -139,13 +138,13 @@ module Flapjack
139
138
 
140
139
  def unscheduled_maintenances(entity, options = {})
141
140
  check = options.delete(:check)
142
- args = options.merge( check ? {:check => {entity => check}} : {:entity => entity} )
143
141
 
144
- validate_bulk_params(args) do
142
+ validate_params(options) do
145
143
  validate :query => [:start_time, :end_time], :as => :time
146
144
  end
147
145
 
148
- perform_get('/unscheduled_maintenances', args)
146
+ ec_path = entity_check_path(entity, check)
147
+ perform_get("/unscheduled_maintenances/#{ec_path}", options)
149
148
  end
150
149
 
151
150
  def bulk_unscheduled_maintenances(options = {})
@@ -158,13 +157,13 @@ module Flapjack
158
157
 
159
158
  def outages(entity, options = {})
160
159
  check = options.delete(:check)
161
- args = options.merge( check ? {:check => {entity => check}} : {:entity => entity} )
162
160
 
163
- validate_bulk_params(args) do
161
+ validate_params(options) do
164
162
  validate :query => [:start_time, :end_time], :as => :time
165
163
  end
166
164
 
167
- perform_get('/outages', args)
165
+ ec_path = entity_check_path(entity, check)
166
+ perform_get("/outages/#{ec_path}", options)
168
167
  end
169
168
 
170
169
  def bulk_outages(options = {})
@@ -177,13 +176,14 @@ module Flapjack
177
176
 
178
177
  def downtime(entity, options = {})
179
178
  check = options.delete(:check)
180
- args = options.merge( check ? {:check => {entity => check}} : {:entity => entity} )
181
179
 
182
- validate_bulk_params(args) do
180
+ validate_params(options) do
183
181
  validate :query => [:start_time, :end_time], :as => :time
184
182
  end
185
183
 
186
- perform_get('/downtime', args)
184
+ ec_path = entity_check_path(entity, check)
185
+
186
+ perform_get("/downtime/#{ec_path}", options)
187
187
  end
188
188
 
189
189
  def bulk_downtime(options = {})
@@ -341,7 +341,8 @@ module Flapjack
341
341
  response_body = response.body
342
342
  response_start = response_body ? response_body[0..300] : nil
343
343
  if logger
344
- logger.info " Response Code: #{response.code}#{response.message ? response.message : ''}"
344
+ response_message = " #{response.message}" unless (response.message.nil? || response.message == "")
345
+ logger.info " Response Code: #{response.code}#{response_message}"
345
346
  logger.info " Response Body: #{response_start}" if response_start
346
347
  end
347
348
  parsed_response = response.respond_to?(:parsed_response) ? response.parsed_response : nil
@@ -374,9 +375,17 @@ module Flapjack
374
375
  raise ArgumentError.new("Entity and/or check arguments must be provided")
375
376
  end
376
377
 
378
+ validate_params(query, &validation)
379
+ end
380
+
381
+ def validate_params(query = {}, &validation)
377
382
  ArgumentValidator.new(query).instance_eval(&validation) if block_given?
378
383
  end
379
384
 
385
+ def entity_check_path(entity, check)
386
+ check.nil? ? "#{escape(entity)}" : "#{escape(entity)}/#{escape(check)}"
387
+ end
388
+
380
389
  # copied from Rack::Utils -- builds the query string for GETs
381
390
  def build_nested_query(value, prefix = nil)
382
391
  if value.respond_to?(:iso8601)
@@ -28,7 +28,9 @@ module Flapjack
28
28
  def time(*elements)
29
29
  elements.each do |element|
30
30
  if target = @query[element]
31
- @errors << "'#{target}' should contain some kind of time object which responds to." unless target.respond_to?(:iso8601)
31
+ next if target.respond_to?(:iso8601) || (target.is_a?(String) &&
32
+ (begin; Time.iso8601(target); true; rescue ArgumentError; false; end))
33
+ @errors << "'#{target}' should be a time object or ISO 8601-formatted string."
32
34
  end
33
35
  end
34
36
  end
@@ -1,5 +1,5 @@
1
1
  module Flapjack
2
2
  module Diner
3
- VERSION = "0.12"
3
+ VERSION = "0.15"
4
4
  end
5
5
  end
@@ -61,6 +61,16 @@ describe Flapjack::ArgumentValidator do
61
61
  query[:end_time] = Date.today
62
62
  lambda { subject.validate(:query => :end_time, :as => :time) }.should_not raise_exception(ArgumentError)
63
63
  end
64
+
65
+ it 'handles ISO 8601 strings as query values' do
66
+ query[:end_time] = Time.now.iso8601
67
+ lambda { subject.validate(:query => :end_time, :as => :time) }.should_not raise_exception(ArgumentError)
68
+ end
69
+
70
+ it 'raises an exception when invalid time strings are provided' do
71
+ query[:end_time] = '2011-08-01T00:00'
72
+ lambda { subject.validate(:query => :end_time, :as => :time) }.should raise_exception(ArgumentError)
73
+ end
64
74
  end
65
75
 
66
76
  context 'integer via method missing' do
@@ -68,6 +68,16 @@ describe Flapjack::Diner do
68
68
  with(:query => {:entity => entity}).
69
69
  to_return(:body => response)
70
70
 
71
+ result = Flapjack::Diner.bulk_status(:entity => entity)
72
+ req.should have_been_requested
73
+ result.should_not be_nil
74
+ result.should == response_body
75
+ end
76
+
77
+ it "returns a json list of check statuses for an entity, legacy" do
78
+ req = stub_request(:get, "http://#{server}/status/#{entity}").
79
+ to_return(:body => response)
80
+
71
81
  result = Flapjack::Diner.status(entity)
72
82
  req.should have_been_requested
73
83
  result.should_not be_nil
@@ -90,6 +100,16 @@ describe Flapjack::Diner do
90
100
  with(:query => {:check => {entity => check}}).
91
101
  to_return(:body => response)
92
102
 
103
+ result = Flapjack::Diner.bulk_status(:check => {entity => check})
104
+ req.should have_been_requested
105
+ result.should_not be_nil
106
+ result.should == response_body
107
+ end
108
+
109
+ it "returns a single check status for an entity, legacy" do
110
+ req = stub_request(:get, "http://#{server}/status/#{entity}/#{check}").
111
+ to_return(:body => response)
112
+
93
113
  result = Flapjack::Diner.status(entity, :check => check)
94
114
  req.should have_been_requested
95
115
  result.should_not be_nil
@@ -97,8 +117,7 @@ describe Flapjack::Diner do
97
117
  end
98
118
 
99
119
  it "returns a list of scheduled maintenance periods for all checks on an entity" do
100
- req = stub_request(:get, "http://#{server}/scheduled_maintenances").
101
- with(:query => {:entity => entity}).
120
+ req = stub_request(:get, "http://#{server}/scheduled_maintenances/#{entity}").
102
121
  to_return(:body => response)
103
122
 
104
123
  result = Flapjack::Diner.scheduled_maintenances(entity)
@@ -108,8 +127,7 @@ describe Flapjack::Diner do
108
127
  end
109
128
 
110
129
  it "returns a list of scheduled maintenance periods for a check on an entity" do
111
- req = stub_request(:get, "http://#{server}/scheduled_maintenances").
112
- with(:query => {:check => {entity => check}}).
130
+ req = stub_request(:get, "http://#{server}/scheduled_maintenances/#{entity}/#{check}").
113
131
  to_return(:body => response)
114
132
 
115
133
  result = Flapjack::Diner.scheduled_maintenances(entity, :check => check)
@@ -130,8 +148,7 @@ describe Flapjack::Diner do
130
148
  end
131
149
 
132
150
  it "returns a list of unscheduled maintenance periods for all checks on an entity" do
133
- req = stub_request(:get, "http://#{server}/unscheduled_maintenances").
134
- with(:query => {:entity => entity}).
151
+ req = stub_request(:get, "http://#{server}/unscheduled_maintenances/#{entity}").
135
152
  to_return(:body => response)
136
153
 
137
154
  result = Flapjack::Diner.unscheduled_maintenances(entity)
@@ -141,8 +158,7 @@ describe Flapjack::Diner do
141
158
  end
142
159
 
143
160
  it "returns a list of unscheduled maintenance periods for a check on an entity" do
144
- req = stub_request(:get, "http://#{server}/unscheduled_maintenances").
145
- with(:query => {:check => {entity => check}}).
161
+ req = stub_request(:get, "http://#{server}/unscheduled_maintenances/#{entity}/#{check}").
146
162
  to_return(:body => response)
147
163
 
148
164
  result = Flapjack::Diner.unscheduled_maintenances(entity, :check => check)
@@ -163,8 +179,7 @@ describe Flapjack::Diner do
163
179
  end
164
180
 
165
181
  it "returns a list of outages for all checks on an entity" do
166
- req = stub_request(:get, "http://#{server}/outages").
167
- with(:query => {:entity => entity}).
182
+ req = stub_request(:get, "http://#{server}/outages/#{entity}").
168
183
  to_return(:body => response)
169
184
 
170
185
  result = Flapjack::Diner.outages(entity)
@@ -174,8 +189,7 @@ describe Flapjack::Diner do
174
189
  end
175
190
 
176
191
  it "returns a list of outages for a check on an entity" do
177
- req = stub_request(:get, "http://#{server}/outages").
178
- with(:query => {:check => {entity => check}}).
192
+ req = stub_request(:get, "http://#{server}/outages/#{entity}/#{check}").
179
193
  to_return(:body => response)
180
194
 
181
195
  result = Flapjack::Diner.outages(entity, :check => check)
@@ -196,8 +210,7 @@ describe Flapjack::Diner do
196
210
  end
197
211
 
198
212
  it "returns a list of downtimes for all checks on an entity" do
199
- req = stub_request(:get, "http://#{server}/downtime").
200
- with(:query => {:entity => entity}).
213
+ req = stub_request(:get, "http://#{server}/downtime/#{entity}").
201
214
  to_return(:body => response)
202
215
 
203
216
  result = Flapjack::Diner.downtime(entity)
@@ -210,8 +223,8 @@ describe Flapjack::Diner do
210
223
  start = Time.iso8601('2011-08-01T00:00:00+10:00')
211
224
  finish = Time.iso8601('2011-08-31T00:00:00+10:00')
212
225
 
213
- req = stub_request(:get, "http://#{server}/downtime").
214
- with(:query => {:entity => entity, :start_time => start.iso8601, :end_time => finish.iso8601}).
226
+ req = stub_request(:get, "http://#{server}/downtime/#{entity}").
227
+ with(:query => {:start_time => start.iso8601, :end_time => finish.iso8601}).
215
228
  to_return(:body => response)
216
229
 
217
230
  result = Flapjack::Diner.downtime(entity, :start_time => start, :end_time => finish)
@@ -221,8 +234,7 @@ describe Flapjack::Diner do
221
234
  end
222
235
 
223
236
  it "returns a list of downtimes for a check on an entity" do
224
- req = stub_request(:get, "http://#{server}/downtime").
225
- with(:query => {:check => {entity => check}}).
237
+ req = stub_request(:get, "http://#{server}/downtime/#{entity}/#{check}").
226
238
  to_return(:body => response)
227
239
 
228
240
  result = Flapjack::Diner.downtime(entity, :check => check)
@@ -774,7 +786,7 @@ describe Flapjack::Diner do
774
786
  timezone_data = {:timezone => "Australia/Perth"}
775
787
 
776
788
  req = stub_request(:put, "http://#{server}/contacts/#{contact_id}/timezone").with(
777
- :body => timezone_data).to_return(:body => timezone_data.to_json, :status => [200, ' OK'])
789
+ :body => timezone_data).to_return(:body => timezone_data.to_json, :status => [200, 'OK'])
778
790
 
779
791
  logger.should_receive(:info).
780
792
  with("PUT http://#{server}/contacts/#{contact_id}/timezone\n Params: #{timezone_data.inspect}")
@@ -860,7 +872,7 @@ describe Flapjack::Diner do
860
872
 
861
873
  it "raises an exception if a time argument is provided with the wrong data type" do
862
874
  start_str = '2011-08-01T00:00:00+10:00'
863
- finish_str = '2011-08-31T00:00:00+10:00'
875
+ finish_str = 'yesterday'
864
876
 
865
877
  start = Time.iso8601(start_str)
866
878
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flapjack-diner
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.12'
4
+ version: '0.15'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
12
+ date: 2013-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -131,7 +131,6 @@ extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
133
  - .gitignore
134
- - .rbenv-version
135
134
  - .rspec
136
135
  - .travis.yml
137
136
  - Gemfile
@@ -157,18 +156,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
156
  - - ! '>='
158
157
  - !ruby/object:Gem::Version
159
158
  version: '0'
160
- segments:
161
- - 0
162
- hash: 2019754927088119775
163
159
  required_rubygems_version: !ruby/object:Gem::Requirement
164
160
  none: false
165
161
  requirements:
166
162
  - - ! '>='
167
163
  - !ruby/object:Gem::Version
168
164
  version: '0'
169
- segments:
170
- - 0
171
- hash: 2019754927088119775
172
165
  requirements: []
173
166
  rubyforge_project:
174
167
  rubygems_version: 1.8.23
data/.rbenv-version DELETED
@@ -1 +0,0 @@
1
- 1.9.3-p125