wavefront-sdk 3.3.3 → 3.3.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 +4 -4
- data/.rubocop.yml +2 -17
- data/Gemfile +2 -0
- data/HISTORY.md +4 -0
- data/Rakefile +2 -0
- data/lib/wavefront-sdk/alert.rb +5 -2
- data/lib/wavefront-sdk/api_mixins/acl.rb +3 -0
- data/lib/wavefront-sdk/api_mixins/tag.rb +2 -0
- data/lib/wavefront-sdk/api_mixins/user.rb +4 -0
- data/lib/wavefront-sdk/apitoken.rb +2 -0
- data/lib/wavefront-sdk/cloudintegration.rb +4 -0
- data/lib/wavefront-sdk/core/api.rb +3 -0
- data/lib/wavefront-sdk/core/api_caller.rb +16 -10
- data/lib/wavefront-sdk/core/exception.rb +2 -0
- data/lib/wavefront-sdk/core/logger.rb +6 -3
- data/lib/wavefront-sdk/core/response.rb +6 -3
- data/lib/wavefront-sdk/credentials.rb +5 -2
- data/lib/wavefront-sdk/dashboard.rb +3 -0
- data/lib/wavefront-sdk/defs/constants.rb +3 -1
- data/lib/wavefront-sdk/defs/version.rb +3 -1
- data/lib/wavefront-sdk/derivedmetric.rb +3 -0
- data/lib/wavefront-sdk/distribution.rb +36 -16
- data/lib/wavefront-sdk/event.rb +16 -12
- data/lib/wavefront-sdk/externallink.rb +3 -0
- data/lib/wavefront-sdk/integration.rb +2 -0
- data/lib/wavefront-sdk/maintenancewindow.rb +4 -1
- data/lib/wavefront-sdk/message.rb +2 -0
- data/lib/wavefront-sdk/metric.rb +3 -0
- data/lib/wavefront-sdk/metric_helper.rb +6 -4
- data/lib/wavefront-sdk/notificant.rb +3 -0
- data/lib/wavefront-sdk/paginator/base.rb +5 -0
- data/lib/wavefront-sdk/paginator/delete.rb +2 -0
- data/lib/wavefront-sdk/paginator/get.rb +2 -0
- data/lib/wavefront-sdk/paginator/post.rb +2 -0
- data/lib/wavefront-sdk/paginator/put.rb +2 -0
- data/lib/wavefront-sdk/proxy.rb +2 -0
- data/lib/wavefront-sdk/query.rb +6 -3
- data/lib/wavefront-sdk/report.rb +2 -0
- data/lib/wavefront-sdk/savedsearch.rb +4 -0
- data/lib/wavefront-sdk/search.rb +4 -1
- data/lib/wavefront-sdk/settings.rb +2 -0
- data/lib/wavefront-sdk/source.rb +3 -0
- data/lib/wavefront-sdk/stdlib/array.rb +2 -0
- data/lib/wavefront-sdk/stdlib/hash.rb +5 -1
- data/lib/wavefront-sdk/stdlib/string.rb +2 -0
- data/lib/wavefront-sdk/support/mixins.rb +5 -1
- data/lib/wavefront-sdk/support/parse_time.rb +3 -0
- data/lib/wavefront-sdk/types/status.rb +4 -0
- data/lib/wavefront-sdk/user.rb +18 -8
- data/lib/wavefront-sdk/usergroup.rb +3 -0
- data/lib/wavefront-sdk/validators.rb +28 -0
- data/lib/wavefront-sdk/webhook.rb +3 -0
- data/lib/wavefront-sdk/write.rb +43 -28
- data/lib/wavefront-sdk/writers/api.rb +2 -0
- data/lib/wavefront-sdk/writers/core.rb +21 -4
- data/lib/wavefront-sdk/writers/http.rb +9 -2
- data/lib/wavefront-sdk/writers/socket.rb +11 -9
- data/lib/wavefront-sdk/writers/summary.rb +2 -0
- data/lib/wavefront-sdk/writers/unix.rb +10 -7
- data/lib/wavefront_sdk.rb +3 -1
- data/spec/.rubocop.yml +10 -14
- data/spec/constants.rb +10 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/support/bad_mocket.rb +2 -0
- data/spec/support/hash.rb +2 -0
- data/spec/support/minitest_assertions.rb +2 -0
- data/spec/support/mocket.rb +2 -0
- data/spec/test_mixins/acl.rb +2 -0
- data/spec/test_mixins/general.rb +2 -0
- data/spec/test_mixins/tag.rb +2 -0
- data/spec/test_mixins/update_keys.rb +2 -0
- data/spec/wavefront-sdk/alert_spec.rb +10 -9
- data/spec/wavefront-sdk/api_mixins/user_mixins_spec.rb +1 -0
- data/spec/wavefront-sdk/apitoken_spec.rb +1 -0
- data/spec/wavefront-sdk/cloudintegration_spec.rb +2 -1
- data/spec/wavefront-sdk/core/api_caller_spec.rb +1 -0
- data/spec/wavefront-sdk/core/api_spec.rb +1 -0
- data/spec/wavefront-sdk/core/logger_spec.rb +1 -0
- data/spec/wavefront-sdk/core/response_spec.rb +4 -3
- data/spec/wavefront-sdk/credentials_spec.rb +1 -0
- data/spec/wavefront-sdk/dashboard_spec.rb +1 -0
- data/spec/wavefront-sdk/derivedmetric_spec.rb +1 -0
- data/spec/wavefront-sdk/distribution_spec.rb +6 -5
- data/spec/wavefront-sdk/event_spec.rb +8 -7
- data/spec/wavefront-sdk/externallink_spec.rb +5 -4
- data/spec/wavefront-sdk/integration_spec.rb +1 -0
- data/spec/wavefront-sdk/maintenancewindow_spec.rb +6 -5
- data/spec/wavefront-sdk/message_spec.rb +2 -1
- data/spec/wavefront-sdk/metric_helper_spec.rb +10 -9
- data/spec/wavefront-sdk/metric_spec.rb +1 -0
- data/spec/wavefront-sdk/notificant_spec.rb +1 -0
- data/spec/wavefront-sdk/paginator/base_spec.rb +1 -0
- data/spec/wavefront-sdk/paginator/post_spec.rb +1 -0
- data/spec/wavefront-sdk/proxy_spec.rb +1 -0
- data/spec/wavefront-sdk/query_spec.rb +1 -0
- data/spec/wavefront-sdk/report_spec.rb +1 -0
- data/spec/wavefront-sdk/resources/dummy_points.rb +10 -8
- data/spec/wavefront-sdk/savedsearch_spec.rb +1 -0
- data/spec/wavefront-sdk/search_spec.rb +5 -4
- data/spec/wavefront-sdk/settings_spec.rb +1 -0
- data/spec/wavefront-sdk/source_spec.rb +3 -2
- data/spec/wavefront-sdk/stdlib/array_spec.rb +1 -0
- data/spec/wavefront-sdk/stdlib/hash_spec.rb +1 -0
- data/spec/wavefront-sdk/stdlib/string_spec.rb +1 -0
- data/spec/wavefront-sdk/support/mixins_spec.rb +1 -0
- data/spec/wavefront-sdk/support/parse_time_spec.rb +1 -2
- data/spec/wavefront-sdk/user_spec.rb +1 -0
- data/spec/wavefront-sdk/usergroup_spec.rb +2 -1
- data/spec/wavefront-sdk/validators_spec.rb +1 -2
- data/spec/wavefront-sdk/webhook_spec.rb +7 -6
- data/spec/wavefront-sdk/write_spec.rb +50 -30
- data/spec/wavefront-sdk/writers/api_spec.rb +1 -0
- data/spec/wavefront-sdk/writers/core_spec.rb +1 -0
- data/spec/wavefront-sdk/writers/http_spec.rb +2 -1
- data/spec/wavefront-sdk/writers/socket_spec.rb +1 -0
- data/spec/wavefront-sdk/writers/summary_spec.rb +1 -0
- data/wavefront-sdk.gemspec +4 -2
- metadata +6 -6
data/lib/wavefront-sdk/event.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'core/api'
|
|
2
4
|
require_relative 'api_mixins/tag'
|
|
3
5
|
|
|
@@ -28,19 +30,11 @@ module Wavefront
|
|
|
28
30
|
#
|
|
29
31
|
def list(from = nil, to = Time.now, limit = 100, cursor = nil)
|
|
30
32
|
raise ArgumentError unless from && to
|
|
31
|
-
wf_event_id?(cursor) if cursor
|
|
32
|
-
|
|
33
|
-
from = parse_time(from, true)
|
|
34
|
-
to = parse_time(to, true)
|
|
35
|
-
|
|
36
|
-
wf_ms_ts?(from)
|
|
37
|
-
wf_ms_ts?(to)
|
|
38
|
-
|
|
39
|
-
body = { earliestStartTimeEpochMillis: from,
|
|
40
|
-
latestStartTimeEpochMillis: to,
|
|
41
|
-
cursor: cursor,
|
|
42
|
-
limit: limit }
|
|
43
33
|
|
|
34
|
+
body = list_body(from, to, limit, cursor)
|
|
35
|
+
wf_event_id?(cursor) if cursor
|
|
36
|
+
wf_ms_ts?(body[:earliestStartTimeEpochMillis])
|
|
37
|
+
wf_ms_ts?(body[:latestStartTimeEpochMillis])
|
|
44
38
|
api.get('', body.cleanse)
|
|
45
39
|
end
|
|
46
40
|
|
|
@@ -56,6 +50,7 @@ module Wavefront
|
|
|
56
50
|
#
|
|
57
51
|
def create(body)
|
|
58
52
|
raise ArgumentError unless body.is_a?(Hash)
|
|
53
|
+
|
|
59
54
|
api.post('', body, 'application/json')
|
|
60
55
|
end
|
|
61
56
|
|
|
@@ -121,5 +116,14 @@ module Wavefront
|
|
|
121
116
|
def valid_id?(id)
|
|
122
117
|
wf_event_id?(id)
|
|
123
118
|
end
|
|
119
|
+
|
|
120
|
+
private
|
|
121
|
+
|
|
122
|
+
def list_body(t_start, t_end, limit, cursor)
|
|
123
|
+
{ earliestStartTimeEpochMillis: parse_time(t_start, true),
|
|
124
|
+
latestStartTimeEpochMillis: parse_time(t_end, true),
|
|
125
|
+
cursor: cursor,
|
|
126
|
+
limit: limit }
|
|
127
|
+
end
|
|
124
128
|
end
|
|
125
129
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'core/api'
|
|
2
4
|
|
|
3
5
|
module Wavefront
|
|
@@ -32,6 +34,7 @@ module Wavefront
|
|
|
32
34
|
#
|
|
33
35
|
def create(body)
|
|
34
36
|
raise ArgumentError unless body.is_a?(Hash)
|
|
37
|
+
|
|
35
38
|
api.post('', body, 'application/json')
|
|
36
39
|
end
|
|
37
40
|
|
|
@@ -110,7 +113,7 @@ module Wavefront
|
|
|
110
113
|
ret = pending
|
|
111
114
|
|
|
112
115
|
items = { UPCOMING: ret.response.items,
|
|
113
|
-
CURRENT:
|
|
116
|
+
CURRENT: ongoing.response.items }
|
|
114
117
|
|
|
115
118
|
ret.response.items = items
|
|
116
119
|
ret
|
data/lib/wavefront-sdk/metric.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'write'
|
|
2
4
|
|
|
3
5
|
module Wavefront
|
|
@@ -18,7 +20,7 @@ module Wavefront
|
|
|
18
20
|
#
|
|
19
21
|
def initialize(creds, opts = {})
|
|
20
22
|
@opts = opts
|
|
21
|
-
@buf = { gauges:
|
|
23
|
+
@buf = { gauges: empty_gauges,
|
|
22
24
|
counters: empty_counters }
|
|
23
25
|
@writer = setup_writer(creds, opts)
|
|
24
26
|
@dist_writer = setup_dist_writer(creds, opts) if opts[:dist_port]
|
|
@@ -139,9 +141,9 @@ module Wavefront
|
|
|
139
141
|
def dists_to_wf(dists)
|
|
140
142
|
dists.map do |k, v|
|
|
141
143
|
path, interval, tags = k
|
|
142
|
-
dist = { path:
|
|
143
|
-
value:
|
|
144
|
-
ts:
|
|
144
|
+
dist = { path: path,
|
|
145
|
+
value: dist_writer.mk_distribution(v),
|
|
146
|
+
ts: Time.now.utc.to_i,
|
|
145
147
|
interval: interval }
|
|
146
148
|
dist[:tags] = tags unless tags.nil?
|
|
147
149
|
dist
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative '../defs/constants'
|
|
2
4
|
|
|
3
5
|
module Wavefront
|
|
@@ -71,6 +73,7 @@ module Wavefront
|
|
|
71
73
|
def user_page_size(args)
|
|
72
74
|
arg_val = limit_and_offset(args)[:offset].to_i
|
|
73
75
|
return arg_val if arg_val&.positive?
|
|
76
|
+
|
|
74
77
|
PAGE_SIZE
|
|
75
78
|
end
|
|
76
79
|
|
|
@@ -114,6 +117,7 @@ module Wavefront
|
|
|
114
117
|
api_caller.verbosity(conn, method, *p_args)
|
|
115
118
|
resp = api_caller.respond(conn.public_send(method, *p_args))
|
|
116
119
|
raise StopIteration unless resp.ok?
|
|
120
|
+
|
|
117
121
|
ret.response.items += resp.response.items
|
|
118
122
|
return finalize_response(ret) unless resp.more_items?
|
|
119
123
|
end
|
|
@@ -154,6 +158,7 @@ module Wavefront
|
|
|
154
158
|
unless resp.ok?
|
|
155
159
|
raise(Wavefront::Exception::EnumerableError, resp.status)
|
|
156
160
|
end
|
|
161
|
+
|
|
157
162
|
p_args = set_pagination(offset, page_size, p_args)
|
|
158
163
|
resp.response.items.map { |i| y.<< i }
|
|
159
164
|
raise StopIteration unless resp.more_items?
|
data/lib/wavefront-sdk/proxy.rb
CHANGED
data/lib/wavefront-sdk/query.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'core/api'
|
|
2
4
|
|
|
3
5
|
module Wavefront
|
|
@@ -32,6 +34,7 @@ module Wavefront
|
|
|
32
34
|
options = {})
|
|
33
35
|
|
|
34
36
|
raise ArgumentError unless query.is_a?(String)
|
|
37
|
+
|
|
35
38
|
wf_granularity?(granularity)
|
|
36
39
|
raise Wavefront::Exception::InvalidTimestamp if t_start.nil?
|
|
37
40
|
|
|
@@ -87,9 +90,9 @@ module Wavefront
|
|
|
87
90
|
status = 400 if status == 200 && !err_msg.empty?
|
|
88
91
|
|
|
89
92
|
{ response: resp,
|
|
90
|
-
status:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
status: { result: status == 200 ? 'OK' : 'ERROR',
|
|
94
|
+
message: err_msg,
|
|
95
|
+
code: status } }.to_json
|
|
93
96
|
end
|
|
94
97
|
|
|
95
98
|
# A bad query doesn't send back a JSON object. It sends back a
|
data/lib/wavefront-sdk/report.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'core/api'
|
|
2
4
|
|
|
3
5
|
module Wavefront
|
|
@@ -26,6 +28,7 @@ module Wavefront
|
|
|
26
28
|
#
|
|
27
29
|
def create(body)
|
|
28
30
|
raise ArgumentError unless body.is_a?(Hash)
|
|
31
|
+
|
|
29
32
|
api.post('', body, 'application/json')
|
|
30
33
|
end
|
|
31
34
|
|
|
@@ -60,6 +63,7 @@ module Wavefront
|
|
|
60
63
|
def update(id, body)
|
|
61
64
|
wf_savedsearch_id?(id)
|
|
62
65
|
raise ArgumentError unless body.is_a?(Hash)
|
|
66
|
+
|
|
63
67
|
api.put(id, body)
|
|
64
68
|
end
|
|
65
69
|
|
data/lib/wavefront-sdk/search.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'core/api'
|
|
2
4
|
|
|
3
5
|
module Wavefront
|
|
@@ -39,6 +41,7 @@ module Wavefront
|
|
|
39
41
|
#
|
|
40
42
|
def search(entity, query, options = {})
|
|
41
43
|
raise ArgumentError unless options.is_a?(Hash)
|
|
44
|
+
|
|
42
45
|
raw_search(entity, body(query, options), options[:deleted] || false)
|
|
43
46
|
end
|
|
44
47
|
|
|
@@ -71,7 +74,7 @@ module Wavefront
|
|
|
71
74
|
def sort_field(options, query)
|
|
72
75
|
field = options[:sort_field] || [query].flatten.first[:key]
|
|
73
76
|
|
|
74
|
-
{ field:
|
|
77
|
+
{ field: field,
|
|
75
78
|
ascending: !options[:desc] || true }
|
|
76
79
|
end
|
|
77
80
|
|
data/lib/wavefront-sdk/source.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'core/api'
|
|
2
4
|
require_relative 'api_mixins/tag'
|
|
3
5
|
|
|
@@ -37,6 +39,7 @@ module Wavefront
|
|
|
37
39
|
#
|
|
38
40
|
def create(body)
|
|
39
41
|
raise ArgumentError unless body.is_a?(Hash)
|
|
42
|
+
|
|
40
43
|
api.post('', body, 'application/json')
|
|
41
44
|
end
|
|
42
45
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'string'
|
|
2
4
|
|
|
3
5
|
# Extensions to stdlib Hash
|
|
@@ -7,7 +9,9 @@ class Hash
|
|
|
7
9
|
# the WF wire-format guide. No validation is performed here.
|
|
8
10
|
#
|
|
9
11
|
def to_wf_tag
|
|
10
|
-
map
|
|
12
|
+
map do |k, v|
|
|
13
|
+
format('%<key>s="%<value>s"', key: k, value: v.tagescape)
|
|
14
|
+
end.join(' ')
|
|
11
15
|
end
|
|
12
16
|
|
|
13
17
|
# Drop any key-value pairs where the value is not truthy
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'date'
|
|
2
4
|
require_relative 'parse_time'
|
|
3
5
|
require_relative '../core/exception'
|
|
@@ -22,6 +24,7 @@ module Wavefront
|
|
|
22
24
|
#
|
|
23
25
|
def parse_time(time, in_ms = false)
|
|
24
26
|
return relative_time(time, in_ms) if time =~ /^[\-+]/
|
|
27
|
+
|
|
25
28
|
ParseTime.new(time, in_ms).parse!
|
|
26
29
|
end
|
|
27
30
|
|
|
@@ -57,7 +60,7 @@ module Wavefront
|
|
|
57
60
|
end
|
|
58
61
|
|
|
59
62
|
m = in_ms ? 1000 : 1
|
|
60
|
-
time.delete
|
|
63
|
+
time = time.delete('+')
|
|
61
64
|
match = time.match(/^(-?\d*\.?\d*)([smhdwy])$/)
|
|
62
65
|
(match[1].to_f * time_multiplier(match[2]) * m).to_i
|
|
63
66
|
end
|
|
@@ -85,6 +88,7 @@ module Wavefront
|
|
|
85
88
|
u = { s: 1, m: 60, h: 3600, d: 86_400, w: 604_800, y: 31_536_000 }
|
|
86
89
|
|
|
87
90
|
return u[suffix.to_sym] if u.key?(suffix.to_sym)
|
|
91
|
+
|
|
88
92
|
raise Wavefront::Exception::InvalidTimeUnit
|
|
89
93
|
end
|
|
90
94
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Wavefront
|
|
2
4
|
#
|
|
3
5
|
# Status types are used by the Wavefront::Response class. They
|
|
@@ -37,6 +39,7 @@ module Wavefront
|
|
|
37
39
|
def message
|
|
38
40
|
return obj[:message] if obj[:message]
|
|
39
41
|
return obj[:error] if obj[:error]
|
|
42
|
+
|
|
40
43
|
nil
|
|
41
44
|
end
|
|
42
45
|
|
|
@@ -47,6 +50,7 @@ module Wavefront
|
|
|
47
50
|
def result
|
|
48
51
|
return obj[:result] if obj[:result]
|
|
49
52
|
return 'OK' if status.between?(200, 299)
|
|
53
|
+
|
|
50
54
|
'ERROR'
|
|
51
55
|
end
|
|
52
56
|
end
|
data/lib/wavefront-sdk/user.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'core/api'
|
|
2
4
|
require_relative 'api_mixins/user'
|
|
3
5
|
|
|
@@ -25,6 +27,7 @@ module Wavefront
|
|
|
25
27
|
#
|
|
26
28
|
def create(body, send_email = false)
|
|
27
29
|
raise ArgumentError unless body.is_a?(Hash)
|
|
30
|
+
|
|
28
31
|
api.post("?sendEmail=#{send_email}", body, 'application/json')
|
|
29
32
|
end
|
|
30
33
|
|
|
@@ -115,6 +118,7 @@ module Wavefront
|
|
|
115
118
|
def grant(id, pgroup)
|
|
116
119
|
wf_user_id?(id)
|
|
117
120
|
raise ArgumentError unless pgroup.is_a?(String)
|
|
121
|
+
|
|
118
122
|
api.post([id, 'grant'].uri_concat, "group=#{pgroup}",
|
|
119
123
|
'application/x-www-form-urlencoded')
|
|
120
124
|
end
|
|
@@ -131,6 +135,7 @@ module Wavefront
|
|
|
131
135
|
def revoke(id, pgroup)
|
|
132
136
|
wf_user_id?(id)
|
|
133
137
|
raise ArgumentError unless pgroup.is_a?(String)
|
|
138
|
+
|
|
134
139
|
api.post([id, 'revoke'].uri_concat, "group=#{pgroup}",
|
|
135
140
|
'application/x-www-form-urlencoded')
|
|
136
141
|
end
|
|
@@ -145,6 +150,7 @@ module Wavefront
|
|
|
145
150
|
#
|
|
146
151
|
def delete_users(user_list)
|
|
147
152
|
raise ArgumentError unless user_list.is_a?(Array)
|
|
153
|
+
|
|
148
154
|
validate_user_list(user_list)
|
|
149
155
|
api.post('deleteUsers', user_list, 'application/json')
|
|
150
156
|
end
|
|
@@ -160,6 +166,7 @@ module Wavefront
|
|
|
160
166
|
#
|
|
161
167
|
def grant_permission(permission, user_list)
|
|
162
168
|
raise ArgumentError unless user_list.is_a?(Array)
|
|
169
|
+
|
|
163
170
|
validate_user_list(user_list)
|
|
164
171
|
api.post(['grant', permission].uri_concat, user_list,
|
|
165
172
|
'application/json')
|
|
@@ -176,6 +183,7 @@ module Wavefront
|
|
|
176
183
|
#
|
|
177
184
|
def revoke_permission(permission, user_list)
|
|
178
185
|
raise ArgumentError unless user_list.is_a?(Array)
|
|
186
|
+
|
|
179
187
|
validate_user_list(user_list)
|
|
180
188
|
api.post(['revoke', permission].uri_concat, user_list,
|
|
181
189
|
'application/json')
|
|
@@ -190,6 +198,7 @@ module Wavefront
|
|
|
190
198
|
def invite(body)
|
|
191
199
|
raise ArgumentError unless body.is_a?(Array)
|
|
192
200
|
raise ArgumentError unless body.first.is_a?(Hash)
|
|
201
|
+
|
|
193
202
|
api.post('invite', body, 'application/json')
|
|
194
203
|
end
|
|
195
204
|
|
|
@@ -213,21 +222,21 @@ module Wavefront
|
|
|
213
222
|
end
|
|
214
223
|
|
|
215
224
|
def itemize_response(body_obj)
|
|
216
|
-
{ status:
|
|
225
|
+
{ status: body_obj[:status],
|
|
217
226
|
response: { items: [body_obj[:response]].flatten } }.to_json
|
|
218
227
|
end
|
|
219
228
|
|
|
220
229
|
# Construct a response almost from scratch. Used for 'list', among others.
|
|
221
230
|
#
|
|
222
231
|
def construct_response(body_obj, status)
|
|
223
|
-
{ status:
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
response: { items:
|
|
227
|
-
offset:
|
|
228
|
-
limit:
|
|
232
|
+
{ status: { result: status.to_s.start_with?('2') ? 'OK' : 'ERROR',
|
|
233
|
+
message: extract_api_message(status, body_obj),
|
|
234
|
+
code: status },
|
|
235
|
+
response: { items: [body_obj].flatten,
|
|
236
|
+
offset: 0,
|
|
237
|
+
limit: body_obj.size,
|
|
229
238
|
totalItems: body_obj.size,
|
|
230
|
-
moreItems:
|
|
239
|
+
moreItems: false } }.to_json
|
|
231
240
|
end
|
|
232
241
|
|
|
233
242
|
# the user API class does not support pagination. Be up-front
|
|
@@ -248,6 +257,7 @@ module Wavefront
|
|
|
248
257
|
|
|
249
258
|
def extract_api_message(status, items)
|
|
250
259
|
return '' if status < 300
|
|
260
|
+
|
|
251
261
|
items.fetch(:message, 'no message from API')
|
|
252
262
|
end
|
|
253
263
|
|