react-native-spike-sdk 1.0.23 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +243 -185
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/spikesdk/SpikeMappers.kt +9 -3
  4. package/android/src/main/java/com/spikesdk/SpikeSdkModule.kt +54 -98
  5. package/ios/SpikeConnectionListener.swift +1 -1
  6. package/ios/SpikeDataTypeMapper.swift +2 -2
  7. package/ios/SpikeExceptionMapper.swift +2 -0
  8. package/ios/SpikeSdk.m +1 -24
  9. package/ios/SpikeSdk.swift +15 -110
  10. package/lib/commonjs/Spike.js +4 -39
  11. package/lib/commonjs/Spike.js.map +1 -1
  12. package/lib/commonjs/SpikeBackgroundDeliveriesLogger.js +2 -0
  13. package/lib/{module/SpikeWebhookConnectionListener.js.map → commonjs/SpikeBackgroundDeliveriesLogger.js.map} +1 -1
  14. package/lib/commonjs/SpikeConnection.js +82 -8
  15. package/lib/commonjs/SpikeConnection.js.map +1 -1
  16. package/lib/commonjs/SpikeException.js +3 -1
  17. package/lib/commonjs/SpikeException.js.map +1 -1
  18. package/lib/commonjs/index.js +9 -8
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/module/Spike.js +4 -35
  21. package/lib/module/Spike.js.map +1 -1
  22. package/lib/module/SpikeBackgroundDeliveriesLogger.js +2 -0
  23. package/lib/{commonjs/SpikeWebhookConnectionListener.js.map → module/SpikeBackgroundDeliveriesLogger.js.map} +1 -1
  24. package/lib/module/SpikeConnection.js +82 -8
  25. package/lib/module/SpikeConnection.js.map +1 -1
  26. package/lib/module/SpikeException.js +1 -0
  27. package/lib/module/SpikeException.js.map +1 -1
  28. package/lib/module/index.js +4 -9
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/typescript/Spike.d.ts +10 -8
  31. package/lib/typescript/Spike.d.ts.map +1 -1
  32. package/lib/typescript/SpikeBackgroundDeliveriesLogger.d.ts +4 -0
  33. package/lib/typescript/SpikeBackgroundDeliveriesLogger.d.ts.map +1 -0
  34. package/lib/typescript/SpikeConnection.d.ts +21 -4
  35. package/lib/typescript/SpikeConnection.d.ts.map +1 -1
  36. package/lib/typescript/SpikeException.d.ts +2 -0
  37. package/lib/typescript/SpikeException.d.ts.map +1 -1
  38. package/lib/typescript/index.d.ts +6 -10
  39. package/lib/typescript/index.d.ts.map +1 -1
  40. package/package.json +1 -1
  41. package/react-native-spike-sdk.podspec +2 -2
  42. package/src/Spike.ts +16 -71
  43. package/src/SpikeBackgroundDeliveriesLogger.ts +3 -0
  44. package/src/SpikeConnection.ts +157 -21
  45. package/src/SpikeException.ts +1 -0
  46. package/src/index.ts +6 -13
  47. package/lib/commonjs/SpikeWebhookConnection.js +0 -111
  48. package/lib/commonjs/SpikeWebhookConnection.js.map +0 -1
  49. package/lib/commonjs/SpikeWebhookConnectionListener.js +0 -2
  50. package/lib/module/SpikeWebhookConnection.js +0 -104
  51. package/lib/module/SpikeWebhookConnection.js.map +0 -1
  52. package/lib/module/SpikeWebhookConnectionListener.js +0 -2
  53. package/lib/typescript/SpikeWebhookConnection.d.ts +0 -22
  54. package/lib/typescript/SpikeWebhookConnection.d.ts.map +0 -1
  55. package/lib/typescript/SpikeWebhookConnectionListener.d.ts +0 -4
  56. package/lib/typescript/SpikeWebhookConnectionListener.d.ts.map +0 -1
  57. package/src/SpikeWebhookConnection.ts +0 -173
  58. package/src/SpikeWebhookConnectionListener.ts +0 -3
package/README.md CHANGED
@@ -1,15 +1,43 @@
1
1
  Spike ReactNative SDK is a library on top of Apple HealthKit and Android HealthConnect that 
2
2
 
3
- 1. helps with the extraction of data.
3
+ 1. Helps with the extraction of data.
4
4
 
5
- 2. pushes data to SpikeAPI and delivers standardized data.
5
+ 2. Pushes data to SpikeAPI and delivers standardized data.
6
6
 
7
- ## Requirements
7
+ # Table of contents
8
+
9
+ - [Requirements](#requirements)
10
+ - [Installation](#installation)
11
+ - [iOS Setup](#ios_setup)
12
+ - [Android Setup](#android_setup)
13
+ - [Spike SDK usage](#sdk_usage)
14
+ 1. [Create Spike connection](#create_connection)
15
+ 2. [Permissions](#permissions)
16
+ 3. [Extract data](#extract_data)
17
+ - [Background deliveries (iOS Only)](#background_deliveries)
18
+ - [Logging](#logging)
19
+ - [Spike Data types](#spike_data_types)
20
+ - [Classes](#classes)
21
+ - [Errors and Exceptions](#exceptions)
22
+
23
+ ## Requirements <a name="requirements"></a>
8
24
 
9
25
  - iOS 13.0+
10
26
 
11
27
  - Android 9.0+
12
28
 
29
+ ## Installation <a name="installation"></a>
30
+
31
+ Install the `react-native-spike-sdk` package from [npm](https://www.npmjs.com/package/react-native-spike-sdk)
32
+
33
+ > yarn add react-native-spike-sdk
34
+
35
+ > npm install react-native-spike-sdk
36
+
37
+ Use `pod install` and `pod update` commands from `ios/` folder of your app to install/update pods afterward.
38
+
39
+ ## iOS Setup <a name="ios_setup"></a>
40
+
13
41
  ### iOS Signing & Capabilities
14
42
 
15
43
  To add HealthKit support to your application's Capabilities.
@@ -18,9 +46,9 @@ To add HealthKit support to your application's Capabilities.
18
46
 
19
47
  - Select the project name in the left sidebar
20
48
 
21
- - Open Signing & Capabilities section
49
+ - Open `Signing & Capabilities` section
22
50
 
23
- - In the main view select `+ Capability` and double click HealthKit
51
+ - In the main view select `+ Capability` and double click `HealthKit`
24
52
 
25
53
  - Allow `Clinical Health Records` and `Background Delivery` if needed.
26
54
 
@@ -43,9 +71,10 @@ Add Health Kit permissions descriptions to your Info.plist file.
43
71
  <string>We will use your health information to better track workouts.</string>
44
72
  ```
45
73
 
46
- ## Android Setup
74
+ ## Android Setup <a name="android_setup"></a>
47
75
 
48
76
  First of all you have to add the required health permissions to a [resource file](https://developer.android.com/guide/topics/resources/providing-resources). You can reuse an existing one or create a new one. That allows you to fully utilise this SDK and to read the necessary data from apps that integrate with HealthConnect.
77
+ Create config.xml in the following path: android/app/src/main/res/values. Content of this file must be the following:
49
78
 
50
79
  ```xml
51
80
  <resources>
@@ -96,155 +125,158 @@ As well as that you have to add intent filter to your activity definition so tha
96
125
  </intent-filter>
97
126
  ```
98
127
 
99
- ## Installation
128
+ ## Spike SDK usage <a name="sdk_usage"></a>
100
129
 
101
- Install the react-native-spike-sdk package from [npm](https://www.npmjs.com/package/react-native-spike-sdk)
130
+ Start getting Spike data in 3 steps.
131
+ All Spike SDK async method calls should be wrapped into try catch block.
102
132
 
103
- > yarn add react-native-spike-sdk
133
+ ### 1. Create Spike connection <a name="create_connection"></a>
104
134
 
105
- Use `pod install` and `pod update` commands from `ios/` folder of your app to install/update pods afterward.
135
+ To set up the Spike SDK create [SpikeConnection](#class_SpikeConnection) instance with [SpikeConnectionConfig](#type_SpikeConnectionConfig) object.
136
+ From the 1.1.x version Spike SDK automatically manages connection persistance and restore connection if finds one with same `appId`, `authToken` and `customerEndUserId`.
137
+ With each new connection creating call `callbackUrl` and `env` could be overridden.
138
+ Provide [SpikeLogger](#class_SpikeLogger) implementation to handle connection logs.
106
139
 
107
- ## Configuration
140
+ ```javascript
141
+ import Spike from 'react-native-spike-sdk';
108
142
 
109
- &#x20; 1\. Import Spike to your project.
143
+ const conn = await Spike.createConnection(
144
+ {
145
+ appId: 'my_app_id',
146
+ authToken: 'my_app_access_token',
147
+ customerEndUserId: 'my_user_id',
148
+ callbackUrl: 'my_callback_url', // Optional, provides functionality to send data to webhook and use background deliveries.
149
+ env: SpikeEnvironment.PROD, // Optional, default value PROD.
150
+ },
151
+ logger // Optional, class which conforms to SpikeLogger interface
152
+ );
153
+ ```
110
154
 
111
- > import Spike from 'react-native-spike-sdk';
155
+ ### 2. Permissions <a name="permissions"></a>
112
156
 
113
- &#x20; 2\. Add Spike initialization code to `ios/<Project Name>/AppDelegate.mm` file inside `application:didFinishLaunchingWithOptions: `method.
157
+ Provide permissions to access iOS HealthKit and Android HealthConnect data. Spike SDK methods will check required permissions and request them if needed. Permission dialog may not be shown according on platform permissions rules.
114
158
 
115
159
  ```javascript
116
- #import <SpikeSDK/SpikeSDK-Swift.h>
117
- ...
118
-
119
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
120
- {
121
- ...
122
- [Spike configure];
123
- ...
160
+ // conn was created in the previous step
124
161
 
162
+ if (Platform.OS === 'android') {
163
+ await conn.checkPermissionsGranted(); // Method should be called on connection instance
125
164
  }
126
165
 
166
+ if (Platform.OS === 'ios') {
167
+ await Spike.ensurePermissionsAreGranted([
168
+ // Method should be called on Spike class
169
+ SpikeDataTypes.activitiesStream,
170
+ SpikeDataTypes.steps,
171
+ ]); // Provide required Spike data types
172
+ }
127
173
  ```
128
174
 
129
- &#x20; 3\. To set up the React Native SDK, please provide the application ID, authentication token, and your customer user ID. You can find the application ID and authentication token in the Spike developer console. Personal identifiable information, such as emails, should not be part of user IDs.
175
+ ### 3. Extract data <a name="extract_data"></a>
130
176
 
131
- ```javascript
132
- import Spike from 'react-native-spike-sdk';
177
+ There are two ways to get Spike data: to your webhook or directly in your app. Extract data methods requires [SpikeExtractConfig](#type_SpikeExtractConfig) object, where date range can be provided optionally. By providing range greater than one day samples array of result object will be empty. The maximum permitted date range for iOS is 90 days, while for Android it's 30 days.
133
178
 
134
- const conn = await Spike.createConnection(
135
- 'my_app_id',
136
- 'my_app_access_token',
137
- 'my_user_id'
138
- );
139
- ```
179
+ #### Extract data locally
140
180
 
141
- ## Getting and using data
142
-
143
- Once a connection has been created data can be retrieved using the extractData method. The below example shows how to retrieve daily steps for today which are returned as part of the activities summary (An instance of SpikeData). The concrete type will depend on the data type requested.
181
+ According to the provided [SpikeDataType](#spike_data_types) result object may be different. See all Spike Data Entry objects here.
144
182
 
145
183
  ```javascript
146
184
  // conn was created in the previous step
147
185
 
148
- /*
149
- * Extracting activities summary data for today.
150
- */
151
- const activitiesSummary = await conn.extractData(
152
- SpikeDataTypes.activitiesSummary
153
- );
154
-
155
- /*
156
- * Accessing daily steps.
157
- */
158
- console.log('Steps:', activitiesSummary.entries[0].steps);
186
+ // Extract steps data for today
187
+ const data = await conn.extractData({
188
+ dataType: SpikeDataTypes.steps,
189
+ });
159
190
  ```
160
191
 
161
- ### Extracting data by time range
162
-
163
- Params `from` and `to` enable the extraction of local device data for the given time range. The maximum allowed single-query time interval is 7 days. If required, data of any longer time period can be accessed by iterating multiple queries of 7 days.
164
-
165
192
  ```javascript
166
- const toDate = new Date(); // Today's date
167
-
168
- const fromDate = new Date(toDate);
169
- fromDate.setDate(toDate.getDate() - 5); // 5 days ago
193
+ // conn was created in the previous step
170
194
 
171
- const activitiesSummary = await conn.extractDataInRange(
172
- SpikeDataTypes.activitiesSummary,
173
- fromDate,
174
- toDate
175
- );
195
+ // Extract steps data for yesterday and today.
196
+ const today = new Date();
197
+ const yesterday = new Date().setDate(today.getDate() - 1);
198
+ const data = await conn.extractData({
199
+ dataType: SpikeDataTypes.steps,
200
+ from: yesterday,
201
+ to: today,
202
+ });
176
203
  ```
177
204
 
178
- ### Sending data to webhook
205
+ #### Extract data to webhook
179
206
 
180
- Extracts local device data for the given time range and sends it as a webhook notification to the customer’s backend.
207
+ Ensure `callbackUrl` was provided to [SpikeConnection](#class_SpikeConnection), otherwise you will get _SpikeCallbackURLNotProvidedException_ error.
208
+ Method will return job information object.
181
209
 
182
210
  ```javascript
183
- import Spike from 'react-native-spike-sdk';
211
+ // conn was created in the previous step
184
212
 
185
- const conn = await Spike.createWebhookConnection(
186
- 'my_app_id',
187
- 'my_app_access_token',
188
- 'my_user_id',
189
- 'https://example.com/data'
190
- );
213
+ // Send today's steps data to webhook
214
+ const data = await conn.extractAndPostData({
215
+ dataType: SpikeDataTypes.steps,
216
+ });
217
+ ```
191
218
 
192
- /*
193
- * Extracting and sending activities summary data.
194
- */
195
- const response = await conn.extractAndPostData(
196
- SpikeDataTypes.activitiesSummary
197
- );
219
+ ```javascript
220
+ // conn was created in the previous step
221
+
222
+ // Send yesterday's and today's steps data to webhook
223
+ const today = new Date();
224
+ const yesterday = new Date().setDate(today.getDate() - 1);
225
+ const data = await conn.extractAndPostData({
226
+ dataType: SpikeDataTypes.steps,
227
+ from: yesterday,
228
+ to: today,
229
+ });
198
230
  ```
199
231
 
200
- ### Sending data to webhook by time range
232
+ ## Background deliveries (iOS Only) <a name="background_deliveries"></a>
233
+
234
+ Background delivery enables asynchronous data delivery to the customer backend by means of webhooks. It enables data updates to be sent to the backend even when the application is hidden or closed. Background delivery is only supported on iOS devices at the moment. Background deliveries will send whole day data to the webhook.
235
+
236
+ ### Configure for background deliveries
201
237
 
202
- Params `from` and `to` enable the extraction of local device data for the given time range. The maximum allowed single-query time interval is 7 days. If required, data of any longer time period can be accessed by iterating multiple queries of 7 days.
238
+ Under your project `Signing & Capabilities` section enable `Background Delivery` for `HealthKit`.
239
+ Call Spike configure methods on each app start to trigger background deliveries tasks.
240
+ Add Spike initialization code to `ios/<Project Name>/AppDelegate.mm` file inside `application:didFinishLaunchingWithOptions:` method.
203
241
 
204
242
  ```javascript
205
- const toDate = new Date(); // Today's date
243
+ #import <SpikeSDK/SpikeSDK-Swift.h>
244
+ ...
206
245
 
207
- const fromDate = new Date(toDate);
208
- fromDate.setDate(toDate.getDate() - 5); // 5 days ago
246
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
247
+ {
248
+ ...
249
+ [Spike configure];
250
+ ...
209
251
 
210
- const activitiesSummary = await conn.extractAndPostDataInRange(
211
- SpikeDataTypes.activitiesSummary,
212
- fromDate,
213
- toDate
214
- );
252
+ }
215
253
  ```
216
254
 
217
- ## Background Delivery
218
-
219
- Background delivery enables asynchronous data delivery to the customer backend by means of webhooks. It enables data updates to be sent to the backend even when the application is hidden or closed. Background delivery is only supported on iOS devices at the moment.
255
+ ### Register connection for background deliveries
220
256
 
221
- ### Example
257
+ Ensure `callbackUrl` was provided to [SpikeConnection](#class_SpikeConnection), otherwise you will get _SpikeCallbackURLNotProvidedException_ error.
258
+ Provide required [Spike Data types](#spike_data_types) to `enableBackgroundDelivery` method, it could be called after connection is created.
222
259
 
223
260
  ```javascript
224
- import Spike from 'react-native-spike-sdk';
225
-
226
- const conn = await Spike.createWebhookConnection(
227
- 'my_app_id',
228
- 'my_app_access_token',
229
- 'my_user_id',
230
- 'https://example.com/data'
231
- );
232
-
233
- /*
234
- * Enabling background delivery.
235
- */
236
- conn.enableBackgroundDelivery([SpikeDataTypes.activitiesSummary]);
261
+ await conn.enableBackgroundDelivery([
262
+ SpikeDataTypes.activitiesSummary,
263
+ SpikeDataTypes.steps,
264
+ ]);
237
265
  ```
238
266
 
239
- - If `dataTypes` is not empty, then a daemon task is started which will listen for data updates coming from the platform and send them via webhooks in the background; the operation is not compound and new data types replace any previously configured ones should they exist;
267
+ - If `dataTypes` is not empty, then a daemon task is started which will listen for data updates coming from the platform and send them via webhooks in the background; the operation is not compound and each method call will override enabled background data types list;
240
268
 
241
269
  - If `dataTypes` parameter is empty or null, then background data delivery is stopped for this connection if it was enabled;
242
270
 
243
- - Function `conn.getBackgroundDeliveryDataTypes` gets the data types for which background delivery is enabled. If background delivery is not enabled, an empty set is returned.
271
+ You can check if connection have active background deliveries listeners. If background delivery is not enabled, an empty set is returned.
244
272
 
245
- ## Logging
273
+ ```javascript
274
+ const dataTypes = await conn.getBackgroundDeliveryDataTypes();
275
+ ```
276
+
277
+ ## Logging <a name="logging"></a>
246
278
 
247
- Internally, the React Native SDK supports logging on various levels to assist with troubleshooting. However, to avoid imposing additional third-party dependencies on library users, the SDK expects a concrete logging implementation to be provided externally. This can be done by implementing the SpikeLogger class and providing it when creating or unpacking a connection.
279
+ Internally, the React Native SDK supports logging on various levels to assist with troubleshooting. However, to avoid imposing additional third-party dependencies on library users, the SDK expects a concrete logging implementation to be provided externally. This can be done by implementing the [SpikeLogger](#class_SpikeLogger) class and providing it when creating a connection.
248
280
 
249
281
  Below is an example of how to implement a simple console logger.
250
282
 
@@ -262,28 +294,33 @@ class ConsoleLogger implements SpikeLogger {
262
294
  return true;
263
295
  }
264
296
 
265
- debug(message) {
266
- console.log('DEBUG:', message);
297
+ debug(connection: SpikeConnection, message: string) {
298
+ console.log(`[SPIKE_DEBUG] ${message}`);
267
299
  }
268
300
 
269
- info(message) {
270
- console.log('INFO:', message);
301
+ info(connection: SpikeConnection, message: string) {
302
+ console.log(`[SPIKE_INFO] ${message}`);
271
303
  }
272
304
 
273
- error(message) {
274
- console.log('ERROR:', message);
305
+ error(connection: SpikeConnection, message: string) {
306
+ console.log(`[SPIKE_ERROR] ${message}`);
275
307
  }
276
308
  }
309
+ ```
277
310
 
278
- const conn = Spike.createConnection(
279
- 'my_app_id',
280
- 'my_app_access_token',
281
- 'my_user_id',
282
- new ConsoleLogger()
283
- );
311
+ Spike SDK provides background delivery process logs. This can be done by implementing the [SpikeBackgroundDeliveriesLogger](#class_SpikeBackgroundDeliveriesLogger) class and providing it though connection's `setListener` method.
312
+
313
+ Below is an example of how to implement a simple console logger.
314
+
315
+ ```javascript
316
+ class BackgroundDeliveriesLogger implements SpikeBackgroundDeliveriesLogger {
317
+ onBackgroundLog(log: string) {
318
+ console.log(`[BACKGROUND_LOG] ${log}`);
319
+ }
320
+ }
284
321
  ```
285
322
 
286
- ## Data types
323
+ ## Spike Data types <a name="spike_data_types"></a>
287
324
 
288
325
  - SpikeDataTypes.activitiesStream
289
326
  - SpikeDataTypes.activitiesSummary
@@ -298,102 +335,123 @@ const conn = Spike.createConnection(
298
335
  - SpikeDataTypes.sleep
299
336
  - SpikeDataTypes.steps
300
337
 
301
- ## Classes
302
-
303
- ### Spike
304
-
305
- | Class | Method | Description |
306
- | ----- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
307
- | Spike | createConnection | Creates a new SpikeConnection instance with the given user details.**Parameters**: appId, authToken, customerEndUserId, logger**Returns**: An instance of the SpikeConnection class. |
308
- | Spike | createWebhookConnection | Creates a new connection instance with the given user details that is capable of delivering data to the customer backend via **_webhooks_**.**Parameters**: appId, authToken, customerEndUserId, callbackUrl, logger**Returns**: An instance of the SpikeWebhookConnection class. |
309
- | Spike | unpackConnection | Restores a connection instance from a previously serialised state. A connection cannot be unpacked if a strong reference to a connection with the same session ID already exists.**Parameters:** connection, logger**Returns: **An instance of the SpikeConnection or SpikeWebhookConnection class. The method return type should be that of a base class, i.e., SpikeConnection. |
310
- | Spike | getBackgroundConnections | Returns all connections that are configured to deliver data in the background.**Returns: **A collection (a set) of SpikeWebhookConnection instances. |
311
- | Spike | ensurePermissionsAreGranted | Verifies that platform-specific permissions corresponding to the Spike data types provided are granted. In the event that some permissions are not granted, a platform-specific permissions dialogue will be presented to the end-user.This method should only be invoked from a UI component**Parameters: **permissions (Set\<SpikeDataType>) |
312
-
313
- ### SpikeConnection
314
-
315
- | Class | Method | Description | iOS | Android |
316
- |-----------------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|---------|
317
- | SpikeConnection | getAppId | Retrieves the unique Spike application identifier.**Returns**: string | yes | yes |
318
- | SpikeConnection | getSpikeEndUserId | Retrieves the unique identifier assigned to the end-user by Spike.**Returns**: string | yes | yes |
319
- | SpikeConnection | getCustomerEndUserId | Retrieves the unique identifier assigned to the end-user by the customer.**Returns**: string | yes | yes |
320
- | SpikeConnection | close | Terminates any ongoing connections with Spike’s backend servers, clears any caches, and removes provided user details and tokens from the memory. Once the connection is closed, it cannot be used, and any method other than close() will throw a _SpikeConnectionIsClosed_ exception. | yes | yes |
321
- | SpikeConnection | extractData | Extracts local device data for the current date in the end-user’s time zone.**Parameters**: dataType(SpikeDataType)**Returns**: An instance of SpikeData. The concrete type will depend on the data type requested. | yes | yes |
322
- | SpikeConnection | extractDataInRange | Extracts local device data for the given time range. \***\*The maximum allowed single-query time interval is 7 days. If required, data of any longer time period can be accessed by iterating multiple queries of 7 days.\*\*\*\***Parameters**: dataType(SpikeDataType), from(DateTime), to(DateTime)**Returns\*\*: An instance of SpikeData. The concrete type will depend on the data type requested. | yes | yes |
323
- | SpikeConnection | pack | Creates a string representation of the connection state. This method facilitates the persistence of connections.**Returns**: String | yes | yes |
324
- | SpikeConnection | manageHealthConnect | Opens your device's HealthConnect menu, where you can switch on and off data access for the app as well as delete data. | no | yes |
325
- | SpikeConnection | checkPermissionsGranted | Initiates a check on whether all health permissions have been granted to ensure proper functioning of the SDK | no | yes |
326
- | SpikeConnection | getHealthConnectAvailability | Provides information on whether HealthConnect is available on the device. | no | yes |
327
- | SpikeConnection | revokeAllPermissions | Revokes all granted health permissions for the application. | no | yes |
328
- | SpikeConnection | requestHealthPermissions | Requests all the supported health read permissions from HealthConnect. | no | yes |
329
-
330
- ### SpikeWebhookConnection
331
-
332
- | Class | Method | Description | iOS | Android |
333
- | ---------------------- |--------------------------------| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |------|---------|
334
- | SpikeWebhookConnection | getAppId | Retrieves the unique Spike application identifier.**Returns**: string | yes | yes |
335
- | SpikeWebhookConnection | getSpikeEndUserId | Retrieves the unique identifier assigned to the end-user by Spike.**Returns**: string | yes | yes |
336
- | SpikeWebhookConnection | getCustomerEndUserId | Retrieves the unique identifier assigned to the end-user by the customer.**Returns**: string | yes | yes |
337
- | SpikeWebhookConnection | getCallbackUrl | Returns the URL that will receive webhook notifications. | yes | yes |
338
- | SpikeWebhookConnection | close | Terminates any ongoing connections with Spike’s backend servers, clears any caches, and removes provided user details and tokens from the memory. Once the connection is closed, it cannot be used, and any method other than close() will throw a _SpikeConnectionIsClosed_ exception. | yes | yes |
339
- | SpikeWebhookConnection | extractData | Extracts local device data for the current date in the end-user’s time zone.**Parameters**: dataType(SpikeDataType)**Returns**: An instance of SpikeData. The concrete type will depend on the data type requested. | yes | yes |
340
- | SpikeWebhookConnection | extractDataInRange | Extracts local device data for the given time range. \***\*The maximum allowed single-query time interval is 7 days. If required, data of any longer time period can be accessed by iterating multiple queries of 7 days.\*\*\*\***Parameters**: dataType(SpikeDataType), from(DateTime), to(DateTime)**Returns\*\*: An instance of SpikeData. The concrete type will depend on the data type requested. | yes | yes |
341
- | SpikeWebhookConnection | extractAndPostData | Extracts local device data for the current date in the local user time zone and sends it as a webhook notification to the customer’s backend.**Parameters**: dataType(SpikeDataType) | yes | yes |
342
- | SpikeWebhookConnection | extractAndPostDataInRange | Extracts local device data for the given time range and sends it as a webhook notification to the customer’s backend.**Parameters**: dataType(SpikeDataType), from(DateTime), to(DateTime) | yes | yes |
343
- | SpikeWebhookConnection | enableBackgroundDelivery&#xA; | Enables background data delivery for selected data types. No-op on Android (for now).**Parameters**: dataType(SpikeDataType) | yes | no |
344
- | SpikeWebhookConnection | getBackgroundDeliveryDataTypes | Gets the data types for which background delivery is enabled. If background delivery is not enabled, an empty set is returned.**Returns**: Returns: A collection (a set) of SpikeDataType objects. | yes | no |
345
- | SpikeWebhookConnection | pack | Creates a string representation of the connection state. This method facilitates the persistence of connections.**Returns**: String | yes | no |
346
- | SpikeWebhookConnection | setListener | Sets a listener that is to handle notifications from the background delivery process.**Parameters: **listener(SpikeWebhookConnectionListener)\* If listener is not null, then any existing listener is replaced | yes | no |
347
- | SpikeWebhookConnection | manageHealthConnect | Opens your device's HealthConnect menu, where you can switch on and off data access for the app as well as delete data. | no | yes |
348
- | SpikeWebhookConnection | checkPermissionsGranted | Initiates a check on whether all health permissions have been granted to ensure proper functioning of the SDK | no | yes |
349
- | SpikeWebhookConnection | getHealthConnectAvailability | Provides information on whether HealthConnect is available on the device. | no | yes |
350
- | SpikeWebhookConnection | revokeAllPermissions | Revokes all granted health permissions for the application. | no | yes |
351
- | SpikeWebhookConnection | requestHealthPermissions | Requests all the supported health read permissions from HealthConnect. | no | yes |
352
-
353
- - If listener is null, then any existing listener is removed |
354
-
355
- ### SpikeWebhookConnectionListener
338
+ ## Classes <a name="classes"></a>
339
+
340
+ ### Spike <a name="class_Spike"></a>
341
+
342
+ | Class | Method | Description |
343
+ | ----- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
344
+ | Spike | createConnection | Creates a new SpikeConnection instance with the given user details.<br />**Parameters:** config ([SpikeConnectionConfig](#type_SpikeConnectionConfig)), logger? ([SpikeLogger](#class_SpikeLogger)) .<br />**Returns:** An instance of the SpikeConnection class ([SpikeConnection](#class_SpikeConnection)). |
345
+ | Spike | getBackgroundConnections | Returns all connections that are configured to deliver data in the background.<br />**Returns:** An array of SpikeConnection instances with callbackUrl (Array\<[SpikeConnection](#class_SpikeConnection)>). |
346
+ | Spike | ensurePermissionsAreGranted | Verifies that platform-specific permissions corresponding to the Spike data types provided are granted. In the event that some permissions are not granted, a platform-specific permissions dialogue will be presented to the end-user. This method should only be invoked from a UI component.<br />**Parameters:** permissions (Array\<[SpikeDataType](#spike_data_types)>) |
347
+
348
+ ### SpikeConnection <a name="class_SpikeConnection"></a>
349
+
350
+ | Class | Method | Description | iOS | Android |
351
+ | --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- | ------- |
352
+ | SpikeConnection | getAppId | Retrieves the unique Spike application identifier.<br />**Returns:** appId (string) | yes | yes |
353
+ | SpikeConnection | getSpikeEndUserId | Retrieves the unique identifier assigned to the end-user by Spike.<br />**Returns:** spikeEndUserId (string) | yes | yes |
354
+ | SpikeConnection | getCustomerEndUserId | Retrieves the unique identifier assigned to the end-user by the customer.<br />**Returns:** customerEndUserId (string) | yes | yes |
355
+ | SpikeConnection | getCallbackUrl | Returns the URL that will receive webhook notifications.<br />**Returns:** callbackUrl (string) | yes | yes |
356
+ | SpikeConnection | close | Terminates any ongoing connections with Spike’s backend servers, clears any caches, and removes provided user details and tokens from the memory. Once the connection is closed, it cannot be used, and any method other than close() will throw a _SpikeConnectionIsClosedException_ exception. | yes | yes |
357
+ | SpikeConnection | extractData | Extracts local device data for the current date in the end-user’s time zone. Optionally time range can be provided.<br />**\*On iOS, the maximum allowed single-query time interval is 90 days. If required, data of any longer time period can be accessed by iterating multiple queries of 90 days.**<br />**\*On Android the earliest date data can be requested for is 30 days before a permission was given to the user's app to read from HealthConnect. There is no limit on how many days in total.**<br />**Parameters:** config ([SpikeExtractConfig](#type_SpikeExtractConfig))<br />**Returns:** An instance of SpikeData. The concrete type will depend on the data type requested | yes | yes |
358
+ | SpikeConnection | extractAndPostData | Extracts local device data for the current date in the local user time zone and sends it as a webhook notification to the customer’s backend. Optionally time range can be provided.<br />**\*On iOS, the maximum allowed single-query time interval is 90 days. If required, data of any longer time period can be accessed by iterating multiple queries of 90 days.**<br />**\*On Android the earliest date data can be requested for is 30 days before a permission was given to the user's app to read from HealthConnect. There is no limit on how many days in total.**<br />**Parameters:** config ([SpikeExtractConfig](#type_SpikeExtractConfig)) | yes | yes |
359
+ | SpikeConnection | setListener | Sets a listener that is to handle notifications from the background delivery process.<br />**Parameters:** listener ([SpikeBackgroundDeliveriesLogger](#class_SpikeBackgroundDeliveriesLogger))<br />**\*If listener is not null, then any existing listener is replaced** | yes | no |
360
+ | SpikeConnection | manageHealthConnect | Opens your device's HealthConnect menu, where you can switch on and off data access for the app as well as delete data. | no | yes |
361
+ | SpikeConnection | checkPermissionsGranted | Initiates a check on whether all health permissions have been granted to ensure proper functioning of the SDK | no | yes |
362
+ | SpikeConnection | getHealthConnectAvailability | Provides information on whether HealthConnect is available on the device. | no | yes |
363
+ | SpikeConnection | revokeAllPermissions | Revokes all granted health permissions for the application. | no | yes |
364
+ | SpikeConnection | requestHealthPermissions | Requests all the supported health read permissions from HealthConnect. | no | yes |
365
+
366
+ ### SpikeLogger <a name="class_SpikeLogger"></a>
367
+
368
+ Abstract class allowing to receive notifications from the SDK's processes.
369
+
370
+ | Class | Method | Description | iOS | Android |
371
+ | ----------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------ | --- | ------- |
372
+ | SpikeLogger | isDebugEnabled | Manages is Debug level logging enabled.<br />**Returns**: are Debug level logs enabled (boolean) | yes | yes |
373
+ | SpikeLogger | isInfoEnabled | Manages is Info level logging enabled.<br />**Returns**: are Info level logs enabled (boolean) | yes | yes |
374
+ | SpikeLogger | isErrorEnabled | Manages is Error level logging enabled.<br />**Returns**: are Error level logs enabled (boolean) | yes | yes |
375
+ | SpikeLogger | debug | Invoked on Spike SKD Debug log events.<br />**Parameters**: connection ([SpikeConnection](#class_SpikeConnection)), message (string) | yes | yes |
376
+ | SpikeLogger | info | Invoked on Spike SKD Info log events.<br />**Parameters**: connection ([SpikeConnection](#class_SpikeConnection)), message (string) | yes | yes |
377
+ | SpikeLogger | error | Invoked on Spike SKD Error log events.<br />**Parameters**: connection ([SpikeConnection](#class_SpikeConnection)), message (string) | yes | yes |
378
+
379
+ ### SpikeBackgroundDeliveriesLogger <a name="class_SpikeBackgroundDeliveriesLogger"></a>
356
380
 
357
381
  Abstract class allowing to receive notifications from the background data delivery process.
358
382
 
359
- | Class | Method | Description | iOS | Android |
360
- | ------------------------------ | --------------- | ------------------------------------------------------------------------------- | --- |---------|
361
- | SpikeWebhookConnectionListener | onBackgroundLog | Invoked on an asynchronous data submission failure.**Parameters**: log (String) | yes | no |
383
+ | Class | Method | Description | iOS | Android |
384
+ | ------------------------------- | --------------- | -------------------------------------------------------------------------- | --- | ------- |
385
+ | SpikeBackgroundDeliveriesLogger | onBackgroundLog | Invoked on background deliveries events.<br />**Parameters**: log (string) | yes | no |
386
+
387
+ ### SpikeConnectionConfig <a name="type_SpikeConnectionConfig"></a>
362
388
 
363
- # Errors and Exceptions
389
+ Type required to create Spike connection instance.
364
390
 
365
- ## SpikeException
391
+ | Type | Property | Type | Description | iOS | Android |
392
+ | --------------------- | ----------------- | ------------------------------------------ | --------------------------------------------------------------- | --- | ------- |
393
+ | SpikeConnectionConfig | appId | string | The unique Spike application identifier | yes | yes |
394
+ | SpikeConnectionConfig | authToken | string | The unique identifier assigned to the end-user by Spike. | yes | yes |
395
+ | SpikeConnectionConfig | customerEndUserId | string | the unique identifier assigned to the end-user by the customer. | yes | yes |
396
+ | SpikeConnectionConfig | callbackUrl | string | URL that will receive webhook notifications | yes | yes |
397
+ | SpikeConnectionConfig | env | [SpikeEnvironment](#type_SpikeEnvironment) | Spike environment | yes | yes |
398
+
399
+ ### SpikeExtractConfig <a name="type_SpikeExtractConfig"></a>
400
+
401
+ Type required to extract data.
402
+
403
+ | Type | Property | Type | Description | iOS | Android |
404
+ | ------------------ | -------- | ---------------------------------- | ------------------------------------------------------------------------------ | --- | ------- |
405
+ | SpikeExtractConfig | dataType | [SpikeDataType](#spike_data_types) | The Spike data type to make extraction for. | yes | yes |
406
+ | SpikeExtractConfig | from | Date (optional) | Extraction time range start date.<br />**\*Required if `to` property passed.** | yes | yes |
407
+ | SpikeExtractConfig | to | Date (optional) | Extraction time range end date.<br />**\*Required if `from` property passed.** | yes | yes |
408
+
409
+ ### SpikeEnvironment <a name="type_SpikeEnvironment"></a>
410
+
411
+ Type required to set Spike connection environment.
412
+
413
+ > 'PROD' - Production environment
414
+
415
+ > 'DEV' - Test environment
416
+
417
+ ## Errors and Exceptions <a name="exceptions"></a>
418
+
419
+ ### SpikeException
366
420
 
367
421
  The abstract parent of all concrete exceptions.
368
422
 
369
- ## SpikeConnectionIsClosedException
423
+ ### SpikeConnectionIsClosedException
370
424
 
371
425
  Thrown if any method is invoked on SpikeConnection or one of its subclasses after the connection has been closed.
372
426
 
373
- ## SpikeInvalidCredentialsException
427
+ ### SpikeInvalidCredentialsException
374
428
 
375
429
  Thrown if the credentials provided are not recognised, i.e. are invalid or expired.
376
430
 
377
- ## SpikeInvalidDateRangeException
431
+ ### SpikeInvalidDateRangeException
378
432
 
379
433
  Thrown if duration exceeds the allowed maximum or if ‘from’ date is greater than ‘to’ date. The message will contain a specific cause description.
380
434
 
381
- ## SpikeInvalidCallbackUrlException
435
+ ### SpikeInvalidCallbackUrlException
382
436
 
383
437
  Thrown if the callback URL is not a valid URL, does not have HTTPS schema, or is not a sub-URL of the main callback URL configured for the application. The exception message will contain a specific reason.
384
438
 
385
- ## SpikePackException
439
+ ### SpikePackException
386
440
 
387
441
  Thrown when a connection cannot be serialised to a packed state. The exception cause will contain the underlying error.
388
442
 
389
- ## SpikePermissionsNotGrantedException
443
+ ### SpikePermissionsNotGrantedException
390
444
 
391
445
  Thrown when Spike SDK is unable to access the data due to permissions not being granted.
392
446
 
393
- ## SpikeServerException
447
+ ### SpikeServerException
394
448
 
395
449
  Whenever any operation with the Spike backend fails and the error does not fall into any of the above exceptions. The exception cause will contain the underlying error.
396
450
 
397
- ## SpikeUnpackException
451
+ ### SpikeUnpackException
398
452
 
399
453
  Thrown when a connection cannot be deserialised from a packed state. The exception cause will contain the underlying error.
454
+
455
+ ### SpikeCallbackURLNotProvidedException
456
+
457
+ Thrown when a method which requires callback url is called, but callback url is not set for current connection.