pingdom 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a45132f86fb8147a8460e7d24e5e1e59a54e6b13
4
- data.tar.gz: 546aaf6606c793da5747fcecbac4f20fd5b7b3ff
3
+ metadata.gz: ec0019c8887e2600c0ad0b892ebd9e00ccd427d1
4
+ data.tar.gz: d9f0c1b704fa686b34720798c4d2f53f440aa1e5
5
5
  SHA512:
6
- metadata.gz: 34324306c1c34ddb73626181e5cf7e8155b3cea840059340429ca167fce604866964bf5a73a1d0ea3f42ab4c2dac121fd91c3ec53579ad7aac3e0c89e811a34e
7
- data.tar.gz: 14605b20900211985c6d38c524e732b29e07ca2272b0d02c48d6802fe7cfab180f39379ae9625d64a4079f7ed384cd0e76ec6168e1a60a158d071703cbe27736
6
+ metadata.gz: 3e2cdb42f5084b038f8ccba8f03fa6d5bfb09893b0dde8576fb076269485930ed80092a06c8811895d8f3aca041e724661c9483ae88fc69c06fe0cbfeef86ced
7
+ data.tar.gz: 5d9fd6ddfca6d3fde03125758c94032f5563b867d269d9773e21837152baae904e85cf952162d28a568df4c0197591bf3baa9b8f7a63ae18634ab9efc90bb101
data/lib/pingdom/base.rb CHANGED
@@ -17,15 +17,10 @@ module Pingdom
17
17
  end
18
18
  end
19
19
 
20
- def find id, from: nil, to: nil, order: nil, resolution: nil, includeuptime: nil
20
+ def find id, *args
21
+ validator=Pingdom::Validator.new
21
22
 
22
- @@params={}
23
-
24
- @@params[:from]= from.to_i if from
25
- @@params[:to]= to.to_i if to
26
- @@params[:order]= order if order and %q(ask desc).include?(order)
27
- @@params[:resolution]= resolution if resolution and %q(hour day week).include?(resolution)
28
- @@params[:includeuptime]= includeuptime if includeuptime and %q(true false).include?(includeuptime)
23
+ @@params=validator.validate input: args, permit: permit, params: params
29
24
 
30
25
  parse client.get( path: "#{path}/#{id}" , params: params)
31
26
 
@@ -38,6 +33,10 @@ module Pingdom
38
33
  def path
39
34
  end
40
35
 
36
+ def permit
37
+ {}
38
+ end
39
+
41
40
  def collection_type
42
41
  path[1..-2]
43
42
  end
@@ -82,6 +81,7 @@ module Pingdom
82
81
  def limited
83
82
  body['counts']['limited']
84
83
  end
84
+
85
85
  end
86
86
 
87
87
  attr_accessor :additional_field
@@ -121,6 +121,5 @@ module Pingdom
121
121
  def is_time_attribute? key
122
122
  time_attributes.include?(key)
123
123
  end
124
-
125
124
  end
126
125
  end
@@ -20,6 +20,14 @@ module Pingdom
20
20
  'summary'
21
21
  end
22
22
 
23
+ def permit
24
+ {
25
+ from: :valid_time?,
26
+ to: :valid_time?,
27
+ order: :valid_order?
28
+ }
29
+ end
30
+
23
31
  end
24
32
 
25
33
  attr_accessor :states
@@ -18,6 +18,17 @@ module Pingdom
18
18
  'summary'
19
19
  end
20
20
 
21
+ def permit
22
+ {
23
+ probes: :valid_int_list?,
24
+ to: :valid_time?,
25
+ from: :valid_time?,
26
+ resolution: :valid_resolution?,
27
+ order: :valid_order?,
28
+ includeuptime: :valid_boolean_str?
29
+ }
30
+ end
31
+
21
32
  end
22
33
 
23
34
  attr_accessor :hours, :days, :weeks
@@ -0,0 +1,80 @@
1
+ module Pingdom
2
+ class Validator
3
+
4
+ attr :input, :permit, :params
5
+
6
+ def validate input: , permit: , params:
7
+ @input= input.first || {}
8
+ @permit=permit
9
+ @params=params
10
+
11
+ params.merge(format)
12
+ end
13
+
14
+ private
15
+
16
+ def filter
17
+ input.select do |k,v|
18
+ permit.keys.include?k and !v.nil?
19
+ end
20
+ end
21
+
22
+ def validate_all
23
+ filter.each_pair do |key, value|
24
+ raise "'#{key}' param with value: '#{value}', cannot pass the '#{permit[key]}' validation" unless send(permit[key], value)
25
+ end
26
+ end
27
+
28
+ def format
29
+ validate_all.each_pair.map do |key, value|
30
+ value=value.to_i if permit[key]==:valid_time?
31
+ [key, value]
32
+ end.to_h
33
+ end
34
+
35
+ def valid_time? time
36
+ time.is_a? Time
37
+ end
38
+
39
+ def valid_positive_int? value
40
+ value.is_a? Integer and value>=0
41
+ end
42
+
43
+ def valid_order? order
44
+ ['asc','desc'].include? order
45
+ end
46
+
47
+ def valid_resolution? resolution
48
+ %q(hour day week).include? resolution
49
+ end
50
+
51
+ def valid_boolean_str? boolstring
52
+ ['true','false'].include? boolstring
53
+ end
54
+
55
+ def valid_int_list? int_list
56
+
57
+ list=int_list.split(',')
58
+ raise 'Not valid list' if list.empty?
59
+
60
+ list.each do |i|
61
+ raise "Not valid Integer" if Integer(i)!=i.to_i
62
+ end
63
+
64
+ true
65
+ rescue
66
+ false
67
+ end
68
+
69
+ def valid_str_list? str_list
70
+
71
+ list=str_list.split(',')
72
+ raise 'Not valid list' if list.empty? || str_list.count(' ')>0
73
+
74
+ true
75
+ rescue
76
+ false
77
+ end
78
+
79
+ end
80
+ end
@@ -1,3 +1,3 @@
1
1
  module Pingdom
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/pingdom.rb CHANGED
@@ -5,6 +5,7 @@ require "pingdom/base"
5
5
  require 'pingdom/check'
6
6
  require 'pingdom/summary_outage'
7
7
  require 'pingdom/summary_performance'
8
+ require 'pingdom/validator'
8
9
  require 'active_support/core_ext/numeric/time'
9
10
  require 'active_support/core_ext/time/acts_like'
10
11
  require 'active_support/core_ext/time/calculations'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pingdom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Piccinini Lagos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-04 00:00:00.000000000 Z
11
+ date: 2017-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ files:
131
131
  - lib/pingdom/client.rb
132
132
  - lib/pingdom/summary_outage.rb
133
133
  - lib/pingdom/summary_performance.rb
134
+ - lib/pingdom/validator.rb
134
135
  - lib/pingdom/version.rb
135
136
  - pingdom.gemspec
136
137
  homepage: https://github.com/diegopiccinini/pingdom