Class: Aliyun::OSS::Base::Response

Inherits:
String show all
Defined in:
lib/aliyun/oss/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#previous, #previous!, #remove_extended, #remove_extended!, #tap, #to_header, #underscore, #valid_utf8?

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
# File 'lib/aliyun/oss/response.rb', line 8

def initialize(response)
  @response = response
  @body     = response.body.to_s
  super(body)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/aliyun/oss/response.rb', line 7

def body
  @body
end

#parsedObject (readonly)

Returns the value of attribute parsed.



7
8
9
# File 'lib/aliyun/oss/response.rb', line 7

def parsed
  @parsed
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/aliyun/oss/response.rb', line 7

def response
  @response
end

Instance Method Details

#[](header) ⇒ Object



23
24
25
# File 'lib/aliyun/oss/response.rb', line 23

def [](header)
  headers[header]
end

#codeObject



31
32
33
# File 'lib/aliyun/oss/response.rb', line 31

def code
  response.code.to_i
end

#each(&block) ⇒ Object



27
28
29
# File 'lib/aliyun/oss/response.rb', line 27

def each(&block)
  headers.each(&block)
end

#errorObject



49
50
51
# File 'lib/aliyun/oss/response.rb', line 49

def error
  Error.new(parsed, self)
end

#error?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/aliyun/oss/response.rb', line 45

def error?
  !success? && response['content-type'] == 'application/xml' && parsed.root == 'error'
end

#headersObject



14
15
16
17
18
19
20
# File 'lib/aliyun/oss/response.rb', line 14

def headers
  headers = {}
  response.each do |header, value|
    headers[header] = value
  end
  headers
end

#inspectObject



60
61
62
# File 'lib/aliyun/oss/response.rb', line 60

def inspect
  "#<%s:0x%s %s %s>" % [self.class, object_id, response.code, response.message]
end