Class: ConnectWiseRest::Report

Inherits:
Client
  • Object
show all
Defined in:
lib/connect_wise_rest/report.rb

Constant Summary

Constants inherited from Client

Client::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Client

#options, #resource

Instance Method Summary collapse

Methods inherited from Client

#data, #next_page, #next_page?, #previous_page, #previous_page?, #request_options, #response, #url

Constructor Details

#initialize(name, options = {}) ⇒ Report

Returns a new instance of Report.



6
7
8
9
10
# File 'lib/connect_wise_rest/report.rb', line 6

def initialize(name, options = {})
  @name = name
  @resource = '/system/reports/' + name
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/connect_wise_rest/report.rb', line 4

def name
  @name
end

Instance Method Details

#fetch(query = {}) ⇒ Object



12
13
14
15
# File 'lib/connect_wise_rest/report.rb', line 12

def fetch(query = {})
  super
  format!
end

#format!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/connect_wise_rest/report.rb', line 17

def format!
  if @data && @data['row_values'].is_a?(Array)
    rows = []

    @data['row_values'].each do |values|
      row = {}

      values.each_with_index do |value, index|
        key = @data['column_definitions'][index].keys[0]
        row[key] = value
      end

      rows << row
    end

    @data = rows

  else
    @data = []
  end
end