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

Commit

Permalink
Merge pull request #23 from bachya/current-ip-address
Browse files Browse the repository at this point in the history
Add getCurrentIpAddress action
  • Loading branch information
joshfarrant authored Dec 1, 2018
2 parents 0cbab36 + 4c168f5 commit 3a90ca6
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 0 deletions.
48 changes: 48 additions & 0 deletions __tests__/actions/getCurrentIpAddress.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { getCurrentIpAddress } from '../../src/actions';

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

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

it('builds a getCurrentIpAddress action', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress',
WFWorkflowActionParameters: {
WFIPAddressSourceOption: 'External',
WFIPAddressTypeOption: 'IPv4',
},
};
const actual = getCurrentIpAddress({});

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

it('builds a getCurrentIpAddress action when an address is passed', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress',
WFWorkflowActionParameters: {
WFIPAddressSourceOption: 'Local',
WFIPAddressTypeOption: 'IPv4',
},
};
const actual = getCurrentIpAddress({ address: 'Local' });

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

it('builds a getCurrentIpAddress action when a type is passed', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress',
WFWorkflowActionParameters: {
WFIPAddressSourceOption: 'External',
WFIPAddressTypeOption: 'IPv6',
},
};
const actual = getCurrentIpAddress({ type: 'IPv6' });

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

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

import WFIPAddressSourceOption from '../interfaces/WF/WFIPAddressSourceOption';
import WFIPAddressTypeOption from '../interfaces/WF/WFIPAddressTypeOption';
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
* Get Current IP Address Action. Returns the public/private IPv4 or IPv6
* address of the device.
*
* ```js
* getCurrentIpAddress({
* 'address': 'External',
* 'type': 'IPv4',
* });
* ```
*/
const getCurrentIpAddress = (
options: {
/** The address (public or private) to get */
address?: WFIPAddressSourceOption,
/** The type of address to get */
type?: WFIPAddressTypeOption,
},
): WFWorkflowAction => {
const {
address = 'External',
type = 'IPv4',
} = options;

return {
WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress',
WFWorkflowActionParameters: {
WFIPAddressSourceOption: address,
WFIPAddressTypeOption: type,
},
};
};

export default withActionOutput(getCurrentIpAddress);
2 changes: 2 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import count from './count';
import exitShortcut from './exitShortcut';
import getBatteryLevel from './getBatteryLevel';
import getContentsOfUrl from './getContentsOfUrl';
import getCurrentIpAddress from './getCurrentIpAddress';
import getDictionaryValue from './getDictionaryValue';
import getName from './getName';
import getType from './getType';
Expand Down Expand Up @@ -46,6 +47,7 @@ export {
exitShortcut,
getBatteryLevel,
getContentsOfUrl,
getCurrentIpAddress,
getDictionaryValue,
getName,
getType,
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/WF/WFIPAddressSourceOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type WFIPAddressSourceOption = (
'External'
| 'Local'
);

export default WFIPAddressSourceOption;
6 changes: 6 additions & 0 deletions src/interfaces/WF/WFIPAddressTypeOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type WFIPAddressTypeOption = (
'IPv4'
| 'IPv6'
);

export default WFIPAddressTypeOption;
1 change: 1 addition & 0 deletions src/interfaces/WF/WFWorkflowActionIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type WFWorkflowActionIdentifier = (
| 'is.workflow.actions.exit'
| 'is.workflow.actions.flashlight'
| 'is.workflow.actions.getbatterylevel'
| 'is.workflow.actions.getipaddress'
| 'is.workflow.actions.getitemname'
| 'is.workflow.actions.getitemtype'
| 'is.workflow.actions.gettext'
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/WF/WFWorkflowActionParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import WFGetDictionaryValueType from './WFGetDictionaryValueType';
import WFHTTPBodyType from './WFHTTPBodyType';
import WFHTTPMethod from './WFHTTPMethod';
import WFInputType from './WFInputType';
import WFIPAddressSourceOption from './WFIPAddressSourceOption';
import WFIPAddressTypeOption from './WFIPAddressTypeOption';
import WFMathOperation from './WFMathOperation';
import WFSerialization from './WFSerialization';

Expand Down Expand Up @@ -36,6 +38,8 @@ interface WFWorkflowActionParameters {
WFHTTPHeaders?: WFSerialization;
WFHTTPMethod?: WFHTTPMethod;
WFInputType?: WFInputType;
WFIPAddressSourceOption?: WFIPAddressSourceOption;
WFIPAddressTypeOption?: WFIPAddressTypeOption;
WFJSONValues?: WFSerialization;
WFMathOperand?: number;
WFMathOperation?: WFMathOperation;
Expand Down

0 comments on commit 3a90ca6

Please sign in to comment.