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 =
""
"/tmp/swift_file.cookie"
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#group ⇒ Object
Returns the value of attribute group.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(params) ⇒ SwiftUpload
constructor
A new instance of SwiftUpload.
- #upload ⇒ Object
Constructor Details
#initialize(params) ⇒ SwiftUpload
Returns a new instance of SwiftUpload.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/swift_file/swift_upload.rb', line 11 def initialize(params) if File.readable?(params[:file]) && File.file?(params[:file]) @file = params[:file] else raise ArgumentError.new('Invalid file supplied for upload') end @group = params[:group] || '' @password = params[:password] || '' end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
9 10 11 |
# File 'lib/swift_file/swift_upload.rb', line 9 def file @file end |
#group ⇒ Object
Returns the value of attribute group.
9 10 11 |
# File 'lib/swift_file/swift_upload.rb', line 9 def group @group end |
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/swift_file/swift_upload.rb', line 9 def url @url end |
Instance Method Details
#upload ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/swift_file/swift_upload.rb', line 23 def upload # start a session by requestion the url via GET client.perform # now post client.multipart_form_post = true client.http_post( Curl::PostField.file('file1', "#{@file.path}"), Curl::PostField.content('file_group[name]', @group), Curl::PostField.content('file_group[password]', @password), Curl::PostField.content('file_group_expiration', '1m') ) @url = client.last_effective_url @url end |