Skip to content

Commit

Permalink
Merge 665f21a into 3a90ca6
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed Dec 2, 2018
2 parents 3a90ca6 + 665f21a commit ed0dee4
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 3 deletions.
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. Returns a particular property of the 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);
53 changes: 53 additions & 0 deletions src/actions/getNetworkDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { withActionOutput } from '../utils';

import WFCellularDetail from '../interfaces/WF/WFCellularDetail';
import WFNetworkDetailsNetwork from '../interfaces/WF/WFNetworkDetailsNetwork';
import WFSerialization from '../interfaces/WF/WFSerialization';
import WFWiFiDetail from '../interfaces/WF/WFWiFiDetail';
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
* Get Network Details Action. Gets various network-related information from
* the device.
*
* ```js
* getNetworkDetails({
* network: 'Wi-Fi',
* get: 'Network Name',
* });
*
* getNetworkDetails({
* network: 'Cellular',
* get: 'Carrier Name',
* });
* ```
*/
const getNetworkDetails = (
options: {
/** The type of network to look at */
network?: WFNetworkDetailsNetwork,

/** The particular network detail to retrieve */
attribute?: WFSerialization | WFWiFiDetail | WFCellularDetail,
},
): WFWorkflowAction => {
const {
network = 'Wi-Fi',
attribute = 'Network Name',
} = options;

let detailKey = 'WFWiFiDetail';
if (network === 'Cellular') {
detailKey = 'WFCellularDetail';
}

return {
WFWorkflowActionIdentifier: 'is.workflow.actions.getwifi',
WFWorkflowActionParameters: {
WFNetworkDetailsNetwork: network,
[detailKey]: attribute,
},
};
};

export default withActionOutput(getNetworkDetails);
4 changes: 4 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ 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 getNetworkDetails from './getNetworkDetails';
import getType from './getType';
import getVariable from './getVariable';
import nothing from './nothing';
Expand Down Expand Up @@ -48,8 +50,10 @@ export {
getBatteryLevel,
getContentsOfUrl,
getCurrentIpAddress,
getDeviceDetails,
getDictionaryValue,
getName,
getNetworkDetails,
getType,
getVariable,
nothing,
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/WF/WFCellularDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type WFCellularDetail = (
'Carrier Name'
| 'Radio Technology'
| 'Country Code'
| 'WFTextTokenAttachment'
);

export default WFCellularDetail;
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;
6 changes: 6 additions & 0 deletions src/interfaces/WF/WFNetworkDetailsNetwork.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type WFNetworkDetailsNetwork = (
'Wi-Fi'
| 'Cellular'
);

export default WFNetworkDetailsNetwork;
6 changes: 6 additions & 0 deletions src/interfaces/WF/WFWiFiDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type WFWiFiDetail = (
'Network Name'
| 'BSSID'
);

export default WFWiFiDetail;
2 changes: 2 additions & 0 deletions src/interfaces/WF/WFWorkflowActionIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ 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'
| 'is.workflow.actions.getvalueforkey'
| 'is.workflow.actions.getvariable'
| 'is.workflow.actions.getwifi'
| 'is.workflow.actions.handoff'
| 'is.workflow.actions.lowpowermode.set'
| 'is.workflow.actions.math'
Expand Down
10 changes: 7 additions & 3 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 All @@ -9,6 +10,7 @@ import WFInputType from './WFInputType';
import WFIPAddressSourceOption from './WFIPAddressSourceOption';
import WFIPAddressTypeOption from './WFIPAddressTypeOption';
import WFMathOperation from './WFMathOperation';
import WFNetworkDetailsNetwork from './WFNetworkDetailsNetwork';
import WFSerialization from './WFSerialization';

interface WFWorkflowActionParameters {
Expand All @@ -29,6 +31,7 @@ interface WFWorkflowActionParameters {
WFControlFlowMode?: number;
WFCountType?: WFCountType;
WFDelayTime?: number;
WFDeviceDetail?: WFSerialization | WFDeviceDetail;
WFDictionaryKey?: string;
WFDontIncludeFileExtension?: boolean;
WFFlashlightSetting?: WFFlashlightSetting;
Expand All @@ -37,24 +40,25 @@ interface WFWorkflowActionParameters {
WFHTTPBodyType?: WFHTTPBodyType;
WFHTTPHeaders?: WFSerialization;
WFHTTPMethod?: WFHTTPMethod;
WFInputType?: WFInputType;
WFIPAddressSourceOption?: WFIPAddressSourceOption;
WFIPAddressTypeOption?: WFIPAddressTypeOption;
WFInputType?: WFInputType;
WFJSONValues?: WFSerialization;
WFMathOperand?: number;
WFMathOperation?: WFMathOperation;
WFMenuItems?: string[];
WFMenuItemTitle?: string;
WFMenuItems?: string[];
WFMenuPrompt?: string;
WFName?: string;
WFNetworkDetailsNetwork?: WFNetworkDetailsNetwork;
WFNumberActionNumber?: number;
WFNumberValue?: number;
WFShowWorkflow?: boolean;
WFSSHHost?: WFSerialization | string;
WFSSHPassword?: WFSerialization | string;
WFSSHPort?: WFSerialization | string;
WFSSHScript?: WFSerialization | string;
WFSSHUser?: WFSerialization | string;
WFShowWorkflow?: boolean;
WFTextActionText?: WFSerialization | string;
WFURLActionURL?: string;
WFVariable?: WFSerialization | string;
Expand Down

0 comments on commit ed0dee4

Please sign in to comment.