CLASS
HaapiFlowViewModel
Contents
- Methods
init(haapiUIKitApplication:)init(haapiUIKitConfiguration:dataMapper:oAuthDataMapper:)deinitstart()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, anHaapiFlowViewModelis created. - Note: It is impossible to have multiple instances of
HaapiFlowViewModelin use at the same time when using the samehaapiUIKitConfiguration. By trying to have multiple instances ofHaapiFlowViewModelusing 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:oAuthDataMapper:)
public init(haapiUIKitConfiguration: HaapiUIKitConfiguration,
dataMapper: DataMapper,
oAuthDataMapper: OAuthDataMapper = OAuthDataMapperBuilder().build()) 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.
- oAuthDataMapper: The data mapper to map Token SDK object to OAuthModel UIKit objects. Defaults to an internal implementation.
- Throws:
HaapiErrorif the configuration is incorrect.
Parameters
| Name | Description |
|---|---|
| haapiUIKitConfiguration | The HaapiUIKit configuration. |
| dataMapper | The data mapper to map Haapi SDK object to Haapi UIKit object. |
| oAuthDataMapper | The data mapper to map Token SDK object to OAuthModel UIKit objects. Defaults to an internal implementation. |
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,uiModelor/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,uiModelor/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,uiModelor/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
isLoadingandtokenResponse. - 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
isLoadingandtokenResponse. - 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. |