Class: Sistrix::Monitoring::Report

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/sistrix/monitoring/report.rb,
lib/sistrix/monitoring/report/download.rb

Defined Under Namespace

Classes: Download, Recipient, Record

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#base_uri, #fetch, #method_name

Constructor Details

#initialize(options = {}) ⇒ Report

Returns a new instance of Report.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sistrix/monitoring/report.rb', line 11

def initialize(options = {})
  @options = {
    'project' => nil,
    'report' => nil,
    'api_key' => Sistrix.config.api_key,
  }.merge(options)

  if Sistrix.config.proxy
    RestClient.proxy = Sistrix.config.proxy
  end
end

Instance Attribute Details

#creditsObject (readonly)

Returns the value of attribute credits.



9
10
11
# File 'lib/sistrix/monitoring/report.rb', line 9

def credits
  @credits
end

#formatObject (readonly)

Returns the value of attribute format.



9
10
11
# File 'lib/sistrix/monitoring/report.rb', line 9

def format
  @format
end

#frequencyObject (readonly)

Returns the value of attribute frequency.



9
10
11
# File 'lib/sistrix/monitoring/report.rb', line 9

def frequency
  @frequency
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/sistrix/monitoring/report.rb', line 9

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/sistrix/monitoring/report.rb', line 9

def name
  @name
end

#recipientsObject (readonly)

Returns the value of attribute recipients.



9
10
11
# File 'lib/sistrix/monitoring/report.rb', line 9

def recipients
  @recipients
end

#reportsObject (readonly)

Returns the value of attribute reports.



9
10
11
# File 'lib/sistrix/monitoring/report.rb', line 9

def reports
  @reports
end

Instance Method Details

#call(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sistrix/monitoring/report.rb', line 23

def call(options = {})
  data = fetch(options)

  @credits   = data.xpath('/response/credits').first['used'].to_i
  @name      = data.xpath('/response/answer/name').first['value'].to_s.strip
  @id        = data.xpath('/response/answer/id').first['value'].to_s.strip
  @frequency = data.xpath('/response/answer/frequency').first['value'].to_s.strip
  @format    = data.xpath('/response/answer/format').first['value'].to_s.strip

  @recipients = []
  data.xpath('/response/answer/recipients/recipient').each do |r|
    @recipients << Recipient.new(r)
  end

  @reports = []
  data.xpath('/response/answer/archive/report').each do |r|
    @reports << Record.new(r)
  end

  self
end