kapacitor-ruby 0.0.7 → 0.0.8

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: 648af550f8893599e7dab2e111d49ac09e3f8cd1
4
- data.tar.gz: 174d98096322da6abec4f25d797fb7d47d0ebd6a
3
+ metadata.gz: b4a827c3d35b876031f859fc3f4c63d92f206b52
4
+ data.tar.gz: 42a48f344172b64698d2dba66fd904904a70b6ef
5
5
  SHA512:
6
- metadata.gz: 4a5056e8f63bdf1ea80ea00a21ce04cc8d5425e57404a73970d139564b2c083aec48d44be9e55961a69e9d504f4de13639b8083dedb4ac74d48cf1c8413b49ce
7
- data.tar.gz: 7a60ee7d837261bbc527839606522465c55e67c99ffb25e310076c39f4c210a3a43268ffc5113d53e93a182acfc7780d0c85536fbb770b2b309d36bc2954fd8e
6
+ metadata.gz: d2f7791aa7238868888e1324d618409451af8c32f5de39b943e6dbbf6c132472649338c7d366221f6cedd77714dcf56609685e034fb9256267f340c861b97096
7
+ data.tar.gz: f20fe970cce5c7d481222b90a66169b55aa8622a3390b24b7970e50f68ee0b9fdb11111e0c2a8d3b17d7daa60978dac87c1dec34ebf33632387962a0f2031491
@@ -11,30 +11,44 @@ module Kapacitor
11
11
  class Client
12
12
  attr_reader :uri, :http
13
13
 
14
- def initialize(host: 'localhost:9092', version: 'v1')
15
- @uri = URI.parse("http://#{host}/kapacitor/#{version}")
14
+ def initialize(opts = {})
15
+ raise ArgumentError, "Kapacitor host is required" unless opts['host']
16
+ raise ArgumentError, "Kapacitor API version is required" unless opts['version']
17
+
18
+ @uri = URI.parse("http://#{opts['host']}/kapacitor/#{opts['version']}")
16
19
  @http = Net::HTTP.new(@uri.host, @uri.port)
17
20
  end
18
21
 
19
- def define_template(id:, type:, script:)
22
+ def define_template(id, opts = {})
23
+ raise ArgumentError, "Kapacitor template type is required" unless opts['type']
24
+ raise ArgumentError, "Kapacitor template tickscript required" unless opts['script']
25
+
26
+ if opts['type']
27
+ raise ArgumentError, "Kapacitor template type can be either 'batch' or 'stream'" unless (opts['type'] == 'batch' or opts['type'] == 'stream')
28
+ end
29
+
20
30
  req = {
21
31
  'id' => id,
22
- 'type' => type,
23
- 'script' => script
32
+ 'type' => opts['type'],
33
+ 'script' => opts['script']
24
34
  }
25
35
 
26
36
  api_post('/templates', req)
27
37
  end
28
38
 
29
- def update_template(id:, type: nil, script: nil)
39
+ def update_template(id, opts = {})
30
40
  req = {}
31
- req['type'] = type if type
32
- req['script'] = script if script
41
+ req['type'] = type if opts['type']
42
+ req['script'] = script if opts['script']
43
+
44
+ if opts['type']
45
+ raise ArgumentError, "Kapacitor template type can be either 'batch' or 'stream'" unless (opts['type'] == 'batch' or opts['type'] == 'stream')
46
+ end
33
47
 
34
48
  api_patch("/templates/#{id}", req) unless req.empty?
35
49
  end
36
50
 
37
- def delete_template(id:)
51
+ def delete_template(id)
38
52
  api_delete("/templates/#{id}")
39
53
  end
40
54
 
@@ -42,44 +56,62 @@ module Kapacitor
42
56
  api_get('/templates')['templates']
43
57
  end
44
58
 
45
- def define_task(id:, template_id: nil, type: nil, dbrps: , script: nil, status: 'enabled', vars: nil)
46
- if (template_id.nil? and type.nil? and script.nil?) or (template_id and (type or script))
59
+ def define_task(id, opts = {})
60
+ raise ArgumentError, "Kapacitor task dbrps is required"
61
+
62
+ if (opts['template_id'].nil? and opts['type'].nil? and opts['script'].nil?) or (opts['template_id'] and (opts['type'] or opts['script']))
47
63
  raise ArgumentError, "Must specify either a Template ID or a script and type"
48
- elsif template_id.nil? and (type.nil? or script.nil?)
64
+ elsif opts['template_id'].nil? and (opts['type'].nil? or opts['script'].nil?)
49
65
  raise ArgumentError, "Must specify both task type and script when not using a Template ID"
50
66
  end
51
67
 
68
+ if opts['status']
69
+ raise ArgumentError, "Kapacitor task status can be either 'enabled' or 'disabled'" unless (opts['status'] == 'enabled' or opts['status'] == 'disabled')
70
+ end
71
+
72
+ if opts['type']
73
+ raise ArgumentError, "Kapacitor task type can be either 'batch' or 'stream'" unless (opts['type'] == 'batch' or opts['type'] == 'stream')
74
+ end
75
+
52
76
  req = {
53
77
  'id' => id,
54
- 'dbrps' => dbrps,
55
- 'status' => status
78
+ 'dbrps' => opts['dbrps'],
79
+ 'status' => opts['status'] || 'enabled'
56
80
  }
57
81
 
58
- if template_id
59
- req['template-id'] = template_id
82
+ if opts['template_id']
83
+ req['template-id'] = opts['template_id']
60
84
  else
61
- req['type'] = type
62
- req['script'] = script
85
+ req['type'] = opts['type']
86
+ req['script'] = opts['script']
63
87
  end
64
88
 
65
- req['vars'] = vars if vars
89
+ req['vars'] = opts['vars'] if opts['vars']
66
90
 
67
91
  api_post('/tasks', req)
68
92
  end
69
93
 
70
- def update_task(id:, template_id: nil, type: nil, dbrps: nil, script: nil, status: nil, vars: nil)
94
+ def update_task(id, opts = {})
71
95
  req = {}
72
- req['template-id'] = template_id if template_id
73
- req['type'] = type if type
74
- req['dbrps'] = dbrps if dbrps
75
- req['script'] = script if script
76
- req['status'] = status if status
77
- req['vars'] = vars if vars
96
+ req['template-id'] = opts['template_id'] if opts['template_id']
97
+ req['type'] = opts['type'] if opts['type']
98
+ req['dbrps'] = opts['dbrps'] if opts['dbrps']
99
+ req['script'] = opts['script'] if opts['script']
100
+ req['status'] = opts['status'] if opts['status']
101
+ req['vars'] = opts['vars'] if opts['vars']
102
+
103
+ if opts['type']
104
+ raise ArgumentError, "Kapacitor template type can be either 'batch' or 'stream'" unless (opts['type'] == 'batch' or opts['type'] == 'stream')
105
+ end
106
+
107
+ if opts['status']
108
+ raise ArgumentError, "Kapacitor task status can be either 'enabled' or 'disabled'" unless (opts['status'] == 'enabled' or opts['status'] == 'disabled')
109
+ end
78
110
 
79
111
  api_patch("/tasks/#{id}", req) unless req.empty?
80
112
  end
81
113
 
82
- def delete_task(id:)
114
+ def delete_task(id)
83
115
  api_delete("/tasks/#{id}")
84
116
  end
85
117
 
@@ -5,7 +5,7 @@
5
5
  #
6
6
 
7
7
  module Kapacitor
8
- VERSION = "0.0.7"
8
+ VERSION = "0.0.8"
9
9
 
10
10
  def self.version
11
11
  VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kapacitor-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Cerutti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json