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

Instance Method Summary collapse

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm.



56
57
58
# File 'lib/altcha.rb', line 56

def algorithm
  @algorithm
end

#challengeObject

Returns the value of attribute challenge.



56
57
58
# File 'lib/altcha.rb', line 56

def challenge
  @challenge
end

#numberObject

Returns the value of attribute number.



56
57
58
# File 'lib/altcha.rb', line 56

def number
  @number
end

#saltObject

Returns the value of attribute salt.



56
57
58
# File 'lib/altcha.rb', line 56

def salt
  @salt
end

#signatureObject

Returns the value of attribute signature.



56
57
58
# File 'lib/altcha.rb', line 56

def signature
  @signature
end

Instance 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.



74
75
76
77
# File 'lib/altcha.rb', line 74

def from_json(string)
  data = JSON.parse(string)
  new data['algorithm'], data['verificationData'], data['signature'], data['verified']
end

#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.



61
62
63
64
65
66
67
68
69
# File 'lib/altcha.rb', line 61

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