Class: NewStoreApi::Error

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/error.rb

Overview

Error Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(code = nil, message = nil, product_id = SKIP) ⇒ Error

Returns a new instance of Error.



45
46
47
48
49
# File 'lib/new_store_api/models/error.rb', line 45

def initialize(code = nil, message = nil, product_id = SKIP)
  @code = code
  @message = message
  @product_id = product_id unless product_id == SKIP
end

Instance Attribute Details

#codeCodeEnum

A unique error code.

Returns:



14
15
16
# File 'lib/new_store_api/models/error.rb', line 14

def code
  @code
end

#messageString

A detailed message about the error.

Returns:

  • (String)


18
19
20
# File 'lib/new_store_api/models/error.rb', line 18

def message
  @message
end

#product_idString

The SKU of the product with an error.

Returns:

  • (String)


22
23
24
# File 'lib/new_store_api/models/error.rb', line 22

def product_id
  @product_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/new_store_api/models/error.rb', line 52

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  code = hash.key?('code') ? hash['code'] : nil
  message = hash.key?('message') ? hash['message'] : nil
  product_id = hash.key?('product_id') ? hash['product_id'] : SKIP

  # Create object from extracted values.
  Error.new(code,
            message,
            product_id)
end

.namesObject

A mapping from model property names to API property names.



25
26
27
28
29
30
31
# File 'lib/new_store_api/models/error.rb', line 25

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['code'] = 'code'
  @_hash['message'] = 'message'
  @_hash['product_id'] = 'product_id'
  @_hash
end

.nullablesObject

An array for nullable fields



41
42
43
# File 'lib/new_store_api/models/error.rb', line 41

def self.nullables
  []
end

.optionalsObject

An array for optional fields



34
35
36
37
38
# File 'lib/new_store_api/models/error.rb', line 34

def self.optionals
  %w[
    product_id
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



73
74
75
76
77
# File 'lib/new_store_api/models/error.rb', line 73

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} code: #{@code.inspect}, message: #{@message.inspect}, product_id:"\
  " #{@product_id.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



67
68
69
70
# File 'lib/new_store_api/models/error.rb', line 67

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} code: #{@code}, message: #{@message}, product_id: #{@product_id}>"
end