Class: SwiftFile::SwiftUpload

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#fileObject

Returns the value of attribute file.



9
10
11
# File 'lib/swift_file/swift_upload.rb', line 9

def file
  @file
end

#groupObject

Returns the value of attribute group.



9
10
11
# File 'lib/swift_file/swift_upload.rb', line 9

def group
  @group
end

#urlObject

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

#uploadObject



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