Class: SBF::Client::Api::Response
- Inherits:
-
BaseEntity
- Object
- BaseEntity
- SBF::Client::Api::Response
- Defined in:
- lib/stbaldricks/entities/response.rb
Constant Summary
Constants inherited from BaseEntity
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#error ⇒ Object
Returns the value of attribute error.
-
#http_code ⇒ Object
Returns the value of attribute http_code.
Attributes inherited from BaseEntity
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(http_code: nil, data: nil, error: nil) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
- #to_hash ⇒ Object
- #to_json ⇒ Object
Methods inherited from BaseEntity
#add_errors, allow_instantiation?, attr_accessor, attr_reader, attr_writer, attributes, #attributes=, collection_attributes, entity_attr_accessor, entity_attr_reader, entity_attr_writer, entity_attributes, entity_collection_attr_accessor, entity_collection_attr_reader, entity_collection_attr_writer, inherited, #model_name, multitype_attr_accessor, multitype_attr_reader, multitype_attr_writer, multitype_collection_attr_accessor, multitype_collection_attr_reader, multitype_collection_attr_writer, #not_provided_attributes, optional_attributes, #persisted?
Constructor Details
#initialize(http_code: nil, data: nil, error: nil) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/stbaldricks/entities/response.rb', line 9 def initialize(http_code: nil, data: nil, error: nil) @http_code = http_code @data = data @error = error || SBF::Client::ErrorEntity.new(nil) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/stbaldricks/entities/response.rb', line 7 def data @data end |
#error ⇒ Object
Returns the value of attribute error.
7 8 9 |
# File 'lib/stbaldricks/entities/response.rb', line 7 def error @error end |
#http_code ⇒ Object
Returns the value of attribute http_code.
7 8 9 |
# File 'lib/stbaldricks/entities/response.rb', line 7 def http_code @http_code end |
Instance Method Details
#error? ⇒ Boolean
19 20 21 |
# File 'lib/stbaldricks/entities/response.rb', line 19 def error? !success? end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/stbaldricks/entities/response.rb', line 15 def success? http_code.to_s.start_with?('2') end |
#to_hash ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/stbaldricks/entities/response.rb', line 27 def to_hash { http_code: http_code, data: data, error: error } end |
#to_json ⇒ Object
23 24 25 |
# File 'lib/stbaldricks/entities/response.rb', line 23 def to_json to_hash.to_json end |