Class: Morpheus::ReportsInterface

Inherits:
APIClient
  • Object
show all
Defined in:
lib/morpheus/api/reports_interface.rb

Instance Method Summary collapse

Instance Method Details

#create(payload) ⇒ Object



18
19
20
21
22
# File 'lib/morpheus/api/reports_interface.rb', line 18

def create(payload)
  url = "#{@base_url}/api/reports"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  execute(method: :post, url: url, headers: headers, payload: payload.to_json)
end

#destroy(id, params = {}) ⇒ Object

def update(id, payload) url = "#@base_url/api/reports/#id" headers = { :authorization => "Bearer #@access_token", 'Content-Type' => 'application/json' } execute(method: :put, url: url, headers: headers, payload: payload.to_json) end



30
31
32
33
34
# File 'lib/morpheus/api/reports_interface.rb', line 30

def destroy(id, params={})
  url = "#{@base_url}/api/reports/#{id}"
  headers = { :params => params, :authorization => "Bearer #{@access_token}"}
  execute(method: :delete, url: url, headers: headers)
end

#export(id, outfile, params = {}, report_format = 'json') ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/morpheus/api/reports_interface.rb', line 42

def export(id, outfile, params={}, report_format='json')
  url = "#{@base_url}/api/reports/export/#{id}.#{report_format}"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  opts = {method: :get, url: url, headers: headers, timeout: 172800}
  # execute(opts, {parse_json: false})
  if Dir.exist?(outfile)
    raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
  end
  # if @verify_ssl == false
  #   opts[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
  # end
  if @dry_run
    return opts
  end
  http_response = nil
  File.open(outfile, 'w') {|f|
    block = proc { |response|
      response.read_body do |chunk|
        # writing to #{outfile} ..."
        f.write chunk
      end
    }
    opts[:block_response] = block
    http_response = Morpheus::RestClient.execute(opts)
  }
  return http_response
end

#get(id, params = {}) ⇒ Object



5
6
7
8
9
10
# File 'lib/morpheus/api/reports_interface.rb', line 5

def get(id, params={})
  raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
  url = "#{@base_url}/api/reports/#{id}"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  execute(method: :get, url: url, headers: headers)
end

#list(params = {}) ⇒ Object



12
13
14
15
16
# File 'lib/morpheus/api/reports_interface.rb', line 12

def list(params={})
  url = "#{@base_url}/api/reports"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  execute(method: :get, url: url, headers: headers)
end

#types(params = {}) ⇒ Object



36
37
38
39
40
# File 'lib/morpheus/api/reports_interface.rb', line 36

def types(params={})
  url = "#{@base_url}/api/report-types"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  execute(method: :get, url: url, headers: headers)
end