DXDataClient
This class is responsible for making requests to the DX data API.
The DXDataClient
class allows you to create and update buckets to store your app's data. Buckets can be created for a single user for private data. or for multiple users, allowing them to access shared data. Buckets are essentially JSON objects with key-value pairs and can be updated by creating and writing to a new key, or overwriting an existing one.
You will need to enable the "Lightning Database" scope for your app in the developer dashboard before using the data API.
Properties
Singleton instance of DXDataClient
. You will access all the available DXDataClient
methods through this instance.
Methods
readPrivateData
Read a user's private app data.
Parameter | Type | Description |
userId |
| User id for the owner of the app data to retrieve. A user can only query for his or her own app data of the app data of their kids' accounts. |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
data |
| The private app data returned for a successful request. |
writePrivateData
Update a user's private app data.
Parameter | Type | Description |
atKey |
| Location in app data to update, using dot object notation. |
withValue |
| Value to insert or update at the location specified by the |
userId |
| User id for the owner of the app data to update. A user can only update his or her own app data or the app data of their kids' accounts. |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
data |
| The update data returned for a successful request. |
create
Create a named bucket and specify what users have access to it. By default, the user creating the bucket (the currently authenticated user) will have access to the bucket.
Parameter | Type | Description |
bucketNamed |
| Name given to the bucket. |
includingUsers |
| An array of DX user ids representing who will have access to the bucket; by default, the user creating the bucket will have access. |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
write
Write data to a bucket at a key. If key is an empty String
, the bucket will be overwritten with the value provided. If the key does not exist in the bucket, it will be created in the bucket as a key-value pair. All data written to a bucket has to conform to Swift's Codable
protocol (introduced in version 4.2), as it will otherwise cause an error when attempting to serialize the value to JSON. For more information on Codable
, check out this link.
Attempting to write to a bucket that hasn't been created will return an error.
Parameter | Type | Description |
toBucket |
| Name of the bucket being written to. |
atKey |
| Key in the bucket where the data will be written. For nested keys, use a period-separated string, e.g. "root.sub". |
withValue |
| The value being written to the bucket. |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
data |
| The newly updated bucket returned for an unsuccessful request. |
read
Read data from a bucket. If a key is provided, it will read data from that key in the bucket.
Attempting to read from a bucket that hasn't been created will return an error.
Parameter | Type | Description |
fromBucket |
| The name of the bucket being read from. |
atKey |
| If provided, will read data from the bucket at this key; defaults to nil, which will return the entire bucket. For nested keys, provided a period-separated string. |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
value |
| The data returned for a successful request. If no key is provided, the entire bucket will be returned, otherwise, the data at the key in the bucket will be returned. |
readAllBuckets
Read all buckets that the current user has access to. Will return an array of the buckets' names.
Parameter | Type | Description |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
buckets |
| An array of the names of the buckets the current user has access to. |
delete
Delete a key in the bucket, including all nested data at that key.
Attempting to delete a key in a bucket that hasn't been created will return an error.
Parameter | Type | Description |
fromBucket |
| Name of the bucket the key is being deleted from. |
atKey |
| The key in the bucket that is being deleted. |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
bucket |
| The updated bucket returned for a successful request. |
delete
Delete an entire bucket.
Attempting to delete a bucket that hasn't been created will return an error.
Parameter | Type | Description |
bucketNamed |
| Name of the bucket to delete. |
completion |
| The closure invoked when the request finishes. |
error |
| The error returned for an unsuccessful request. |
Last updated