Class: BosClient::Object
- Inherits:
-
Object
- Object
- BosClient::Object
- Defined in:
- lib/bos_client/object.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#last_modified ⇒ Object
Returns the value of attribute last_modified.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#size ⇒ Object
Returns the value of attribute size.
-
#storage_class ⇒ Object
Returns the value of attribute storage_class.
Class Method Summary collapse
Instance Method Summary collapse
- #destory ⇒ Object
-
#initialize(options = {}) ⇒ Object
constructor
A new instance of Object.
- #save ⇒ Object
- #save_as(name) ⇒ Object
- #save_to(path, name = nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Object
Returns a new instance of Object.
6 7 8 9 10 11 12 13 |
# File 'lib/bos_client/object.rb', line 6 def initialize( = {}) @bucket = [:bucket] @size = [:size] @file = [:key] @path, @name = File.split([:key]) @last_modified = [:last_modified] @storage_class = [:storage_class] end |
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
4 5 6 |
# File 'lib/bos_client/object.rb', line 4 def bucket @bucket end |
#last_modified ⇒ Object
Returns the value of attribute last_modified.
4 5 6 |
# File 'lib/bos_client/object.rb', line 4 def last_modified @last_modified end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/bos_client/object.rb', line 4 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/bos_client/object.rb', line 4 def path @path end |
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'lib/bos_client/object.rb', line 4 def size @size end |
#storage_class ⇒ Object
Returns the value of attribute storage_class.
4 5 6 |
# File 'lib/bos_client/object.rb', line 4 def storage_class @storage_class end |
Class Method Details
.upload(options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bos_client/object.rb', line 51 def self.upload = {} bucket = [:bucket] file = [:file] origin_file_name = File.basename(file) filename = [:filename] || origin_file_name path = [:path] || '' storage_class = [:storage_class] || "STANDARD" headers = [:headers] || {} params = { append: "" } headers.merge!({"x-bce-storage-class" => storage_class}) request = BosClient::Request.new "#{bucket.bucket_host}/#{File.join(path,filename)}?append", method: :post, params:params, headers: headers, body: File.open(file,"r").read response = request.run response[:result] end |
Instance Method Details
#destory ⇒ Object
45 46 47 48 49 |
# File 'lib/bos_client/object.rb', line 45 def destory request = BosClient::Request.new "#{@bucket.bucket_host}/#{@file}", method: :delete response = request.run response[:result] end |
#save ⇒ Object
16 17 18 |
# File 'lib/bos_client/object.rb', line 16 def save save_to nil end |
#save_as(name) ⇒ Object
20 21 22 |
# File 'lib/bos_client/object.rb', line 20 def save_as name save_to nil, name end |
#save_to(path, name = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bos_client/object.rb', line 24 def save_to path, name = nil headers = { "host" => @bucket.bucket_host, } params = {} url = URI.encode("http://#{@bucket.bucket_host}/#{@file}") request = Typhoeus::Request.new(url, method: :get,headers:headers,params:params) request = BosClient::Authable.(request) request.on_complete do |response| if path flie = "#{path}/#{name || @name}" else flie = "#{name || @name}" end write_file flie, response.body end request.run end |