Class: Grist::Response
- Inherits:
-
Object
- Object
- Grist::Response
- Defined in:
- lib/grist/response.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(data: nil, error: nil, code: nil, type: nil) ⇒ Response
constructor
A new instance of Response.
- #log_error ⇒ Object
- #not_found? ⇒ Boolean
- #print_error ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(data: nil, error: nil, code: nil, type: nil) ⇒ Response
7 8 9 10 11 12 |
# File 'lib/grist/response.rb', line 7 def initialize(data: nil, error: nil, code: nil, type: nil) @data = data @error = error @type = type @code = code&.to_i end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/grist/response.rb', line 5 def code @code end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/grist/response.rb', line 5 def data @data end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/grist/response.rb', line 5 def error @error end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/grist/response.rb', line 5 def type @type end |
Instance Method Details
#error? ⇒ Boolean
18 19 20 |
# File 'lib/grist/response.rb', line 18 def error? !error.nil? || !(@code >= 200 && @code < 400) end |
#log_error ⇒ Object
33 34 35 36 37 |
# File 'lib/grist/response.rb', line 33 def log_error return unless error? Grist.logger.error("Grist API Error: #{@type} (code: #{@code})- #{@error}") end |
#not_found? ⇒ Boolean
22 23 24 |
# File 'lib/grist/response.rb', line 22 def not_found? @code == 404 end |
#print_error ⇒ Object
26 27 28 29 30 31 |
# File 'lib/grist/response.rb', line 26 def print_error err = "#{@type}: #{@error}" err += " (code: #{@code})" if @code err += "\n#{@type.help}" if @type.respond_to?(:help) && !@type.help.nil? err end |
#success? ⇒ Boolean
14 15 16 |
# File 'lib/grist/response.rb', line 14 def success? error.nil? && (@code >= 200 && @code < 400) end |