Module: Grafana::Modules::Folder

Included in:
Folders
Defined in:
lib/grafana/modules/folder.rb

Instance Method Summary collapse

Instance Method Details

#create_folder(title:, uid: nil) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/grafana/modules/folder.rb', line 28

def create_folder(title:, uid: nil)
  req_body = {
    title: title
  }

  req_body.merge(uid: uid) if uid.present?

  post('/api/folders', req_body)
end

#delete_folder(uid:) ⇒ Object



46
47
48
# File 'lib/grafana/modules/folder.rb', line 46

def delete_folder(uid:)
  delete("/api/folders#{uid}")
end

#folder(uid:) ⇒ Object



24
25
26
# File 'lib/grafana/modules/folder.rb', line 24

def folder(uid:)
  get("/api/folders/#{uid}")
end

#folder_search(**options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/grafana/modules/folder.rb', line 4

def folder_search(**options)
  options = options.slice(:query, :tag, :dashboard_ids, :folder_ids, :starred, :limit, :page)

  options[:folderIds] = Array.wrap(options.delete(:folder_ids)) if options[:folder_ids].present?
  options[:dashboardIds] = Array.wrap(options.delete(:dashboard_ids)) if options[:dashboard_ids].present?

  options.delete(:starred) unless options[:starred].is_a?(Boolean)
  options.delete(:limit) unless options[:limit].is_a?(Integer) && options[:limit] <= 5000
  options.delete(:page) unless options[:page].is_a?(Integer)

  options.merge({ type: 'dash-folder' })

  search_url = '/api/search'
  search_url = "?#{URI.encode_www_form(options)}"
  get(search_url)
end

#foldersObject



20
21
22
# File 'lib/grafana/modules/folder.rb', line 20

def folders
  get('/api/folders')
end

#update_folder(uid:, **options) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/grafana/modules/folder.rb', line 38

def update_folder(uid:, **options)
  # Drop any keys that are not valid for the request
  options = options.slice(:title, :new_uid, :version, :overwrite)
  options[:uid] = options.delete(:new_uid) if options.key(:new_uid)

  post("/api/folders/#{uid}", options)
end