CLASS
HaapiFlowViewModel
Contents
- Methods
init(haapiUIKitApplication:)
init(haapiUIKitConfiguration:dataMapper:)
deinit
start()
submit(form:parameters:)
followLink(_:)
fetchAccessToken(authorizationCode:additionalParameters:)
refreshAccessToken(refreshToken:additionalParameters:)
public final class HaapiFlowViewModel: NSObject, ObservableObject
An HaapiFlowViewModel
is responsible for storing state and managing interactions with the server during the HaapiFlow execution.
- Remark: When instantiating an
HaapiFlowViewController
, anHaapiFlowViewModel
is created. - Note: It is impossible to have multiple instances of
HaapiFlowViewModel
in use at the same time when using the samehaapiUIKitConfiguration
. By trying to have multiple instances ofHaapiFlowViewModel
using the same configuration, the second will throw an error.
Methods
init(haapiUIKitApplication:)
public convenience init(haapiUIKitApplication: HaapiUIKitApplication) throws
Creates an instance of HaapiFlowViewModel
based on the provided parameters: HaapiUIKitApplication
.
- Parameters:
- haapiUIKitApplication: The HaapiUIKitApplication configuration.
Parameters
Name | Description |
---|---|
haapiUIKitApplication | The HaapiUIKitApplication configuration. |
init(haapiUIKitConfiguration:dataMapper:)
public init(haapiUIKitConfiguration: HaapiUIKitConfiguration,
dataMapper: DataMapper) throws
Creates an instance of HaapiFlowViewModel
based on the provided parameters: HaapiUIKitConfiguration
and DataMapper
.
- Parameters:
- haapiUIKitConfiguration: The HaapiUIKit configuration.
- dataMapper: The data mapper to map Haapi SDK object to Haapi UIKit object.
- Throws:
HaapiError
if the configuration is incorrect.
Parameters
Name | Description |
---|---|
haapiUIKitConfiguration | The HaapiUIKit configuration. |
dataMapper | The data mapper to map Haapi SDK object to Haapi UIKit object. |
deinit
deinit
start()
public func start()
Prepares and starts the execution of an HAAPI flow interaction with the server.
- Note: State changes are applied to the view model's data variable such as
isLoading
,uiModel
or/anderror
.
submit(form:parameters:)
public func submit(form: FormActionModel, parameters: [String: Any])
Submits a form action model to move forward in the HAAPI flow.
The parameters supplied to this method override the field values present in the form
. If the parameters do not include a value for a given form field name,
the original value in the form is used.
- Note: State changes are applied to the view model's data variable such as
isLoading
,uiModel
or/anderror
. - Parameters:
- form: A form action model to be submitted.
- parameters: The parameters that are sent along with the form. Keys should match the corresponding form field names otherwise they will be discarded.
Parameters
Name | Description |
---|---|
form | A form action model to be submitted. |
parameters | The parameters that are sent along with the form. Keys should match the corresponding form field names otherwise they will be discarded. |
followLink(_:)
public func followLink(_ link: Link)
Follows a link to an alternative HAAPI flow.
- Note: State changes are applied to the view model's data variable such as
isLoading
,uiModel
or/anderror
. - Parameters:
- link: The link to be followed.
Parameters
Name | Description |
---|---|
link | The link to be followed. |
fetchAccessToken(authorizationCode:additionalParameters:)
public func fetchAccessToken(authorizationCode: String, additionalParameters: [String: String]? = nil)
Fetches an access token using an authorization code grant.
- Note: State changes are applied to the view model's data variable such as
isLoading
andtokenResponse
. - Parameters:
- authorizationCode: The authorization code.
- additionalParameters: The additional parameters for the request body. The default value is nil.
Parameters
Name | Description |
---|---|
authorizationCode | The authorization code. |
additionalParameters | The additional parameters for the request body. The default value is nil. |
refreshAccessToken(refreshToken:additionalParameters:)
public func refreshAccessToken(refreshToken: String, additionalParameters: [String: String]? = nil)
Refreshes an access token.
- Note: State changes are applied to the view model's data variable such as
isLoading
andtokenResponse
. - Parameters:
- refreshToken: The refresh token.
- additionalParameters: The additional parameters for the request body. The default value is nil.
Parameters
Name | Description |
---|---|
refreshToken | The refresh token. |
additionalParameters | The additional parameters for the request body. The default value is nil. |