Class: Atmos::Response
- Inherits:
-
Object
show all
- Defined in:
- lib/atmos/response.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(response, action) ⇒ Response
Returns a new instance of Response.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/atmos/response.rb', line 5
def initialize(response, action)
@http_response = response
@action = action
if (response.kind_of?(Net::HTTPServerError))
raise Atmos::Exceptions::ServerException, response.message
elsif (response.kind_of?(Net::HTTPClientError))
raise Atmos::Exceptions::AtmosException, "Atmos got a bad request. This is probably a problem in this library." if (response.kind_of?(Net::HTTPBadRequest))
Atmos::LOG.debug("#{response.class}")
Atmos::LOG.debug("#{response.body}")
Atmos::Parser::response_check_action_error(@action, response)
elsif (!response.kind_of?(Net::HTTPSuccess))
raise Atmos::Exceptions::NotImplementedException, "This library doesn't handle these kinds of responses: #{response}"
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/atmos/response.rb', line 43
def method_missing(sym, *args)
Atmos::LOG.info("method missing: #{sym}")
= "x-emc-#{sym.id2name.sub(/_/, '-')}"
if (REST[@action][:return_headers].include?())
Atmos::LOG.info("header: #{}")
rv = Atmos::Util.(, @http_response[])
Atmos::LOG.debug("rv: #{rv.inspect}")
return rv
else
return super.method_missing(sym, *args)
end
end
|
Instance Attribute Details
#http_response ⇒ Object
Returns the value of attribute http_response.
3
4
5
|
# File 'lib/atmos/response.rb', line 3
def http_response
@http_response
end
|
Instance Method Details
#[](header) ⇒ Object
88
89
90
|
# File 'lib/atmos/response.rb', line 88
def []()
@http_response[]
end
|
39
40
41
|
# File 'lib/atmos/response.rb', line 39
def body
@http_response.body
end
|
56
57
58
59
60
61
62
|
# File 'lib/atmos/response.rb', line 56
def delta
if (REST[@action][:return_headers].include?('x-emc-delta'))
@http_response['x-emc-delta']
else
raise "A #{@action} request doesn't return a delta."
end
end
|
#each(header) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/atmos/response.rb', line 26
def each()
if (!self[].nil?)
self[].split(',').each do |elt|
if (!elt.index('=').nil?)
key,val = elt.split('=')
yield key.strip, val.strip
else
yield elt.strip
end
end
end
end
|
80
81
82
83
84
85
86
|
# File 'lib/atmos/response.rb', line 80
def
= {}
@http_response.each do |, value|
[] = value
end
end
|
72
73
74
75
76
77
78
|
# File 'lib/atmos/response.rb', line 72
def id
if (REST[@action][:return_headers].include?('location'))
@http_response['location'][@http_response['location'].rindex('/')+1..-1]
else
raise "A #{@action} request doesn't return an id."
end
end
|
64
65
66
67
68
69
70
|
# File 'lib/atmos/response.rb', line 64
def policy
if (REST[@action][:return_headers].include?('x-emc-policy'))
@http_response['x-emc-policy']
else
raise "A #{@action} request doesn't return a policy description."
end
end
|