Class: Xeroizer::Report::Factory

Inherits:
Object
  • Object
show all
Includes:
ApplicationHttpProxy
Defined in:
lib/xeroizer/report/factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApplicationHttpProxy

included

Constructor Details

#initialize(application, report_type) ⇒ Factory

Returns a new instance of Factory.



16
17
18
19
# File 'lib/xeroizer/report/factory.rb', line 16

def initialize(application, report_type)
  @application = application
  @report_type = report_type
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



11
12
13
# File 'lib/xeroizer/report/factory.rb', line 11

def application
  @application
end

#report_typeObject (readonly)

Returns the value of attribute report_type.



12
13
14
# File 'lib/xeroizer/report/factory.rb', line 12

def report_type
  @report_type
end

Instance Method Details

#api_controller_nameObject



31
32
33
# File 'lib/xeroizer/report/factory.rb', line 31

def api_controller_name
  "Reports/#{report_type}"
end

#get(options = {}) ⇒ Object

Retreive a report with the ‘options` as a hash containing valid query-string parameters to pass to the API.



23
24
25
26
27
28
29
# File 'lib/xeroizer/report/factory.rb', line 23

def get(options = {})
  response_xml = options[:cache_file] ? File.read(options[:cache_file]) : http_get(options)          
  response = Response.parse(response_xml, options) do | response, elements |
    parse_reports(response, elements)
  end
  response.response_items.first # there is is only one
end

#klassObject



35
36
37
38
39
40
41
# File 'lib/xeroizer/report/factory.rb', line 35

def klass
  begin
    @_klass_cache ||= Xeroizer::Report.const_get(report_type)
  rescue NameError => ex # use default class
    Base
  end
end