Class: Aliyun::OSS::HTTP
- Inherits:
-
Object
- Object
- Aliyun::OSS::HTTP
- Includes:
- Logging
- Defined in:
- lib/aliyun/oss/http.rb
Overview
HTTP wraps the HTTP functionalities for accessing OSS RESTful API. It handles the OSS-specific protocol elements, and rest-client details for the user, which includes:
-
automatically generate signature for every request
-
parse response headers/body
-
raise exceptions and capture the request id
-
encapsulates streaming upload/download
Defined Under Namespace
Classes: StreamPayload, StreamWriter
Constant Summary collapse
- DEFAULT_CONTENT_TYPE =
'application/octet-stream'
Constants included from Logging
Instance Method Summary collapse
- #delete(resources = {}, http_options = {}, &block) ⇒ Object
-
#get(resources = {}, http_options = {}, &block) ⇒ Object
helper methods.
- #get_request_url(bucket, object) ⇒ Object
- #get_resource_path(bucket, object) ⇒ Object
-
#handle_response(r, &block) ⇒ Object
Handle Net::HTTPRespoonse.
- #head(resources = {}, http_options = {}, &block) ⇒ Object
-
#initialize(config) ⇒ HTTP
constructor
A new instance of HTTP.
- #options(resources = {}, http_options = {}, &block) ⇒ Object
- #post(resources = {}, http_options = {}, &block) ⇒ Object
- #put(resources = {}, http_options = {}, &block) ⇒ Object
Methods included from Logging
#logger, set_log_file, set_log_level
Constructor Details
#initialize(config) ⇒ HTTP
Returns a new instance of HTTP.
117 118 119 |
# File 'lib/aliyun/oss/http.rb', line 117 def initialize(config) @config = config end |
Instance Method Details
#delete(resources = {}, http_options = {}, &block) ⇒ Object
167 168 169 |
# File 'lib/aliyun/oss/http.rb', line 167 def delete(resources = {}, = {}, &block) do_request('DELETE', resources, , &block) end |
#get(resources = {}, http_options = {}, &block) ⇒ Object
helper methods
155 156 157 |
# File 'lib/aliyun/oss/http.rb', line 155 def get(resources = {}, = {}, &block) do_request('GET', resources, , &block) end |
#get_request_url(bucket, object) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/aliyun/oss/http.rb', line 121 def get_request_url(bucket, object) url = "" url += "#{@config.endpoint.scheme}://" url += "#{bucket}." if bucket and not @config.cname url += @config.endpoint.host url += "/#{CGI.escape(object)}" if object url end |
#get_resource_path(bucket, object) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/aliyun/oss/http.rb', line 131 def get_resource_path(bucket, object) if bucket res = "/#{bucket}/" res += "#{object}" if object res end end |
#handle_response(r, &block) ⇒ Object
Handle Net::HTTPRespoonse
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/aliyun/oss/http.rb', line 140 def handle_response(r, &block) # read all body on error if r.code.to_i >= 300 r.read_body else # streaming read body on success r.read_body do |chunk| yield RestClient::Request.decode(r['content-encoding'], chunk) end end end |
#head(resources = {}, http_options = {}, &block) ⇒ Object
171 172 173 |
# File 'lib/aliyun/oss/http.rb', line 171 def head(resources = {}, = {}, &block) do_request('HEAD', resources, , &block) end |
#options(resources = {}, http_options = {}, &block) ⇒ Object
175 176 177 |
# File 'lib/aliyun/oss/http.rb', line 175 def (resources = {}, = {}, &block) do_request('OPTIONS', resources, , &block) end |
#post(resources = {}, http_options = {}, &block) ⇒ Object
163 164 165 |
# File 'lib/aliyun/oss/http.rb', line 163 def post(resources = {}, = {}, &block) do_request('POST', resources, , &block) end |
#put(resources = {}, http_options = {}, &block) ⇒ Object
159 160 161 |
# File 'lib/aliyun/oss/http.rb', line 159 def put(resources = {}, = {}, &block) do_request('PUT', resources, , &block) end |