API

public class API

Represents a utility singleton class for calling through the Cheetah Loyalty API.

  • The shared instance of the API.

    Declaration

    Swift

    public static let shared: API
  • The URLSession object used by the API to execute requests.

    Declaration

    Swift

    public var session: URLSession
  • A class conforming to the UserLocation protocol. This property is used to get user location coordinates to be passed in the request header if the location tracking is enabled. This is advised to be set on application launch.

    Declaration

    Swift

    public weak var userLocation: UserLocation?

Session management

  • Resets the session by cancelling current tasks and invalidating current session and then creates a new session.

    Declaration

    Swift

    public func resetSession()

Managing session credentials

  • Gets the access token of the user of the current session.

    Declaration

    Swift

    public func getAccessToken() -> String?

    Return Value

    The access token as an optional String (May be nil if there is not currently logged in user session).

  • Gets the refresh token of the user of the current session.

    Declaration

    Swift

    public func getRefreshToken() -> String?

    Return Value

    The refresh token as an optional String (May be nil if there is it has not been set).

  • Saves the credentials of the user of the current session.

    Declaration

    Swift

    public func setCredentials(_ accessToken: String, refreshToken: String? = nil)

    Parameters

    accessToken

    The access token as a String.

    refreshToken

    The refresh token used for refreshing the access token as a String.

  • Deletes the current user session’s saved credentials.

    Declaration

    Swift

    public func deleteCredentials()

Sending requests