Class: GdsApi::Response
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/gds_api/response.rb
Instance Method Summary
collapse
Constructor Details
#initialize(net_http_response) ⇒ Response
Returns a new instance of Response.
12
13
14
|
# File 'lib/gds_api/response.rb', line 12
def initialize(net_http_response)
@net_http_response = net_http_response
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/gds_api/response.rb', line 29
def method_missing(method)
if to_hash.has_key?(method.to_s)
to_ostruct.send(method)
else
nil
end
end
|
Instance Method Details
#blank? ⇒ Boolean
42
|
# File 'lib/gds_api/response.rb', line 42
def blank?; false; end
|
#code ⇒ Object
20
21
22
23
|
# File 'lib/gds_api/response.rb', line 20
def code
@net_http_response.code.to_i
end
|
#present? ⇒ Boolean
41
|
# File 'lib/gds_api/response.rb', line 41
def present?; ! blank?; end
|
#respond_to_missing?(method, include_private) ⇒ Boolean
37
38
39
|
# File 'lib/gds_api/response.rb', line 37
def respond_to_missing?(method, include_private)
to_hash.has_key?(method.to_s)
end
|
#to_hash ⇒ Object
16
17
18
|
# File 'lib/gds_api/response.rb', line 16
def to_hash
@parsed ||= JSON.parse(@net_http_response.body)
end
|
#to_ostruct ⇒ Object
25
26
27
|
# File 'lib/gds_api/response.rb', line 25
def to_ostruct
self.class.build_ostruct_recursively(to_hash)
end
|