lib/peddler/legacy_reports.rb in peddler-0.2.4 vs lib/peddler/legacy_reports.rb in peddler-0.3.0

- old
+ new

@@ -1,10 +1,10 @@ module Peddler - + # This module contains methods to manage legacy reports -- anything that comes before section 7 in the API docs. module LegacyReports - + # Returns statuses of most recent reports in an array of OpenStructs. def self.latest(transport,name,params={}) transport.legacize_request if name == :upload transport.path << 'catalog-upload/get-batches' @@ -15,37 +15,37 @@ transport.headers[:number_of_reports] = params[:count] if params[:count] end res = transport.execute_request Peddler::Handlers::XMLHandler.parse_legacy(Hash.from_xml(res)) || [] end - + # Requests a report to be generated and returns the report instance if request is successful. def self.generate(transport,name,params={}) transport.legacize_request transport.path << 'manual-reports/generate-report-now' transport.headers[:report_name] = name.to_s.camelize transport.headers.merge!(params) res = transport.execute_request res =~ /SUCCESS/ ? Peddler::LegacyReports::Report.new(transport, name) : false end - + # A legacy report class Report attr_accessor :name, :id, :product_line, :frequency - + def initialize(transport, name=nil, params={}) @transport, @name = transport, name params.each_pair{ |key, value| self.send "#{key}=", value } end - + def body return nil if @name == :upload && @id.nil? @body ||= download end - + private - + def download return false if @name.nil? && @id.nil? case @name.to_s when 'upload' @transport.legacize_request @@ -66,33 +66,33 @@ end @transport.execute_request end end end - + class Status < OpenStruct def initialize(input) if input.kind_of? String hash = input.scan(/([a-z]+)=([^=]+)($| )/).inject({}){ |memo, value| memo.merge( { @keymap[value[0]] => value[1].strip }) } end super(hash) end - + def id @table[:id] || self.object_id end end - + class ReportStatus < Status def initialize(input) @keymap = { 'reportstarttime' => 'starts_at', 'reportendtime' => 'ends_at', 'reportid' => 'id' } super(input) end end - + class UploadStatus < Status def initialize(input) @keymap = { 'status' => 'status', 'batchid' => 'id',