Class: Altcha::V2::Payload

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

Overview

The client payload submitted after solving a v2 challenge.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(challenge:, solution:) ⇒ Payload

Returns a new instance of Payload.



128
129
130
131
# File 'lib/altcha/v2.rb', line 128

def initialize(challenge:, solution:)
  @challenge = challenge
  @solution  = solution
end

Instance Attribute Details

#challengeObject

Returns the value of attribute challenge.



126
127
128
# File 'lib/altcha/v2.rb', line 126

def challenge
  @challenge
end

#solutionObject

Returns the value of attribute solution.



126
127
128
# File 'lib/altcha/v2.rb', line 126

def solution
  @solution
end

Class Method Details

.from_json(string) ⇒ Object



137
138
139
140
141
142
143
144
145
146
# File 'lib/altcha/v2.rb', line 137

def self.from_json(string)
  data = JSON.parse(string)
  new(
    challenge: Challenge.from_h(data['challenge']),
    solution:  Solution.new(
      counter:     data['solution']['counter'],
      derived_key: data['solution']['derivedKey']
    )
  )
end

Instance Method Details

#to_json(options = {}) ⇒ Object



133
134
135
# File 'lib/altcha/v2.rb', line 133

def to_json(options = {})
  { 'challenge' => challenge.to_h, 'solution' => solution.to_h }.to_json(options)
end