wavefront-sdk 0.2.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -4
- data/lib/wavefront-sdk/search.rb +59 -8
- data/lib/wavefront-sdk/version.rb +1 -1
- data/spec/wavefront-sdk/search_spec.rb +10 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19b69376bae0fb003a885f84caec73b642242144
|
4
|
+
data.tar.gz: 09c37865d29c17fb1fd9f8d98b79982dcae7491f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eec85994ce6b03d2921b968d9f44e62372ab676117a5eb706c0f1d3b57e835889d2833366d035aa2539a66fe24a0cd59d790081a4147ac65ec3dd23503aa3e0e
|
7
|
+
data.tar.gz: ff10d6af734516be10162cd4dc900751563517b8b1841b76bc796b8510374c36c9b8f001b387a003135cf4efab05cb11e6f2d807baad44c67f6651424a5f4c76
|
data/README.md
CHANGED
@@ -4,10 +4,6 @@
|
|
4
4
|
This is a Ruby SDK for v2 of
|
5
5
|
[Wavefront](https://www.wavefront.com/)'s public API. It supports Ruby >= 2.2.
|
6
6
|
|
7
|
-
Note that it currently has major version number `0`. This means *it
|
8
|
-
is not finished*. Until version `1` comes out, I reserve the right
|
9
|
-
to change, break, and befoul the code and the gem.
|
10
|
-
|
11
7
|
## Installation
|
12
8
|
|
13
9
|
```
|
data/lib/wavefront-sdk/search.rb
CHANGED
@@ -9,23 +9,74 @@ module Wavefront
|
|
9
9
|
#
|
10
10
|
class Search < Base
|
11
11
|
|
12
|
-
# POST /api/v2/search/
|
13
|
-
# POST /api/v2/search/
|
12
|
+
# POST /api/v2/search/entity
|
13
|
+
# POST /api/v2/search/entity/deleted
|
14
|
+
# Run a search query. This single method maps to many API paths.
|
15
|
+
# It is a wrapper around #raw_search() for common, single
|
16
|
+
# key-value searches. If you need to do more complicated things,
|
17
|
+
# use #raw_search().
|
18
|
+
#
|
19
|
+
# @param entity [String, Symbol] the type of Wavefront object
|
20
|
+
# you wish to search. e.g. :alert, :dashboard
|
21
|
+
# @param query [Array, Hash] A single hash, or array of hashes,
|
22
|
+
# containing the following keys:
|
23
|
+
# key [String] the field on which to search
|
24
|
+
# value [String] what to search for
|
25
|
+
# matchingMethod [String] the method to match values. Defaults
|
26
|
+
# to 'CONTAINS'. Must be one of CONTAINS, STARTSWITH, EXACT,
|
27
|
+
# TAGPATH
|
28
|
+
# If an array of hashes is supplied, Wavefront will apply a
|
29
|
+
# logical AND to the given key-value pairs.
|
30
|
+
# @param value [String] the value to search for
|
31
|
+
# @param options [Hash] tune the query: keys are:
|
32
|
+
# deleted [Boolean] whether to search deleted (true) or active
|
33
|
+
# (false) entities
|
34
|
+
# limit [Integer] how many results to return. Defaults to 0
|
35
|
+
# (all of them)
|
36
|
+
# offset [Integer] return results after this offset
|
37
|
+
# desc: [Boolean] return results in descending order. Defaults
|
38
|
+
# to false. Sorting is done on the 'key' of the first query
|
39
|
+
# hash.
|
40
|
+
#
|
41
|
+
def search(entity, query, options = {})
|
42
|
+
raise ArgumentError unless options.is_a?(Hash)
|
43
|
+
raw_search(entity, body(query, options), options[:deleted] || false)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Build a query body
|
47
|
+
#
|
48
|
+
def body(query, options)
|
49
|
+
ret = {
|
50
|
+
limit: options[:limit] || 10,
|
51
|
+
offset: options[:offset] || 0,
|
52
|
+
query: [query].flatten,
|
53
|
+
sort: { field: [query].flatten.first[:key],
|
54
|
+
ascending: !options[:desc] || true }
|
55
|
+
}
|
56
|
+
|
57
|
+
ret[:query].map { |q| q[:matchingMethod] ||= 'CONTAINS' }
|
58
|
+
ret
|
59
|
+
end
|
60
|
+
|
61
|
+
# POST /api/v2/search/entity
|
62
|
+
# POST /api/v2/search/entity/deleted
|
14
63
|
# Run a search query. This single method maps to many API paths.
|
15
64
|
#
|
16
65
|
# @param entity [String] the type of Wavefront object you wish
|
17
66
|
# to search
|
18
67
|
# @param body [Hash] the query to use for searching. Refer to
|
19
68
|
# the Wavefront Swagger docs for the correct format.
|
69
|
+
# Specifying multiple key - value pairs performs a logical AND
|
70
|
+
# on the constraints.
|
20
71
|
# @param deleted [Boolean] whether to search deleted (true) or
|
21
72
|
# active (false) entities
|
22
73
|
#
|
23
|
-
def
|
24
|
-
raise ArgumentError unless entity.is_a?(String)
|
74
|
+
def raw_search(entity = nil, body = nil, deleted = false)
|
75
|
+
raise ArgumentError unless entity.is_a?(String) || entity.is_a?(Symbol)
|
25
76
|
raise ArgumentError unless body.is_a?(Hash)
|
26
|
-
path = [
|
77
|
+
path = [entity]
|
27
78
|
path.<< 'deleted' if deleted
|
28
|
-
api_post(path, body, 'application/json')
|
79
|
+
api_post(path, body.to_json, 'application/json')
|
29
80
|
end
|
30
81
|
|
31
82
|
# @param entity [String] the type of Wavefront object you wish
|
@@ -39,11 +90,11 @@ module Wavefront
|
|
39
90
|
# specified in the body. See the Swagger docs for more
|
40
91
|
# information.
|
41
92
|
#
|
42
|
-
def
|
93
|
+
def raw_facet_search(entity = nil, body = nil, deleted = false,
|
43
94
|
facet = false)
|
44
95
|
raise ArgumentError unless entity.is_a?(String)
|
45
96
|
raise ArgumentError unless body.is_a?(Hash)
|
46
|
-
path = [
|
97
|
+
path = [entity]
|
47
98
|
path.<< 'deleted' if deleted
|
48
99
|
path.<< facet ? facet : 'facets'
|
49
100
|
api_post(path, body, 'application/json')
|
@@ -1 +1 @@
|
|
1
|
-
WF_SDK_VERSION = '0.
|
1
|
+
WF_SDK_VERSION = '1.0.0'.freeze
|
@@ -16,32 +16,32 @@ SEARCH_BODY = {
|
|
16
16
|
#
|
17
17
|
class WavefrontSearchTest < WavefrontTestBase
|
18
18
|
def test_search
|
19
|
-
should_work(:
|
19
|
+
should_work(:raw_search, ['agent', SEARCH_BODY], 'agent', :post,
|
20
20
|
JSON_POST_HEADERS, SEARCH_BODY.to_json)
|
21
|
-
should_work(:
|
21
|
+
should_work(:raw_search, ['agent', SEARCH_BODY, true], 'agent/deleted',
|
22
22
|
:post, JSON_POST_HEADERS, SEARCH_BODY.to_json)
|
23
|
-
assert_raises(ArgumentError) { wf.
|
24
|
-
assert_raises(ArgumentError) { wf.
|
23
|
+
assert_raises(ArgumentError) { wf.raw_search }
|
24
|
+
assert_raises(ArgumentError) { wf.raw_search('ALERT', 'junk') }
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_facet_search
|
28
|
-
should_work(:
|
28
|
+
should_work(:raw_facet_search, ['agent', SEARCH_BODY],
|
29
29
|
'agent/facets', :post, JSON_POST_HEADERS,
|
30
30
|
SEARCH_BODY.to_json)
|
31
31
|
|
32
|
-
should_work(:
|
32
|
+
should_work(:raw_facet_search, ['agent', SEARCH_BODY, true],
|
33
33
|
'agent/deleted/facets', :post, JSON_POST_HEADERS,
|
34
34
|
SEARCH_BODY.to_json)
|
35
35
|
|
36
|
-
should_work(:
|
36
|
+
should_work(:raw_facet_search, ['agent', SEARCH_BODY, false, 'Tags'],
|
37
37
|
'agent/Tags', :post, JSON_POST_HEADERS,
|
38
38
|
SEARCH_BODY.to_json)
|
39
39
|
|
40
|
-
should_work(:
|
40
|
+
should_work(:raw_facet_search, ['agent', SEARCH_BODY, true, 'Tags'],
|
41
41
|
'agent/deleted/Tags', :post, JSON_POST_HEADERS,
|
42
42
|
SEARCH_BODY.to_json)
|
43
43
|
|
44
|
-
assert_raises(ArgumentError) { wf.
|
45
|
-
assert_raises(ArgumentError) { wf.
|
44
|
+
assert_raises(ArgumentError) { wf.raw_facet_search }
|
45
|
+
assert_raises(ArgumentError) { wf.raw_facet_search('ALERT', 'junk') }
|
46
46
|
end
|
47
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wavefront-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Fisher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|