Class: Hook0::Generated::Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/hook0/generated/models.rb

Overview

The Problem the API declares.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(detail:, id:, status:, title:, type:, validation: nil) ⇒ Problem

Returns a new instance of Problem.

Parameters:

  • detail (String)

    carries detail.

  • id (String)

    carries id, one of ProblemId::VALUES: Identifier of the problem that occurred, stable across releases

  • status (Integer)

    carries status.

  • title (String)

    carries title.

  • type (String)

    carries type: Documentation page of this problem, which is also what distinguishes one problem type from another as RFC 7807 asks. Prefer matching on id: it says the same thing without parsing a URL.

  • validation (Object, nil) (defaults to: nil)

    carries validation: Which submitted values were rejected and why, keyed by the name of the field they were submitted under. Carried by validation failures (Validation, status 422) and null for every other problem, as



1991
1992
1993
1994
1995
1996
1997
1998
1999
# File 'lib/hook0/generated/models.rb', line 1991

def initialize(detail:, id:, status:, title:, type:, validation: nil)
  @detail = detail
  @id = id
  @status = status
  @title = title
  @type = type
  @validation = validation
  freeze
end

Instance Attribute Details

#detailObject (readonly)

Returns the value of attribute detail.



1973
1974
1975
# File 'lib/hook0/generated/models.rb', line 1973

def detail
  @detail
end

#idObject (readonly)

Returns the value of attribute id.



1973
1974
1975
# File 'lib/hook0/generated/models.rb', line 1973

def id
  @id
end

#statusObject (readonly)

Returns the value of attribute status.



1973
1974
1975
# File 'lib/hook0/generated/models.rb', line 1973

def status
  @status
end

#titleObject (readonly)

Returns the value of attribute title.



1973
1974
1975
# File 'lib/hook0/generated/models.rb', line 1973

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



1973
1974
1975
# File 'lib/hook0/generated/models.rb', line 1973

def type
  @type
end

#validationObject (readonly)

Returns the value of attribute validation.



1973
1974
1975
# File 'lib/hook0/generated/models.rb', line 1973

def validation
  @validation
end

Class Method Details

.from_json(value) ⇒ Problem

Read one out of what the API answered.

Parameters:

  • value (Object)

    the JSON document the API answered

Returns:



2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
# File 'lib/hook0/generated/models.rb', line 2005

def self.from_json(value)
  fields = Runtime.as_fields(value, "Problem")
  new(
    detail: Runtime.read(fields, "detail", Runtime::TEXT),
    id: Runtime.read(fields, "id", Runtime.member_of(ProblemId)),
    status: Runtime.read(fields, "status", Runtime::INTEGER),
    title: Runtime.read(fields, "title", Runtime::TEXT),
    type: Runtime.read(fields, "type", Runtime::TEXT),
    validation: Runtime.maybe(fields, "validation", Runtime::JSON_VALUE)
  )
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Whether that value carries the same members as this one.

Parameters:

  • other (Object)

Returns:

  • (Boolean)


2035
2036
2037
# File 'lib/hook0/generated/models.rb', line 2035

def ==(other)
  other.is_a?(Problem) && to_h == other.to_h
end

#hashInteger

A value two equal instances share, so that either may key a hash.

Returns:

  • (Integer)


2043
2044
2045
# File 'lib/hook0/generated/models.rb', line 2043

def hash
  to_h.hash
end

#to_hHash{String => Object}

Write one back the way the API reads it.

Returns:

  • (Hash{String => Object})


2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
# File 'lib/hook0/generated/models.rb', line 2020

def to_h
  out = {}
  out["detail"] = @detail
  out["id"] = @id
  out["status"] = @status
  out["title"] = @title
  out["type"] = @type
  out["validation"] = @validation unless @validation.nil?
  out
end