Structure
Disruptive
public struct Disruptive
This is the core of the Disruptive
Swift API, and implements the majority of the Disruptive Technologies REST API endpoints.
The most straight-forward usage is to create one single shared instance of this, and use it across
the entire app (although you can create multiple instances if you need to). When initialized with an
Authenticator
, a Disruptive
instance will keep an access token up-to-date automatically,
so all requests are authenticated.
Initializers
init(authenticator:baseURL:emulatorBaseURL:)
public init(authenticator: Authenticator, baseURL: String = Disruptive.defaultBaseURL, emulatorBaseURL: String = Disruptive.defaultBaseEmulatorURL)
Initializes a Disruptive
instance.
Parameters
Name | Type | Description |
---|---|---|
authenticator | Authenticator |
Used to authenticate against the Disruptive Technologies REST API. It is recommended to pass an |
baseURL | String |
Optional parameter. The base URL for the REST API. The default value is |
Properties
defaultBaseURL
public static let defaultBaseURL = "https://api.disruptive-technologies.com/v2/"
The default base URL for the Disruptive Technologies REST API in the production environment.
defaultBaseEmulatorURL
public static let defaultBaseEmulatorURL = "https://emulator.disruptive-technologies.com/v2/"
The default base URL for the Disruptive Technologies emulator REST API in the production environment.
defaultAuthURL
public static let defaultAuthURL = "https://identity.disruptive-technologies.com/oauth2/token"
The default base URL for authenticating against the Disruptive Technologies REST API in the production environment.
emulatorBaseURL
public let emulatorBaseURL: String
The base URL for the Disruptive Technologies emulator REST API.
loggingEnabled
public static var loggingEnabled = false
Whether or not the DisruptiveAPI should log to the console. Defaults to false
.
authenticator
public let authenticator: Authenticator
The authentication mechanism used by Disruptive
. This will be
checked to see if it has a non-expired access token before every request
is sent to the Disruptive backend. If no non-expired access token were found
the refreshAccessToken
method will be called before attempting to send the request.
Methods
getAllDataConnectors(projectID:completion:)
public func getAllDataConnectors(
projectID : String,
completion : @escaping (_ result: Result<[DataConnector], DisruptiveError>) -> ())
Gets all the Data Connectors that are available in a specific project.
This will handle pagination automatically and send multiple network requests in
the background if necessary. If a lot of Data Connectors are expected to be in the project,
it might be better to load pages of Data Connectors as they're needed using the
getDataConnectorsPage
function instead.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get Data Connectors from. |
completion | @escaping (_ result: Result<[DataConnector], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getDataConnectorsPage(projectID:pageSize:pageToken:completion:)
public func getDataConnectorsPage(
projectID : String,
pageSize : Int = 100,
pageToken : String?,
completion : @escaping (_ result: Result<(nextPageToken: String?, dataConnectors: [DataConnector]), DisruptiveError>) -> ())
Gets one page of Data Connectors.
Useful if a lot of Data Connectors are expected in the specified project. This function
provides better control for when to get Data Connectors and how many to get at a time so
that Data Connectors are only fetch when they are needed. This can also improve performance,
at a cost of convenience compared to the getAllDataConnectors
function.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get Data Connectors from. |
pageSize | Int |
The maximum number of Data Connectors to get for this page. The maximum page size is 100, which is also the default |
pageToken | String? |
The token of the page to get. For the first page, set this to |
completion | @escaping (_ result: Result<(nextPageToken: String?, dataConnectors: [DataConnector]), DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getDataConnector(projectID:dataConnectorID:completion:)
public func getDataConnector(
projectID : String,
dataConnectorID : String,
completion : @escaping (_ result: Result<DataConnector, DisruptiveError>) -> ())
Gets a specific Data Connector within a project by its identifier.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get the Data Connector from. |
dataConnectorID | String |
The identifier of the Data Connector to get within the specified project. |
completion | @escaping (_ result: Result<DataConnector, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
createDataConnector(projectID:displayName:pushType:eventTypes:labels:isActive:completion:)
public func createDataConnector(
projectID : String,
displayName : String,
pushType : DataConnector.PushType,
eventTypes : [EventType],
labels : [String] = [],
isActive : Bool = true,
completion : @escaping (_ result: Result<DataConnector, DisruptiveError>) -> ())
Creates a new Data Connector. See the Data Connectors guide on the developer website to learn more about how Data Connectors work, and how to set up an external service to receive the events that are sent out by a Data Connector.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to create the Data Connector in. |
displayName | String |
The display name to give the Data Connector. |
pushType | DataConnector.PushType |
The mechanism to use to push events to an external service. This will also include the parameters to configure the push mechanism. |
eventTypes | [EventType] |
The event types that the Data Connector will send to the external service. |
labels | [String] |
The labels to be included along with the events. If a device that an event originates from has a label that is not included in this list, it will not be included in the event from the Data Connector. Note that if you want the display name of the device to be included in the events to the external service, you need to include the |
isActive | Bool |
Whether or not the Data Connector should start in the active state. This can be changed later by calling the |
completion | @escaping (_ result: Result<DataConnector, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
updateDataConnector(projectID:dataConnectorID:displayName:httpPush:isActive:eventTypes:labels:completion:)
public func updateDataConnector(
projectID : String,
dataConnectorID : String,
displayName : String? = nil,
httpPush : (url: String?, signatureSecret: String?, headers: [String: String]?)? = nil,
isActive : Bool? = nil,
eventTypes : [EventType]? = nil,
labels : [String]? = nil,
completion : @escaping (_ result: Result<DataConnector, DisruptiveError>) -> ())
Updates the configuration of a Data Connector. Only the parameters that are set will be updated, and the remaining will be left unchanged.
Examples:
// Deactivates a Data Connector by only using the `active` parameter
disruptive.updateDataConnector(
projectID : "<PROJECT_ID>",
dataConnectorID : "<DC_ID>",
active : false)
{ result in
...
}
// Updates the signature secret of a Data Connector, and nothing else
disruptive.updateDataConnector(
projectID : "<PROJECT_ID>",
dataConnectorID : "<DC_ID>",
httpPush : (url: nil, signatureSecret: "NEW_SECRET", headers: nil))
{ result in
...
}
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the Data Connector to update is in. |
dataConnectorID | String |
The identifier of the Data Connector to update. |
displayName | String? |
The new display name to use for the Data Connector. Will be ignored if not set (or |
httpPush | (url: String?, signatureSecret: String?, headers: [String: String]?)? |
The new configuration of the |
isActive | Bool? |
The new active status of the Data Connector. Will be ignored if not set (or |
eventTypes | [EventType]? |
The new list of event types the Data Connector will send out. Will be ignored if not set (or |
labels | [String]? |
The new labels that will be included for every event pushed to an external service by the Data Connector. Will be ignored if not set (or |
completion | @escaping (_ result: Result<DataConnector, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
deleteDataConnector(projectID:dataConnectorID:completion:)
public func deleteDataConnector(
projectID : String,
dataConnectorID : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Deletes a Data Connector.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to delete the Data Connector from. |
dataConnectorID | String |
The identifier of the Data Connector to delete. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getDataConnectorMetrics(projectID:dataConnectorID:completion:)
public func getDataConnectorMetrics(
projectID : String,
dataConnectorID : String,
completion : @escaping (_ result: Result<DataConnector.Metrics, DisruptiveError>) -> ())
Retrieves the metrics for the past 3 hours for a Data Connector.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to delete the Data Connector from. |
dataConnectorID | String |
The identifier of the Data Connector to delete. |
completion | @escaping (_ result: Result<DataConnector.Metrics, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
syncDataConnector(projectID:dataConnectorID:completion:)
public func syncDataConnector(
projectID : String,
dataConnectorID : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Synchronizes a Data Connector with the external service. When this is called, the last known event for each event type of every device in the project will be re-pushed to the external service.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the Data Connector to synchronize is in. |
dataConnectorID | String |
The identifier of the Data Connector to synchronize. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getAllDevices(projectID:query:deviceIDs:deviceTypes:productNumbers:labelFilters:orderBy:completion:)
public func getAllDevices(
projectID : String,
query : String? = nil,
deviceIDs : [String]? = nil,
deviceTypes : [Device.DeviceType]? = nil,
productNumbers : [String]? = nil,
labelFilters : [String: String]? = nil,
orderBy : (field: String, ascending: Bool)? = nil,
completion : @escaping (_ result: Result<[Device], DisruptiveError>) -> ())
Gets all the devices in a specific project (including emulated devices).
This will handle pagination automatically and send multiple network requests in
the background if necessary. If a lot of devices are expected to be in the project,
it might be better to load pages of devices as they're needed using the
getDevicesPage
function instead.
Examples:
// Get all the devices in the project
disruptive.getAllDevices(projectID: "<PROJECT_ID>") { result in
...
}
// Get all the temperature devices in the project ordered by
// the temperature (highest temperatures first)
disruptive.getAllDevices(
projectID : "<PROJECT_ID>",
deviceTypes : [.temperature],
orderBy : (field: "reported.temperature.value", ascending: false))
{ result in
...
}
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get devices from. |
query | String? |
Simple keyword based search. Will be ignored if not set (or |
deviceIDs | [String]? |
Filters on a list of device identifiers. Will be ignored if not set (or |
deviceTypes | [Device.DeviceType]? |
Filters on a list of device types. Will be ignored if not set (or |
productNumbers | [String]? |
Filters on a list of product numbers. This is the same product number that can be found on the support pages for both Sensors and Cloud Connectors. |
labelFilters | [String: String]? |
Filters on a set of labels. Will be ignored if not set (or |
orderBy | (field: String, ascending: Bool)? |
Defines a field to order the retrieved devices by. Uses a dot notation format (eg. |
completion | @escaping (_ result: Result<[Device], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getDevicesPage(projectID:query:deviceIDs:deviceTypes:productNumbers:labelFilters:orderBy:pageSize:pageToken:completion:)
public func getDevicesPage(
projectID : String,
query : String? = nil,
deviceIDs : [String]? = nil,
deviceTypes : [Device.DeviceType]? = nil,
productNumbers : [String]? = nil,
labelFilters : [String: String]? = nil,
orderBy : (field: String, ascending: Bool)? = nil,
pageSize : Int = 100,
pageToken : String?,
completion : @escaping (_ result: Result<(nextPageToken: String?, devices: [Device]), DisruptiveError>) -> ())
Gets one page of devices (including emulated devices).
Useful if a lot of devices are expected in the specified project. This function
provides better control for when to get devices and how many to get at a time so
that devices are only fetch when they are needed. This can also improve performance,
at a cost of convenience compared to the getAllDevices
function.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get devices from. |
query | String? |
Simple keyword based search. Will be ignored if not set (or |
deviceIDs | [String]? |
Filters on a list of device identifiers. Will be ignored if not set (or |
deviceTypes | [Device.DeviceType]? |
Filters on a list of device types. Will be ignored if not set (or |
productNumbers | [String]? |
Filters on a list of product numbers. This is the same product number that can be found on the support pages for both Sensors and Cloud Connectors. |
labelFilters | [String: String]? |
Filters on a set of labels. Will be ignored if not set (or |
orderBy | (field: String, ascending: Bool)? |
Defines a field to order the retrieved devices by. Uses a dot notation format (eg. |
pageSize | Int |
The maximum number of devices to get for this page. The maximum page size is 100, which is also the default |
pageToken | String? |
The token of the page to get. For the first page, set this to |
completion | @escaping (_ result: Result<(nextPageToken: String?, devices: [Device]), DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getDevice(projectID:deviceID:completion:)
public func getDevice(
projectID : String? = nil,
deviceID : String,
completion : @escaping (_ result: Result<Device, DisruptiveError>) -> ())
Gets details for a specific device. This device could be found within a specific project, or if the projectID
argument is not specified (or nil), throughout all the project available to the authenticated account.
Parameters
Name | Type | Description |
---|---|---|
projectID | String? |
The identifier of the project to find the device in. If default value (nil) is used, a wildcard character will be used for the projectID that searches through all the project the authenticated account has access to. |
deviceID | String |
The identifier of the device to get details for. |
completion | @escaping (_ result: Result<Device, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
updateDeviceDisplayName(projectID:deviceID:newDisplayName:completion:)
public func updateDeviceDisplayName(
projectID : String,
deviceID : String,
newDisplayName : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Updates the display name of a device to a new value (overwrites it if a display name already exists).
This is a convenience function for batchUpdateDeviceLabels
by setting the name
label to the new display name.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the device is in. |
deviceID | String |
The identifier of the device to change the display name of. |
newDisplayName | String |
The new display name to set for the device. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
deleteDeviceLabel(projectID:deviceID:labelKey:completion:)
public func deleteDeviceLabel(
projectID : String,
deviceID : String,
labelKey : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Deletes the specified label for the device. Will return success if the label didn't exist.
This is a convenience function for batchUpdateDeviceLabels
.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the device is in. |
deviceID | String |
The identifier of the device to delete a label from. |
labelKey | String |
The key of the label to delete. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
setDeviceLabel(projectID:deviceID:labelKey:labelValue:completion:)
public func setDeviceLabel(
projectID : String,
deviceID : String,
labelKey : String,
labelValue : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Assigns a value to a label key for a specific device. If the label key doesn't already exists it will be created, otherwise the value for the key is updated. This is in effect an upsert.
This is a convenience function for batchUpdateDeviceLabels
.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the device is in. |
deviceID | String |
The identifier of the device to set the label for. |
labelKey | String |
The key of the label. |
labelValue | String |
The new value of the label. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
batchUpdateDeviceLabels(projectID:deviceIDs:labelsToSet:labelsToRemove:completion:)
public func batchUpdateDeviceLabels(
projectID : String,
deviceIDs : [String],
labelsToSet : [String: String],
labelsToRemove : [String],
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Performs a batch update to add or remove one or more labels to one or more devices in a project.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the devices are in. |
deviceIDs | [String] |
An array of identifiers for the devices to set or remove labels from. |
labelsToSet | [String: String] |
The key-value pairs to set for the device. If the labels already exists they will be updated, otherwise they will be created, effectively doing an upsert. Any labels that already exists on a device, but are not provided here will be left as-is. |
labelsToRemove | [String] |
An array of label keys to remove from the device. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
moveDevices(deviceIDs:fromProjectID:toProjectID:completion:)
public func moveDevices(
deviceIDs : [String],
fromProjectID : String,
toProjectID : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Moves a list of devices from one project to another. The authenticated account must be an admin
in the toProjectID
, or an organization admin in which the toProjectID
resides.
Parameters
Name | Type | Description |
---|---|---|
deviceIDs | [String] |
A list of the device identifiers to move from one project to another. |
fromProjectID | String |
The identifier of the project to move the devices from. |
toProjectID | String |
The identifier of the project to move the devices to. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getEmulatedDevice(projectID:deviceID:completion:)
public func getEmulatedDevice(
projectID : String,
deviceID : String,
completion : @escaping (_ result: Result<Device, DisruptiveError>) -> ())
Gets details for a specific emulated device within a project.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to find the device in. |
deviceID | String |
The identifier of the emulated device to get details for. |
completion | @escaping (_ result: Result<Device, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getAllEmulatedDevices(projectID:completion:)
public func getAllEmulatedDevices(
projectID : String,
completion : @escaping (_ result: Result<[Device], DisruptiveError>) -> ())
Gets all the emulated devices in a specific project (without any physical devices).
This will handle pagination automatically and send multiple network requests in
the background if necessary. If a lot of emulated devices are expected to be in the project,
it might be better to load pages of emulated devices as they're needed using the
getEmulatedDevicesPage
function instead.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get emulated devices from. |
completion | @escaping (_ result: Result<[Device], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getEmulatedDevicesPage(projectID:pageSize:pageToken:completion:)
public func getEmulatedDevicesPage(
projectID : String,
pageSize : Int = 100,
pageToken : String?,
completion : @escaping (_ result: Result<(nextPageToken: String?, devices: [Device]), DisruptiveError>) -> ())
Gets one page of emulated devices.
Useful if a lot of emulated devices are expected in the specified project. This function
provides better control for when to get emulated devices and how many to get at a time so
that emulated devices are only fetch when they are needed. This can also improve performance,
at a cost of convenience compared to the getAllEmulatedDevices
function.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get emulated devices from. |
pageSize | Int |
The maximum number of emulated devices to get for this page. The maximum page size is 100, which is also the default |
pageToken | String? |
The token of the page to get. For the first page, set this to |
completion | @escaping (_ result: Result<(nextPageToken: String?, devices: [Device]), DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
createEmulatedDevice(projectID:deviceType:displayName:labels:completion:)
public func createEmulatedDevice(
projectID : String,
deviceType : Device.DeviceType,
displayName : String,
labels : [String: String] = [:],
completion : @escaping (_ result: Result<Device, DisruptiveError>) -> ())
Creates a new emulated device in a specific project.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to create the emulated device in. |
deviceType | Device.DeviceType |
The type of device the emulated device should emulate. |
displayName | String |
The display name of the new emulated device. This will be added as a label with the key |
labels | [String: String] |
A set of keys and values to use as labels for the emulated device. |
completion | @escaping (_ result: Result<Device, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
deleteEmulatedDevice(projectID:deviceID:completion:)
public func deleteEmulatedDevice(
projectID : String,
deviceID : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Deletes an emulated device.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to delete the emulated device from. |
deviceID | String |
The identifier of the emulated device to delete. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
publishEmulatedEvent(projectID:deviceID:event:completion:)
public func publishEmulatedEvent<Event: PublishableEvent>(
projectID : String,
deviceID : String,
event : Event,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Publishes a new event to an emulated device.
Any of the event types in Sources/Disruptive/Helpers/EventTypes.swift
can be published,
although not all event types can be published for every device type. For example, an emulated temperature sensor
cannot publish an EthernetStatusEvent
.
For more details about the different event types, see the Developer Website.
Example:
// Publish a temperature event
publishEmulatedEvent(
projectID : "<PROJECT_ID>",
deviceID : "<DEVICE_ID>",
event : TemperatureEvent(value: 10, timestamp: Date())
{ result in
...
}
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the emulated device is in. |
deviceID | String |
The identifier of the emulated device to publish the event to. |
event | Event |
The event to publish to the emulated device. This can be any event type such as |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getEvents(projectID:deviceID:startDate:endDate:eventTypes:completion:)
public func getEvents(
projectID : String,
deviceID : String,
startDate : Date? = nil,
endDate : Date? = nil,
eventTypes : [EventType]? = nil,
completion : @escaping (_ result: Result<Events, DisruptiveError>) -> ())
Fetches historical data for a specific device from the server. The events are returned with the oldest event at the beginning of the array, and the newest event at the end.
If one or more eventTypes
are specified, only those events will be fetched.
Otherwise, all the events available for the specified device will be fetched.
Note that not all event types are available for all devices.
If startDate
or endDate
is not specified, it defaults to the last 24 hours.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project where the device is. |
deviceID | String |
The identifier of the device to get events from. |
startDate | Date? |
The timestamp of the first event to fetch. Defaults to 24 hours ago. |
endDate | Date? |
The timestamp of the last event to fetch. Defaults to now. |
eventTypes | [EventType]? |
A list of event types to fetch. Defaults to fetching all events for specified device. |
completion | @escaping (_ result: Result<Events, DisruptiveError>) -> () |
The completion handler that is called when data is returned from the server. This is a |
result |
|
getAllMembers(organizationID:completion:)
public func getAllMembers(
organizationID : String,
completion : @escaping (_ result: Result<[Member], DisruptiveError>) -> ())
Gets all the Members for a specific organization.
This will handle pagination automatically and send multiple network requests in
the background if necessary. If a lot of Members are expected to be in the organization,
it might be better to load pages of Members as they're needed using the
getMembersPage
function instead.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String |
The identifier of the organization to get Members for. |
completion | @escaping (_ result: Result<[Member], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getAllMembers(projectID:completion:)
public func getAllMembers(
projectID : String,
completion : @escaping (_ result: Result<[Member], DisruptiveError>) -> ())
Gets all the Members for a specific project.
This will handle pagination automatically and send multiple network requests in
the background if necessary. If a lot of Members are expected to be in the project,
it might be better to load pages of Members as they're needed using the
getMembersPage
function instead.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get Members for. |
completion | @escaping (_ result: Result<[Member], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getMembersPage(organizationID:pageSize:pageToken:completion:)
public func getMembersPage(
organizationID : String,
pageSize : Int = 100,
pageToken : String?,
completion : @escaping (_ result: Result<(nextPageToken: String?, members: [Member]), DisruptiveError>) -> ())
Gets one page of Members for a specific organization.
Useful if a lot of Members are expected in the specified organization. This function
provides better control for when to get Members and how many to get at a time so
that Members are only fetch when they are needed. This can also improve performance,
at a cost of convenience compared to the getAllMembers
function.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String |
The identifier of the organization to get Members from. |
pageSize | Int |
The maximum number of Members to get for this page. The maximum page size is 100, which is also the default |
pageToken | String? |
The token of the page to get. For the first page, set this to |
completion | @escaping (_ result: Result<(nextPageToken: String?, members: [Member]), DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getMembersPage(projectID:pageSize:pageToken:completion:)
public func getMembersPage(
projectID : String,
pageSize : Int = 100,
pageToken : String?,
completion : @escaping (_ result: Result<(nextPageToken: String?, members: [Member]), DisruptiveError>) -> ())
Gets one page of Members for a specific project.
Useful if a lot of Members are expected in the specified project. This function
provides better control for when to get Members and how many to get at a time so
that Members are only fetch when they are needed. This can also improve performance,
at a cost of convenience compared to the getAllMembers
function.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get Members from. |
pageSize | Int |
The maximum number of Members to get for this page. The maximum page size is 100, which is also the default |
pageToken | String? |
The token of the page to get. For the first page, set this to |
completion | @escaping (_ result: Result<(nextPageToken: String?, members: [Member]), DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getMember(organizationID:memberID:completion:)
public func getMember(
organizationID : String,
memberID : String,
completion : @escaping (_ result: Result<Member, DisruptiveError>) -> ())
Gets a specific Member within an organization by its identifier.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String |
The identifier of the organization to get the Member from. |
memberID | String |
The identifier of the Member to get within the specific organization. |
completion | @escaping (_ result: Result<Member, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getMember(projectID:memberID:completion:)
public func getMember(
projectID : String,
memberID : String,
completion : @escaping (_ result: Result<Member, DisruptiveError>) -> ())
Gets a specific Member within a project by its identifier.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get the Member from. |
memberID | String |
The identifier of the Member to get within the specific project. |
completion | @escaping (_ result: Result<Member, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
inviteMember(organizationID:roles:email:completion:)
public func inviteMember(
organizationID : String,
roles : [Role.RoleType],
email : String,
completion : @escaping (_ result: Result<Member, DisruptiveError>) -> ())
Invites a new member to an organization.
If the email belongs to a user that already has an account or a service account, the member
will get the status .accepted
immediately. Otherwise, the member will get the status .pending
,
and an invite email will be sent to the user.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String |
The identifier of the organization to invite a member to. |
roles | [Role.RoleType] |
The list of roles for the member. Currently, only one role is allowed for a member. The role has to be an organization based role (ie. |
String |
The email of the member to invite. Could be the email of a user or a service account. |
|
completion | @escaping (_ result: Result<Member, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
inviteMember(projectID:roles:email:completion:)
public func inviteMember(
projectID : String,
roles : [Role.RoleType],
email : String,
completion : @escaping (_ result: Result<Member, DisruptiveError>) -> ())
Invites a new member to a project.
If the email belongs to a user that already has an account or a service account, the member
will get the status .accepted
immediately. Otherwise, the member will get the status .pending
,
and an invite email will be sent to the user.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to invite a member to. |
roles | [Role.RoleType] |
The list of roles for the member. Currently, only one role is allowed for a member. The role has to be a project based role (ie. |
String |
The email of the member to invite. Could be the email of a user or a service account. |
|
completion | @escaping (_ result: Result<Member, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
updateMember(projectID:memberID:roles:completion:)
public func updateMember(
projectID : String,
memberID : String,
roles : [Role.RoleType],
completion : @escaping (_ result: Result<Member, DisruptiveError>) -> ())
Updates the Member of a project.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the Member is in. |
memberID | String |
The identifier of the Member to update. |
roles | [Role.RoleType] |
The new role to assign to the Member. Must be a role appropriate a project (ie. |
completion | @escaping (_ result: Result<Member, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
deleteMember(organizationID:memberID:completion:)
public func deleteMember(
organizationID : String,
memberID : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Deletes a member from an organization.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String |
The identifier of the organization the member is a part of. |
memberID | String |
The identifier of the member to delete. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
deleteMember(projectID:memberID:completion:)
public func deleteMember(
projectID : String,
memberID : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Deletes a member from a project.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the member is a part of. |
memberID | String |
The identifier of the member to delete. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getMemberInviteURL(organizationID:memberID:completion:)
public func getMemberInviteURL(
organizationID : String,
memberID : String,
completion : @escaping (_ result: Result<URL, DisruptiveError>) -> ())
Retrieves the invite URL that allows a new user to set up their account in an organization.
-
The
accountType
of the member must be.user
. -
The
status
of the member must be.pending
.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String |
The identifier of the organization the member is a part of. |
memberID | String |
The identifier of the member to get an invite URL for. |
completion | @escaping (_ result: Result<URL, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getMemberInviteURL(projectID:memberID:completion:)
public func getMemberInviteURL(
projectID : String,
memberID : String,
completion : @escaping (_ result: Result<URL, DisruptiveError>) -> ())
Retrieves the invite URL that allows a new user to set up their account in a project.
-
The
accountType
of the member must be.user
. -
The
status
of the member must be.pending
.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the member is a part of. |
memberID | String |
The identifier of the member to get an invite URL for. |
completion | @escaping (_ result: Result<URL, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getAllOrganizations(completion:)
public func getAllOrganizations(
completion: @escaping (_ result: Result<[Organization], DisruptiveError>) -> ())
Gets all the organizations available to the authenticated account.
This will handle pagination automatically and send multiple network requests in
the background if necessary. If a lot of organizations are expected to be available,
it might be better to load pages of organizations as they're needed using the
getOrganizationsPage
function instead.
Parameters
Name | Type | Description |
---|---|---|
completion | @escaping (_ result: Result<[Organization], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getOrganizationsPage(pageSize:pageToken:completion:)
public func getOrganizationsPage(
pageSize : Int = 100,
pageToken : String?,
completion : @escaping (_ result: Result<(nextPageToken: String?, organizations: [Organization]), DisruptiveError>) -> ())
Gets one page of organizations available to the authenticated account.
Useful if a lot of organizations are expected to be available. This function
provides better control for when to get organizations and how many to get at a time so
that organizations are only fetch when they are needed. This can also improve performance,
at a cost of convenience compared to the getAllOrganizations
function.
Parameters
Name | Type | Description |
---|---|---|
pageSize | Int |
The maximum number of organizations to get for this page. The maximum page size is 100, which is also the default |
pageToken | String? |
The token of the page to get. For the first page, set this to |
completion | @escaping (_ result: Result<(nextPageToken: String?, organizations: [Organization]), DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getOrganization(organizationID:completion:)
public func getOrganization(
organizationID: String,
completion: @escaping (_ result: Result<Organization, DisruptiveError>) -> ())
Gets a single organization based on an organization identifier.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String |
The identifier of the organization to get. |
completion | @escaping (_ result: Result<Organization, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getPermissions(organizationID:completion:)
public func getPermissions(
organizationID : String,
completion : @escaping (_ result: Result<[Permission], DisruptiveError>) -> ())
Gets all the permissions the currently logged in user has for the given organization.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String |
The identifier of the organization to get the permissions for. |
completion | @escaping (_ result: Result<[Permission], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getPermissions(projectID:completion:)
public func getPermissions(
projectID : String,
completion : @escaping (_ result: Result<[Permission], DisruptiveError>) -> ())
Gets all the permissions the currently logged in user has for the given project.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get the permissions for. |
completion | @escaping (_ result: Result<[Permission], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getAllProjects(organizationID:query:completion:)
public func getAllProjects(
organizationID : String? = nil,
query : String? = nil,
completion : @escaping (_ result: Result<[Project], DisruptiveError>) -> ())
Gets a list of all projects that matches the query
/organizationID
.
If an organizationID
is specified, only projects within this organization are fetched.
Otherwise, all the projects the authenticated account has access to is returned. A query
string can also be used for simple keyword based search.
This will handle pagination automatically and send multiple network requests in
the background if necessary. If a lot of projects are expected to be available,
it might be better to load pages of projects as they're needed using the
getProjectsPage
function instead.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String? |
Optional parameter. The identifier of the organization to get projects from. If not specified (or nil), will fetch all the project the authenticated account has access to. |
query | String? |
Optional parameter. Simple keyword based search. If not specified (or nil), all projects will be returned. |
completion | @escaping (_ result: Result<[Project], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getProjectsPage(organizationID:query:pageSize:pageToken:completion:)
public func getProjectsPage(
organizationID : String? = nil,
query : String? = nil,
pageSize : Int = 100,
pageToken : String?,
completion : @escaping (_ result: Result<(nextPageToken: String?, projects: [Project]), DisruptiveError>) -> ())
Gets one page of projects that matches the query
/organizationID
If an organizationID
is specified, only projects within this organization are fetched.
Otherwise, one page of the projects the authenticated account has access to is returned.
A query
string can also be used for simple keyword based search.
Useful if a lot of projects are expected to be available. This function
provides better control for when to get projects and how many to get at a time so
that projects are only fetch when they are needed. This can also improve performance,
at a cost of convenience compared to the getAllProjects
function.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String? |
Optional parameter. The identifier of the organization to get projects from. If not specified (or nil), will fetch projects the authenticated account has access to from all organizations. |
query | String? |
Optional parameter. Simple keyword based search. If not specified (or nil), any projects will be returned. |
pageSize | Int |
The maximum number of projects to get for this page. The maximum page size is 100, which is also the default |
pageToken | String? |
The token of the page to get. For the first page, set this to |
completion | @escaping (_ result: Result<(nextPageToken: String?, projects: [Project]), DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getProject(projectID:completion:)
public func getProject(
projectID : String,
completion : @escaping (_ result: Result<Project, DisruptiveError>) -> ())
Gets details for a specific project.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get details for. |
completion | @escaping (_ result: Result<Project, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
createProject(organizationID:displayName:completion:)
public func createProject(
organizationID : String,
displayName : String,
completion : @escaping (_ result: Result<Project, DisruptiveError>) -> ())
Creates a new project in a specific organization. The newly created project will be returned (including it's identifier, etc) if successful.
Parameters
Name | Type | Description |
---|---|---|
organizationID | String |
The identifier of the organization to create the project in. |
displayName | String |
The display name of the new project. |
completion | @escaping (_ result: Result<Project, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
deleteProject(projectID:completion:)
public func deleteProject(
projectID : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Deletes a project. Deleting a project can only be done if it has no devices, Service Accounts, or Data Connectors in it. Otherwise, an error will be returned.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to delete. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
updateProjectDisplayName(projectID:newDisplayName:completion:)
public func updateProjectDisplayName(
projectID : String,
newDisplayName : String,
completion : @escaping (_ result: Result<Project, DisruptiveError>) -> ())
Updates the display name of a project, and returns the new project (with the updated name) if successful.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to update the display name of. |
newDisplayName | String |
The new display name to set for the project. |
completion | @escaping (_ result: Result<Project, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getRoles(completion:)
public func getRoles(
completion: @escaping (_ result: Result<[Role], DisruptiveError>) -> ())
Get a list of all the available roles that can be assigned to a member of a project or an organization.
Parameters
Name | Type | Description |
---|---|---|
completion | @escaping (_ result: Result<[Role], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getRole(roleType:completion:)
public func getRole(
roleType: Role.RoleType,
completion: @escaping (_ result: Result<Role, DisruptiveError>) -> ())
Get the details for a specific role.
Parameters
Name | Type | Description |
---|---|---|
roleType | Role.RoleType |
The type of role to get. |
completion | @escaping (_ result: Result<Role, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getAllServiceAccounts(projectID:completion:)
public func getAllServiceAccounts(
projectID : String,
completion : @escaping (_ result: Result<[ServiceAccount], DisruptiveError>) -> ())
Gets all the Service Accounts that are available in a specific project.
This will handle pagination automatically and send multiple network requests in
the background if necessary. If a lot of Service Accounts are expected to be in the project,
it might be better to load pages of Service Accounts as they're needed using the
getServiceAccountsPage
function instead.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get Service Accounts from. |
completion | @escaping (_ result: Result<[ServiceAccount], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getServiceAccountsPage(projectID:pageSize:pageToken:completion:)
public func getServiceAccountsPage(
projectID : String,
pageSize : Int = 100,
pageToken : String?,
completion : @escaping (_ result: Result<(nextPageToken: String?, serviceAccounts: [ServiceAccount]), DisruptiveError>) -> ())
Gets one page of Service Accounts.
Useful if a lot of Service Accounts are expected in the specified project. This function
provides better control for when to get Service Accounts and how many to get at a time so
that Service Accounts are only fetch when they are needed. This can also improve performance,
at a cost of convenience compared to the getAllServiceAccounts
function.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get Service Accounts from. |
pageSize | Int |
The maximum number of Service Accounts to get for this page. The maximum page size is 100, which is also the default |
pageToken | String? |
The token of the page to get. For the first page, set this to |
completion | @escaping (_ result: Result<(nextPageToken: String?, serviceAccounts: [ServiceAccount]), DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getServiceAccount(projectID:serviceAccountID:completion:)
public func getServiceAccount(
projectID : String,
serviceAccountID : String,
completion : @escaping (_ result: Result<ServiceAccount, DisruptiveError>) -> ())
Gets a specific Service Account within a project by its identifier.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to get the Service Account from. |
serviceAccountID | String |
The identifier of the Service Account to get within the specified project. |
completion | @escaping (_ result: Result<ServiceAccount, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
createServiceAccount(projectID:displayName:basicAuthEnabled:completion:)
public func createServiceAccount(
projectID : String,
displayName : String,
basicAuthEnabled : Bool = false,
completion : @escaping (_ result: Result<ServiceAccount, DisruptiveError>) -> ())
Creates a new Service Account within a specific project.
NOTE: This Service Account will by default not have access to any resources.
In order to allow the Service Account to send API requests, add it as a Member
to a project
or an organization.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to create the Service Account in. |
displayName | String |
The display name to give the Service Account. |
basicAuthEnabled | Bool |
Whether or not the Service Account should be able to be authenticated using HTTP basic auth. This is not recommended in a production environment. The default value is |
completion | @escaping (_ result: Result<ServiceAccount, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
updateServiceAccount(projectID:serviceAccountID:displayName:basicAuthEnabled:completion:)
public func updateServiceAccount(
projectID : String,
serviceAccountID : String,
displayName : String? = nil,
basicAuthEnabled : Bool? = nil,
completion : @escaping (_ result: Result<ServiceAccount, DisruptiveError>) -> ())
Updates parameters of a specific Service Account. Only the parameters that are set will be updated, and the remaining will be left unchanged.
Examples:
// Enable basic auth
disruptive.updateServiceAccount(
projectID : "<PROJECT_ID>",
serviceAccountID : "<SERVICE_ACCOUNT_ID>",
basicAuthEnabled : true)
{ result in
...
}
// Change the display name
disruptive.updateServiceAccount(
projectID : "<PROJECT_ID>",
serviceAccountID : "<SERVICE_ACCOUNT_ID>",
displayName : "New Display Name")
{ result in
...
}
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the Service Account to update is in. |
serviceAccountID | String |
The identifier of the Service Account to update. |
displayName | String? |
The new display name to use for the Service Account. Will be ignored if not set (or |
basicAuthEnabled | Bool? |
Enables or disables HTTP basic auth for a Service Account. It is recommended to set this to false in a production environment. Will be ignored if not set (or |
completion | @escaping (_ result: Result<ServiceAccount, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
deleteServiceAccount(projectID:serviceAccountID:completion:)
public func deleteServiceAccount(
projectID : String,
serviceAccountID : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Deletes a Service Account.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project to delete the Service Account from. |
serviceAccountID | String |
The identifier of the Service Account to delete. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getAllServiceAccountKeys(projectID:serviceAccountID:completion:)
public func getAllServiceAccountKeys(
projectID : String,
serviceAccountID : String,
completion : @escaping (_ result: Result<[ServiceAccount.Key], DisruptiveError>) -> ())
Gets all the keys for a specific Service Account.
This will handle pagination automatically and send multiple network requests in
the background if necessary. If a lot of keys are expected to be available for the Service Account,
it might be better to load pages of keys as they're needed using the
getServiceAccountKeysPage
function instead.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the Service Account is in. |
serviceAccountID | String |
The identifier of the Service Account to get keys for. |
completion | @escaping (_ result: Result<[ServiceAccount.Key], DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getServiceAccountKeysPage(projectID:serviceAccountID:pageSize:pageToken:completion:)
public func getServiceAccountKeysPage(
projectID : String,
serviceAccountID : String,
pageSize : Int = 100,
pageToken : String?,
completion : @escaping (_ result: Result<(nextPageToken: String?, keys: [ServiceAccount.Key]), DisruptiveError>) -> ())
Gets one page of keys for a specific Service Account.
Useful if a lot of keys are expected to be available for this Service Account. This function
provides better control for when to get keys and how many to get at a time so
that keys are only fetch when they are needed. This can also improve performance,
at a cost of convenience compared to the getAllServiceAccountKeys
function.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the Service Account is in. |
serviceAccountID | String |
The identifier of the Service Account to get keys for. |
pageSize | Int |
The maximum number of keys to get for this page. The maximum page size is 100, which is also the default |
pageToken | String? |
The token of the page to get. For the first page, set this to |
completion | @escaping (_ result: Result<(nextPageToken: String?, keys: [ServiceAccount.Key]), DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
getServiceAccountKey(projectID:serviceAccountID:keyID:completion:)
public func getServiceAccountKey(
projectID : String,
serviceAccountID : String,
keyID : String,
completion : @escaping (_ result: Result<ServiceAccount.Key, DisruptiveError>) -> ())
Gets a single key for a specific Service Account.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the Service Account is in. |
serviceAccountID | String |
The identifier of the Service Account to get a key for. |
keyID | String |
The identifier of the key to get. |
completion | @escaping (_ result: Result<ServiceAccount.Key, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
createServiceAccountKey(projectID:serviceAccountID:completion:)
public func createServiceAccountKey(
projectID : String,
serviceAccountID : String,
completion : @escaping (_ result: Result<ServiceAccount.KeySecret, DisruptiveError>) -> ())
Creates a new key for a Service Account, and gets both the key and the corresponding secret in return.
Note a couple of things:
-
The secret that is returned can not be retrieved later, so make sure to take a note of it.
-
A Service Account can have a maximum of 10 keys.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the Service Account is in. |
serviceAccountID | String |
The identifier of the Service Account to create a new key for. |
completion | @escaping (_ result: Result<ServiceAccount.KeySecret, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
deleteServiceAccountKey(projectID:serviceAccountID:keyID:completion:)
public func deleteServiceAccountKey(
projectID : String,
serviceAccountID : String,
keyID : String,
completion : @escaping (_ result: Result<Void, DisruptiveError>) -> ())
Deletes a key for a Service Account.
This will prevent the Service Account from being able to authenticate using the deleted key.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the Service Account is in. |
serviceAccountID | String |
The identifier of the Service Account to delete a key for. |
keyID | String |
The identifier of the key to delete. |
completion | @escaping (_ result: Result<Void, DisruptiveError>) -> () |
The completion handler to be called when a response is received from the server. If successful, the |
result |
|
subscribeToDevices(projectID:deviceIDs:deviceTypes:productNumbers:labelFilters:eventTypes:)
public func subscribeToDevices(
projectID : String,
deviceIDs : [String]? = nil,
deviceTypes : [Device.DeviceType]? = nil,
productNumbers : [String]? = nil,
labelFilters : [String]? = nil,
eventTypes : [EventType]? = nil)
-> DeviceEventStream?
Sets up a device stream to one or more devices in a specific project using server-sent-events. By default, all events for all the devices in the specified project will be subscribed to. The various arguments are ways to limit which devices and event types gets subscribed to.
Example:
let stream = disruptive.subscribeToDevices(projectID: "<PROJECT_ID>")
stream?.onTemperature = { deviceID, tempEvent in
print("Got \(tempEvent) from \(deviceID)")
}
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project that contains the device(s). |
deviceIDs | [String]? |
An array of device identifiers to subscribe to. If not specified (or |
deviceTypes | [Device.DeviceType]? |
An array of device types to subscribe to. This is useful if |
productNumbers | [String]? |
An array of product numbers to subscribe to. This is the same product number that can be found on the support pages for both Sensors and Cloud Connectors. |
labelFilters | [String]? |
An array of label filter expressions that filters the set of devices for the results. Each expression takes the form labelKey=labelValue. |
eventTypes | [EventType]? |
An array of event types to subscribe to. |
Returns
A DeviceEventStream
device stream object with callbacks for each type of event. For example, set a closure on the onNetworkStatus
property to receive an event each time a device sends out a heart beat.
subscribeToDevice(projectID:deviceID:eventTypes:)
public func subscribeToDevice(projectID: String, deviceID: String, eventTypes: [EventType]? = nil) -> DeviceEventStream?
Convenience function to subscribe to just a single device. See subscribeToDevices
for more details.
Parameters
Name | Type | Description |
---|---|---|
projectID | String |
The identifier of the project the device is currently in. |
deviceID | String |
The identifier of the device to subscribe to. |
eventTypes | [EventType]? |
Optional parameter to specify which event types to subscribe to. If this is omitted, all the available event types for this device will be received. |