Class: Peddler::Feeds::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/peddler/feeds.rb

Overview

This is the base class.

Constant Summary collapse

MAPPED_PARAMS =
{
'UploadStatus'              => 'status',
'UploadType'                => 'type',
'UploadId'                  => 'id',
'SubmittedDate'             => 'submitted_at',
'StartedProcessingDate'     => 'started_processing_at',
'CompletedProcessingDate'   => 'completed_processing_at',
'CompletedProcesssingDate'  => 'completed_processing_at',
'MessagesProcessed'         => 'messages_processed',
'MessagesSuccessful'        => 'messages_successful',
'MessagesWithErrors'        => 'messages_with_errors',
'MessagesWithWarnings'      => 'messages_with_warnings'}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ Feed

Returns a new instance of Feed.



58
59
60
61
# File 'lib/peddler/feeds.rb', line 58

def initialize(transport)
  @transport = transport
  @batch = []
end

Instance Attribute Details

#batchObject

Returns the value of attribute batch.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def batch
  @batch
end

#completed_processing_atObject

Returns the value of attribute completed_processing_at.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def completed_processing_at
  @completed_processing_at
end

#downloadObject

Returns the value of attribute download.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def download
  @download
end

#file_contentObject

Returns content of the upload file.



64
65
66
67
68
69
# File 'lib/peddler/feeds.rb', line 64

def file_content
  return @file_content if @file_content 
  out = @file_header
  @batch.each{ |item| out << item.to_s }
  @file_content = out
end

#idObject

Returns the value of attribute id.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def id
  @id
end

#messages_processedObject

Returns the value of attribute messages_processed.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def messages_processed
  @messages_processed
end

#messages_successfulObject

Returns the value of attribute messages_successful.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def messages_successful
  @messages_successful
end

#messages_with_errorsObject

Returns the value of attribute messages_with_errors.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def messages_with_errors
  @messages_with_errors
end

#messages_with_warningsObject

Returns the value of attribute messages_with_warnings.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def messages_with_warnings
  @messages_with_warnings
end

#started_processing_atObject

Returns the value of attribute started_processing_at.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def started_processing_at
  @started_processing_at
end

#statusObject

Returns the value of attribute status.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def status
  @status
end

#submitted_atObject

Returns the value of attribute submitted_at.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def 
  @submitted_at
end

#typeObject

Returns the value of attribute type.



43
44
45
# File 'lib/peddler/feeds.rb', line 43

def type
  @type
end

Instance Method Details

#<<(item) ⇒ Object

Adds an item to the batch.



92
93
94
# File 'lib/peddler/feeds.rb', line 92

def <<(item)
  @batch << item
end

#status!Object

Returns status and will also refresh if not already “done.”



72
73
74
75
76
# File 'lib/peddler/feeds.rb', line 72

def status!
  return @status if @status.nil? || @status =~ /_DONE_/
  refresh_status
  @status
end

#uploadObject

Uploads batch.

Raises:



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/peddler/feeds.rb', line 79

def upload
  raise PeddlerError.new('Batch already uploaded') unless @id.nil?
  @transport.modernize_request
  @transport.query_params.merge!({
    'Action'     => 'upload',
    'uploadType' => @type})
  @transport.body = file_content
  res = @transport.execute_request
  process_response(res)
  @status
end