Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getDeviceDetails action #27

Merged
merged 8 commits into from
Dec 3, 2018

Conversation

bachya
Copy link
Contributor

@bachya bachya commented Nov 30, 2018

Checks

  • I've checked there are no linting errors.
  • I've checked the code is still at 100% test coverage.

Added Actions (if relevant)

  • Get Device Details

Are you happy to be listed as a contributor on Shortcuts.fun?

Yes

Any other information / comments

N/A

@bachya
Copy link
Contributor Author

bachya commented Dec 1, 2018

@joshfarrant One thing I don't see any examples of how we handle "Ask When Run" parameter values. Any thoughts? I see there's an askWhenRun constant in src/variables.ts; I just don't know how to use it. 😄

@xAlien95
Copy link
Contributor

xAlien95 commented Dec 1, 2018

One thing I don't see any examples of how we handle "Ask When Run" parameter values. Any thoughts? I see there's an askWhenRun constant in src/variables.ts; I just don't know how to use it.

My fault, I didn't add any concrete example since my work on the variables in still in progress (#14).

You can use those global variables like this:

const {
  askWhenRun,
  clipboard,
} = require('@joshfarrant/shortcuts-js/variables');

const actions = [
  text({
    text: withVariables`I need ${askWhenRun} cups of ${clipboard} ☕️`
  }),
];

Or, if you have a local copy of the git:

const {
  askWhenRun,
  clipboard,
} = require('./build/variables');

@bachya
Copy link
Contributor Author

bachya commented Dec 1, 2018

Great! Thanks so much, @xAlien95!

@bachya
Copy link
Contributor Author

bachya commented Dec 1, 2018

@xAlien95, quick follow-up: what would I do in situations where “Ask When Run” is part of an option set?

Image

@xAlien95
Copy link
Contributor

xAlien95 commented Dec 2, 2018

... what would I do in situations where “Ask When Run” is part of an option set?

@bachya, you have to add WFSerialization as possible type for WFDeviceDetail:

const getDeviceDetails = (
  options: {
    /** The particular detail to retrieve */
    detail?: WFDeviceDetail | WFSerialization,
  },
): WFWorkflowAction => {
  const {
    detail = 'Device Name',
  } = options;

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

Take a look at actions/text.ts as an example.

@bachya
Copy link
Contributor Author

bachya commented Dec 2, 2018

@xAlien95 I believe I added support correctly, but, inexperienced as I am, I can't seem to test it successfully (i.e., I can't establish what code produces a shortcut that actually uses "Ask When Run" in this case). Please correct me where I'm wrong!

@xAlien95
Copy link
Contributor

xAlien95 commented Dec 2, 2018

@bachya, thanks for looking into it. I added some comments to let you separate WFDeviceDetail type from the WFSerialization (askWhenRun variable).

I can't establish what code produces a shortcut that actually uses "Ask When Run" in this case

At the moment askWhenRun global variable is based on the Attachment type, in the next few days I'll present a pull request in which variables are based on WFSerialization.

If you want to test now your action with askWhenRun, you have to write the following:

getDeviceDetails({
  detail: {
    Value: askWhenRun,
    WFSerializationType: 'WFTextTokenAttachment',
  },
})

In the future, you'll just have to write:

getDeviceDetails({
  detail: askWhenRun,
})

@xAlien95 xAlien95 mentioned this pull request Dec 2, 2018
@joshfarrant
Copy link
Owner

Thanks both, looks good 👍

Copy link
Owner

@joshfarrant joshfarrant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one tiny tweak then we're good to go 👍

src/actions/getDeviceDetails.ts Outdated Show resolved Hide resolved
@joshfarrant joshfarrant merged commit b1d3f74 into joshfarrant:master Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants