wavefront-sdk 0.2.3 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a834d2f501fb52ddaf2675e357d5a0ed285a12b9
4
- data.tar.gz: 93635191aae83d66e6dde2ec1deaf564046269e3
3
+ metadata.gz: 19b69376bae0fb003a885f84caec73b642242144
4
+ data.tar.gz: 09c37865d29c17fb1fd9f8d98b79982dcae7491f
5
5
  SHA512:
6
- metadata.gz: 8bc7656d0c303bfb6eb9bbb79229afac145331535014fdb852b7213f13ea477f14d26edf85ff04dfd169cb3384714fef7904b6623b2f3ce2e46b8bda0e742277
7
- data.tar.gz: b19a17c7a2e6e2d52c6016f4bd3e1e6420b57dd6bf77361d6875fb0a1c3ea384570213a8460a5f81d58bd089a340ed06e41c957dc493bcb8a8e263f739d7347b
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
  ```
@@ -9,23 +9,74 @@ module Wavefront
9
9
  #
10
10
  class Search < Base
11
11
 
12
- # POST /api/v2/search/agent
13
- # POST /api/v2/search/agent/deleted
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 search(entity = nil, body = nil, deleted = false)
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 = ['agent']
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 facet_search(entity = nil, body = nil, deleted = false,
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 = ['agent']
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.2.3'.freeze
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(:search, ['agent', SEARCH_BODY], 'agent', :post,
19
+ should_work(:raw_search, ['agent', SEARCH_BODY], 'agent', :post,
20
20
  JSON_POST_HEADERS, SEARCH_BODY.to_json)
21
- should_work(:search, ['agent', SEARCH_BODY, true], 'agent/deleted',
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.search }
24
- assert_raises(ArgumentError) { wf.search('ALERT', 'junk') }
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(:facet_search, ['agent', SEARCH_BODY],
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(:facet_search, ['agent', SEARCH_BODY, true],
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(:facet_search, ['agent', SEARCH_BODY, false, 'Tags'],
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(:facet_search, ['agent', SEARCH_BODY, true, 'Tags'],
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.facet_search }
45
- assert_raises(ArgumentError) { wf.facet_search('ALERT', 'junk') }
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.2.3
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 00:00:00.000000000 Z
11
+ date: 2017-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday