Class: Postgrest::Responses::BaseResponse

Inherits:
Object
  • Object
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

#requestObject (readonly)

Returns the value of attribute request.



6
7
8
# File 'lib/postgrest/responses/base_response.rb', line 6

def request
  @request
end

#responseObject (readonly)

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

#countObject



22
23
24
# File 'lib/postgrest/responses/base_response.rb', line 22

def count
  data.count
end

#dataObject 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

#errorObject



18
19
20
# File 'lib/postgrest/responses/base_response.rb', line 18

def error
  !response.is_a?(Net::HTTPSuccess)
end

#inspectObject



14
15
16
# File 'lib/postgrest/responses/base_response.rb', line 14

def inspect
  "\#<#{self.class} #{request.method} #{response.message} data=#{@data}>"
end

#paramsObject



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

#statusObject



26
27
28
# File 'lib/postgrest/responses/base_response.rb', line 26

def status
  response.code.to_i
end

#status_textObject



30
31
32
# File 'lib/postgrest/responses/base_response.rb', line 30

def status_text
  response.message
end