Class: Altcha::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/altcha.rb

Overview

Class representing the payload of a challenge.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algorithm:, challenge:, number:, salt:, signature:) ⇒ Payload

Returns a new instance of Payload.



69
70
71
72
73
74
75
# File 'lib/altcha.rb', line 69

def initialize(algorithm:, challenge:, number:, salt:, signature:)
  @algorithm = algorithm
  @challenge = challenge
  @number = number
  @salt = salt
  @signature = signature
end

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm.



67
68
69
# File 'lib/altcha.rb', line 67

def algorithm
  @algorithm
end

#challengeObject

Returns the value of attribute challenge.



67
68
69
# File 'lib/altcha.rb', line 67

def challenge
  @challenge
end

#numberObject

Returns the value of attribute number.



67
68
69
# File 'lib/altcha.rb', line 67

def number
  @number
end

#saltObject

Returns the value of attribute salt.



67
68
69
# File 'lib/altcha.rb', line 67

def salt
  @salt
end

#signatureObject

Returns the value of attribute signature.



67
68
69
# File 'lib/altcha.rb', line 67

def signature
  @signature
end

Class Method Details

.from_json(string) ⇒ Payload

Creates a Payload object from a JSON string.

Parameters:

  • string (String)

    JSON string to parse.

Returns:

  • (Payload)

    Parsed Payload object.



93
94
95
96
97
98
99
100
101
102
# File 'lib/altcha.rb', line 93

def self.from_json(string)
  data = JSON.parse(string)
  new(
    algorithm: data['algorithm'],
    challenge: data['challenge'],
    number: data['number'],
    salt: data['salt'],
    signature: data['signature']
  )
end

Instance Method Details

#to_json(options = {}) ⇒ String

Converts the Payload object to a JSON string.

Parameters:

  • options (Hash) (defaults to: {})

    options to customize JSON encoding.

Returns:

  • (String)

    JSON representation of the Payload object.



80
81
82
83
84
85
86
87
88
# File 'lib/altcha.rb', line 80

def to_json(options = {})
  {
    algorithm: @algorithm,
    challenge: @challenge,
    number: @number,
    salt: @salt,
    signature: @signature
  }.to_json(options)
end