Module: GrandCloud::Base
- Defined in:
- lib/grand_cloud/base.rb
Class Attribute Summary collapse
-
.secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
-
.snda_access_key_id ⇒ Object
Returns the value of attribute snda_access_key_id.
Class Method Summary collapse
Class Attribute Details
.secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
8 9 10 |
# File 'lib/grand_cloud/base.rb', line 8 def secret_access_key @secret_access_key end |
.snda_access_key_id ⇒ Object
Returns the value of attribute snda_access_key_id.
8 9 10 |
# File 'lib/grand_cloud/base.rb', line 8 def snda_access_key_id @snda_access_key_id end |
Class Method Details
.file_upload(options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/grand_cloud/base.rb', line 31 def file_upload pn_file = [:pn_file] auth = GrandCloud::Authentication.new(@secret_access_key, @snda_access_key_id) protocal_params = auth.generate_upload_params [:request_params] signature = auth.create_signature({ :method => [:method], :uri => [:uri], :host => [:host], :protocal_params => protocal_params }) url = URI.escape([:url] + "?" + protocal_params) + '&Signature=' + CGI::escape(signature) #multipart patch partfile = Part.new( :name => 'file', :filename => pn_file.basename(pn_file.extname), :body => pn_file.read ) parts = [partfile] body = MultipartBody.new(parts) EM::HttpRequest.new(url).post( :head => { 'content-type' => "multipart/form-data; boundary=#{body.boundary}" }, :body => body.to_s ) end |
.send_request(options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/grand_cloud/base.rb', line 10 def send_request auth = GrandCloud::Authentication.new(@secret_access_key, @snda_access_key_id) protocal_params = auth.generate_protocol_params [:additional_params] signature = auth.create_signature({ :method => [:method], :uri => [:uri], :protocal_params => protocal_params, :host => [:host] }) url = URI.escape(([:url] || ("http://#{(options[:host] || DEFAULT_HOST_URL)+options[:uri]}")) + "?" + protocal_params)+'&Signature='+CGI::escape(signature) request_params = {} request_params.merge!([:timeout]) if [:timeout] params = {:head => {:Accept => [:header_accept] || 'application/json'}} params.merge!([:request_params]) if [:request_params] EM::HttpRequest.new(url, request_params).send(([:method] && [:method].downcase) || "get", params) end |