zeusclient 0.1.2 → 0.1.3

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: 6de2b427eec1b61a32dca4dd4db821f5757bcc43
4
- data.tar.gz: 3ec31374ecedd07fa548713da44306981531fe38
3
+ metadata.gz: 2c9b1fe09cdda854fc306b53d850844882fcfb8c
4
+ data.tar.gz: 67609f973c1bb564d651d09e684e5cd02e423389
5
5
  SHA512:
6
- metadata.gz: 65d27734ac92912a91f689342037a4faf9528348af1e42f04bfc5e0907241ff6e6e5263f2f1d794a92819f273e382c0a738ec56fc75b18903cab97389505347c
7
- data.tar.gz: 0596048bd3d412b4f861bea183d02d798be717b8f02139b9f2568b9967916d641ee6c142f079a249f01db214ff409f8e5c72eb10a4f450627a053324f753d7cb
6
+ metadata.gz: 3ebb415c828ccb35f9146ba6d85b15893538fabcaed53f44c61f91b480a90f66d2909f4e06274b4b833267842e3a36c01d0e1b3f86d7a57ad9ccdd21332b2eaf
7
+ data.tar.gz: 8a291264fc2236aa6fd0968135518621d9f1e38d00e9fac8301988f5ae80903ca7b1211c7d0527776a7ffdceabaa3bf3eb0c5d4a9579d7f5adc0099c9285941b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zeusclient (0.1.1)
4
+ zeusclient (0.1.3)
5
5
  json
6
6
  rest-client
7
7
 
@@ -23,6 +23,7 @@ GEM
23
23
  unf (0.1.4)
24
24
  unf_ext
25
25
  unf_ext (0.0.7.1)
26
+ yard (0.8.7.6)
26
27
 
27
28
  PLATFORMS
28
29
  ruby
@@ -30,4 +31,5 @@ PLATFORMS
30
31
  DEPENDENCIES
31
32
  bundler (~> 1.8)
32
33
  rake (~> 10.0)
34
+ yard (~> 0.8.0)
33
35
  zeusclient!
@@ -18,13 +18,36 @@ require 'zeus/api_client/version'
18
18
 
19
19
  module Zeus
20
20
 
21
+ # API Client for Zeus Service
21
22
  class APIClient
22
23
 
24
+ # constructor for Zeus::APIClient
25
+ # @param [Hash] opts the options to create z Zeus::APIClient instance
26
+ # @option opts [String] :access_token The tokens for Zeus Service
27
+ # @option opts [String] :endpoint The base url for API endpoint
23
28
  def initialize(opts={})
24
29
  @access_token = opts[:access_token]
25
30
  @endpoint = opts[:endpoint] || "http://api.ciscozeus.io"
26
31
  end
27
32
 
33
+ # Get metrics list
34
+ # @param [String] regex a factor for filtering by metrics name
35
+ # [optional]
36
+ # [Examples] metric.name, metric.name*, metric.name.* etc.
37
+ # @param [String] from_date a factor for filtering by start timestamp
38
+ # [optional]
39
+ # @param [String] to_date a factor for filtering by end timestamp
40
+ # [optional]
41
+ # @param [String] aggregator an aggregation methods
42
+ # [optional]
43
+ # @param [String] group_interval grouping values by time interval
44
+ # [optional]
45
+ # [Examples] 1000s, 100m, 10h, 1d , 1w. Use 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days and 'w' for weeks.
46
+ # @param [String] filter_condition a factor for filtering by metrics name
47
+ # [optional]
48
+ # @param [String] limit a maximum number of returning values
49
+ # [optional]
50
+ # @return [Zeus::APIClient::Result]
28
51
  def list_metrics(regex=nil, from_date=nil, to_date=nil, aggregator=nil, group_interval=nil, filter_condition=nil, limit=nil)
29
52
  params = {}
30
53
  params.merge!(metric_name: regex) if regex
@@ -35,23 +58,46 @@ module Zeus
35
58
  params.merge!(filter_condition: filter_condition) if filter_condition
36
59
  params.merge!(limit: limit) if limit
37
60
  begin
38
- response = self.get("/metrics/#{@access_token}/_names/", params)
61
+ response = get("/metrics/#{@access_token}/_names/", params)
39
62
  Result.new(response)
40
63
  rescue => e
41
64
  Result.new(e.response)
42
65
  end
43
66
  end
44
67
 
68
+ # Send metrics list
69
+ # @param [String] name a name of metrics
70
+ # [Examples] metric.name, metric.name*, metric.name.* etc.
71
+ # @param [Array] metrics a list of hash objects
72
+ # @return [Zeus::APIClient::Result]
45
73
  def send_metrics(name, metrics)
46
74
  params = {metrics: metrics}
47
75
  begin
48
- response = self.post("/metrics/#{@access_token}/#{name}/", params)
76
+ response = post("/metrics/#{@access_token}/#{name}/", params)
49
77
  Result.new(response)
50
78
  rescue => e
51
79
  Result.new(e.response)
52
80
  end
53
81
  end
54
82
 
83
+ # Get metrics
84
+ # @param [String] regex a factor for filtering by metrics name
85
+ # [optional]
86
+ # @param [String] from_date a factor for filtering by start timestamp
87
+ # [optional]
88
+ # @param [String] to_date a factor for filtering by end timestamp
89
+ # [optional]
90
+ # @param [String] aggregator an aggregation methods
91
+ # [optional]
92
+ # @param [String] group_interval grouping values by time interval
93
+ # [optional]
94
+ # [Examples] 1000s, 100m, 10h, 1d , 1w. Use 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days and 'w' for weeks.
95
+ # @param [String] filter_condition filters to be applied to metric values
96
+ # [optional]
97
+ # [Examples] "column1 > 0", "column1 > 50 AND column2 = 10".
98
+ # @param [Integer] limit a maximum number of returning values
99
+ # [optional]
100
+ # @return [Zeus::APIClient::Result]
55
101
  def get_metrics(regex=nil, from_date=nil, to_date=nil, aggregator=nil, group_interval=nil, filter_condition=nil, limit=nil)
56
102
  params = {}
57
103
  params.merge!(metric_name: regex) if regex
@@ -62,50 +108,73 @@ module Zeus
62
108
  params.merge!(filter_condition: filter_condition) if filter_condition
63
109
  params.merge!(limit: limit) if limit
64
110
  begin
65
- response = self.get("/metrics/#{@access_token}/_values/", params)
111
+ response = get("/metrics/#{@access_token}/_values/", params)
66
112
  Result.new(response)
67
113
  rescue => e
68
114
  Result.new(e.response)
69
115
  end
70
116
  end
71
117
 
118
+ # delete metrics
119
+ # @param [String] name a target metrics name
120
+ # @return [Zeus::APIClient::Result]
72
121
  def delete_metrics(name)
73
- response = self.delete("/metrics/#{@access_token}/#{name}/")
122
+ response = delete("/metrics/#{@access_token}/#{name}/")
74
123
  Result.new(response)
75
124
  end
76
125
 
126
+ # send logs
127
+ # @param [String] name a log name
128
+ # @param [Array] logs a list of hash objects
129
+ # @return [Zeus::APIClient::Result]
77
130
  def send_logs(name, logs)
78
131
  params = {logs:logs}
79
132
  begin
80
- response = self.post("/logs/#{@access_token}/#{name}/", params)
133
+ response = post("/logs/#{@access_token}/#{name}/", params)
81
134
  Result.new(response)
82
135
  rescue => e
83
136
  Result.new(e.response)
84
137
  end
85
138
  end
86
139
 
87
- def get_logs(name, pattern=nil, from_date=nil, to_date=nil, offset=nil, limit=nil)
140
+ # get logs
141
+ # @param [String] name a log name
142
+ # @param [String] attribute_name Name of the attribute within the log to be searched.
143
+ # [optional]
144
+ # [Examples] if the submitted log has the format {"key1": "value1", "key2": "value2", "timestamp": 1430268064} then the value of this field can be "key1" or "key2"
145
+ # @param [String] pattern a factor for fitering by name
146
+ # [optional]
147
+ # @param [String] from_date a factor for filtering by start timestamp
148
+ # [optional]
149
+ # @param [String] to_date a factor for filtering by end timestamp
150
+ # [optional]
151
+ # @param [Integer] offset a factor for filtering by metrics name
152
+ # [optional]
153
+ # @param [Integer] limit a maximum number of returning values
154
+ # [optional]
155
+ # @return [Zeus::APIClient::Result]
156
+ def get_logs(name, attribute_name=nil, pattern=nil, from_date=nil, to_date=nil, offset=nil, limit=nil)
88
157
  params = {log_name: name} # required fields
158
+ params.merge!(attribute_name: attribute_name) if attribute_name
89
159
  params.merge!(pattern: pattern) if pattern
90
160
  params.merge!(from: from_date) if from_date
91
161
  params.merge!(to: to_date) if to_date
92
162
  params.merge!(offset: offset) if offset
93
163
  params.merge!(limit: limit) if limit
94
164
  begin
95
- response = self.get("/logs/#{@access_token}", params)
165
+ response = get("/logs/#{@access_token}", params)
96
166
  Result.new(response)
97
167
  rescue => e
98
168
  Result.new(e.response)
99
169
  end
100
170
  end
101
171
 
172
+ private
102
173
  def get(path, params={})
103
174
  RestClient.get "#{@endpoint}#{path}", {params: params}
104
175
  end
105
176
 
106
177
  def post(path, data={})
107
- p "#{@endpoint}#{path}"
108
- p data
109
178
  RestClient.post "#{@endpoint}#{path}", data.to_json, :content_type => :json, :accept => :json
110
179
  end
111
180
 
@@ -16,32 +16,39 @@ require 'json'
16
16
 
17
17
  module Zeus
18
18
  class APIClient
19
+ # Wrapper for a response of REST API
19
20
  class Result
20
21
 
22
+ # constructor for Result class
21
23
  def initialize(response)
22
24
  @response = response
23
25
  end
24
26
 
27
+ # request is successed?
25
28
  def success?
26
29
  @response.code == 200 || @response.code == 201
27
30
  end
28
31
 
32
+ # request is error?
29
33
  def error?
30
34
  !self.success?
31
35
  end
32
36
 
37
+ # response code
33
38
  def code
34
39
  @response.code
35
40
  end
36
41
 
37
- def data
38
- JSON.parse(@response)
39
- end
40
-
42
+ # response header
41
43
  def header
42
44
  @response.headers
43
45
  end
44
46
 
47
+ # response body
48
+ def data
49
+ JSON.parse(@response)
50
+ end
51
+
45
52
  end
46
53
  end
47
54
  end
@@ -14,6 +14,7 @@
14
14
 
15
15
  module Zeus
16
16
  class APIClient
17
- VERSION = "0.1.2"
17
+ # package version number
18
+ VERSION = "0.1.3"
18
19
  end
19
20
  end
@@ -42,4 +42,5 @@ Gem::Specification.new do |spec|
42
42
  spec.add_dependency "rest-client"
43
43
  spec.add_development_dependency "bundler", "~> 1.8"
44
44
  spec.add_development_dependency "rake", "~> 10.0"
45
+ spec.add_development_dependency "yard", "~> 0.8.0"
45
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeusclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Komei Shimamura
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.0
69
83
  description: Client for Cisco Zeus. This allows users to send and receive data to
70
84
  and from Cisco Zeus.
71
85
  email:
@@ -111,3 +125,4 @@ signing_key:
111
125
  specification_version: 4
112
126
  summary: Ruby Client for Cisco Zeus
113
127
  test_files: []
128
+ has_rdoc: