This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
recipe.js
76 lines (65 loc) · 2.63 KB
/
recipe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const listRecipes = (z, bundle) => {
// `z.console.log()` is similar to `console.log()`.
z.console.log('console says hello world!');
const params = {};
if (bundle.inputData.style) {
params.style = bundle.inputData.style;
}
// You can build requests and our client will helpfully inject all the variables
// you need to complete. You can also register middleware to control this.
const requestOptions = {
url: 'https://auth-json-server.zapier.ninja/recipes',
params: params
};
// You may return a promise or a normal data structure from any perform method.
return z.request(requestOptions)
.then((response) => z.JSON.parse(response.content));
};
// We recommend writing your triggers separate like this and rolling them
// into the App definition at the end.
module.exports = {
key: 'recipe',
// You'll want to provide some helpful display labels and descriptions
// for users. Zapier will put them into the UX.
noun: 'Recipe',
display: {
label: 'New Recipe',
description: 'Trigger when a new recipe is added.'
},
// `operation` is where the business logic goes.
operation: {
// `inputFields` can define the fields a user could provide,
// we'll pass them in as `bundle.inputData` later.
inputFields: [
{key: 'style', type: 'string', helpText: 'Which styles of cuisine this should trigger on.'}
],
perform: listRecipes,
// In cases where Zapier needs to show an example record to the user, but we are unable to get a live example
// from the API, Zapier will fallback to this hard-coded sample. It should reflect the data structure of
// returned records, and have obviously dummy values that we can show to any user.
sample: {
id: 1,
createdAt: 1472069465,
name: 'Best Spagetti Ever',
authorId: 1,
directions: '1. Boil Noodles\n2.Serve with sauce',
style: 'italian'
},
// If the resource can have fields that are custom on a per-user basis, define a function to fetch the custom
// field definitions. The result will be used to augment the sample.
// outputFields: [
// () => { return []; }
// ]
// For a more complete example of using dynamic fields see
// https://github.com/zapier/zapier-platform-cli#customdynamic-fields.
// Alternatively, a static field definition should be provided, to specify labels for the fields
outputFields: [
{key: 'id', label: 'ID'},
{key: 'createdAt', label: 'Created At'},
{key: 'name', label: 'Name'},
{key: 'directions', label: 'Directions'},
{key: 'authorId', label: 'Author ID'},
{key: 'style', label: 'Style'}
]
},
};