Class: BaiduNetDisk::Uploader
- Inherits:
-
Object
- Object
- BaiduNetDisk::Uploader
- Defined in:
- lib/baidu-netdisk/uploader.rb
Constant Summary collapse
- SLICE_SIZE =
4 * 1024 * 1024
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(source_path, target_path, options = {}) ⇒ Uploader
constructor
A new instance of Uploader.
Constructor Details
#initialize(source_path, target_path, options = {}) ⇒ Uploader
Returns a new instance of Uploader.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/baidu-netdisk/uploader.rb', line 7 def initialize(source_path, target_path, = {}) @is_dir = File.directory?(source_path) ? true : false raise BaiduNetDisk::Exception::UploadDirectoryNotSupported, 'Uploading directory is not supported at present.' if @is_dir @source_path = source_path @target_path = target_path @verbose = [:verbose] @slice_prefix = ".tmp_#{Random.hex(6)}_" @rtype = [:overwrite] ? 3 : 1 @file_size = File.size @source_path @content_md5 = Digest::MD5.hexdigest(File.read @source_path) @upload_id = nil @slices = [] @refresh_token = [:refresh_token] || BaiduNetDisk.refresh_token @access_token = [:access_token] || BaiduNetDisk.access_token end |
Instance Method Details
#execute ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/baidu-netdisk/uploader.rb', line 26 def execute prepare pre_upload upload_by_slices create_file rescue BaiduNetDisk::Exception::PermissionDenied $stderr.puts 'You are not authorised to upload files to your target path.' return false rescue BaiduNetDisk::Exception::AuthenticationFailed, BaiduNetDisk::Exception::AccessTokenExpired => e raise e if @tried_refresh_token retry if refresh_token! ensure clear_up end |