Class: Chimps::Workflows::Upload::UploadToken
- Defined in:
- lib/chimps/workflows/upload/token.rb
Overview
Encapsulates the process of obtaining an upload token for a dataset from Infochimps.
Instance Attribute Summary collapse
-
#dataset ⇒ Object
The ID or slug of the dataset for which to obtain an upload token.
-
#fmt ⇒ Object
The format (csv, xls, tsv, &c.) of the data in the upload.
-
#pkg_fmt ⇒ Object
The package format (zip, tar.bz2, &c.) of the data in the upload.
-
#response ⇒ Object
The response from Infochimps to the request for an upload token.
Instance Method Summary collapse
-
#[](param) ⇒ Object
Delegate slicing to the returned response.
-
#bucket ⇒ String
Parses the ‘url’ property of the response from Infochimps to determine the bucket name.
-
#get ⇒ Object
Make the request to get an upload token from Infochimps.
-
#initialize(dataset, options = {}) ⇒ UploadToken
constructor
Instantiate a new UploadToken for the given
datasetwith the givenfmtandpkg_fmt. -
#params ⇒ Hash
Parameters passed to Infochimps to request an upload token.
-
#path ⇒ String
The path on Infochimps to submit upload token requests to.
Constructor Details
#initialize(dataset, options = {}) ⇒ UploadToken
Instantiate a new UploadToken for the given dataset with the given fmt and pkg_fmt.
30 31 32 33 34 |
# File 'lib/chimps/workflows/upload/token.rb', line 30 def initialize dataset, ={} @dataset = dataset @fmt = [:fmt] @pkg_fmt = [:pkg_fmt] end |
Instance Attribute Details
#dataset ⇒ Object
The ID or slug of the dataset for which to obtain an upload token.
11 12 13 |
# File 'lib/chimps/workflows/upload/token.rb', line 11 def dataset @dataset end |
#fmt ⇒ Object
The format (csv, xls, tsv, &c.) of the data in the upload.
14 15 16 |
# File 'lib/chimps/workflows/upload/token.rb', line 14 def fmt @fmt end |
#pkg_fmt ⇒ Object
The package format (zip, tar.bz2, &c.) of the data in the upload.
18 19 20 |
# File 'lib/chimps/workflows/upload/token.rb', line 18 def pkg_fmt @pkg_fmt end |
#response ⇒ Object
The response from Infochimps to the request for an upload token.
22 23 24 |
# File 'lib/chimps/workflows/upload/token.rb', line 22 def response @response end |
Instance Method Details
#[](param) ⇒ Object
Delegate slicing to the returned response.
37 38 39 |
# File 'lib/chimps/workflows/upload/token.rb', line 37 def [] param response && response[param] end |
#bucket ⇒ String
Parses the ‘url’ property of the response from Infochimps to determine the bucket name.
68 69 70 |
# File 'lib/chimps/workflows/upload/token.rb', line 68 def bucket File.basename(response['url']) end |
#get ⇒ Object
Make the request to get an upload token from Infochimps
56 57 58 59 60 61 62 |
# File 'lib/chimps/workflows/upload/token.rb', line 56 def get @response = Request.new(path, :params => params, :signed => true).get if response.error? response.print raise AuthenticationError.new("Unauthorized for an upload token for dataset #{dataset}") end end |
#params ⇒ Hash
Parameters passed to Infochimps to request an upload token.
51 52 53 |
# File 'lib/chimps/workflows/upload/token.rb', line 51 def params { :package => { :fmt => fmt, :pkg_fmt => pkg_fmt } } end |
#path ⇒ String
The path on Infochimps to submit upload token requests to.
44 45 46 |
# File 'lib/chimps/workflows/upload/token.rb', line 44 def path "/datasets/#{dataset}/packages/new.json" end |