Class: ApiEntreprise::Commons::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/api_entreprise/commons/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw:, http_status:, headers:, rate_limit: nil) ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
14
# File 'lib/api_entreprise/commons/response.rb', line 9

def initialize(raw:, http_status:, headers:, rate_limit: nil)
  @raw = raw.is_a?(Hash) ? raw : {}
  @http_status = http_status
  @headers = headers || {}
  @rate_limit = rate_limit
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/api_entreprise/commons/response.rb', line 7

def headers
  @headers
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



7
8
9
# File 'lib/api_entreprise/commons/response.rb', line 7

def http_status
  @http_status
end

#rate_limitObject (readonly)

Returns the value of attribute rate_limit.



7
8
9
# File 'lib/api_entreprise/commons/response.rb', line 7

def rate_limit
  @rate_limit
end

#rawObject (readonly)

Returns the value of attribute raw.



7
8
9
# File 'lib/api_entreprise/commons/response.rb', line 7

def raw
  @raw
end

Instance Method Details

#dataObject



16
17
18
# File 'lib/api_entreprise/commons/response.rb', line 16

def data
  raw['data']
end


20
21
22
# File 'lib/api_entreprise/commons/response.rb', line 20

def links
  raw['links'] || {}
end

#metaObject



24
25
26
# File 'lib/api_entreprise/commons/response.rb', line 24

def meta
  raw['meta'] || {}
end

#success?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/api_entreprise/commons/response.rb', line 28

def success?
  http_status.to_i.between?(200, 299)
end