Class: ROSS::Client
- Inherits:
-
Object
- Object
- ROSS::Client
- Defined in:
- lib/ross/client.rb
Instance Method Summary collapse
- #get(path) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #put(path, file, options = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ross/client.rb', line 7 def initialize() return nil unless @bucket_name = [:bucket_name] @appid = [:appid] @appkey = [:appkey] @aliyun_host = "oss.aliyuncs.com" if [:aliyun_internal] == true @aliyun_host = "oss-internal.aliyuncs.com" end end |
Instance Method Details
#get(path) ⇒ Object
36 37 38 |
# File 'lib/ross/client.rb', line 36 def get(path) return "http://#{@bucket_name}.#{@aliyun_host}/#{path}" end |
#put(path, file, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ross/client.rb', line 18 def put(path, file, ={}) content_md5 = Digest::MD5.hexdigest(file) content_type = [:content_type] || "image/jpg" date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT") path = "#{@bucket_name}/#{path}" url = "http://#{@aliyun_host}/#{path}" auth_sign = sign("PUT", path, content_md5, content_type, date) headers = { "Authorization" => auth_sign, "Content-Type" => content_type, "Content-Length" => file.length, "Date" => date, "Host" => @aliyun_host, } response = RestClient.put(url, file, headers) end |