Class: SBF::Client::Api::Response

Inherits:
BaseEntity show all
Defined in:
lib/stbaldricks/entities/response.rb

Constant Summary

Constants inherited from BaseEntity

BaseEntity::ELSE

Instance Attribute Summary collapse

Attributes inherited from BaseEntity

#errors

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/stbaldricks/entities/response.rb', line 7

def data
  @data
end

#errorObject

Returns the value of attribute error.



7
8
9
# File 'lib/stbaldricks/entities/response.rb', line 7

def error
  @error
end

#http_codeObject

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

Returns:



19
20
21
# File 'lib/stbaldricks/entities/response.rb', line 19

def error?
  !success?
end

#success?Boolean

Returns:



15
16
17
# File 'lib/stbaldricks/entities/response.rb', line 15

def success?
  http_code.to_s.start_with?('2')
end

#to_hashObject



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_jsonObject



23
24
25
# File 'lib/stbaldricks/entities/response.rb', line 23

def to_json
  to_hash.to_json
end