Class: DeviseScim::Scim::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/devise_scim/scim/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, detail:, scim_type: nil) ⇒ Error

Returns a new instance of Error.



12
13
14
15
16
# File 'lib/devise_scim/scim/error.rb', line 12

def initialize(status:, detail:, scim_type: nil)
  @status    = status
  @detail    = detail
  @scim_type = scim_type
end

Instance Attribute Details

#detailObject (readonly)

Returns the value of attribute detail.



10
11
12
# File 'lib/devise_scim/scim/error.rb', line 10

def detail
  @detail
end

#scim_typeObject (readonly)

Returns the value of attribute scim_type.



10
11
12
# File 'lib/devise_scim/scim/error.rb', line 10

def scim_type
  @scim_type
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/devise_scim/scim/error.rb', line 10

def status
  @status
end

Class Method Details

.bad_request(detail, scim_type: "invalidValue") ⇒ Object



45
46
47
# File 'lib/devise_scim/scim/error.rb', line 45

def bad_request(detail, scim_type: "invalidValue")
  new(status: 400, detail: detail, scim_type: scim_type)
end

.conflict(detail = "Resource already exists", scim_type: "uniqueness") ⇒ Object



41
42
43
# File 'lib/devise_scim/scim/error.rb', line 41

def conflict(detail = "Resource already exists", scim_type: "uniqueness")
  new(status: 409, detail: detail, scim_type: scim_type)
end

.not_found(detail = "Resource not found") ⇒ Object



37
38
39
# File 'lib/devise_scim/scim/error.rb', line 37

def not_found(detail = "Resource not found")
  new(status: 404, detail: detail)
end

.server_error(detail = "Internal server error") ⇒ Object



53
54
55
# File 'lib/devise_scim/scim/error.rb', line 53

def server_error(detail = "Internal server error")
  new(status: 500, detail: detail)
end

.unauthorized(detail = "Unauthorized") ⇒ Object



33
34
35
# File 'lib/devise_scim/scim/error.rb', line 33

def unauthorized(detail = "Unauthorized")
  new(status: 401, detail: detail)
end

.unprocessable(detail) ⇒ Object



49
50
51
# File 'lib/devise_scim/scim/error.rb', line 49

def unprocessable(detail)
  new(status: 422, detail: detail)
end

Instance Method Details

#to_hObject



18
19
20
21
22
23
24
25
26
# File 'lib/devise_scim/scim/error.rb', line 18

def to_h
  h = {
    "schemas" => [ERROR_SCHEMA],
    "status" => status.to_s,
    "detail" => detail
  }
  h["scimType"] = scim_type if scim_type
  h
end

#to_jsonObject



28
29
30
# File 'lib/devise_scim/scim/error.rb', line 28

def to_json(*)
  to_h.to_json
end