Class: NewStoreApi::Problem

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

Overview

Problem 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(detail = SKIP, error_code = SKIP, instance = SKIP, message = SKIP, messages = SKIP, request_id = SKIP, status = SKIP, title = SKIP, type = 'about:blank') ⇒ Problem

Returns a new instance of Problem.



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/new_store_api/models/problem.rb', line 103

def initialize(detail = SKIP, error_code = SKIP, instance = SKIP,
               message = SKIP, messages = SKIP, request_id = SKIP,
               status = SKIP, title = SKIP, type = 'about:blank')
  @detail = detail unless detail == SKIP
  @error_code = error_code unless error_code == SKIP
  @instance = instance unless instance == SKIP
  @message = message unless message == SKIP
  @messages = messages unless messages == SKIP
  @request_id = request_id unless request_id == SKIP
  @status = status unless status == SKIP
  @title = title unless title == SKIP
  @type = type unless type == SKIP
end

Instance Attribute Details

#detailString

A human readable explanation specific to this occurrence of the problem that is helpful to locate the problem and give advice on how to proceed. Written in English and readable for engineers, usually not suited for non technical stakeholders and not localized.

Returns:

  • (String)


17
18
19
# File 'lib/new_store_api/models/problem.rb', line 17

def detail
  @detail
end

#error_codeString

A human readable explanation specific to this occurrence of the problem that is helpful to locate the problem and give advice on how to proceed. Written in English and readable for engineers, usually not suited for non technical stakeholders and not localized.

Returns:

  • (String)


24
25
26
# File 'lib/new_store_api/models/problem.rb', line 24

def error_code
  @error_code
end

#instanceString

A URI reference that identifies the specific occurrence of the problem, e.g. by adding a fragment identifier or sub-path to the problem type. May be used to locate the root of this problem in the source code.

Returns:

  • (String)


30
31
32
# File 'lib/new_store_api/models/problem.rb', line 30

def instance
  @instance
end

#messageString

A URI reference that identifies the specific occurrence of the problem, e.g. by adding a fragment identifier or sub-path to the problem type. May be used to locate the root of this problem in the source code.

Returns:

  • (String)


36
37
38
# File 'lib/new_store_api/models/problem.rb', line 36

def message
  @message
end

#messagesArray[String]

A URI reference that identifies the specific occurrence of the problem, e.g. by adding a fragment identifier or sub-path to the problem type. May be used to locate the root of this problem in the source code.

Returns:

  • (Array[String])


42
43
44
# File 'lib/new_store_api/models/problem.rb', line 42

def messages
  @messages
end

#request_idString

A URI reference that identifies the specific occurrence of the problem, e.g. by adding a fragment identifier or sub-path to the problem type. May be used to locate the root of this problem in the source code.

Returns:

  • (String)


48
49
50
# File 'lib/new_store_api/models/problem.rb', line 48

def request_id
  @request_id
end

#statusInteger

The HTTP status code generated by the origin server for this occurrence of the problem.

Returns:

  • (Integer)


53
54
55
# File 'lib/new_store_api/models/problem.rb', line 53

def status
  @status
end

#titleString

A short summary of the problem type. Written in English and readable for engineers, usually not suited for non technical stakeholders and not localized.

Returns:

  • (String)


59
60
61
# File 'lib/new_store_api/models/problem.rb', line 59

def title
  @title
end

#typeString

A URI reference that uniquely identifies the problem type only in the context of the provided API. Opposed to the specification in RFC-7807, it is neither recommended to be dereferenceable and point to a human-readable documentation nor globally unique for the problem type.

Returns:

  • (String)


66
67
68
# File 'lib/new_store_api/models/problem.rb', line 66

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/new_store_api/models/problem.rb', line 118

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  detail = hash.key?('detail') ? hash['detail'] : SKIP
  error_code = hash.key?('error_code') ? hash['error_code'] : SKIP
  instance = hash.key?('instance') ? hash['instance'] : SKIP
  message = hash.key?('message') ? hash['message'] : SKIP
  messages = hash.key?('messages') ? hash['messages'] : SKIP
  request_id = hash.key?('request_id') ? hash['request_id'] : SKIP
  status = hash.key?('status') ? hash['status'] : SKIP
  title = hash.key?('title') ? hash['title'] : SKIP
  type = hash['type'] ||= 'about:blank'

  # Create object from extracted values.
  Problem.new(detail,
              error_code,
              instance,
              message,
              messages,
              request_id,
              status,
              title,
              type)
end

.namesObject

A mapping from model property names to API property names.



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/new_store_api/models/problem.rb', line 69

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['detail'] = 'detail'
  @_hash['error_code'] = 'error_code'
  @_hash['instance'] = 'instance'
  @_hash['message'] = 'message'
  @_hash['messages'] = 'messages'
  @_hash['request_id'] = 'request_id'
  @_hash['status'] = 'status'
  @_hash['title'] = 'title'
  @_hash['type'] = 'type'
  @_hash
end

.nullablesObject

An array for nullable fields



99
100
101
# File 'lib/new_store_api/models/problem.rb', line 99

def self.nullables
  []
end

.optionalsObject

An array for optional fields



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/new_store_api/models/problem.rb', line 84

def self.optionals
  %w[
    detail
    error_code
    instance
    message
    messages
    request_id
    status
    title
    type
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



153
154
155
156
157
158
159
# File 'lib/new_store_api/models/problem.rb', line 153

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} detail: #{@detail.inspect}, error_code: #{@error_code.inspect}, instance:"\
  " #{@instance.inspect}, message: #{@message.inspect}, messages: #{@messages.inspect},"\
  " request_id: #{@request_id.inspect}, status: #{@status.inspect}, title: #{@title.inspect},"\
  " type: #{@type.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



145
146
147
148
149
150
# File 'lib/new_store_api/models/problem.rb', line 145

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} detail: #{@detail}, error_code: #{@error_code}, instance: #{@instance},"\
  " message: #{@message}, messages: #{@messages}, request_id: #{@request_id}, status:"\
  " #{@status}, title: #{@title}, type: #{@type}>"
end