Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Add getDeviceDetails action #27

Merged
merged 8 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions __tests__/actions/getDeviceDetails.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { getDeviceDetails } from '../../src/actions';

describe('getDeviceDetails function', () => {

it('is a function', () => {
expect(typeof getDeviceDetails).toBe('function');
});

it('builds a getDeviceDetails action', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.getdevicedetails',
WFWorkflowActionParameters: {
WFDeviceDetail: 'Device Name',
},
};
const actual = getDeviceDetails({});

expect(actual).toEqual(expected);
});

it('builds a getDeviceDetails action when a detail is passed', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.getdevicedetails',
WFWorkflowActionParameters: {
WFDeviceDetail: 'System Version',
},
};
const actual = getDeviceDetails({ detail: 'System Version' });

expect(actual).toEqual(expected);
});

});
34 changes: 34 additions & 0 deletions src/actions/getDeviceDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { withActionOutput } from '../utils';

import WFDeviceDetail from '../interfaces/WF/WFDeviceDetail';
import WFSerialization from '../interfaces/WF/WFSerialization';
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
* Get Device Details Action. Gets information about the current device.
*
* ```js
* getDeviceDetails({
* detail: 'Device Name',
* });
* ```
*/
const getDeviceDetails = (
options: {
/** The particular detail to retrieve */
detail?: WFSerialization | WFDeviceDetail,
},
): WFWorkflowAction => {
const {
detail = 'Device Name',
} = options;

return {
WFWorkflowActionIdentifier: 'is.workflow.actions.getdevicedetails',
WFWorkflowActionParameters: {
WFDeviceDetail: detail,
},
};
};

export default withActionOutput(getDeviceDetails);
2 changes: 2 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import exitShortcut from './exitShortcut';
import getBatteryLevel from './getBatteryLevel';
import getContentsOfUrl from './getContentsOfUrl';
import getCurrentIpAddress from './getCurrentIpAddress';
import getDeviceDetails from './getDeviceDetails';
import getDictionaryValue from './getDictionaryValue';
import getName from './getName';
import getType from './getType';
Expand Down Expand Up @@ -48,6 +49,7 @@ export {
getBatteryLevel,
getContentsOfUrl,
getCurrentIpAddress,
getDeviceDetails,
getDictionaryValue,
getName,
getType,
Expand Down
11 changes: 11 additions & 0 deletions src/interfaces/WF/WFDeviceDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type WFDeviceDetail = (
'Device Name'
| 'Device Model'
| 'System Version'
| 'Screen Width'
| 'Screen Height'
| 'Current Volume'
| 'Current Brightness'
);

export default WFDeviceDetail;
1 change: 1 addition & 0 deletions src/interfaces/WF/WFWorkflowActionIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type WFWorkflowActionIdentifier = (
| 'is.workflow.actions.flashlight'
| 'is.workflow.actions.getbatterylevel'
| 'is.workflow.actions.getipaddress'
| 'is.workflow.actions.getdevicedetails'
| 'is.workflow.actions.getitemname'
| 'is.workflow.actions.getitemtype'
| 'is.workflow.actions.gettext'
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/WF/WFWorkflowActionParameters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import WFAskActionDateGranularity from './WFAskActionDateGranularity';
import WFCondition from './WFCondition';
import WFCountType from './WFCountType';
import WFDeviceDetail from './WFDeviceDetail';
import WFFlashlightSetting from './WFFlashlightSetting';
import WFGetDictionaryValueType from './WFGetDictionaryValueType';
import WFHTTPBodyType from './WFHTTPBodyType';
Expand Down Expand Up @@ -29,6 +30,7 @@ interface WFWorkflowActionParameters {
WFControlFlowMode?: number;
WFCountType?: WFCountType;
WFDelayTime?: number;
WFDeviceDetail?: WFSerialization | WFDeviceDetail;
WFDictionaryKey?: string;
WFDontIncludeFileExtension?: boolean;
WFFlashlightSetting?: WFFlashlightSetting;
Expand Down