Class: Chimps::Workflows::Up
Overview
Uploads data to Infochimps by first asking for authorization, creating an archive, obtaining a token, uploading data, and notifing Infochimps.
A helper object from Chimps::Workflows::Upload is delegated to for each step:
-
authorization & obtaining a token: Chimps::Workflows::Upload::UploadToken
-
creating an archive: Chimps::Workflows::Upload::Bundler
-
uploading data: Chimps::Workflows::Upload::Uploader
-
notifying Infochimps: Chimps::Workflows::Upload::Notifier
Instance Attribute Summary collapse
-
#archive ⇒ Object
The path to the archive to create when uploading.
-
#dataset ⇒ Object
The ID or handle of the dataset to download.
-
#fmt ⇒ Object
The format to annotate the upload with.
-
#paths ⇒ Object
An array of paths to files and directories to package into an archive.
Instance Method Summary collapse
-
#ask_for_token! ⇒ Object
Obtain an upload token from Infochimps.
-
#authorization_token ⇒ Chimps::Workflows::Upload::UploadToken
The token authorizing an upload.
-
#authorize_for_upload! ⇒ Object
Authorize the Chimps user for this upload.
-
#bundle! ⇒ Object
Bundle the data together.
-
#bundler ⇒ Chimps::Workflows::Upload::Bundler
The bundler that will aggregate data for the upload.
-
#execute! ⇒ Object
Upload data to Infochimps by first asking for authorization, creating an archive, obtaining a token, uploading data, and notifing Infochimps.
-
#initialize(options = {}) ⇒ Up
constructor
Create a new Uploader from the given parameters.
-
#notifier ⇒ Chimps::Workflows::Upload::Notifer
The notifier that will inform Infochimps of the new data.
-
#notify_infochimps! ⇒ Chimps::Response
Make a final POST request to Infochimps, creating the final resource.
-
#upload! ⇒ Object
Upload the data to Infochimps.
-
#upload_token ⇒ Chimps::Workflows::Upload::UploadToken
The token consumed for an upload.
-
#uploader ⇒ Chimps::Workflows::Upload::Uploader
The uploader that will actually send data to Infochimps.
Constructor Details
#initialize(options = {}) ⇒ Up
Create a new Uploader from the given parameters.
If :fmt is provided it will be used as the data format to annotate the upload with. If not, Chimps will try to guess.
50 51 52 53 54 55 |
# File 'lib/chimps/workflows/up.rb', line 50 def initialize ={} self.dataset = [:dataset] or raise PackagingError.new("Must provide the ID or handle of a dataset to upload data to.") self.paths = [:paths] self.archive = [:archive] self.fmt = [:fmt] end |
Instance Attribute Details
#archive ⇒ Object
The path to the archive to create when uploading.
37 38 39 |
# File 'lib/chimps/workflows/up.rb', line 37 def archive @archive end |
#dataset ⇒ Object
The ID or handle of the dataset to download.
27 28 29 |
# File 'lib/chimps/workflows/up.rb', line 27 def dataset @dataset end |
#fmt ⇒ Object
The format to annotate the upload with.
34 35 36 |
# File 'lib/chimps/workflows/up.rb', line 34 def fmt @fmt end |
#paths ⇒ Object
An array of paths to files and directories to package into an archive.
31 32 33 |
# File 'lib/chimps/workflows/up.rb', line 31 def paths @paths end |
Instance Method Details
#ask_for_token! ⇒ Object
Obtain an upload token from Infochimps.
Delegates to Chimps::Workflows::Upload::UploadToken
128 129 130 |
# File 'lib/chimps/workflows/up.rb', line 128 def ask_for_token! upload_token.get end |
#authorization_token ⇒ Chimps::Workflows::Upload::UploadToken
The token authorizing an upload.
75 76 77 |
# File 'lib/chimps/workflows/up.rb', line 75 def @authorization_token ||= Chimps::Workflows::Upload::UploadToken.new(dataset) end |
#authorize_for_upload! ⇒ Object
Authorize the Chimps user for this upload.
Delegates to Chimps::Workflows::Upload::UploadToken
114 115 116 |
# File 'lib/chimps/workflows/up.rb', line 114 def .get end |
#bundle! ⇒ Object
Bundle the data together.
Delegates to Chimps::Workflows::Upload::Bundler
121 122 123 |
# File 'lib/chimps/workflows/up.rb', line 121 def bundle! bundler.bundle! end |
#bundler ⇒ Chimps::Workflows::Upload::Bundler
The bundler that will aggregate data for the upload.
82 83 84 |
# File 'lib/chimps/workflows/up.rb', line 82 def bundler @bundler ||= Chimps::Workflows::Upload::Bundler.new(dataset, paths, :fmt => fmt, :archive => archive) end |
#execute! ⇒ Object
Upload data to Infochimps by first asking for authorization, creating an archive, obtaining a token, uploading data, and notifing Infochimps.
60 61 62 63 64 65 66 |
# File 'lib/chimps/workflows/up.rb', line 60 def execute! bundle! ask_for_token! upload! notify_infochimps! end |
#notifier ⇒ Chimps::Workflows::Upload::Notifer
The notifier that will inform Infochimps of the new data.
103 104 105 |
# File 'lib/chimps/workflows/up.rb', line 103 def notifier @notifier ||= Chimps::Workflows::Upload::Notifier.new(upload_token, bundler) end |
#notify_infochimps! ⇒ Chimps::Response
Make a final POST request to Infochimps, creating the final resource.
143 144 145 |
# File 'lib/chimps/workflows/up.rb', line 143 def notify_infochimps! notifier.post end |
#upload! ⇒ Object
Upload the data to Infochimps.
Delegates to Chimps::Workflows::Upload::Uploader
135 136 137 |
# File 'lib/chimps/workflows/up.rb', line 135 def upload! uploader.upload! end |
#upload_token ⇒ Chimps::Workflows::Upload::UploadToken
The token consumed for an upload.
89 90 91 |
# File 'lib/chimps/workflows/up.rb', line 89 def upload_token @upload_token ||= Chimps::Workflows::Upload::UploadToken.new(dataset, :fmt => bundler.fmt, :pkg_fmt => bundler.pkg_fmt) end |