class AliyunSDK::OSS::Callback
Callback
represents a HTTP
call made by OSS
to user’s application server after an event happens, such as an object is successfully uploaded to OSS
. See: {help.aliyun.com/document_detail/oss/api-reference/object/Callback.html} Attributes:
-
url [String] the URL WITHOUT the query string
-
query [Hash] the query to generate query string
-
body [String] the body of the request
-
content_type [String] the Content-Type of the request
-
host [String] the Host in
HTTP
header for this request
Public Instance Methods
serialize()
click to toggle source
# File lib/aliyun_sdk/oss/struct.rb, line 168 def serialize query_string = (query || {}).map { |k, v| [CGI.escape(k.to_s), CGI.escape(v.to_s)].join('=') }.join('&') cb = { 'callbackUrl' => "#{normalize_url(url)}?#{query_string}", 'callbackBody' => body, 'callbackBodyType' => content_type || default_content_type } cb['callbackHost'] = host if host logger.debug("Callback json: #{cb}") Base64.strict_encode64(cb.to_json) end
Private Instance Methods
default_content_type()
click to toggle source
# File lib/aliyun_sdk/oss/struct.rb, line 200 def default_content_type "application/x-www-form-urlencoded" end
normalize_url(url)
click to toggle source
# File lib/aliyun_sdk/oss/struct.rb, line 185 def normalize_url(url) uri = URI.parse(url) uri = URI.parse("http://#{url}") unless uri.scheme if uri.scheme != 'http' and uri.scheme != 'https' fail ClientError, "Only HTTP and HTTPS endpoint are accepted." end unless uri.query.nil? fail ClientError, "Query parameters should not appear in URL." end uri.to_s end