APIClient

public class APIClient : NSObject

Class used to access the API associated with this app

  • Shared instance of the APIClient

    Declaration

    Swift

    public static let shared: APIClient
  • Authenticates user with server (needs to be done before other requests, otherwise an APIError.notAuthenticated occurs)

    Declaration

    Swift

    public func loginUser(username: String, password: String, cloudUserId: String? = nil, environment: SPManager.SPKeychainEnvironment = .local, completion: @escaping (_ success: Bool, _ error: APIError?) -> Void)
    Parameters
    username

    Username of user

    password

    Password of user

    cloudUserId

    Associated Cloud User Id

    environment

    Environment to use

    completion

    Completion block that gets called on response

  • Fetches all gateways associated with user

    Declaration

    Swift

    public func getAllGateways(completion: @escaping (_ gateways: [SPGateway]?, _ error: APIError?) -> Void)
    Parameters
    completion

    Completion block that gets called on response (either an error or an array of SPGateways

  • Fetches a gateway by its IMEI

    Declaration

    Swift

    public func getGateway(imei: String, completion: @escaping (_ gateway: SPGateway?, _ error: APIError?) -> Void)
    Parameters
    imei

    IMEI of the gateway

    completion

    Completion block that gets called on response

  • Update name of gateway

    Declaration

    Swift

    public func updateGateway(name newName: String, of gateway: SPGateway, completion: @escaping (APIError?) -> Void)
    Parameters
    newName

    New name of the gateway

    gateway

    The gateway to update

    completion

    Completion block that gets called on response

  • Update color of gateway

    Declaration

    Swift

    public func updateGateway(color newColor: UIColor, of gateway: SPGateway, completion: @escaping (APIError?) -> Void)
    Parameters
    newColor

    New color of the gateway

    gateway

    The gateway to update

    completion

    Completion block that gets called on response

  • Creates a new account for the service

    Declaration

    Swift

    public func registerAccount(_ account: SPAccount, completion: @escaping (_ success: Bool, _ error: APIError?) -> Void)
    Parameters
    account

    SPAccount representing new account

    completion

    Completion block that gets called on response

  • Type of push notification (SSE) to the gateway

    Declaration

    Swift

    public enum GatewayPushEvent
  • Push event to gateway (SSE)

    Declaration

    Swift

    public func pushEventToGateway(_ gateway: SPGateway, event: GatewayPushEvent, completion: @escaping (_ success: Bool, _ response: JSON?, _ error: APIError?) -> Void)
    Parameters
    gateway

    SPGateway that should receive the notification

    event

    The type of the notification

    completion

    Completion block that gets called on response

  • Sends a SMS message to the provided receiver

    Declaration

    Swift

    public func sendSMS(message: String, to receiver: SPNumber, on gateway: SPGateway, completion: @escaping (Error?) -> Void)
    Parameters
    message

    The message

    receiver

    SPNumber that should receive the message

    gateway

    SPGateway that should send out the message

    completion

    Completion block that gets called on response

  • Gives back all the SPDevices connected to an user

    Declaration

    Swift

    public func getAllDevices(completion: @escaping (_ success: Bool, _ devices: [SPDevice]?, _ error: APIError?) -> Void)
    Parameters
    completion

    Completion block that gets called on response (either an error or an array of SPDevices)

  • Cross-checks local device info and registers/updates info on server (gives back an error if the device got revoked by server)

    Declaration

    Swift

    public func register(deviceWithServer device: SPDevice, completion: @escaping (_ success: Bool, _ error: APIError?) -> Void)
    Parameters
    device

    SPDevice object of the current device

    completion

    Closure that gets called after server response

  • Cross-checks local device info and registers/updates VoIP APN Token of device

    Declaration

    Swift

    public func register(voipToken token: String, completion: @escaping (_ success: Bool, _ error: APIError?) -> Void)
    Parameters
    token

    VoIP APN Token provided by PushKit

    completion

    Closure that gets called after server response

  • Sets the iCloud Sync State of the current device (either sync or keep data local)

    Declaration

    Swift

    public func setiCloudSyncState(_ newState: Bool, completion: @escaping (_ success: Bool, _ error: APIError?) -> Void)
    Parameters
    newState

    New state. Either synced by iCloud (true) or not (false).

    completion

    Closure that gets called after server response

  • Revokes a device using its Identifier

    Declaration

    Swift

    public func revokeDevice(withId id: String, completion: @escaping (_ success: Bool, _ error: APIError?) -> Void)
    Parameters
    id

    Identifier of the device

    completion

    Closure that gets called after server response

  • Revokes all devices with iCloud Sync enabled of the provided account

    Declaration

    Swift

    public func revokeAllDevicesWithiCloudSyncEnabled(completion: @escaping (_ success: Bool, _ error: APIError?) -> Void)
    Parameters
    completion

    Closure that gets called after server response

  • Rekoves the device that makes the request

    Declaration

    Swift

    public func revokeThisDevice(completion: @escaping (_ success: Bool, _ error: APIError?) -> Void)
    Parameters
    completion

    Closure that gets called after server response