0.6.2 • Published 2 months ago

react-native-rook-ios-transmission v0.6.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

SDK Rook Transmission in React Native

This SDK will allow you to transmit health connect data to Rook services.

For Android

Content

  1. Installation
  2. Configuration
  3. Package usage
    1. useRookAHBodyTransmission
    2. useRookAHPhysicalTransmission
    3. useRookAHSleepTransmission
    4. useRookAHActivityEventsTransmission
    5. useRookAHOxygenationEventsTransmission
    6. useRookAHHeartRateEventsTransmission
    7. useRookAHConfiguration

Installation

To build a project using the Rook Transmission Health Connect in React native you need to use at least react v16 and react native v65. This SDK is only available on iOS this means that it won't work with Android.

  1. Install the dependencies

npm

npm i react-native-rook-ios-transmission

yarn

yarn add react-native-rook-ios-transmission

Configuration

Add your client uuid in order to be authorized, follow the next example, add at the top level of your tree components the RookConnectProvider.

import {RookConnectProvider} from 'rook_auth';

const App => () {
  return (
    <RookConnectProvider
      keys={{
        clientUUID: 'YOUR-CLIENT-UUID',
        apiURL: 'API-URL',
        password: 'YOUR-PASSWORD',
      }}>
      <YourComponents />
    </RookConnectProvider>
  );
}

Content

  1. Installation
  2. Configuration
  3. Package usage

Installation

To build a project using the Rook Transmission Health Connect in React native you need to use at least react v16 and react native v65. This SDK is only available on iOS this means that it won't work with android.

  1. Install the dependencies

npm

npm i react-native-rook-ios-transmission

yarn

yarn add react-native-rook-ios-transmission

Important after do the installation run pod install

Configuration

Add your client uuid in order to be authorized, follow the next example, add at the top level of your tree components the RookConnectProvider.

import {RookConnectProvider} from 'rook_auth';

const App => () {
  return (
    <RookConnectProvider
      keys={{
        clientUUID: 'YOUR-CLIENT-UUID',
        apiURL: 'API-URL',
        password: 'YOUR-PASSWORD',
      }}>
      <YourComponents />
    </RookConnectProvider>
  );
}

Package usage

useRookAHBodyTransmission

Definition

If you need more details about BodySummary please use right click an Go to definition to se the whole definition

type BodyProps = {
  userID: string;
};

export declare const useRookAHBodyTransmission: ({ userID }: BodyProps) => {
  ready: boolean;
  enqueueBodySummary: (date: string, data: BodySummary) => Promise<boolean>;
  getBodySummariesStored: () => Promise<any>;
  uploadBodySummaries: () => Promise<any>;
};
  • ready: indicates when the hook is ready.
  • enqueueBodySummary: saves the body summary to queue to later upload
    • date: indicates the date of the body summary
    • data: it's the summary to save
  • getBodySummariesStored: Retrieves the queue saved into the device
  • uploadBodySummaries: Send the queue to the server

NOTE: The date should be formatted as YYYY-MM-DD

Example

import React, { FC } from 'react';
import { Button, View } from 'react-native';
import { useRookAHBodyTransmission } from 'react-native-rook-ios-transmission';
import { useRookAHPermissions, useRookAHBody } from 'react-native-rook_ah';

type BodyTransmissionProps = {
  // We need to make sure that we already have a user registered.
  // To register a user please check rook_users
  userID: string;
  date: string;
};

export const BodyTransmission: FC<BodyTransmissionProps> = ({
  userID,
  date,
}) => {
  const { enqueueBodySummary, getBodySummariesStored, uploadBodySummaries } =
    useRookAHBodyTransmission({
      userID,
    });
  const { requestBodyPermissions } = useRookAHPermissions();
  const { getBodySummary } = useRookAHBody();

  const requestPermission = async (): Promise<void> => {
    await requestBodyPermissions();
  };

  const handleEnqueueSleep = async (): Promise<void> => {
    try {
      const summary = await getBodySummary(date);
      await enqueueBodySummary(date, summary);
      console.log('Summary saved');
    } catch (error) {
      console.log(error);
    }
  };

  const handleGetQueue = async (): Promise<void> => {
    try {
      const result = await getBodySummariesStored();
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  const handleUploadQueue = async (): Promise<void> => {
    try {
      const result = await uploadBodySummaries();
      console.log(`Queue uploaded: ${result}`);
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <View>
      <Button title="Request Body permissions" onPress={requestPermission} />
      <Button title="Enqueue Body summary" onPress={handleEnqueueSleep} />
      <Button title="Get Enqueue" onPress={handleGetQueue} />
      <Button title="Upload Enqueue" onPress={handleUploadQueue} />
    </View>
  );
};

useRookAHSleepTransmission

Definition

If you need more details about SleepSummary please use right click an Go to definition to se the whole definition

type SleepProps = {
  userID: string;
};
export declare const useRookAHSleepTransmission: ({ userID }: SleepProps) => {
  ready: boolean;
  saveSleepSummary: (data: SleepSummary) => Promise<boolean>;
  getSleepSummariesStored: () => Promise<any>;
  uploadSleepSummaries: () => Promise<any>;
};
  • ready: indicates when the hook is ready.
  • saveSleepSummary: saves the sleep summary to queue to later upload
    • data: it's the summary to save
  • getSleepSummariesStored: Retrieves the queue saved into the device
  • uploadSleepSummaries: Send the queue to the server

NOTE: The date should be formatted as YYYY-MM-DD

Example

import React, { FC } from 'react';
import { useRookAHSleepTransmission } from 'react-native-rook-ios-transmission';
import { useRookAHPermissions, useRookAHSleep } from 'react-native-rook_ah';
import { Button, View } from 'react-native';

type SleepTransmissionProps = {
  // We need to make sure that we already have a user registered.
  // To register a user please check rook_users
  userID: string;
  date: string;
};

export const SleepTransmission: FC<SleepTransmissionProps> = ({
  userID,
  date,
}) => {
  const { saveSleepSummary, getSleepSummariesStored, uploadSleepSummaries } =
    useRookAHSleepTransmission({ userID });

  const { requestSleepPermissions } = useRookAHPermissions();

  const { getSleepSummary } = useRookAHSleep();

  const requestPermission = async (): Promise<void> => {
    await requestSleepPermissions();
  };

  const handleEnqueueSleep = async (): Promise<void> => {
    try {
      const summary = await getSleepSummary(date);
      await saveSleepSummary(summary);
      console.log('Summary saved');
    } catch (error) {
      console.log(error);
    }
  };

  const handleGetQueue = async (): Promise<void> => {
    try {
      const result = await getSleepSummariesStored();
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  const handleUploadQueue = async (): Promise<void> => {
    try {
      const result = await uploadSleepSummaries();
      console.log(`Queue uploaded: ${result}`);
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <View>
      <Button title="Request sleep permissions" onPress={requestPermission} />
      <Button title="Enqueue sleep summary" onPress={handleEnqueueSleep} />
      <Button title="Get Enqueue" onPress={handleGetQueue} />
      <Button title="Upload Enqueue" onPress={handleUploadQueue} />
    </View>
  );
};

useRookAHPhysicalTransmission

Definition

If you need more details about Physical please use right click an Go to definition to se the whole definition

type PhysicalProps = {
  userID: string;
};
export declare const useRookAHPhysicalTransmission: ({
  userID,
}: PhysicalProps) => {
  ready: boolean;
  enqueuePhysicalSummary: (
    date: string,
    data: PhysicalSummary
  ) => Promise<boolean>;
  getPhysicalSummariesStored: () => Promise<any>;
  uploadPhysicalSummaries: () => Promise<any>;
};
  • ready: indicates when the hook is ready.
  • enqueuePhysicalSummary: saves the physical summary to queue to later upload
    • data: it's the summary to save
  • getPhysicalSummariesStored: Retrieves the queue saved into the device
  • uploadPhysicalSummaries: Send the queue to the server

NOTE: The date should be formatted as YYYY-MM-DD

Example

import React, { FC } from 'react';
import { Button, View } from 'react-native';
import { useRookAHPhysicalTransmission } from 'react-native-rook-ios-transmission';
import { useRookAHPermissions, useRookAHPhysical } from 'react-native-rook_ah';

type PhysicalTransmissionProps = {
  // We need to make sure that we already have a user registered.
  // To register a user please check rook_users
  userID: string;
  date: string;
};

export const PhysicalTransmission: FC<PhysicalTransmissionProps> = ({
  userID,
  date,
}) => {
  const {
    enqueuePhysicalSummary,
    getPhysicalSummariesStored,
    uploadPhysicalSummaries,
  } = useRookAHPhysicalTransmission({
    userID,
  });
  const { requestPhysicalPermissions } = useRookAHPermissions();
  const { getPhysicalSummary } = useRookAHPhysical();

  const requestPermission = async (): Promise<void> => {
    await requestPhysicalPermissions();
  };

  const handleEnqueueSleep = async (): Promise<void> => {
    try {
      const summary = await getPhysicalSummary(date);
      await enqueuePhysicalSummary(date, summary);
      console.log('Summary saved');
    } catch (error) {
      console.log(error);
    }
  };

  const handleGetQueue = async (): Promise<void> => {
    try {
      const result = await getPhysicalSummariesStored();
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  const handleUploadQueue = async (): Promise<void> => {
    try {
      const result = await uploadPhysicalSummaries();
      console.log(`Queue uploaded: ${result}`);
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <View>
      <Button
        title="Request Physical permissions"
        onPress={requestPermission}
      />
      <Button title="Enqueue Physical summary" onPress={handleEnqueueSleep} />
      <Button title="Get Enqueue" onPress={handleGetQueue} />
      <Button title="Upload Enqueue" onPress={handleUploadQueue} />
    </View>
  );
};

useRookAHActivityEventsTransmission

Definition

If you need more details about Activity events please use right click an Go to definition to se the whole definition

type ActivityProps = {
  userID: string;
};
const useRookAHActivityEventsTransmission: ({ userID }: ActivityProps) => {
  ready: boolean;
  enqueueActivityEvents: (data: ActivityEvent[]) => Promise<boolean>;
  getCountActivityEvents: () => Promise<number>;
  uploadActivityEvents: () => Promise<boolean>;
};
  • ready: indicates when the hook is ready.
  • enqueueActivityEvents: saves the activity events to queue to later upload
    • data: it's the summary to save
  • getCountActivityEvents: Retrieves the number of activity events queued to upload
  • uploadActivityEvents: Send the queue to the server

NOTE: The date should be formatted as YYYY-MM-DD

Example

import React from 'react';
import { Button, View } from 'react-native';
import { useRookAHActivityEventsTransmission } from 'react-native-rook-transmission';
import { useRookAHEvents } from 'react-native-rook_ah';

export const EventsView = () => {
  const { enqueueActivityEvents, uploadActivityEvents, ...rest } =
    useRookAHActivityEventsTransmission({
      userID: 'USER_ID',
    });

  const { getActivityEvents } = useRookAHEvents();

  const handleEnqueueActivityEvents = async (): Promise<void> => {
    try {
      const date = '2023-08-06';
      const summary = await getActivityEvents(date);
      const response = await enqueueActivityEvents(summary);
      console.log(response);
    } catch (error) {
      console.log(error);
    }
  };

  const handleGetQueue = async (): Promise<void> => {
    try {
      const results = await rest.getCountActivityEvents();
      console.log(results);
    } catch (error) {
      console.log(error);
    }
  };

  const handleUploadQueue = async (): Promise<void> => {
    try {
      const results = await uploadActivityEvents();
      console.log(results);
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <View>
      <Button
        title="Enqueue Activity events"
        onPress={handleEnqueueActivityEvents}
      />
      <Button title="Get activity events" onPress={handleGetQueue} />

      <Button title="Upload activity events" onPress={handleUploadQueue} />
    </View>
  );
};

useRookAHHeartRateEventsTransmission

Definition

If you need more details about Heart rate events please use right click an Go to definition to se the whole definition

type HeartRateProps = {
  userID: string;
};
const useRookAHHeartRateEventsTransmission: ({ userID }: HeartRateProps) => {
  ready: boolean;
  enqueueHeartRateEvents: (data: BodyHeartRateEvent[]) => Promise<boolean>;
  getCountPhysicalHeartRateEvents: () => Promise<number>;
  getCountBodyHeartRateEvents: () => Promise<number>;
  uploadHeartRateEvents: () => Promise<boolean>;
};
  • ready: indicates when the hook is ready.
  • enqueueHeartRateEvents: saves the heart rate events to queue to later upload
    • data: it's the summary to save
  • getCountPhysicalHeartRateEvents: Retrieves the number of physical heart events queued to upload
  • getCountBodyHeartRateEvents: Retrieves the number of body heart rate events queued to upload
  • uploadHeartRateEvents: Send the queue to the server

NOTE: The date should be formatted as YYYY-MM-DD

Example

import React from 'react';
import { Button, View } from 'react-native';
import { useRookAHHeartRateEventsTransmission } from 'react-native-rook-transmission';
import { useRookAHEvents } from 'react-native-rook_ah';

export const HeartRateEventsView = () => {
  const {
    enqueueHeartRateEvents,
    getCountBodyHeartRateEvents,
    getCountPhysicalHeartRateEvents,
    uploadHeartRateEvents,
  } = useRookAHHeartRateEventsTransmission({
    userID: '9808762',
  });

  const { getPhysicalHeartRateEvents, getBodyHeartRateEvents } =
    useRookAHEvents();

  const handleEnqueueEvents = async (): Promise<void> => {
    try {
      const date = '2023-08-06';
      const summary = await getPhysicalHeartRateEvents(date);
      const summary2 = await getBodyHeartRateEvents(date);

      const response = await enqueueHeartRateEvents([...summary, ...summary2]);
      console.log(response);
    } catch (error) {
      console.log(error);
    }
  };

  const handleGetQueue = async (): Promise<void> => {
    try {
      const results = await getCountBodyHeartRateEvents();
      const results3 = await getCountPhysicalHeartRateEvents();

      console.log(results + results3);
    } catch (error) {
      console.log(error);
    }
  };

  const handleUploadQueue = async (): Promise<void> => {
    try {
      const results = await uploadHeartRateEvents();
      console.log(results);
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <View>
      <Button title="Enqueue Heart Rate events" onPress={handleEnqueueEvents} />
      <Button title="Get Heart Rate events" onPress={handleGetQueue} />

      <Button title="Upload Heart Rate events" onPress={handleUploadQueue} />
    </View>
  );
};

useRookAHOxygenationEventsTransmission

Definition

If you need more details about oxygenation events please use right click an Go to definition to se the whole definition

type OxygenationProps = {
  userID: string;
};
const useRookAHOxygenationEventsTransmission: ({
  userID,
}: OxygenationProps) => {
  ready: boolean;
  enqueueOxygenationEvents: (data: BodyOxygenationEvent[]) => Promise<boolean>;
  getCountPhysicalOxygenationEvents: () => Promise<number>;
  getCountBodyOxygenationEvents: () => Promise<number>;
  uploadOxygenationEvents: () => Promise<boolean>;
};
  • ready: indicates when the hook is ready.
  • enqueueOxygenationEvents: saves the heart rate events to queue to later upload
    • data: it's the summary to save
  • getCountPhysicalOxygenationEvents: Retrieves the number of physical oxygenation queued to upload
  • getCountBodyOxygenationEvents: Retrieves the number of body oxygenation events queued to upload
  • uploadOxygenationEvents: Send the queue to the server

NOTE: The date should be formatted as YYYY-MM-DD

Example

import React from 'react';
import { Button, View } from 'react-native';
import { useRookAHOxygenationEventsTransmission } from 'react-native-rook-transmission';
import { useRookAHEvents } from 'react-native-rook_ah';

export const OxygenationEventsView = () => {
  const {
    enqueueOxygenationEvents,
    getCountBodyOxygenationEvents,
    getCountPhysicalOxygenationEvents,
    uploadOxygenationEvents,
  } = useRookAHOxygenationEventsTransmission({
    userID: '9808762',
  });

  const { getBodyOxygenationEvents } = useRookAHEvents();

  const handleEnqueueEvents = async (): Promise<void> => {
    try {
      const date = '2023-08-06';
      const summary = await getBodyOxygenationEvents(date);
      const response = await enqueueOxygenationEvents(summary);
      console.log(response);
    } catch (error) {
      console.log(error);
    }
  };

  const handleGetQueue = async (): Promise<void> => {
    try {
      const results = await getCountBodyOxygenationEvents();
      const results3 = await getCountPhysicalOxygenationEvents();

      console.log(results + results3);
    } catch (error) {
      console.log(error);
    }
  };

  const handleUploadQueue = async (): Promise<void> => {
    try {
      const results = await uploadOxygenationEvents();
      console.log(results);
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <View>
      <Button
        title="Enqueue Oxygenation events"
        onPress={handleEnqueueEvents}
      />
      <Button title="Get Oxygenation events" onPress={handleGetQueue} />

      <Button title="Upload oxygenation events" onPress={handleUploadQueue} />
    </View>
  );
};

useRookAHConfiguration

Definition

This hook help you to update the timezone of the user

type Props = {
  userID: string;
};

type TimezoneProps = {
  timezone: string;
  offset: number;
};

const useRookAHConfiguration: ({ userID }: Props) => {
  ready: boolean;
  uploadUserTimezone: (props: TimezoneProps) => Promise<boolean>;
};
  • ready: indicates when the hook is ready.
  • uploadUserTimezone: update the timezone of the user the offset must be between -18 and 18 and the timezone should be according to IANA Time Zone Database

Example

import React from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { useRookAHConfiguration } from 'react-native-rook-ios-transmission';

const ExampleComponent = () => {
  const { uploadUserTimezone } = useRookAHConfiguration({
    userID: 'YOUR-USER-ID',
  });

  const handleButtonPress = () => {
    const r = await uploadUserTimezone({
      timezone: 'America/Mexico_city',
      offset: -6,
    });

    console.log(r);
  };

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <TouchableOpacity
        onPress={handleButtonPress}
        style={{
          backgroundColor: 'blue',
          padding: 10,
          borderRadius: 5,
          marginTop: 20,
        }}
      >
        <Text style={{ color: 'white' }}>Update Timezone</Text>
      </TouchableOpacity>
    </View>
  );
};

export default ExampleComponent;
0.6.2

2 months ago

0.6.1

2 months ago

0.6.0

5 months ago

0.5.10

6 months ago

0.5.11

6 months ago

0.5.8

7 months ago

0.5.7

7 months ago

0.5.9

7 months ago

0.5.12

5 months ago

0.5.4

7 months ago

0.5.3

7 months ago

0.5.6

7 months ago

0.5.5

7 months ago

0.5.0

7 months ago

0.5.2

7 months ago

0.5.1

7 months ago

0.4.0

8 months ago

0.3.0

8 months ago

0.2.0

8 months ago

0.1.3

12 months ago

0.1.2

1 year ago