Sha256: 3c62b57016e4f264409964f958a8f299697fe7ee285c1eeeb63ee271a75f73bf

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require 'xeroizer/application_http_proxy' 
require 'xeroizer/report/base'

module Xeroizer
  module Report
    class Factory
      
      include ApplicationHttpProxy

      attr_reader :application
      attr_reader :report_type
      
      public
      
        def initialize(application, report_type)
          @application = application
          @report_type = report_type
        end
      
        # Retreive a report with the `options` as a hash containing
        # valid query-string parameters to pass to the API.
        def get(options = {})
          response_xml = options[:cache_file] ? File.read(options[:cache_file]) : http_get(options)          
          Response.parse(response_xml, options) do | response, elements |
            parse_reports(response, elements)
          end.first # there is is only one
        end
      
        def api_controller_name
          "Report/#{report_type}"
        end

      protected
              
        def parse_reports(response, elements)
          elements.each do | element |
            response.response_items << Base.build_from_node(element, self)
          end
        end
        
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xeroizer-0.2.0 lib/xeroizer/report/factory.rb