Class: Dogapi::V1::DashboardService
- Inherits:
-
APIService
- Object
- APIService
- Dogapi::V1::DashboardService
- Defined in:
- lib/dogapi/v1/dashboard.rb
Overview
Dashboard API
Constant Summary collapse
- API_VERSION =
'v1'
- RESOURCE_NAME =
'dashboard'
Instance Attribute Summary
Attributes inherited from APIService
Instance Method Summary collapse
-
#create_board(title, widgets, layout_type, options) ⇒ Object
Create new dashboard.
-
#delete_board(dashboard_id) ⇒ Object
Delete the given dashboard.
-
#get_all_boards ⇒ Object
Fetch all custom dashboards.
-
#get_board(dashboard_id) ⇒ Object
Fetch the given dashboard.
-
#update_board(dashboard_id, title, widgets, layout_type, options) ⇒ Object
Update a dashboard.
Methods inherited from APIService
#connect, #handle_redirect, #handle_response, #initialize, #prepare_params, #prepare_request, #request, #should_set_api_and_app_keys_in_params?, #suppress_error_if_silent
Constructor Details
This class inherits a constructor from Dogapi::APIService
Instance Method Details
#create_board(title, widgets, layout_type, options) ⇒ Object
Create new dashboard
Required arguments: :title => String: Title of the dashboard :widgets => JSON: List of widgets to display on the dashboard :layout_type => String: Layout type of the dashboard.
Allowed values: 'ordered' or 'free'
Optional arguments: :description => String: Description of the dashboard :is_read_only => Boolean: Whether this dashboard is read-only.
If True, only the author and admins can make changes to it.
:notify_list => JSON: List of handles of users to notify when changes are made to this dashboard
e.g. '["[email protected]", "[email protected]"]'
:template_variables => JSON: List of template variables for this dashboard.
e.g. [{"name": "host", "prefix": "host", "default": "my-host"}]
:template_variable_presets => JSON: List of template variables saved views
e.g. {
"name": "my_template_variable_preset",
"template_variables": [{"name": "host", "prefix": "host", "default": "my-host"}]
}
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dogapi/v1/dashboard.rb', line 34 def create_board(title, , layout_type, ) # Required arguments body = { title: title, widgets: , layout_type: layout_type } # Optional arguments body[:description] = [:description] if [:description] body[:is_read_only] = [:is_read_only] if [:is_read_only] body[:notify_list] = [:notify_list] if [:notify_list] body[:template_variables] = [:template_variables] if [:template_variables] body[:template_variable_presets] = [:template_variable_presets] if [:template_variable_presets] request(Net::HTTP::Post, "/api/#{API_VERSION}/#{RESOURCE_NAME}", nil, body, true) end |
#delete_board(dashboard_id) ⇒ Object
Delete the given dashboard
Required argument: :dashboard_id => String: ID of the dashboard
106 107 108 |
# File 'lib/dogapi/v1/dashboard.rb', line 106 def delete_board(dashboard_id) request(Net::HTTP::Delete, "/api/#{API_VERSION}/#{RESOURCE_NAME}/#{dashboard_id}", nil, nil, false) end |
#get_all_boards ⇒ Object
Fetch all custom dashboards
98 99 100 |
# File 'lib/dogapi/v1/dashboard.rb', line 98 def get_all_boards request(Net::HTTP::Get, "/api/#{API_VERSION}/#{RESOURCE_NAME}", nil, nil, false) end |
#get_board(dashboard_id) ⇒ Object
Fetch the given dashboard
Required argument: :dashboard_id => String: ID of the dashboard
93 94 95 |
# File 'lib/dogapi/v1/dashboard.rb', line 93 def get_board(dashboard_id) request(Net::HTTP::Get, "/api/#{API_VERSION}/#{RESOURCE_NAME}/#{dashboard_id}", nil, nil, false) end |
#update_board(dashboard_id, title, widgets, layout_type, options) ⇒ Object
Update a dashboard
Required arguments: :dashboard_id => String: ID of the dashboard :title => String: Title of the dashboard :widgets => JSON: List of widgets to display on the dashboard :layout_type => String: Layout type of the dashboard.
Allowed values: 'ordered' or 'free'
Optional arguments: :description => String: Description of the dashboard :is_read_only => Boolean: Whether this dashboard is read-only.
If True, only the author and admins can make changes to it.
:notify_list => JSON: List of handles of users to notify when changes are made to this dashboard
e.g. '["[email protected]", "[email protected]"]'
:template_variables => JSON: List of template variables for this dashboard.
e.g. [{"name": "host", "prefix": "host", "default": "my-host"}]
:template_variable_presets => JSON: List of template variables saved views
e.g. {
"name": "my_template_variable_preset",
"template_variables": [{"name": "host", "prefix": "host", "default": "my-host"}]
}
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dogapi/v1/dashboard.rb', line 72 def update_board(dashboard_id, title, , layout_type, ) # Required arguments body = { title: title, widgets: , layout_type: layout_type } # Optional arguments body[:description] = [:description] if [:description] body[:is_read_only] = [:is_read_only] if [:is_read_only] body[:notify_list] = [:notify_list] if [:notify_list] body[:template_variables] = [:template_variables] if [:template_variables] body[:template_variable_presets] = [:template_variable_presets] if [:template_variable_presets] request(Net::HTTP::Put, "/api/#{API_VERSION}/#{RESOURCE_NAME}/#{dashboard_id}", nil, body, true) end |