Class: SwiftFile::SwiftUpload
- Inherits:
-
Object
- Object
- SwiftFile::SwiftUpload
- Defined in:
- lib/swift_file/swift_upload.rb
Constant Summary collapse
- SWIFTFILE_HOST =
'https://www.swiftfile.net'
- SWIFTFILE_ENDPOINT =
''
- SWIFTFILE_COOKIE =
'/tmp/swift_file.cookie'
- SWIFTFILE_EXPIRY_OPTIONS =
%w(1m 1w 1d 1h)
- SWIFTFILE_EXPIRY_DEFAULT =
'1d'
Instance Attribute Summary collapse
-
#expiry ⇒ Object
Returns the value of attribute expiry.
-
#files ⇒ Object
Returns the value of attribute files.
-
#group ⇒ Object
Returns the value of attribute group.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #add_file(file) ⇒ Object
-
#initialize(params) ⇒ SwiftUpload
constructor
A new instance of SwiftUpload.
- #transfer ⇒ Object
Constructor Details
#initialize(params) ⇒ SwiftUpload
Returns a new instance of SwiftUpload.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/swift_file/swift_upload.rb', line 13 def initialize(params) @files = params[:files] || [] @group = params[:group] || '' @password = params[:password] || '' if params[:expiry] && SWIFTFILE_EXPIRY_OPTIONS.include?(params[:expiry]) @expiry = params[:expiry] else @expiry = SWIFTFILE_EXPIRY_DEFAULT end end |
Instance Attribute Details
#expiry ⇒ Object
Returns the value of attribute expiry.
11 12 13 |
# File 'lib/swift_file/swift_upload.rb', line 11 def expiry @expiry end |
#files ⇒ Object
Returns the value of attribute files.
11 12 13 |
# File 'lib/swift_file/swift_upload.rb', line 11 def files @files end |
#group ⇒ Object
Returns the value of attribute group.
11 12 13 |
# File 'lib/swift_file/swift_upload.rb', line 11 def group @group end |
#url ⇒ Object
Returns the value of attribute url.
11 12 13 |
# File 'lib/swift_file/swift_upload.rb', line 11 def url @url end |
Instance Method Details
#add_file(file) ⇒ Object
25 26 27 |
# File 'lib/swift_file/swift_upload.rb', line 25 def add_file(file) @files << file unless @files.include?(file) end |
#transfer ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/swift_file/swift_upload.rb', line 29 def transfer if @files.empty? raise 'No files supplied for uploed' end # start a session by requesting the url via GET begin client.perform rescue Curl::Err => e raise "Connection failed: #{e}" end # post the file and capture the resulting url begin client.multipart_form_post = true client.http_post(form) @url = client.last_effective_url rescue Curl::Err => e raise "Upload failed: #{e}" ensure client.close end @url end |