dogapi 1.19.0 → 1.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de64563ab5144d6702205f3880a060f67df51241
4
- data.tar.gz: f05d0e0f8ee326fa9d894ca79dccc7b60de1a936
3
+ metadata.gz: c4468399eb2562412f21f437bac47ce6eee96d64
4
+ data.tar.gz: 02b6507f392f7fdfa051104d466b0378841570fa
5
5
  SHA512:
6
- metadata.gz: 5b4ab9bf5dff9e693be19c9c06e3d4e73650565f79eda03241415d10173df6002ca907ce0a5f8f3ec3101a0ca543f04bb7b311efefebef5d94b586aa912f9769
7
- data.tar.gz: 9863d208e81b87f6fa0f353126253c4d0fe2c1ec6d0b6ff13d6308e5ed4bab1ed8c53027e6f19adac7d9a1107c95b1d1b3636728a3cd8dcd4a4a20351937e269
6
+ metadata.gz: 249b343d68784129d73fadebe8622e73eb2401d5f62f294007cdd7152ae01d1e0461b4eaafc4263d005d71b65f4632abb7e9bd63cd00eec47a9fe06254264ad8
7
+ data.tar.gz: 8170e19e1531983963a4ec44273838d30c8a31b249f192b3b4ba80cd1acd5d3e90caf038f23539c7718dbbcccf8a2ca6f95af084399405c74cdc4733ae5ea3af
@@ -1,6 +1,9 @@
1
1
  Changes
2
2
  =======
3
3
 
4
+ # 1.20.0 / 2015-07-29
5
+ * [FEATURE] Embeddable graphs API. See [#73][]
6
+
4
7
  # 1.19.0 / 2015-06-22
5
8
  * [FEATURE] Revoke a shared a Screenboard. See [#69][]
6
9
 
@@ -130,6 +133,7 @@ Changes
130
133
  [#62]: https://github.com/DataDog/dogapi-rb/issues/62
131
134
  [#64]: https://github.com/DataDog/dogapi-rb/issues/64
132
135
  [#69]: https://github.com/DataDog/dogapi-rb/issues/69
136
+ [#73]: https://github.com/DataDog/dogapi-rb/issues/73
133
137
  [@ArjenSchwarz]: https://github.com/ArjenSchwarz
134
138
  [@Kaixiang]: https://github.com/Kaixiang
135
139
  [@ansel1]: https://github.com/ansel1
@@ -137,4 +141,4 @@ Changes
137
141
  [@byroot]: https://github.com/byroot
138
142
  [@treeder]: https://github.com/treeder
139
143
  [@winebarrel]: https://github.com/winebarrel
140
- [@yyuu]: https://github.com/yyuu
144
+ [@yyuu]: https://github.com/yyuu
@@ -37,6 +37,7 @@ module Dogapi
37
37
  @alert_svc = Dogapi::V1::AlertService.new(@api_key, @application_key, silent, timeout)
38
38
  @user_svc = Dogapi::V1::UserService.new(@api_key, @application_key, silent, timeout)
39
39
  @snapshot_svc = Dogapi::V1::SnapshotService.new(@api_key, @application_key, silent, timeout)
40
+ @embed_svc = Dogapi::V1::EmbedService.new(@api_key, @application_key, silent, timeout)
40
41
  @screenboard_svc = Dogapi::V1::ScreenboardService.new(@api_key, @application_key, silent, timeout)
41
42
  @monitor_svc = Dogapi::V1::MonitorService.new(@api_key, @application_key, silent, timeout)
42
43
  @service_check_svc = Dogapi::V1::ServiceCheckService.new(@api_key, @application_key, silent, timeout)
@@ -295,6 +296,29 @@ module Dogapi
295
296
  @snapshot_svc.snapshot(metric_query, start_ts, end_ts, event_query)
296
297
  end
297
298
 
299
+ #
300
+ # EMBEDS
301
+ #
302
+ def get_all_embeds()
303
+ @embed_svc.get_all_embeds()
304
+ end
305
+
306
+ def get_embed(embed_id, description= {})
307
+ @embed_svc.get_embed(embed_id, description)
308
+ end
309
+
310
+ def create_embed(graph_json, description= {})
311
+ @embed_svc.create_embed(graph_json, description)
312
+ end
313
+
314
+ def enable_embed(embed_id)
315
+ @embed_svc.enable_embed(embed_id)
316
+ end
317
+
318
+ def revoke_embed(embed_id)
319
+ @embed_svc.revoke_embed(embed_id)
320
+ end
321
+
298
322
  #
299
323
  # SCREENBOARD
300
324
  #
@@ -7,6 +7,7 @@ require 'dogapi/v1/dash'
7
7
  require 'dogapi/v1/alert'
8
8
  require 'dogapi/v1/user'
9
9
  require 'dogapi/v1/snapshot'
10
+ require 'dogapi/v1/embed'
10
11
  require 'dogapi/v1/screenboard'
11
12
  require 'dogapi/v1/monitor'
12
13
  require 'dogapi/v1/service_check'
@@ -0,0 +1,106 @@
1
+ require 'dogapi'
2
+
3
+ module Dogapi
4
+ class V1 # for namespacing
5
+
6
+ # ================
7
+ # EMBED API
8
+ # ================
9
+ class EmbedService < Dogapi::APIService
10
+
11
+ API_VERSION = "v1"
12
+
13
+ # Get all embeds for the API user's org
14
+ def get_all_embeds()
15
+ begin
16
+ params = {
17
+ :api_key => @api_key,
18
+ :application_key => @application_key
19
+ }
20
+
21
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed", params, nil, false)
22
+ rescue Exception => e
23
+ suppress_error_if_silent e
24
+ end
25
+ end
26
+
27
+ # Get a specific embed
28
+ #
29
+ # :embed_id => String: embed token for a specific embed
30
+ # :size => String: "small", "medium"(defualt), "large", or "xlarge".
31
+ # :legend => String: "yes" or "no"(default)
32
+ # :template_vars => String: variable name => variable value (any number of template vars)
33
+ def get_embed(embed_id, description= {})
34
+ begin
35
+ # Initialize parameters and merge with description
36
+ params = {
37
+ :api_key => @api_key,
38
+ :application_key => @application_key,
39
+ }.merge(description)
40
+
41
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed/#{embed_id}", params, nil, false)
42
+ rescue Exception => e
43
+ suppress_error_if_silent e
44
+ end
45
+ end
46
+
47
+ # Create an embeddable graph
48
+ #
49
+ # :graph_json => JSON: graph definition
50
+ # :timeframe => String: representing the interval of the graph. Default is "1_hour"
51
+ # :size => String: representing the size of the graph. Default is "medium".
52
+ # :legend => String: flag representing whether a legend is displayed. Default is "no".
53
+ # :title => String: represents title of the graph. Default is "Embed created through API."
54
+ def create_embed(graph_json, description= {})
55
+ begin
56
+ params = {
57
+ :api_key => @api_key,
58
+ :application_key => @application_key
59
+ }
60
+
61
+ body = {
62
+ :graph_json => graph_json,
63
+ }.merge(description)
64
+
65
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/graph/embed", params, body, true)
66
+ rescue Exception => e
67
+ suppress_error_if_silent e
68
+ end
69
+ end
70
+
71
+ # Enable a specific embed
72
+ #
73
+ # :embed_id => String: embed token for a specific embed
74
+ def enable_embed(embed_id)
75
+ begin
76
+ params = {
77
+ :api_key => @api_key,
78
+ :application_key => @application_key
79
+ }
80
+
81
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed/#{embed_id}/enable", params, nil, false)
82
+ rescue Exception => e
83
+ suppress_error_if_silent e
84
+ end
85
+ end
86
+
87
+ # Revoke a specific embed
88
+ #
89
+ # :embed_id => String: embed token for a specific embed
90
+ def revoke_embed(embed_id)
91
+ begin
92
+ params = {
93
+ :api_key => @api_key,
94
+ :application_key => @application_key
95
+ }
96
+
97
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/graph/embed/#{embed_id}/revoke", params, nil, false)
98
+ rescue Exception => e
99
+ suppress_error_if_silent e
100
+ end
101
+ end
102
+
103
+ end
104
+
105
+ end
106
+ end
@@ -1,3 +1,3 @@
1
1
  module Dogapi
2
- VERSION = "1.19.0"
2
+ VERSION = "1.20.0"
3
3
  end
@@ -0,0 +1,194 @@
1
+ require 'dogapi'
2
+ require 'time'
3
+ require 'test_base.rb'
4
+
5
+ class TestEmbed < Test::Unit::TestCase
6
+ include TestBase
7
+
8
+ def test_get_all_embeds
9
+ dog = Dogapi::Client.new(@api_key, @app_key)
10
+
11
+ # Attempt API Call
12
+ status, result = dog.get_all_embeds()
13
+ # Sanity check results
14
+ assert_equal status, "200", "invalid HTTP response => #{status}"
15
+ assert result.has_key?("embedded_graphs")
16
+ end
17
+
18
+ def test_create_embed
19
+ dog = Dogapi::Client.new(@api_key, @app_key)
20
+ # create an embed using the embed id and verify that it is valid
21
+ graph_json = '{
22
+ "viz": "toplist",
23
+ "requests": [{
24
+ "q": "top(system.disk.free{$var} by {device}, 10, \'mean\', \'desc\')",
25
+ "style": {
26
+ "palette": "dog_classic"
27
+ },
28
+ "conditional_formats": [{
29
+ "palette": "red",
30
+ "comparator": ">",
31
+ "value": 50000000000
32
+ }, {
33
+ "palette": "green",
34
+ "comparator": ">",
35
+ "value": 30000000000
36
+ }]
37
+ }]
38
+ }'
39
+ timeframe = "1_hour"
40
+ size = "medium"
41
+ legend = "no"
42
+ title = "Sick Title!"
43
+ description = {
44
+ :timeframe => timeframe,
45
+ :size => size,
46
+ :legend => legend,
47
+ :title => title
48
+ }
49
+ status, result = dog.create_embed(graph_json, description)
50
+ # Sanity check results
51
+ assert result["graph_title"] == title
52
+ assert_equal status, "200", "invalid HTTP response => #{status}"
53
+ assert result["html"].include? "legend=false"
54
+ assert result["html"].include? "height=300"
55
+ assert result["html"].include? "width=600"
56
+ end
57
+
58
+ def test_get_embed
59
+ dog = Dogapi::Client.new(@api_key, @app_key)
60
+ # Create an Embed to get a valid embed_id
61
+ graph_json = '{
62
+ "viz": "toplist",
63
+ "requests": [{
64
+ "q": "top(system.disk.free{$var} by {device}, 10, \'mean\', \'desc\')",
65
+ "style": {
66
+ "palette": "dog_classic"
67
+ },
68
+ "conditional_formats": [{
69
+ "palette": "red",
70
+ "comparator": ">",
71
+ "value": 50000000000
72
+ }, {
73
+ "palette": "green",
74
+ "comparator": ">",
75
+ "value": 30000000000
76
+ }]
77
+ }]
78
+ }'
79
+ timeframe = "1_hour"
80
+ size = "medium"
81
+ legend = "no"
82
+ title = "Sick Title!"
83
+ description = {
84
+ :timeframe => timeframe,
85
+ :size => size,
86
+ :legend => legend,
87
+ :title => title
88
+ }
89
+ status, create_result = dog.create_embed(graph_json, description)
90
+ # Sanity check results
91
+ assert_equal status, "200", "invalid HTTP response => #{status}"
92
+ assert create_result["html"].include? "legend=false"
93
+ assert create_result["html"].include? "height=300"
94
+ assert create_result["html"].include? "width=600"
95
+ embed_id = create_result["embed_id"]
96
+ # Get the embed using that embed id
97
+ status, embed_without_var = dog.get_embed(embed_id)
98
+ assert_equal status, "200", "invalid HTTP response => #{status}"
99
+ get_embed_description = {
100
+ :size => size,
101
+ :legend => legend,
102
+ :var => "val"
103
+ }
104
+ status, embed_with_var = dog.get_embed(embed_id, get_embed_description)
105
+ assert_equal status, "200", "invalid HTTP response => #{status}"
106
+ # Verify that the get requests are good
107
+ assert embed_without_var["html"] == create_result["html"]
108
+ assert embed_with_var["html"] != embed_without_var["html"]
109
+ assert embed_with_var["html"].include? "legend=false"
110
+ assert embed_with_var["html"].include? "height=300"
111
+ assert embed_with_var["html"].include? "width=600"
112
+ assert embed_with_var["html"].include? "var=val"
113
+ end
114
+
115
+ def test_enable_embed
116
+ dog = Dogapi::Client.new(@api_key, @app_key)
117
+ # Create an Embed to get a valid embed_id
118
+ graph_json = '{
119
+ "viz": "toplist",
120
+ "requests": [{
121
+ "q": "top(system.disk.free{$var} by {device}, 10, \'mean\', \'desc\')",
122
+ "style": {
123
+ "palette": "dog_classic"
124
+ },
125
+ "conditional_formats": [{
126
+ "palette": "red",
127
+ "comparator": ">",
128
+ "value": 50000000000
129
+ }, {
130
+ "palette": "green",
131
+ "comparator": ">",
132
+ "value": 30000000000
133
+ }]
134
+ }]
135
+ }'
136
+ timeframe = "1_hour"
137
+ size = "medium"
138
+ legend = "no"
139
+ title = "Sick Title!"
140
+ description = {
141
+ :timeframe => timeframe,
142
+ :size => size,
143
+ :legend => legend,
144
+ :title => title
145
+ }
146
+ status, create_result = dog.create_embed(graph_json, description)
147
+ # Sanity check results
148
+ assert_equal status, "200", "invalid HTTP response => #{status}"
149
+ embed_id = create_result["embed_id"]
150
+ status, result = dog.enable_embed(embed_id)
151
+ assert_equal status, "200", "invalid HTTP response => #{status}"
152
+ assert result.has_key?("success")
153
+ end
154
+
155
+ def test_revoke_embed
156
+ dog = Dogapi::Client.new(@api_key, @app_key)
157
+ # Create an Embed to get a valid embed_id
158
+ graph_json = '{
159
+ "viz": "toplist",
160
+ "requests": [{
161
+ "q": "top(system.disk.free{$var} by {device}, 10, \'mean\', \'desc\')",
162
+ "style": {
163
+ "palette": "dog_classic"
164
+ },
165
+ "conditional_formats": [{
166
+ "palette": "red",
167
+ "comparator": ">",
168
+ "value": 50000000000
169
+ }, {
170
+ "palette": "green",
171
+ "comparator": ">",
172
+ "value": 30000000000
173
+ }]
174
+ }]
175
+ }'
176
+ timeframe = "1_hour"
177
+ size = "medium"
178
+ legend = "no"
179
+ title = "Sick Title!"
180
+ description = {
181
+ :timeframe => timeframe,
182
+ :size => size,
183
+ :legend => legend,
184
+ :title => title
185
+ }
186
+ status, create_result = dog.create_embed(graph_json, description)
187
+ # Sanity check results
188
+ assert_equal status, "200", "invalid HTTP response => #{status}"
189
+ embed_id = create_result["embed_id"]
190
+ status, result = dog.revoke_embed(embed_id)
191
+ assert_equal status, "200", "invalid HTTP response => #{status}"
192
+ assert result.has_key?("success")
193
+ end
194
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.0
4
+ version: 1.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-22 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -100,6 +100,7 @@ files:
100
100
  - lib/dogapi/v1/alert.rb
101
101
  - lib/dogapi/v1/comment.rb
102
102
  - lib/dogapi/v1/dash.rb
103
+ - lib/dogapi/v1/embed.rb
103
104
  - lib/dogapi/v1/event.rb
104
105
  - lib/dogapi/v1/metric.rb
105
106
  - lib/dogapi/v1/monitor.rb
@@ -131,6 +132,7 @@ files:
131
132
  - tests/test_client.rb
132
133
  - tests/test_comments.rb
133
134
  - tests/test_dashes.rb
135
+ - tests/test_embed.rb
134
136
  - tests/test_monitors.rb
135
137
  - tests/test_screenboard.rb
136
138
  - tests/test_search.rb
@@ -162,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
164
  version: '0'
163
165
  requirements: []
164
166
  rubyforge_project:
165
- rubygems_version: 2.2.2
167
+ rubygems_version: 2.4.4
166
168
  signing_key:
167
169
  specification_version: 4
168
170
  summary: Ruby bindings for Datadog's API
@@ -183,3 +185,4 @@ test_files:
183
185
  - spec/support/cassettes/Facade/Events/emits_events_and_retrieves_them.yml
184
186
  - spec/support/cassettes/Facade/Events/emits_events_with_specified_priority.yml
185
187
  - spec/support/cassettes/Facade/Tags/adds_updates_and_detaches_tags.yml
188
+ has_rdoc: true