wavefront-sdk 0.0.1 → 0.1.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.
@@ -4,7 +4,7 @@ module Wavefront
4
4
  #
5
5
  # View and manage source metadata.
6
6
  #
7
- class Source < Wavefront::Base
7
+ class Source < Base
8
8
 
9
9
  # GET /api/v2/source
10
10
  # Get all sources for a customer
@@ -30,7 +30,7 @@ module Wavefront
30
30
  api_post('', body, 'application/json')
31
31
  end
32
32
 
33
- # DELETE /api/v2/source/{id}
33
+ # DELETE /api/v2/source/id
34
34
  # Delete metadata (description and tags) for a specific source.
35
35
  #
36
36
  # @param id [String] ID of the source
@@ -41,7 +41,7 @@ module Wavefront
41
41
  api_delete(id)
42
42
  end
43
43
 
44
- # GET /api/v2/source/{id}
44
+ # GET /api/v2/source/id
45
45
  # Get a specific source for a customer.
46
46
  #
47
47
  # @param id [String] ID of the source
@@ -55,7 +55,7 @@ module Wavefront
55
55
  api_get(fragments.uri_concat)
56
56
  end
57
57
 
58
- # PUT /api/v2/source/{id}
58
+ # PUT /api/v2/source/id
59
59
  # Update metadata (description or tags) for a specific source.
60
60
  #
61
61
  # Refer to the Swagger API docs for valid keys.
@@ -69,11 +69,11 @@ module Wavefront
69
69
  api_put(id, body)
70
70
  end
71
71
 
72
- # GET /api/v2/source/{id}/tag
72
+ # GET /api/v2/source/id/tag
73
73
  # Get all tags associated with a specific source.
74
74
  #
75
75
  # @param id [String] ID of the source
76
- # @returns [Hash] object describing the source with status and
76
+ # @return [Hash] object describing the source with status and
77
77
  # response keys
78
78
  #
79
79
  def tags(id)
@@ -81,12 +81,12 @@ module Wavefront
81
81
  api_get([id, 'tag'].uri_concat)
82
82
  end
83
83
 
84
- # POST /api/v2/source/{id}/tag
84
+ # POST /api/v2/source/id/tag
85
85
  # Set all tags associated with a specific source.
86
86
  #
87
87
  # @param id [String] ID of the source
88
88
  # @param tags [Array] list of tags to set.
89
- # @returns [Hash] object describing the source with status and
89
+ # @return [Hash] object describing the source with status and
90
90
  # response keys
91
91
  #
92
92
  def tag_set(id, tags)
@@ -96,12 +96,12 @@ module Wavefront
96
96
  api_post([id, 'tag'].uri_concat, tags.to_json, 'application/json')
97
97
  end
98
98
 
99
- # DELETE /api/v2/source/{id}/tag/{tagValue}
99
+ # DELETE /api/v2/source/id/tag/tagValue
100
100
  # Remove a tag from a specific source.
101
101
  #
102
102
  # @param id [String] ID of the source
103
103
  # @param tag [String] tag to delete
104
- # @returns [Hash] object with 'status' key and empty 'repsonse'
104
+ # @return [Hash] object with 'status' key and empty 'repsonse'
105
105
  #
106
106
  def tag_delete(id, tag)
107
107
  wf_source_id?(id)
@@ -109,12 +109,12 @@ module Wavefront
109
109
  api_delete([id, 'tag', tag].uri_concat)
110
110
  end
111
111
 
112
- # PUT /api/v2/source/{id}/tag/{tagValue}
112
+ # PUT /api/v2/source/id/tag/tagValue
113
113
  # Add a tag to a specific source
114
114
  #
115
115
  # @param id [String] ID of the source
116
116
  # @param tag [String] tag to set.
117
- # @returns [Hash] object with 'status' key and empty 'repsonse'
117
+ # @return [Hash] object with 'status' key and empty 'repsonse'
118
118
  #
119
119
  def tag_add(id, tag)
120
120
  wf_source_id?(id)
@@ -122,10 +122,4 @@ module Wavefront
122
122
  api_put([id, 'tag', tag].uri_concat)
123
123
  end
124
124
  end
125
-
126
- # A standard response
127
- #
128
- class Response
129
- class Source < Base; end
130
- end
131
125
  end
@@ -4,7 +4,7 @@ module Wavefront
4
4
  #
5
5
  # Manage and query Wavefront users
6
6
  #
7
- class User < Wavefront::Base
7
+ class User < Base
8
8
 
9
9
  # GET /api/v2/user
10
10
  # Get all users.
@@ -26,7 +26,7 @@ module Wavefront
26
26
  api_post("?sendEmail=#{send_email}", body, 'application/json')
27
27
  end
28
28
 
29
- # DELETE /api/v2/user/{id}
29
+ # DELETE /api/v2/user/id
30
30
  # Delete a specific user.
31
31
  #
32
32
  # @param id [String] ID of the user
@@ -37,7 +37,7 @@ module Wavefront
37
37
  api_delete(id)
38
38
  end
39
39
 
40
- # GET /api/v2/user/{id}
40
+ # GET /api/v2/user/id
41
41
  # Retrieves a user by identifier (email addr).
42
42
  #
43
43
  # @param id [String] ID of the user
@@ -48,7 +48,7 @@ module Wavefront
48
48
  api_get(id)
49
49
  end
50
50
 
51
- # PUT /api/v2/user/{id}/grant
51
+ # PUT /api/v2/user/id/grant
52
52
  # Grants a specific user permission.
53
53
  #
54
54
  # @param id [String] ID of the user
@@ -68,7 +68,7 @@ module Wavefront
68
68
  'application/x-www-form-urlencoded')
69
69
  end
70
70
 
71
- # PUT /api/v2/user/{id}/revoke
71
+ # PUT /api/v2/user/id/revoke
72
72
  # Revokes a specific user permission.
73
73
  #
74
74
  # @param id [String] ID of the user
@@ -83,26 +83,17 @@ module Wavefront
83
83
  api_post([id, 'revoke'].uri_concat, "group=#{group}",
84
84
  'application/x-www-form-urlencoded')
85
85
  end
86
- end
87
-
88
- class Response
89
86
 
90
- # The User response forges status and response methods to look
91
- # like other classes and create a more consistent interface.
87
+ # Fake a response which looks like we get from all the other
88
+ # paths. I'm expecting the user response model to be made
89
+ # consistent with others in the future.
92
90
  #
93
- class User < Base
94
- def populate(raw, status)
95
- @response = if raw.is_a?(Array)
96
- Struct.new(:items).new(raw).freeze
97
- elsif raw.is_a?(Hash)
98
- Struct.new(*raw.keys).new(*raw.values).freeze
99
- end
100
-
101
- result = status == 200 ? 'OK' : 'ERROR'
102
-
103
- @status = Struct.new(:result, :message, :code).
104
- new(result, nil, status)
105
- end
91
+ def response_shim(body, status)
92
+ { response: JSON.parse(body),
93
+ status: { result: status == 200 ? 'OK' : 'ERROR',
94
+ message: '',
95
+ code: status },
96
+ }.to_json
106
97
  end
107
98
  end
108
99
  end
@@ -141,7 +141,7 @@ module Wavefront
141
141
 
142
142
  # Ensure the given argument is a valid version number
143
143
  #
144
- # @param [Integer] the version number to validate
144
+ # @param v [Integer] the version number to validate
145
145
  # @return True if the version is valid
146
146
  # @raise Wavefront::Exception::InvalidVersion if the alert ID is
147
147
  # not valid
@@ -245,7 +245,7 @@ module Wavefront
245
245
  # event ID is not valid
246
246
  #
247
247
  def wf_event_id?(v)
248
- return true if v.is_a?(String) && v =~ /^\d{13}:[\w\- ]+$/
248
+ return true if v.is_a?(String) && v =~ /^\d{13}:.+/
249
249
  raise Wavefront::Exception::InvalidEventId
250
250
  end
251
251
 
@@ -1 +1 @@
1
- WF_SDK_VERSION = '0.0.1'.freeze
1
+ WF_SDK_VERSION = '0.1.0'.freeze
@@ -4,7 +4,7 @@ module Wavefront
4
4
  #
5
5
  # Manage and query Wavefront webhooks
6
6
  #
7
- class Webhook < Wavefront::Base
7
+ class Webhook < Base
8
8
 
9
9
  # GET /api/v2/webhook
10
10
  # Get all webhooks for a customer.
@@ -29,7 +29,7 @@ module Wavefront
29
29
  api_post('', body, 'application/json')
30
30
  end
31
31
 
32
- # DELETE /api/v2/webhook/{id}
32
+ # DELETE /api/v2/webhook/id
33
33
  # Delete a specific webhook.
34
34
  #
35
35
  # @param id [String, Integer] ID of the webhook
@@ -40,7 +40,7 @@ module Wavefront
40
40
  api_delete(id)
41
41
  end
42
42
 
43
- # GET /api/v2/webhook/{id}
43
+ # GET /api/v2/webhook/id
44
44
  # Get a specific webhook.
45
45
  #
46
46
  # @param id [String, Integer] ID of the webhook
@@ -51,7 +51,7 @@ module Wavefront
51
51
  api_get(id)
52
52
  end
53
53
 
54
- # PUT /api/v2/webhook/{id}
54
+ # PUT /api/v2/webhook/id
55
55
  # Update a specific webhook.
56
56
  #
57
57
  # @param body [Hash] a hash of parameters describing the webhook.
@@ -64,10 +64,4 @@ module Wavefront
64
64
  api_put(id, body)
65
65
  end
66
66
  end
67
-
68
- # A standard response
69
- #
70
- class Response
71
- class Webhook < Base; end
72
- end
73
67
  end
@@ -8,13 +8,14 @@ module Wavefront
8
8
  # This class helps you send points to a Wavefront proxy in native
9
9
  # format. Usually this is done on port 2878.
10
10
  #
11
- class Write < Wavefront::Base
11
+ class Write < Base
12
12
  attr_reader :sock, :summary
13
13
 
14
14
  # Construct an object which allows us to write points to a
15
15
  # Wavefront proxy.
16
16
  #
17
- # @pram creds [Hash] must contain the keys endpoint: and port.
17
+ # @param _creds [Hash] dummy parameter for correct method
18
+ # signature.
18
19
  # @param options [Hash] can contain the following keys:
19
20
  # proxy [String] the address of the Wavefront proxy. ('wavefront')
20
21
  # port [Integer] the port of the Wavefront proxy (2878)
@@ -48,10 +49,13 @@ module Wavefront
48
49
  # Send raw data to a Wavefront proxy, automatically opening and
49
50
  # closing a socket.
50
51
  #
51
- # @param point [Array[String]] an array of points in native
52
+ # @param points [Array[String]] an array of points in native
52
53
  # Wavefront wire format, as described in
53
54
  # https://community.wavefront.com/docs/DOC-1031. No validation
54
55
  # is performed.
56
+ # @param openclose [Boolean] whether or not to automatically
57
+ # open a socket to the proxy before sending points, and
58
+ # afterwards, close it.
55
59
  #
56
60
  def raw(points, openclose = true)
57
61
  open if openclose
@@ -95,7 +99,13 @@ module Wavefront
95
99
  close if openclose
96
100
  end
97
101
 
98
- Wavefront::Response::Write.new(summary.to_json, nil)
102
+ s_str = summary[:unsent] == 0 && summary[:rejected] == 0 ? 'OK' :
103
+ 'ERROR'
104
+
105
+ resp = { status: { result: s_str, message: nil, code: nil },
106
+ response: summary }.to_json
107
+
108
+ Wavefront::Response.new(resp, nil)
99
109
  end
100
110
 
101
111
  def valid_point?(p)
@@ -202,7 +212,7 @@ module Wavefront
202
212
  end
203
213
  end
204
214
 
205
- class Response
215
+ #class Response
206
216
  # The Write response forges status and response methods to look
207
217
  # like other classes and create a more consistent interface. As
208
218
  # the request does not happen over HTTP, there's not much to put
@@ -212,14 +222,14 @@ module Wavefront
212
222
  # @response=#<struct sent=1, rejected=0, unsent=0>,
213
223
  # @status=#<struct result="OK", message=nil, code=nil>>
214
224
  #
215
- class Write < Base
216
- def populate(raw, status)
217
- @response = Struct.new(*raw.keys).new(*raw.values).freeze
218
-
219
- ok = raw[:rejected] == 0 && raw[:unsent] == 0 ? 'OK' : 'ERROR'
220
-
221
- @status = Struct.new(:result, :message, :code).new(ok, nil, nil)
222
- end
223
- end
224
- end
225
+ #class Write < Base
226
+ #def populate(raw, status)
227
+ #@response = Struct.new(*raw.keys).new(*raw.values).freeze
228
+ #
229
+ #ok = raw[:rejected] == 0 && raw[:unsent] == 0 ? 'OK' : 'ERROR'
230
+ #
231
+ #@status = Struct.new(:result, :message, :code).new(ok, nil, nil)
232
+ #end
233
+ #end
234
+ #end
225
235
  end
@@ -16,11 +16,11 @@ class WavefrontCredentialsTest < MiniTest::Test
16
16
  ENV.delete('WAVEFRONT_TOKEN')
17
17
  c = Wavefront::Credentials.new(file: CONF)
18
18
  assert_instance_of(Wavefront::Credentials, c)
19
- assert_instance_of(Hash, c.creds)
20
- assert_instance_of(Hash, c.proxy)
21
- assert_instance_of(Hash, c.config)
19
+ assert_instance_of(Map, c.creds)
20
+ assert_instance_of(Map, c.proxy)
21
+ assert_instance_of(Map, c.config)
22
22
 
23
- assert_equal(c.creds.keys, [:token, :endpoint])
23
+ assert_equal(c.creds.keys, %w(token endpoint))
24
24
  assert_equal(c.creds[:token], '12345678-abcd-1234-abcd-123456789012')
25
25
  assert_equal(c.creds[:endpoint], 'default.wavefront.com')
26
26
  end
@@ -30,11 +30,11 @@ class WavefrontCredentialsTest < MiniTest::Test
30
30
  ENV['WAVEFRONT_TOKEN'] = 'abcdefgh'
31
31
  c = Wavefront::Credentials.new(file: CONF)
32
32
  assert_instance_of(Wavefront::Credentials, c)
33
- assert_instance_of(Hash, c.creds)
34
- assert_instance_of(Hash, c.proxy)
35
- assert_instance_of(Hash, c.config)
33
+ assert_instance_of(Map, c.creds)
34
+ assert_instance_of(Map, c.proxy)
35
+ assert_instance_of(Map, c.config)
36
36
 
37
- assert_equal(c.creds.keys, [:token, :endpoint])
37
+ assert_equal(c.creds.keys, %w(token endpoint))
38
38
  assert_equal(c.creds[:token], 'abcdefgh')
39
39
  assert_equal(c.creds[:endpoint], 'default.wavefront.com')
40
40
  end
@@ -44,11 +44,11 @@ class WavefrontCredentialsTest < MiniTest::Test
44
44
  ENV['WAVEFRONT_ENDPOINT'] = 'endpoint.wavefront.com'
45
45
  c = Wavefront::Credentials.new(file: CONF)
46
46
  assert_instance_of(Wavefront::Credentials, c)
47
- assert_instance_of(Hash, c.creds)
48
- assert_instance_of(Hash, c.proxy)
49
- assert_instance_of(Hash, c.config)
47
+ assert_instance_of(Map, c.creds)
48
+ assert_instance_of(Map, c.proxy)
49
+ assert_instance_of(Map, c.config)
50
50
 
51
- assert_equal(c.creds.keys, [:token, :endpoint])
51
+ assert_equal(c.creds.keys, %w(token endpoint))
52
52
  assert_equal(c.creds[:token], '12345678-abcd-1234-abcd-123456789012')
53
53
  assert_equal(c.creds[:endpoint], 'endpoint.wavefront.com')
54
54
  end
@@ -13,8 +13,8 @@ WF_JSON = '{"status":{"result":"OK","message":"","code":200},' \
13
13
  class WavefrontResponseTest < MiniTest::Test
14
14
 
15
15
  def test_initialize_good_data
16
- wf = Wavefront::Response::Base.new(WF_JSON, 200)
17
- assert_instance_of(Wavefront::Response::Base, wf)
16
+ wf = Wavefront::Response.new(WF_JSON, 200)
17
+ assert_instance_of(Wavefront::Response, wf)
18
18
  assert_respond_to(wf, :status)
19
19
  assert_respond_to(wf, :response)
20
20
  assert_respond_to(wf.response, :items)
@@ -25,22 +25,22 @@ class WavefrontResponseTest < MiniTest::Test
25
25
  end
26
26
 
27
27
  def test_initialize_bad_data
28
- assert_raises(Wavefront::Exception::InvalidResponse) do
29
- Wavefront::Response::Base.new('merp', 200)
28
+ assert_raises(Wavefront::Exception::UnparseableResponse) do
29
+ Wavefront::Response.new('merp', 200)
30
30
  end
31
31
 
32
- assert_raises(Wavefront::Exception::InvalidResponse) do
33
- Wavefront::Response::Base.new(
32
+ assert_raises(Wavefront::Exception::UnparseableResponse) do
33
+ Wavefront::Response.new(
34
34
  '{"status":{"result":"OK","message":"","code":200}', 200)
35
35
  end
36
36
 
37
- assert_raises(Wavefront::Exception::InvalidResponse) do
38
- Wavefront::Response::Base.new(
37
+ assert_raises(Wavefront::Exception::UnparseableResponse) do
38
+ Wavefront::Response.new(
39
39
  '{"status":{"result":"OK","message":"","code":200}', 200)
40
40
  end
41
41
 
42
- assert_raises(Wavefront::Exception::InvalidResponse) do
43
- Wavefront::Response::Base.new(
42
+ assert_raises(Wavefront::Exception::UnparseableResponse) do
43
+ Wavefront::Response.new(
44
44
  '{"response":{"items":[{"name":"test agent"}],"offset":0 }', 200)
45
45
  end
46
46
  end
@@ -122,7 +122,7 @@ class WavefrontValidatorsTest < MiniTest::Test
122
122
 
123
123
  def test_wf_event_id?
124
124
  good = %w(1493370839062:test1)
125
- bad = %w(1493370839062 1493370839062:test!)
125
+ bad = %w(1493370839062 1493370839062test!)
126
126
  good_and_bad('wf_event_id?', 'InvalidEventId', good, bad)
127
127
  end
128
128
 
@@ -21,6 +21,8 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.add_runtime_dependency 'faraday', '>= 0.12.1', '< 0.13'
23
23
  gem.add_runtime_dependency 'inifile', '>= 3.0.0'
24
+ gem.add_runtime_dependency 'addressable', '~> 2.4'
25
+ gem.add_runtime_dependency 'map', '~> 6.6.0'
24
26
 
25
27
  gem.add_development_dependency 'bundler', '~> 1.3'
26
28
  gem.add_development_dependency 'rake', '~> 12.0'
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.0.1
4
+ version: 0.1.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-06-04 00:00:00.000000000 Z
11
+ date: 2017-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -44,6 +44,34 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 3.0.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: addressable
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.4'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.4'
61
+ - !ruby/object:Gem::Dependency
62
+ name: map
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 6.6.0
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 6.6.0
47
75
  - !ruby/object:Gem::Dependency
48
76
  name: bundler
49
77
  requirement: !ruby/object:Gem::Requirement
@@ -238,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
266
  version: '0'
239
267
  requirements: []
240
268
  rubyforge_project:
241
- rubygems_version: 2.5.2
269
+ rubygems_version: 2.4.5
242
270
  signing_key:
243
271
  specification_version: 4
244
272
  summary: SDK for Wavefront API v2