kiwi-sdk-android
  • Introduction
  • Analytics
  • Feedback
  • Newsletter
  • Promocode
  • Push
  • Services
  • Subscription
  • User
  • Authentication
  • Account
  • Media Track
Powered by GitBook
On this page
  • AccountProfile:
  • AccountInfo:
  • List of Account Subscriptions:
  • Account Context
  • Fetch operations
  • Fetch Account Response description
  • Retrieve Local Operations
  • Link Subscription With Account
  • Update Account Context

Account

PreviousAuthenticationNextMedia Track

Last updated 6 years ago

The account module contains the necessary operations to fetch and update the user's account. An account is a representation of a person, not a device. Therefore two devices may be logged to the same account.

One person may have more than one valid credentials for accessing his/her account, but can only have one credential per authentication platform (for example, one credential by e-mail/password and one credential by twitter).

AccountProfile:

An account is represented by an AccountProfile object, which holds the account's basic information (AccountInfo), the list of subscriptions the account has access to, and the context linked to the account.

AccountInfo:

Contains the account's unique identifier, the identifier of the IdentityPool the account belongs to and the list of authentication platforms the owner of the account have already used to sign in.

List of Account Subscriptions:

The subscriptions under an account profile object are accessible from any device that signs in to that account. The subscription object is exactly the same as the one used on section

Account Context

The account context holds all the data the application wants to store and link to that account. It consists on a dictionary accessed by namespaces (namespaces are freely defined by the application).

Fetch operations

Operations to request the server for the most updated information over the account. To perform any fetch operation the user must be logged in, otherwise will receive INVALID_CREDENTIALS error.

There are 3 fetch operations:

1) Fetch full Account Profile:

Retrieves the full account profile from the server and update it locally

    kiwiSDK.account().fetchAccountProfile(new FetchAccountProfileListener() {
        @Override
        public void onSuccess(AccountProfile accountProfile) {
            // do something
        }

        @Override
        public void onError(FetchAccountResponse fetchAccountResponse) {
            // identify error and do something
        }
    });

2) Fetch Account Subscriptions:

Retrieve and update locally only the account subscriptions

    kiwiSDK.account().fetchAccountSubscriptions(new FetchAccountSubscriptionsListener() {
        @Override
        public void onSuccess(Set<Subscription> subscriptions) {
            // do something
        }

        @Override
        public void onError(FetchAccountResponse fetchAccountResponse) {
            // identify error and do something
        }
    });

3) Fetch Account Context:

Retrieve and update locally only the account context

    kiwiSDK.account().fetchAccountContext(new FetchAccountContextListener() {
        @Override
        public void onSuccess(Map<String, Map<String, String>> context) {
            // do something
        }

        @Override
        public void onError(FetchAccountResponse fetchAccountResponse) {
            // identify error and do something
        }
    });

Fetch Account Response description

A FetchAccountResponse object holds a FetchAccountStatus, which may be one of the following:

  • UNKNOWN_ERROR: Unknown error happened while performing request to fetch account information

  • SUCCESS: Fetched information on account successfully

  • SERVER_ERROR_INVALID_TOKEN: Could not fetch account information because was not logged in or was logged with an invalid account

  • SERVER_ERROR_CONNECTION_FAILURE: Could not fetch account information due to connection errors with Kiwi server

  • SERVER_ERROR_UNEXPECTED_RESPONSE: Could not fetch account information due to an unexpected server response

  • SERVER_ERROR_PARSING_RESPONSE: Could not fetch account information due to an error parsing server response

Retrieve Local Operations

Operations that retrieve account's information that had already been fetched. NOTE: If the user is not signed in, the information retrieved here will be null

There are 3 retrieve local operations. Each one of them returns a Future object containg the desired object.

1) Retrieve Local Account Profile

Future<AccountProfile> accountProfileFuture = kiwiSDK.account().retrieveLocalAccountProfile();

2) Retrieve Local Account Subscriptions

Future<Set<Subscription>> subscriptionsFuture = kiwiSDK.account().retrieveLocalAccountSubscriptions();

3) Retrieve Local Account Context

Future<Map<String, Map<String, String>> contextFuture = kiwiSDK.account().retrieveLocalAccountContext();

Link Subscription With Account

This operation will link the target subscription with the current account. In order for the link to work, the current user should already have access to that subscription through kiwi's userId. NOTE: the user must be authenticated in order to perform this request, otherwise will receive INVALID_TOKEN error

Future<LinkSubscriptionWithAccountResponse> statusFuture = kiwiSDK.account().linkSubscriptionWithAccount(subscriptionId)

The possible Link Subscription With Account Status are:

  • UNKNOWN_ERROR: Unknown error while trying to link subscription with account

  • SUCCESS: Linked subscription with account successfully

  • SUCCESS_SUBSCRIPTION_ALREADY_LINKED: Subscription was already linked to the current account

  • ERROR_INVALID_PARAMETERS: Could not link subscription due to missing subscription id

  • SERVER_ERROR_CONNECTION_FAILURE: Could not link subscription due to error with connection to Kiwi server

  • SERVER_ERROR_INVALID_TOKEN: Could not link subscription because it's not logged in or is logged in to an invalid account

  • SERVER_ERROR_SUBSCRIPTION_NOT_FOUND: Could not link subscription because the target subscription does not exist

  • SERVER_ERROR_USER_NOT_AUTHORIZED_TO_SUBSCRIPTION: Could not link subscription because the current user did not have rights over this subscription

  • SERVER_ERROR_SUBSCRIPTION_LINKED_TO_OTHER_ACCOUNT: Could not link subscription because the target subscription was already linked to other account

  • SERVER_ERROR_UNEXPECTED_RESPONSE: Could not link subscription because of an unexpected response from the server

  • SERVER_ERROR_PARSING_RESPONSE: Could not link subscription because of an error parsing response from the server

Update Account Context

This operation will update the account context linked to the current account. NOTE: the user must be authenticated in order to perform this request, otherwise will receive INVALID_TOKEN error

Future<UpdateAccountContextResponse> statusFuture = kiwiSDK.account().updateAccountContext(map)

The possible Update Account Context Status are:

  • UNKNOWN_ERROR: Unknown error while updating account context

  • SUCCESS: Updated account context successfully

  • SERVER_ERROR_INVALID_TOKEN: Could not update account context because was not logged in or was logged to an invalid account

  • SERVER_ERROR_CONNECTION_FAILURE: Could not update account due to error connecting with Kiwi server

  • SERVER_ERROR_UNEXPECTED_RESPONSE: Could not update account due to unexpected response from the server

  • SERVER_ERROR_PARSING_RESPONSE: Could not update account due to an error parsing server response

  • ERROR_INVALID_PARAMETERS: Could not update account due to missing account context on request

subscription