Class: Chimps::Workflows::Upload::Uploader
- 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
-
#bundler ⇒ Object
The bundler from which to glean information about the upload.
-
#token ⇒ Object
The token consumed when uploading.
Instance Method Summary collapse
-
#initialize(token, bundler) ⇒ Uploader
constructor
Instantiate a new Uploader which will consume the given
tokenand upload data from the givenbundler. -
#upload! ⇒ Object
Upload the data.
-
#upload_data ⇒ String
Return a string built from the granted upload token that can be fed to
curlin order to authenticate with and upload to Amazon.
Methods included from Utils::UsesCurl
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
#bundler ⇒ Object
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 |
#token ⇒ Object
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.
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_data ⇒ String
Return a string built from the granted upload token that can be fed to curl in order to authenticate with and upload to Amazon.
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 |