Class: Jahuty::Resource::Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/jahuty/resource/problem.rb

Overview

An application/problem+json response. The API should respond with a problem whenever a client- or server-error occurs.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, type:, detail:) ⇒ Problem

Returns a new instance of Problem.



10
11
12
13
14
# File 'lib/jahuty/resource/problem.rb', line 10

def initialize(status:, type:, detail:)
  @status = status
  @type   = type
  @detail = detail
end

Instance Attribute Details

#detailObject

Returns the value of attribute detail.



8
9
10
# File 'lib/jahuty/resource/problem.rb', line 8

def detail
  @detail
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/jahuty/resource/problem.rb', line 8

def status
  @status
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/jahuty/resource/problem.rb', line 8

def type
  @type
end

Class Method Details

.from(data) ⇒ Object

Raises:

  • (ArgumentError.new)


16
17
18
19
20
21
22
# File 'lib/jahuty/resource/problem.rb', line 16

def self.from(data)
  raise ArgumentError.new, 'Key :status missing' unless data.key?(:status)
  raise ArgumentError.new, 'Key :type missing' unless data.key?(:type)
  raise ArgumentError.new, 'Key :detail missing' unless data.key?(:detail)

  Problem.new(**data.slice(:status, :type, :detail))
end