Class: Tui::Upload
- Inherits:
-
Object
- Object
- Tui::Upload
- Defined in:
- lib/tui/upload.rb
Instance Attribute Summary collapse
-
#authorization ⇒ Object
Returns the value of attribute authorization.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #as_json ⇒ Object
- #chunks ⇒ Object
- #file ⇒ Object
-
#initialize(path) ⇒ Upload
constructor
A new instance of Upload.
- #md5sum ⇒ Object
- #mime_type ⇒ Object
- #original_filename ⇒ Object
- #perform(authorization, &block) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(path) ⇒ Upload
Returns a new instance of Upload.
12 13 14 |
# File 'lib/tui/upload.rb', line 12 def initialize(path) @path = File.realpath(path) end |
Instance Attribute Details
#authorization ⇒ Object
Returns the value of attribute authorization.
10 11 12 |
# File 'lib/tui/upload.rb', line 10 def @authorization end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/tui/upload.rb', line 9 def path @path end |
Instance Method Details
#as_json ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/tui/upload.rb', line 59 def as_json { :original_filename => original_filename, :md5sum => md5sum, :size => size, :mime_type => mime_type } end |
#chunks ⇒ Object
37 38 39 |
# File 'lib/tui/upload.rb', line 37 def chunks @chunks ||= (size / Excon::Connection::CHUNK_SIZE.to_f).ceil end |
#file ⇒ Object
16 17 18 |
# File 'lib/tui/upload.rb', line 16 def file @file ||= File.new(path, "r") end |
#md5sum ⇒ Object
28 29 30 31 |
# File 'lib/tui/upload.rb', line 28 def md5sum @digest ||= Digest::MD5.file(path) @md5sum ||= @digest.hexdigest end |
#mime_type ⇒ Object
33 34 35 |
# File 'lib/tui/upload.rb', line 33 def mime_type @mime_type ||= MIME::Types.type_for(path).first.to_s end |
#original_filename ⇒ Object
24 25 26 |
# File 'lib/tui/upload.rb', line 24 def original_filename @original_filename ||= File.basename(path) end |
#perform(authorization, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tui/upload.rb', line 41 def perform(, &block) connection = Excon.new(.upload_url) headers = { "User-Agent" => user_agent, }.merge(.headers) connection.request_with_uploadprogress( :method => "PUT", :body => file, :headers => headers, :expects => 200, :upload_progress => block ) true end |
#size ⇒ Object
20 21 22 |
# File 'lib/tui/upload.rb', line 20 def size @size ||= File.size(path) end |