react-native-spike-sdk 0.2.10 → 1.0.0
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.
- package/README.md +271 -146
- package/android/build.gradle +14 -1
- package/android/gradle.properties +2 -1
- package/android/src/main/java/com/spikesdk/SpikeConnectionLogger.kt +37 -0
- package/android/src/main/java/com/spikesdk/SpikeMappers.kt +61 -0
- package/android/src/main/java/com/spikesdk/SpikeSdkModule.kt +413 -8
- package/ios/SpikeConnectionListener.swift +17 -0
- package/ios/SpikeConnectionLogger.swift +43 -0
- package/ios/SpikeDataTypeMapper.swift +207 -0
- package/ios/SpikeExceptionMapper.swift +34 -0
- package/ios/SpikeSdk.m +84 -17
- package/ios/SpikeSdk.swift +460 -129
- package/lib/commonjs/DataModels/SpikeActivitiesStreamDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeActivitiesStreamDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeActivitiesSummaryDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeActivitiesSummaryDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeBreathingDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeBreathingDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeCaloriesDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeCaloriesDataEntry.js.map +1 -0
- package/lib/commonjs/{SpikeInterface.js → DataModels/SpikeData.js} +1 -1
- package/lib/commonjs/DataModels/SpikeData.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeDataTypes.js +22 -0
- package/lib/commonjs/DataModels/SpikeDataTypes.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeDistanceDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeDistanceDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeGlucoseDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeGlucoseDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeHeartDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeHeartDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeOxygenSaturationDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeOxygenSaturationDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeSleepDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeSleepDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeStepsDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeStepsDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeWebhookJob.js +2 -0
- package/lib/commonjs/DataModels/SpikeWebhookJob.js.map +1 -0
- package/lib/commonjs/DataTypes/SpikeDataType.js +53 -0
- package/lib/commonjs/DataTypes/SpikeDataType.js.map +1 -0
- package/lib/commonjs/Spike.js +61 -46
- package/lib/commonjs/Spike.js.map +1 -1
- package/lib/commonjs/SpikeConnection.js +104 -0
- package/lib/commonjs/SpikeConnection.js.map +1 -0
- package/lib/commonjs/SpikeException.js +27 -0
- package/lib/commonjs/SpikeException.js.map +1 -0
- package/lib/commonjs/SpikeLogger.js +6 -0
- package/lib/commonjs/{SpikeDataType.js.map → SpikeLogger.js.map} +1 -1
- package/lib/commonjs/SpikeSdk.js +1 -1
- package/lib/commonjs/SpikeSdk.js.map +1 -1
- package/lib/commonjs/SpikeWebhookConnection.js +119 -0
- package/lib/commonjs/SpikeWebhookConnection.js.map +1 -0
- package/lib/commonjs/SpikeWebhookConnectionListener.js +6 -0
- package/lib/commonjs/{SpikeResultData.js.map → SpikeWebhookConnectionListener.js.map} +1 -1
- package/lib/commonjs/index.js +26 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/DataModels/SpikeActivitiesStreamDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeActivitiesStreamDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeActivitiesSummaryDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeActivitiesSummaryDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeBreathingDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeBreathingDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeCaloriesDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeCaloriesDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeData.js +2 -0
- package/lib/module/DataModels/SpikeData.js.map +1 -0
- package/lib/module/DataModels/SpikeDataTypes.js +15 -0
- package/lib/module/DataModels/SpikeDataTypes.js.map +1 -0
- package/lib/module/DataModels/SpikeDistanceDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeDistanceDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeGlucoseDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeGlucoseDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeHeartDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeHeartDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeOxygenSaturationDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeOxygenSaturationDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeSleepDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeSleepDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeStepsDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeStepsDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeWebhookJob.js +2 -0
- package/lib/module/DataModels/SpikeWebhookJob.js.map +1 -0
- package/lib/module/DataTypes/SpikeDataType.js +36 -0
- package/lib/module/DataTypes/SpikeDataType.js.map +1 -0
- package/lib/module/Spike.js +56 -45
- package/lib/module/Spike.js.map +1 -1
- package/lib/module/SpikeConnection.js +97 -0
- package/lib/module/SpikeConnection.js.map +1 -0
- package/lib/module/SpikeException.js +11 -0
- package/lib/module/SpikeException.js.map +1 -0
- package/lib/module/SpikeLogger.js +2 -0
- package/lib/module/{SpikeDataType.js.map → SpikeLogger.js.map} +1 -1
- package/lib/module/SpikeSdk.js +1 -2
- package/lib/module/SpikeSdk.js.map +1 -1
- package/lib/module/SpikeWebhookConnection.js +112 -0
- package/lib/module/SpikeWebhookConnection.js.map +1 -0
- package/lib/module/SpikeWebhookConnectionListener.js +2 -0
- package/lib/{commonjs/SpikeSleepAnalysisResultData.js.map → module/SpikeWebhookConnectionListener.js.map} +1 -1
- package/lib/module/index.js +13 -5
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/{SpikeWorkoutResultData.d.ts → DataModels/SpikeActivitiesStreamDataEntry.d.ts} +15 -14
- package/lib/typescript/DataModels/SpikeActivitiesStreamDataEntry.d.ts.map +1 -0
- package/lib/typescript/{SpikeResultData.d.ts → DataModels/SpikeActivitiesSummaryDataEntry.d.ts} +5 -8
- package/lib/typescript/DataModels/SpikeActivitiesSummaryDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeBreathingDataEntry.d.ts +13 -0
- package/lib/typescript/DataModels/SpikeBreathingDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeCaloriesDataEntry.d.ts +15 -0
- package/lib/typescript/DataModels/SpikeCaloriesDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeData.d.ts +25 -0
- package/lib/typescript/DataModels/SpikeData.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeDataTypes.d.ts +15 -0
- package/lib/typescript/DataModels/SpikeDataTypes.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeDistanceDataEntry.d.ts +13 -0
- package/lib/typescript/DataModels/SpikeDistanceDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeGlucoseDataEntry.d.ts +4 -0
- package/lib/typescript/DataModels/SpikeGlucoseDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeHeartDataEntry.d.ts +32 -0
- package/lib/typescript/DataModels/SpikeHeartDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeOxygenSaturationDataEntry.d.ts +15 -0
- package/lib/typescript/DataModels/SpikeOxygenSaturationDataEntry.d.ts.map +1 -0
- package/lib/typescript/{SpikeSleepAnalysisResultData.d.ts → DataModels/SpikeSleepDataEntry.d.ts} +10 -13
- package/lib/typescript/DataModels/SpikeSleepDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeStepsDataEntry.d.ts +13 -0
- package/lib/typescript/DataModels/SpikeStepsDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeWebhookJob.d.ts +11 -0
- package/lib/typescript/DataModels/SpikeWebhookJob.d.ts.map +1 -0
- package/lib/typescript/DataTypes/SpikeDataType.d.ts +50 -0
- package/lib/typescript/DataTypes/SpikeDataType.d.ts.map +1 -0
- package/lib/typescript/Spike.d.ts +12 -13
- package/lib/typescript/Spike.d.ts.map +1 -1
- package/lib/typescript/SpikeConnection.d.ts +23 -0
- package/lib/typescript/SpikeConnection.d.ts.map +1 -0
- package/lib/typescript/SpikeException.d.ts +21 -0
- package/lib/typescript/SpikeException.d.ts.map +1 -0
- package/lib/typescript/SpikeLogger.d.ts +10 -0
- package/lib/typescript/SpikeLogger.d.ts.map +1 -0
- package/lib/typescript/SpikeSdk.d.ts.map +1 -1
- package/lib/typescript/SpikeWebhookConnection.d.ts +21 -0
- package/lib/typescript/SpikeWebhookConnection.d.ts.map +1 -0
- package/lib/typescript/SpikeWebhookConnectionListener.d.ts +6 -0
- package/lib/typescript/SpikeWebhookConnectionListener.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +16 -7
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/react-native-spike-sdk.podspec +2 -2
- package/src/{SpikeWorkoutResultData.ts → DataModels/SpikeActivitiesStreamDataEntry.ts} +14 -12
- package/src/{SpikeResultData.ts → DataModels/SpikeActivitiesSummaryDataEntry.ts} +4 -4
- package/src/DataModels/SpikeBreathingDataEntry.ts +12 -0
- package/src/DataModels/SpikeCaloriesDataEntry.ts +13 -0
- package/src/DataModels/SpikeData.ts +35 -0
- package/src/DataModels/SpikeDataTypes.ts +27 -0
- package/src/DataModels/SpikeDistanceDataEntry.ts +12 -0
- package/src/DataModels/SpikeGlucoseDataEntry.ts +3 -0
- package/src/DataModels/SpikeHeartDataEntry.ts +34 -0
- package/src/DataModels/SpikeOxygenSaturationDataEntry.ts +14 -0
- package/src/{SpikeSleepAnalysisResultData.ts → DataModels/SpikeSleepDataEntry.ts} +9 -7
- package/src/DataModels/SpikeStepsDataEntry.ts +11 -0
- package/src/DataModels/SpikeWebhookJob.ts +10 -0
- package/src/DataTypes/SpikeDataType.ts +87 -0
- package/src/Spike.ts +132 -73
- package/src/SpikeConnection.ts +151 -0
- package/src/SpikeException.ts +11 -0
- package/src/SpikeLogger.ts +11 -0
- package/src/SpikeSdk.ts +1 -3
- package/src/SpikeWebhookConnection.ts +201 -0
- package/src/SpikeWebhookConnectionListener.ts +9 -0
- package/src/index.ts +32 -20
- package/lib/commonjs/SpikeDataType.js +0 -2
- package/lib/commonjs/SpikeInterface.js.map +0 -1
- package/lib/commonjs/SpikeResultData.js +0 -2
- package/lib/commonjs/SpikeSleepAnalysisResultData.js +0 -2
- package/lib/commonjs/SpikeWorkoutResultData.js +0 -2
- package/lib/commonjs/SpikeWorkoutResultData.js.map +0 -1
- package/lib/commonjs/useSpikeEvents.js +0 -69
- package/lib/commonjs/useSpikeEvents.js.map +0 -1
- package/lib/module/SpikeDataType.js +0 -2
- package/lib/module/SpikeInterface.js +0 -2
- package/lib/module/SpikeInterface.js.map +0 -1
- package/lib/module/SpikeResultData.js +0 -2
- package/lib/module/SpikeResultData.js.map +0 -1
- package/lib/module/SpikeSleepAnalysisResultData.js +0 -2
- package/lib/module/SpikeSleepAnalysisResultData.js.map +0 -1
- package/lib/module/SpikeWorkoutResultData.js +0 -2
- package/lib/module/SpikeWorkoutResultData.js.map +0 -1
- package/lib/module/useSpikeEvents.js +0 -62
- package/lib/module/useSpikeEvents.js.map +0 -1
- package/lib/typescript/SpikeDataType.d.ts +0 -2
- package/lib/typescript/SpikeDataType.d.ts.map +0 -1
- package/lib/typescript/SpikeInterface.d.ts +0 -13
- package/lib/typescript/SpikeInterface.d.ts.map +0 -1
- package/lib/typescript/SpikeResultData.d.ts.map +0 -1
- package/lib/typescript/SpikeSleepAnalysisResultData.d.ts.map +0 -1
- package/lib/typescript/SpikeWorkoutResultData.d.ts.map +0 -1
- package/lib/typescript/useSpikeEvents.d.ts +0 -17
- package/lib/typescript/useSpikeEvents.d.ts.map +0 -1
- package/src/SpikeDataType.ts +0 -12
- package/src/SpikeInterface.ts +0 -30
- package/src/useSpikeEvents.ts +0 -89
package/README.md
CHANGED
|
@@ -1,207 +1,170 @@
|
|
|
1
|
-
|
|
1
|
+
Spike ReactNative SDK is a library on top of Apple HealthKit and Android HealthConnect that 
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
1. helps with the extraction of data.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
2. pushes data to SpikeAPI and delivers standardized data.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- [Installation](#installation)
|
|
9
|
-
- [Configure and Start](#configure)
|
|
10
|
-
- [Setup SpikeSDKDelegate](#delegate)
|
|
11
|
-
- [Setup SpikeSDK](#setup_sdk)
|
|
12
|
-
- [Get data](#get_data)
|
|
13
|
-
- [Enable debug mode](#debug)
|
|
14
|
-
- [Background data updates](#background_updates)
|
|
7
|
+
## Requirements
|
|
15
8
|
|
|
16
|
-
|
|
9
|
+
* iOS 13.0+
|
|
17
10
|
|
|
18
|
-
|
|
11
|
+
* Android 9.0+
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
### iOS Signing & Capabilities
|
|
21
14
|
|
|
22
|
-
To add HealthKit support to your application's
|
|
15
|
+
To add HealthKit support to your application's Capabilities.
|
|
23
16
|
|
|
24
|
-
|
|
25
|
-
- Select the project name in the left sidebar
|
|
26
|
-
- Open `Signing & Capabilities` section.
|
|
27
|
-
- In the main view select '+ Capability' and double click `HealthKit`
|
|
28
|
-
- Allow `Clinical Health Records` and `Background Delivery` if needed.
|
|
17
|
+
* Open the ios/ folder of your project in Xcode
|
|
29
18
|
|
|
30
|
-
|
|
19
|
+
* Select the project name in the left sidebar
|
|
31
20
|
|
|
32
|
-
|
|
21
|
+
* Open Signing & Capabilities section
|
|
33
22
|
|
|
34
|
-
|
|
23
|
+
* In the main view select '+ Capability' and double click HealthKit
|
|
24
|
+
|
|
25
|
+
* Allow Clinical Health Records.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
More details you can find [here](https://developer.apple.com/documentation/healthkit/setting_up_healthkit).
|
|
31
|
+
|
|
32
|
+
### Info.plist
|
|
33
|
+
|
|
34
|
+
Add Health Kit permissions descriptions to your Info.plist file.
|
|
35
|
+
|
|
36
|
+
```xml
|
|
35
37
|
<key>NSHealthShareUsageDescription</key>
|
|
36
|
-
<string>We will use your health information to better track
|
|
38
|
+
<string>We will use your health information to better track workouts.</string>
|
|
37
39
|
|
|
38
40
|
<key>NSHealthUpdateUsageDescription</key>
|
|
39
|
-
<string>We will update your health information to better track
|
|
41
|
+
<string>We will update your health information to better track workouts.</string>
|
|
40
42
|
|
|
41
43
|
<key>NSHealthClinicalHealthRecordsShareUsageDescription</key>
|
|
42
|
-
<string>We will use your health information to better track
|
|
44
|
+
<string>We will use your health information to better track workouts.</string>
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
## Installation
|
|
47
|
+
## Installation
|
|
46
48
|
|
|
47
49
|
Install the react-native-spike-sdk package from [npm](https://www.npmjs.com/package/react-native-spike-sdk)
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
yarn add react-native-spike-sdk
|
|
51
|
-
```
|
|
51
|
+
> yarn add react-native-spike-sdk
|
|
52
52
|
|
|
53
53
|
Use `pod install` and `pod update` commands from `ios/` folder of your app to install/update pods afterward.
|
|
54
54
|
|
|
55
|
-
##
|
|
55
|
+
## Configuration
|
|
56
56
|
|
|
57
|
-
Import
|
|
57
|
+
  1\. Import Spike to your project.
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
import Spike from 'react-native-spike-sdk';
|
|
61
|
-
```
|
|
59
|
+
> import Spike from 'react-native-spike-sdk';
|
|
62
60
|
|
|
63
|
-
Add Spike initialization code to `ios/<Project Name>/AppDelegate.mm` file inside `application:didFinishLaunchingWithOptions
|
|
61
|
+
  2\. Add Spike initialization code to `ios/<Project Name>/AppDelegate.mm` file inside `application:didFinishLaunchingWithOptions: `method.
|
|
64
62
|
|
|
65
|
-
```
|
|
63
|
+
```javascript
|
|
66
64
|
#import <SpikeSDK/SpikeSDK-Swift.h>
|
|
67
65
|
...
|
|
68
66
|
|
|
69
67
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
70
68
|
{
|
|
71
69
|
...
|
|
72
|
-
[
|
|
70
|
+
[Spike configure];
|
|
73
71
|
...
|
|
74
72
|
|
|
75
73
|
}
|
|
76
|
-
```
|
|
77
74
|
|
|
78
|
-
|
|
75
|
+
```
|
|
79
76
|
|
|
80
|
-
|
|
77
|
+
  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.
|
|
81
78
|
|
|
82
|
-
```
|
|
83
|
-
import Spike
|
|
79
|
+
```javascript
|
|
80
|
+
import Spike from 'react-native-spike-sdk';
|
|
84
81
|
|
|
85
|
-
|
|
82
|
+
const conn = await Spike.createConnection(
|
|
83
|
+
'my_app_id',
|
|
84
|
+
'my_app_access_token',
|
|
85
|
+
'my_user_id'
|
|
86
|
+
);
|
|
86
87
|
|
|
87
|
-
useSpikeEvents({
|
|
88
|
-
onInitialize: (uuid) => {
|
|
89
|
-
console.log(`Event: onInitialize: ${uuid}`);
|
|
90
|
-
},
|
|
91
|
-
onInitializationFailure: () => {
|
|
92
|
-
console.log('Event: onInitializationFailure');
|
|
93
|
-
},
|
|
94
|
-
onDataResult: (result: SpikeResult) => {
|
|
95
|
-
console.log(`Event: onDataResult: ${JSON.stringify(result)}`);
|
|
96
|
-
},
|
|
97
|
-
onDataFailure: () => {
|
|
98
|
-
console.log('Event: onDataFailure');
|
|
99
|
-
},
|
|
100
|
-
onWorkoutDataResult: (result: SpikeWorkoutResult) => {
|
|
101
|
-
console.log(`Event: onWorkoutDataResult: ${JSON.stringify(result)}`);
|
|
102
|
-
},
|
|
103
|
-
onWorkoutDataFailure: () => {
|
|
104
|
-
console.log('Event: onWorkoutDataFailure');
|
|
105
|
-
},
|
|
106
|
-
onSleepAnalysisDataResult: (result) => {
|
|
107
|
-
console.log(`Event: onSleepAnalysisDataResult: ${JSON.stringify(result)}`);
|
|
108
|
-
},
|
|
109
|
-
onSleepAnalysisDataFailure: () => {
|
|
110
|
-
console.log('Event: onSleepAnalysisDataFailure');
|
|
111
|
-
},
|
|
112
|
-
onLog: (log) => {
|
|
113
|
-
console.log(`Event Spike log: ${log}`);
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
88
|
```
|
|
117
89
|
|
|
118
|
-
|
|
119
|
-
If you have provided `postbackURL` to setup method, `status` will be returned, otherwise `data`.
|
|
90
|
+
## Getting and using data
|
|
120
91
|
|
|
121
|
-
|
|
92
|
+
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.
|
|
122
93
|
|
|
123
|
-
|
|
94
|
+
```javascript
|
|
95
|
+
// conn was created in the previous step
|
|
124
96
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
97
|
+
/*
|
|
98
|
+
* Extracting activities summary data for today.
|
|
99
|
+
*/
|
|
100
|
+
const activitiesSummary = await conn.extractData(
|
|
101
|
+
SpikeDataTypes.activitiesSummary
|
|
102
|
+
);
|
|
130
103
|
|
|
131
|
-
|
|
132
|
-
|
|
104
|
+
/*
|
|
105
|
+
* Accessing daily steps.
|
|
106
|
+
*/
|
|
107
|
+
console.log("Steps:", activitiesSummary.getEntries()[0].steps);
|
|
133
108
|
```
|
|
134
109
|
|
|
135
|
-
|
|
110
|
+
### Extracting data by time range
|
|
136
111
|
|
|
137
|
-
|
|
138
|
-
Spike.clearData()
|
|
139
|
-
```
|
|
112
|
+
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.
|
|
140
113
|
|
|
141
|
-
|
|
114
|
+
```javascript
|
|
115
|
+
const toDate = new Date(); // Today's date
|
|
142
116
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
You can optionally provide date range which will return data for each day separately.
|
|
117
|
+
const fromDate = new Date(toDate);
|
|
118
|
+
fromDate.setDate(toDate.getDate() - 5); // 5 days ago
|
|
146
119
|
|
|
147
|
-
|
|
148
|
-
|
|
120
|
+
const activitiesSummary = await conn.extractData(
|
|
121
|
+
SpikeDataTypes.activitiesSummary,
|
|
122
|
+
fromDate,
|
|
123
|
+
toDate
|
|
124
|
+
);
|
|
149
125
|
|
|
150
|
-
...
|
|
151
126
|
|
|
152
|
-
Spike.getData(SpikeDataTypesAll);
|
|
153
127
|
```
|
|
154
128
|
|
|
155
|
-
|
|
129
|
+
### Sending data to webhook
|
|
156
130
|
|
|
157
|
-
|
|
158
|
-
Spike.getData(['DataTypeHeartRate', 'DataTypeBasalEnergy'])
|
|
159
|
-
```
|
|
131
|
+
Extracts local device data for the given time range and sends it as a webhook notification to the customer’s backend.
|
|
160
132
|
|
|
161
|
-
|
|
133
|
+
```javascript
|
|
134
|
+
import Spike from 'react-native-spike-sdk';
|
|
162
135
|
|
|
163
|
-
|
|
164
|
-
|
|
136
|
+
const conn = await Spike.createConnection(
|
|
137
|
+
'my_app_id',
|
|
138
|
+
'my_app_access_token',
|
|
139
|
+
'my_user_id',
|
|
140
|
+
'https://example.com/data'
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
/*
|
|
144
|
+
* Extracting and sending activities summary data.
|
|
145
|
+
*/
|
|
146
|
+
const response = await conn.extractAndPostData(
|
|
147
|
+
SpikeDataTypes.activitiesSummary,
|
|
148
|
+
fromDate,
|
|
149
|
+
toDate
|
|
150
|
+
);
|
|
165
151
|
```
|
|
166
152
|
|
|
167
|
-
|
|
168
|
-
`DataTypeStep`
|
|
169
|
-
`DataTypeHeartRate`
|
|
170
|
-
`DataTypeRestingHeartRate`
|
|
171
|
-
`DataTypeActiveEnergy`
|
|
172
|
-
`DataTypeBasalEnergy`
|
|
173
|
-
`DataTypeAppleMoveTime`
|
|
174
|
-
`DataTypeAppleExerciseTime`
|
|
175
|
-
`DataTypeDistanceWalkingRunning`
|
|
176
|
-
`DataTypeFloors`
|
|
177
|
-
`DataTypeWorkout`
|
|
178
|
-
`DataTypeSleepAnalysis`
|
|
179
|
-
|
|
180
|
-
Getting `DataTypeWorkout` data will return result through the `onWorkoutDataResult` and `onWorkoutDataFailure` callbacks of `useSpikeEvents` hook.
|
|
181
|
-
Getting `DataTypeSleepAnalysis` data will return result through the `onSleepAnalysisDataResult` and `onSleepAnalysisDataFailure` callbacks of `useSpikeEvents` hook.
|
|
182
|
-
|
|
183
|
-
### Enable debug mode <a name="debug"></a>
|
|
184
|
-
|
|
185
|
-
With enabled debug mode SpikeSDK will print performed actions.
|
|
186
|
-
You can handle logs through the `onLog` callback of `useSpikeEvents` hook or
|
|
187
|
-
see logs directly running application from Xcode. Use logs filter `[SpikeSDK]`.
|
|
188
|
-
It is better to enable debug before calling `Spike.initialize();`.
|
|
153
|
+
## Background Delivery
|
|
189
154
|
|
|
190
|
-
|
|
191
|
-
Spike.enableDebug();
|
|
192
|
-
```
|
|
155
|
+
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.
|
|
193
156
|
|
|
194
|
-
|
|
157
|
+
### Signing & Capabilities
|
|
195
158
|
|
|
196
|
-
|
|
159
|
+
Go to your target’s `Signing & Capabilities` section and add **Background Modes**. 
|
|
197
160
|
|
|
198
|
-
|
|
161
|
+
Allow **Background fetch.**
|
|
199
162
|
|
|
200
|
-
|
|
201
|
-
Add background task identifier to app `Info.plist` file.
|
|
202
|
-
Allow `Background fetch`. And check `Info.plist` for `UIBackgroundModes`.
|
|
163
|
+
### Info.plist
|
|
203
164
|
|
|
204
|
-
|
|
165
|
+
Add background task identifier to app Info.plist file. And check Info.plist for `UIBackgroundModes`.
|
|
166
|
+
|
|
167
|
+
```xml
|
|
205
168
|
...
|
|
206
169
|
<key>BGTaskSchedulerPermittedIdentifiers</key>
|
|
207
170
|
<array>
|
|
@@ -215,20 +178,182 @@ Allow `Background fetch`. And check `Info.plist` for `UIBackgroundModes`.
|
|
|
215
178
|
...
|
|
216
179
|
```
|
|
217
180
|
|
|
218
|
-
|
|
181
|
+
### Example
|
|
219
182
|
|
|
220
|
-
|
|
183
|
+
```javascript
|
|
184
|
+
import Spike from 'react-native-spike-sdk';
|
|
221
185
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
186
|
+
const conn = await Spike.createConnection(
|
|
187
|
+
'my_app_id',
|
|
188
|
+
'my_app_access_token',
|
|
189
|
+
'my_user_id',
|
|
190
|
+
'https://example.com/data'
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
/*
|
|
194
|
+
* Enabling background delivery.
|
|
195
|
+
*/
|
|
196
|
+
conn.enableBackgroundDelivery(
|
|
197
|
+
[SpikeDataTypes.activitiesSummary]
|
|
198
|
+
);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
* 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;
|
|
204
|
+
|
|
205
|
+
* If `dataTypes` parameter is empty or null, then background data delivery is stopped for this connection if it was enabled;
|
|
206
|
+
|
|
207
|
+
* Function `conn.getBackgroundDeliveryDataTypes` gets the data types for which background delivery is enabled. If background delivery is not enabled, an empty set is returned.
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
## Logging
|
|
211
|
+
|
|
212
|
+
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.
|
|
213
|
+
|
|
214
|
+
Below is an example of how to implement a simple console logger.
|
|
215
|
+
|
|
216
|
+
```javascript
|
|
217
|
+
class ConsoleLogger implements SpikeLogger {
|
|
218
|
+
isDebugEnabled() {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
isInfoEnabled() {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
isErrorEnabled() {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
debug(message) {
|
|
231
|
+
console.log("DEBUG:", message);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
info(message) {
|
|
235
|
+
console.log("INFO:", message);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
error(message) {
|
|
239
|
+
console.log("ERROR:", message);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
225
242
|
|
|
226
|
-
|
|
227
|
-
|
|
243
|
+
const conn = Spike.createConnection(
|
|
244
|
+
'my_app_id',
|
|
245
|
+
'my_app_access_token',
|
|
246
|
+
'my_user_id',
|
|
247
|
+
new ConsoleLogger()
|
|
248
|
+
);
|
|
228
249
|
```
|
|
229
250
|
|
|
230
|
-
|
|
251
|
+
## Data types
|
|
252
|
+
|
|
253
|
+
* SpikeDataTypes.activitiesStream
|
|
254
|
+
* SpikeDataTypes.activitiesSummary
|
|
255
|
+
* SpikeDataTypes.body
|
|
256
|
+
* SpikeDataTypes.breathing
|
|
257
|
+
* SpikeDataTypes.calories
|
|
258
|
+
* SpikeDataTypes.distance
|
|
259
|
+
* SpikeDataTypes.glucose
|
|
260
|
+
* SpikeDataTypes.heart
|
|
261
|
+
* SpikeDataTypes.info
|
|
262
|
+
* SpikeDataTypes.oxygenSaturation
|
|
263
|
+
* SpikeDataTypes.sleep
|
|
264
|
+
* SpikeDataTypes.steps
|
|
265
|
+
|
|
266
|
+
## Classes
|
|
267
|
+
|
|
268
|
+
### Spike
|
|
269
|
+
|
|
270
|
+
| Class | Method | Description |
|
|
271
|
+
| ----- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
272
|
+
| Spike | createConnection | Creates a new SpikeConnection instance with the given user details.**Parameters**: appId, authToken, customerEndUserId, logger**Returns**: An instance of the SpikeConnection class. |
|
|
273
|
+
| Spike | createConnection | 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. |
|
|
274
|
+
| 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. |
|
|
275
|
+
| Spike | getBackgroundConnections | Returns all connections that are configured to deliver data in the background.**Returns: **A collection (a set) of SpikeWebhookConnection instances. |
|
|
276
|
+
| 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>) |
|
|
277
|
+
|
|
278
|
+
### SpikeConnection
|
|
279
|
+
|
|
280
|
+
| Class | Method | Description |
|
|
281
|
+
| --------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
282
|
+
| SpikeConnection | getAppId | Retrieves the unique Spike application identifier.**Returns**: string |
|
|
283
|
+
| SpikeConnection | getSpikeEndUserId | Retrieves the unique identifier assigned to the end-user by Spike.**Returns**: string |
|
|
284
|
+
| SpikeConnection | getCustomerEndUserId | Retrieves the unique identifier assigned to the end-user by the customer.**Returns**: string |
|
|
285
|
+
| 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. |
|
|
286
|
+
| 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. |
|
|
287
|
+
| SpikeConnection | extractData | 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. |
|
|
288
|
+
| SpikeConnection | pack | Creates a string representation of the connection state. This method facilitates the persistence of connections.**Returns**: String |
|
|
289
|
+
|
|
290
|
+
### SpikeWebhookConnection
|
|
291
|
+
|
|
292
|
+
| Class | Method | Description |
|
|
293
|
+
| ---------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
294
|
+
| SpikeWebhookConnection | getAppId | Retrieves the unique Spike application identifier.**Returns**: string |
|
|
295
|
+
| SpikeWebhookConnection | getSpikeEndUserId | Retrieves the unique identifier assigned to the end-user by Spike.**Returns**: string |
|
|
296
|
+
| SpikeWebhookConnection | getCustomerEndUserId | Retrieves the unique identifier assigned to the end-user by the customer.**Returns**: string |
|
|
297
|
+
| SpikeWebhookConnection | getCallbackUrl | Returns the URL that will receive webhook notifications. |
|
|
298
|
+
| 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. |
|
|
299
|
+
| 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. |
|
|
300
|
+
| SpikeWebhookConnection | extractData | 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. |
|
|
301
|
+
| 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) |
|
|
302
|
+
| SpikeWebhookConnection | extractAndPostData | 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) |
|
|
303
|
+
| SpikeWebhookConnection | enableBackgroundDelivery
 | Enables background data delivery for selected data types. No-op on Android (for now).**Parameters**: dataType(SpikeDataType) |
|
|
304
|
+
| 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. |
|
|
305
|
+
| SpikeWebhookConnection | pack | Creates a string representation of the connection state. This method facilitates the persistence of connections.**Returns**: String |
|
|
306
|
+
| 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
|
|
307
|
+
|
|
308
|
+
* If listener is null, then any existing listener is removed |
|
|
309
|
+
|
|
310
|
+
### SpikeWebhookConnectionListener
|
|
311
|
+
|
|
312
|
+
Abstract class allowing to receive notifications from the background data delivery process.
|
|
313
|
+
|
|
314
|
+
| Class | Method | Description |
|
|
315
|
+
| ------------------------------ | ------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
316
|
+
| SpikeWebhookConnectionListener | onSubmissionFailure | Invoked on an asynchronous data submission failure.**Parameters**: webhookJob (SpikeWebhookJob), exception (SpikeException) |
|
|
317
|
+
|
|
318
|
+
# Errors and Exceptions
|
|
319
|
+
|
|
320
|
+
## SpikeException
|
|
321
|
+
|
|
322
|
+
The abstract parent of all concrete exceptions.
|
|
323
|
+
|
|
324
|
+
## SpikeConnectionAlreadyExistsException
|
|
325
|
+
|
|
326
|
+
Thrown if an attempt to unpack a Spike connection is made while a strong reference to the same connection already exists.
|
|
327
|
+
|
|
328
|
+
## SpikeConnectionIsClosedException
|
|
329
|
+
|
|
330
|
+
Thrown if any method is invoked on [SpikeConnection](https://docs.google.com/document/d/1dB0m5QQ4kpTct-xP4mro9ok3NgwCpzS-dnaZLS9VRo8/edit#heading=h.293fovahtkh1) or one of its subclasses after the connection has been closed.
|
|
331
|
+
|
|
332
|
+
## SpikeInvalidCredentialsException
|
|
333
|
+
|
|
334
|
+
Thrown if the credentials provided are not recognised, i.e. are invalid or expired.
|
|
335
|
+
|
|
336
|
+
## SpikeInvalidDateRangeException
|
|
337
|
+
|
|
338
|
+
Thrown if duration exceeds the allowed maximum or if ‘from’ date is greater than ‘to’ date. The message will contain a specific cause description.
|
|
339
|
+
|
|
340
|
+
## SpikeInvalidCallbackUrlException
|
|
341
|
+
|
|
342
|
+
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.
|
|
343
|
+
|
|
344
|
+
## SpikePackException
|
|
345
|
+
|
|
346
|
+
Thrown when a connection cannot be serialised to a packed state. The exception cause will contain the underlying error.
|
|
347
|
+
|
|
348
|
+
## SpikePermissionsNotGrantedException
|
|
349
|
+
|
|
350
|
+
Thrown when Spike SDK is unable to access the data due to permissions not being granted.
|
|
351
|
+
|
|
352
|
+
## SpikeServerException
|
|
353
|
+
|
|
354
|
+
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.
|
|
355
|
+
|
|
356
|
+
## SpikeUnpackException
|
|
357
|
+
|
|
358
|
+
Thrown when a connection cannot be deserialised from a packed state. The exception cause will contain the underlying error.
|
|
231
359
|
|
|
232
|
-
```
|
|
233
|
-
await Spike.isBackgroundUpdateEnabled();
|
|
234
|
-
```
|
package/android/build.gradle
CHANGED
|
@@ -4,6 +4,7 @@ buildscript {
|
|
|
4
4
|
|
|
5
5
|
repositories {
|
|
6
6
|
google()
|
|
7
|
+
mavenLocal()
|
|
7
8
|
mavenCentral()
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -60,7 +61,15 @@ android {
|
|
|
60
61
|
|
|
61
62
|
repositories {
|
|
62
63
|
mavenCentral()
|
|
64
|
+
mavenLocal()
|
|
63
65
|
google()
|
|
66
|
+
maven {
|
|
67
|
+
url 'https://spike-artifact-323760463254.d.codeartifact.eu-central-1.amazonaws.com/maven/maven-central-store/'
|
|
68
|
+
credentials {
|
|
69
|
+
username "aws"
|
|
70
|
+
password System.env.CODEARTIFACT_AUTH_TOKEN
|
|
71
|
+
}
|
|
72
|
+
}
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
@@ -69,8 +78,12 @@ dependencies {
|
|
|
69
78
|
// For < 0.71, this will be from the local maven repo
|
|
70
79
|
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
71
80
|
//noinspection GradleDynamicVersion
|
|
72
|
-
implementation "com.facebook.react:react-
|
|
81
|
+
implementation "com.facebook.react:react-android:0.71.3"
|
|
73
82
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
83
|
+
implementation "com.spikeapi.sdk:spike-sdk:1.0.2"
|
|
84
|
+
implementation 'androidx.core:core-ktx:1.10.0'
|
|
85
|
+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
|
|
86
|
+
implementation 'com.google.code.gson:gson:2.10.1'
|
|
74
87
|
}
|
|
75
88
|
|
|
76
89
|
if (isNewArchitectureEnabled()) {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
package com.spikesdk
|
|
2
|
+
|
|
3
|
+
import com.spikeapi.SpikeLogger
|
|
4
|
+
|
|
5
|
+
enum class SpikeLogLevel(val jsEventName: String) {
|
|
6
|
+
DEBUG(jsEventName = "onDebug"),
|
|
7
|
+
ERROR(jsEventName = "onError"),
|
|
8
|
+
INFO(jsEventName = "onInfo")
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class SpikeConnectionLogger(
|
|
12
|
+
private val connectionUUID: String,
|
|
13
|
+
private val onLog: (
|
|
14
|
+
connectionUUID: String,
|
|
15
|
+
logLevel: SpikeLogLevel,
|
|
16
|
+
message: String
|
|
17
|
+
) -> Unit
|
|
18
|
+
) : SpikeLogger {
|
|
19
|
+
|
|
20
|
+
override fun debug(message: String) {
|
|
21
|
+
onLog(connectionUUID, SpikeLogLevel.DEBUG, message)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override fun error(message: String) {
|
|
25
|
+
onLog(connectionUUID, SpikeLogLevel.ERROR, message)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override fun info(message: String) {
|
|
29
|
+
onLog(connectionUUID, SpikeLogLevel.INFO, message)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override fun isDebugEnabled(): Boolean = true
|
|
33
|
+
|
|
34
|
+
override fun isErrorEnabled(): Boolean = true
|
|
35
|
+
|
|
36
|
+
override fun isInfoEnabled(): Boolean = true
|
|
37
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package com.spikesdk
|
|
2
|
+
|
|
3
|
+
import com.spikeapi.SpikeDataTypes
|
|
4
|
+
import com.spikeapi.SpikeExceptions
|
|
5
|
+
import com.spikeapi.healthconnect.HealthConnectAvailability
|
|
6
|
+
import com.spikeapi.model.SpikeData
|
|
7
|
+
import com.spikeapi.model.SpikeDataType
|
|
8
|
+
import java.time.Instant
|
|
9
|
+
import java.time.OffsetDateTime
|
|
10
|
+
|
|
11
|
+
fun SpikeExceptions.mapException(): String {
|
|
12
|
+
return when (this) {
|
|
13
|
+
is SpikeExceptions.SpikeException -> "SpikeException"
|
|
14
|
+
SpikeExceptions.SpikeConnectionIsClosedException -> "SpikeConnectionIsClosedException"
|
|
15
|
+
SpikeExceptions.SpikeInvalidCredentialsException -> "SpikeInvalidCredentialsException"
|
|
16
|
+
SpikeExceptions.SpikeInvalidDateRangeException -> "SpikeInvalidDateRangeException"
|
|
17
|
+
SpikeExceptions.SpikeInvalidPostbackUrlException -> "SpikeInvalidPostbackUrlException"
|
|
18
|
+
SpikeExceptions.SpikePackException -> "SpikePackException"
|
|
19
|
+
SpikeExceptions.SpikePermissionsNotGrantedException -> "SpikePermissionsNotGrantedException"
|
|
20
|
+
is SpikeExceptions.SpikeServerException -> "SpikeServerException"
|
|
21
|
+
SpikeExceptions.SpikeUnpackException -> "SpikeUnpackException"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fun SpikeDataType<out SpikeData>.toStringType(): String = when (this) {
|
|
26
|
+
SpikeDataTypes.GLUCOSE -> "glucose"
|
|
27
|
+
SpikeDataTypes.HEART_RATE -> "heart"
|
|
28
|
+
SpikeDataTypes.SLEEP -> "sleep"
|
|
29
|
+
SpikeDataTypes.STEPS -> "steps"
|
|
30
|
+
SpikeDataTypes.ACTIVITIES_STREAM -> "activities_stream"
|
|
31
|
+
SpikeDataTypes.ACTIVITIES_SUMMARY -> "activities_summary"
|
|
32
|
+
SpikeDataTypes.BREATHING -> "breathing"
|
|
33
|
+
SpikeDataTypes.CALORIES -> "calories"
|
|
34
|
+
SpikeDataTypes.DISTANCE -> "distance"
|
|
35
|
+
SpikeDataTypes.OXYGEN_SATURATION -> "oxygen_saturation"
|
|
36
|
+
SpikeDataTypes.BODY -> "body"
|
|
37
|
+
else -> "activities_summary"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fun String.toSpikeDataType(): SpikeDataType<out SpikeData> = when (this) {
|
|
41
|
+
"glucose" -> SpikeDataTypes.GLUCOSE
|
|
42
|
+
"heart" -> SpikeDataTypes.HEART_RATE
|
|
43
|
+
"sleep" -> SpikeDataTypes.SLEEP
|
|
44
|
+
"steps" -> SpikeDataTypes.STEPS
|
|
45
|
+
"activities_stream" -> SpikeDataTypes.ACTIVITIES_STREAM
|
|
46
|
+
"activities_summary" -> SpikeDataTypes.ACTIVITIES_SUMMARY
|
|
47
|
+
"breathing" -> SpikeDataTypes.BREATHING
|
|
48
|
+
"calories" -> SpikeDataTypes.CALORIES
|
|
49
|
+
"distance" -> SpikeDataTypes.DISTANCE
|
|
50
|
+
"oxygen_saturation" -> SpikeDataTypes.OXYGEN_SATURATION
|
|
51
|
+
"body" -> SpikeDataTypes.BODY
|
|
52
|
+
else -> SpikeDataTypes.ACTIVITIES_SUMMARY
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fun Long.millisToOffsetDataTime(): OffsetDateTime =
|
|
56
|
+
OffsetDateTime.ofInstant(Instant.ofEpochMilli(this), java.time.ZoneId.systemDefault())
|
|
57
|
+
|
|
58
|
+
fun HealthConnectAvailability.toStringType(): String = when (this) {
|
|
59
|
+
HealthConnectAvailability.INSTALLED -> "installed"
|
|
60
|
+
HealthConnectAvailability.NOT_INSTALLED -> "notInstalled"
|
|
61
|
+
}
|