Class: Metaforce::Job::Retrieve

Inherits:
Metaforce::Job show all
Defined in:
lib/metaforce/job/retrieve.rb

Constant Summary

Constants inherited from Metaforce::Job

DELAY_MULTIPLIER, DELAY_START

Instance Attribute Summary

Attributes inherited from Metaforce::Job

#id

Instance Method Summary collapse

Methods inherited from Metaforce::Job

disable_threading!, #done?, #inspect, #started?, #state, #status

Constructor Details

#initialize(client, options = {}) ⇒ Retrieve

Public: Instantiate a new retrieve job.

Examples

job = Metaforce::Job::Retrieve.new(client)
# => #<Metaforce::Job::Retrieve @id=nil>

Returns self.



12
13
14
15
# File 'lib/metaforce/job/retrieve.rb', line 12

def initialize(client, options={})
  super(client)
  @options = options
end

Instance Method Details

#extract_to(destination) ⇒ Object

Public: Unzips the returned zip file to the location.

destination - Path to extract the contents to.

Examples

job.extract_to('./path')
# => #<Metaforce::Job::Retrieve @id='1234'>

Returns self.



65
66
67
68
69
70
71
# File 'lib/metaforce/job/retrieve.rb', line 65

def extract_to(destination)
  return on_complete { |job| job.extract_to(destination) } unless started?
  with_tmp_zip_file do |file|
    unzip(file, destination)
  end
  self
end

#performObject

Public: Perform the job.

Examples

job = Metaforce::Job::Retrieve.new(client)
job.perform
# => #<Metaforce::Job::Retrieve @id='1234'>

Returns self.



26
27
28
29
# File 'lib/metaforce/job/retrieve.rb', line 26

def perform
  @id = client._retrieve(@options).id
  super
end

#resultObject

Public: Get the detailed status of the retrieve.

Examples

job.result
# => { :id => '1234', :zip_file => '<base64 encoded content>', ... }

Returns the RetrieveResult (www.salesforce.com/us/developer/docs/api_meta/Content/meta_retrieveresult.htm).



39
40
41
# File 'lib/metaforce/job/retrieve.rb', line 39

def result
  @result ||= client.status(id, :retrieve)
end

#zip_fileObject

Public: Decodes the content of the returned zip file.

Examples

job.zip_file
# => '<binary content>'

Returns the decoded content.



51
52
53
# File 'lib/metaforce/job/retrieve.rb', line 51

def zip_file
  Base64.decode64(result.zip_file)
end