Class: Hanko::FlowResponse
- Inherits:
-
Object
- Object
- Hanko::FlowResponse
- Defined in:
- lib/hanko/flow_response.rb
Overview
Structured response from a Hanko passkey flow endpoint.
Wraps the raw response hash and provides convenience accessors for status, available actions, session token, and user ID.
Instance Attribute Summary collapse
-
#actions ⇒ Array<Resource>
readonly
Available actions in the current flow state.
-
#raw ⇒ Hash
readonly
The raw response hash.
-
#session_token ⇒ String?
readonly
The session token, if present in the payload.
-
#status ⇒ Symbol?
readonly
The flow status (e.g. :completed, :error).
-
#user_id ⇒ String?
readonly
The user ID, if present in the payload.
Instance Method Summary collapse
-
#completed? ⇒ Boolean
Returns true when the flow has completed successfully.
-
#error? ⇒ Boolean
Returns true when the flow has entered an error state.
-
#initialize(data) ⇒ FlowResponse
constructor
Creates a new FlowResponse from a parsed response hash.
-
#to_h ⇒ Hash
Returns the raw response hash.
Constructor Details
#initialize(data) ⇒ FlowResponse
Creates a new FlowResponse from a parsed response hash.
27 28 29 30 31 32 33 |
# File 'lib/hanko/flow_response.rb', line 27 def initialize(data) @raw = data @status = data['status']&.to_sym @actions = (data['actions'] || []).map { |a| Resource.new(a) } @session_token = data.dig('payload', 'session_token') @user_id = data.dig('payload', 'user_id') end |
Instance Attribute Details
#actions ⇒ Array<Resource> (readonly)
Returns available actions in the current flow state.
13 14 15 |
# File 'lib/hanko/flow_response.rb', line 13 def actions @actions end |
#raw ⇒ Hash (readonly)
Returns the raw response hash.
22 23 24 |
# File 'lib/hanko/flow_response.rb', line 22 def raw @raw end |
#session_token ⇒ String? (readonly)
Returns the session token, if present in the payload.
16 17 18 |
# File 'lib/hanko/flow_response.rb', line 16 def session_token @session_token end |
#status ⇒ Symbol? (readonly)
Returns the flow status (e.g. :completed, :error).
10 11 12 |
# File 'lib/hanko/flow_response.rb', line 10 def status @status end |
#user_id ⇒ String? (readonly)
Returns the user ID, if present in the payload.
19 20 21 |
# File 'lib/hanko/flow_response.rb', line 19 def user_id @user_id end |
Instance Method Details
#completed? ⇒ Boolean
Returns true when the flow has completed successfully.
38 39 40 |
# File 'lib/hanko/flow_response.rb', line 38 def completed? status == :completed end |
#error? ⇒ Boolean
Returns true when the flow has entered an error state.
45 46 47 |
# File 'lib/hanko/flow_response.rb', line 45 def error? status == :error end |
#to_h ⇒ Hash
Returns the raw response hash.
52 53 54 |
# File 'lib/hanko/flow_response.rb', line 52 def to_h @raw end |