Class: Postgrest::Responses::BaseResponse
- Inherits:
-
Object
- Object
- Postgrest::Responses::BaseResponse
show all
- Defined in:
- lib/postgrest/responses/base_response.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(request, response) ⇒ BaseResponse
Returns a new instance of BaseResponse.
8
9
10
11
12
|
# File 'lib/postgrest/responses/base_response.rb', line 8
def initialize(request, response)
@request = request
@response = response
@data = data
end
|
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
6
7
8
|
# File 'lib/postgrest/responses/base_response.rb', line 6
def request
@request
end
|
#response ⇒ Object
Returns the value of attribute response.
6
7
8
|
# File 'lib/postgrest/responses/base_response.rb', line 6
def response
@response
end
|
Instance Method Details
#count ⇒ Object
22
23
24
|
# File 'lib/postgrest/responses/base_response.rb', line 22
def count
data.count
end
|
#data ⇒ Object
Also known as:
as_json
34
35
36
|
# File 'lib/postgrest/responses/base_response.rb', line 34
def data
error ? [] : safe_json_parse(response.body)
end
|
#error ⇒ Object
18
19
20
|
# File 'lib/postgrest/responses/base_response.rb', line 18
def error
!response.is_a?(Net::HTTPSuccess)
end
|
#inspect ⇒ Object
14
15
16
|
# File 'lib/postgrest/responses/base_response.rb', line 14
def inspect
"\#<#{self.class} #{request.method} #{response.message} data=#{@data}>"
end
|
#params ⇒ Object
39
40
41
42
43
44
|
# File 'lib/postgrest/responses/base_response.rb', line 39
def params
{
query: request.uri.query,
body: safe_json_parse(request.body)
}
end
|
#status ⇒ Object
26
27
28
|
# File 'lib/postgrest/responses/base_response.rb', line 26
def status
response.code.to_i
end
|
#status_text ⇒ Object
30
31
32
|
# File 'lib/postgrest/responses/base_response.rb', line 30
def status_text
response.message
end
|