Class: Wesabe::Upload

Inherits:
BaseModel show all
Defined in:
lib/wesabe/upload.rb

Overview

Encapsulates an upload and allows uploading files to wesabe.com.

Defined Under Namespace

Classes: Exception, StatementError

Instance Attribute Summary collapse

Attributes inherited from BaseModel

#wesabe

Instance Method Summary collapse

Methods inherited from BaseModel

#get, #post

Methods included from Util

#all_or_one

Constructor Details

#initialize {|upload| ... } ⇒ Upload

Initializes a Wesabe::Upload and yields itself.

Yield Parameters:



16
17
18
# File 'lib/wesabe/upload.rb', line 16

def initialize
  yield self if block_given?
end

Instance Attribute Details

#accountsObject

The accounts this upload is associated with.



4
5
6
# File 'lib/wesabe/upload.rb', line 4

def accounts
  @accounts
end

#financial_institutionObject

The financial institution this upload is associated with.



6
7
8
# File 'lib/wesabe/upload.rb', line 6

def financial_institution
  @financial_institution
end

#statementObject

The raw statement to post.



10
11
12
# File 'lib/wesabe/upload.rb', line 10

def statement
  @statement
end

#statusObject

Whether this upload succeeded or failed, or nil if it hasn’t started.



8
9
10
# File 'lib/wesabe/upload.rb', line 8

def status
  @status
end

Instance Method Details

#failed?Boolean

Determines whether this upload failed or not.

Returns:

  • (Boolean)

    false if status is “processed”, true otherwise.



55
56
57
# File 'lib/wesabe/upload.rb', line 55

def failed?
  !successful?
end

#successful?Boolean

Determines whether this upload succeeded or not.

Returns:

  • (Boolean)

    true if status is “processed”, false otherwise.



47
48
49
# File 'lib/wesabe/upload.rb', line 47

def successful?
  status == "processed"
end

#upload!Object

Uploads the statement to Wesabe, raising on problems. It can raise anything that is raised by Wesabe::Request#execute in addition to the list below.

begin
  upload.upload!
rescue Wesabe::Upload::StatementError => e
  $stderr.puts "The file you chose to upload couldn't be imported."
  $stderr.puts "This is what Wesabe said: #{e.message}"
rescue Wesabe::Request::Exception
  $stderr.puts "There was a problem communicating with Wesabe."
end

Raises:

See Also:



37
38
39
40
41
# File 'lib/wesabe/upload.rb', line 37

def upload!
  process_response do
    post(:url => '/rest/upload/statement', :payload => pack_statement)
  end
end