Class: Hanko::FlowResponse

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ FlowResponse

Creates a new FlowResponse from a parsed response hash.

Parameters:

  • data (Hash)

    the parsed JSON response from a flow endpoint



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

#actionsArray<Resource> (readonly)

Returns available actions in the current flow state.

Returns:

  • (Array<Resource>)

    available actions in the current flow state



13
14
15
# File 'lib/hanko/flow_response.rb', line 13

def actions
  @actions
end

#rawHash (readonly)

Returns the raw response hash.

Returns:

  • (Hash)

    the raw response hash



22
23
24
# File 'lib/hanko/flow_response.rb', line 22

def raw
  @raw
end

#session_tokenString? (readonly)

Returns the session token, if present in the payload.

Returns:

  • (String, nil)

    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

#statusSymbol? (readonly)

Returns the flow status (e.g. :completed, :error).

Returns:

  • (Symbol, nil)

    the flow status (e.g. :completed, :error)



10
11
12
# File 'lib/hanko/flow_response.rb', line 10

def status
  @status
end

#user_idString? (readonly)

Returns the user ID, if present in the payload.

Returns:

  • (String, nil)

    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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


45
46
47
# File 'lib/hanko/flow_response.rb', line 45

def error?
  status == :error
end

#to_hHash

Returns the raw response hash.

Returns:

  • (Hash)


52
53
54
# File 'lib/hanko/flow_response.rb', line 52

def to_h
  @raw
end