Class: Chimps::Workflows::Upload::Uploader

Inherits:
Object
  • Object
show all
Includes:
Utils::UsesCurl
Defined in:
lib/chimps/workflows/upload/uploader.rb

Overview

Encapsulates the process of uploading a package to Infochimps.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::UsesCurl

#curl

Constructor Details

#initialize(token, bundler) ⇒ Uploader

Instantiate a new Uploader which will consume the given token and upload data from the given bundler.



21
22
23
24
# File 'lib/chimps/workflows/upload/uploader.rb', line 21

def initialize token, bundler
  self.token   = token
  self.bundler = bundler
end

Instance Attribute Details

#bundlerObject

The bundler from which to glean information about the upload.



14
15
16
# File 'lib/chimps/workflows/upload/uploader.rb', line 14

def bundler
  @bundler
end

#tokenObject

The token consumed when uploading.



11
12
13
# File 'lib/chimps/workflows/upload/uploader.rb', line 11

def token
  @token
end

Instance Method Details

#upload!Object

Upload the data.

Uses curl for the transfer.

Raises:



40
41
42
43
44
45
# File 'lib/chimps/workflows/upload/uploader.rb', line 40

def upload!
  progress_meter = Chimps.verbose? ? '' : '-s -S'
  command = "#{curl} #{progress_meter} -o /dev/null -X POST #{upload_data} #{token['url']}"
  puts command if Chimps.verbose?
  raise UploadError.new("Failed to upload #{bundler.archive.path} to Infochimps") unless system(command)
end

#upload_dataString

Return a string built from the granted upload token that can be fed to curl in order to authenticate with and upload to Amazon.

Returns:



31
32
33
34
35
# File 'lib/chimps/workflows/upload/uploader.rb', line 31

def upload_data
  data = ['AWSAccessKeyId', 'acl', 'key', 'policy', 'success_action_status', 'signature'].map { |param| "-F #{param}='#{token[param]}'" }
  data << ["-F file=@#{bundler.archive.path}"]
  data.join(' ')
end