Skip to content

Commit 5a8071d

Browse files
authored
Merge branch 'master' into issue-13924
2 parents 9616f77 + bde7b75 commit 5a8071d

File tree

23 files changed

+658
-27
lines changed

23 files changed

+658
-27
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import akkio from "../../akkio.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "akkio-make-prediction",
6+
name: "Make Prediction",
7+
description: "Makes a prediction based on the input props. [See the documentation](https://docs.akkio.com/akkio-docs/rest-api/api-options/curl-commands)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
akkio,
12+
data: {
13+
type: "string[]",
14+
label: "Data",
15+
description: "Data in the format of: [{'field name 1': 'value 1', 'field name 2': 0}, {...}, ...]",
16+
},
17+
modelId: {
18+
type: "string",
19+
label: "Model ID",
20+
description: "The ID of the model to make the prediction with",
21+
async options() {
22+
const { models } = await this.akkio.getAllModels();
23+
24+
return models.map(({
25+
id: value, name: label,
26+
}) => ({
27+
label,
28+
value,
29+
}));
30+
},
31+
},
32+
33+
},
34+
async run({ $ }) {
35+
const response = await this.akkio.makePrediction({
36+
$,
37+
data: {
38+
data: parseObject(this.data),
39+
id: this.modelId,
40+
},
41+
});
42+
43+
$.export("$summary", `Successfully made prediction with model ID ${this.modelId}`);
44+
return response;
45+
},
46+
};

components/akkio/akkio.app.mjs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "akkio",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
_baseUrl() {
8+
return "https://api.akkio.com/v1";
9+
},
10+
_headers() {
11+
return {
12+
api_key: `${this.$auth.api_key}`,
13+
};
14+
},
15+
_makeRequest({
16+
$ = this, path, ...opts
17+
}) {
18+
return axios($, {
19+
url: this._baseUrl() + path,
20+
headers: this._headers(),
21+
...opts,
22+
});
23+
},
24+
getAllModels(opts = {}) {
25+
return this._makeRequest({
26+
...opts,
27+
method: "GET",
28+
path: "/models",
29+
});
30+
},
31+
makePrediction(opts = {}) {
32+
return this._makeRequest({
33+
method: "POST",
34+
path: "/models",
35+
...opts,
36+
});
937
},
1038
},
11-
};
39+
};

components/akkio/common/utils.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/akkio/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/akkio",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Akkio Components",
55
"main": "akkio.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
1417
}
15-
}
18+
}
19+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import alerty from "../../alerty.app.mjs";
2+
import { URGENCY_OPTIONS } from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "alerty-notify-devices",
7+
name: "Notify Devices",
8+
description: "Sends a notification to active devices. [See the documentation](https://alerty.dev/api/notify)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
alerty,
13+
message: {
14+
type: "string",
15+
label: "Message",
16+
description: "The message to be included in the push notification.",
17+
},
18+
title: {
19+
type: "string",
20+
label: "Title",
21+
description: "Title for your notification message.",
22+
optional: true,
23+
},
24+
image: {
25+
type: "string",
26+
label: "Image URL",
27+
description: "URL of an image to be displayed in the notification.",
28+
optional: true,
29+
},
30+
icon: {
31+
type: "string",
32+
label: "Icon URL",
33+
description: "URL of an image to be used as an icon by the notification. Default: Alerty Logo",
34+
optional: true,
35+
},
36+
deviceId: {
37+
type: "string[]",
38+
label: "Device ID",
39+
description: "Specific device IDs to send the notification to. If no Device Id is included, the push message will be sent to all active devices on your account.",
40+
optional: true,
41+
},
42+
urgency: {
43+
type: "string",
44+
label: "Urgency",
45+
description: "Urgency of the notification. Default: very-low",
46+
options: URGENCY_OPTIONS,
47+
optional: true,
48+
},
49+
actions: {
50+
type: "string[]",
51+
label: "Actions",
52+
description: "Actions for the notification, each item should be a JSON string. Example: { \"action\": \"https://example.com\", \"title\": \"Open Site\", \"icon\": \"https://example.com/icon.png\" }",
53+
optional: true,
54+
},
55+
},
56+
async run({ $ }) {
57+
const response = await this.alerty.makeRequest({
58+
$,
59+
data: {
60+
message: this.message,
61+
title: this.title,
62+
image: this.image,
63+
icon: this.icon,
64+
device_id: parseObject(this.deviceId),
65+
urgency: this.urgency,
66+
actions: parseObject(this.actions),
67+
},
68+
});
69+
70+
$.export("$summary", `Notification sent with message: "${this.message}"`);
71+
return response;
72+
},
73+
};

components/alerty/alerty.app.mjs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "alerty",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
_baseUrl() {
8+
return `${this.$auth.notification_url}`;
9+
},
10+
_headers() {
11+
return {
12+
Authorization: `Bearer ${this.$auth.api_key}`,
13+
};
14+
},
15+
makeRequest({
16+
$ = this, ...opts
17+
}) {
18+
return axios($, {
19+
method: "POST",
20+
url: this._baseUrl(),
21+
headers: this._headers(),
22+
...opts,
23+
});
924
},
1025
},
11-
};
26+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const URGENCY_OPTIONS = [
2+
"very-low",
3+
"low",
4+
"normal",
5+
"high",
6+
];

components/alerty/common/utils.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/alerty/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/alerty",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Alerty Components",
55
"main": "alerty.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
1417
}
15-
}
18+
}
19+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import toggl from "../../toggl.app.mjs";
2+
3+
export default {
4+
key: "toggl-create-client",
5+
name: "Create Client",
6+
description: "Create a new client in Toggl. [See the documentation](https://engineering.toggl.com/docs/api/clients#post-create-client)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
toggl,
11+
workspaceId: {
12+
propDefinition: [
13+
toggl,
14+
"workspaceId",
15+
],
16+
},
17+
name: {
18+
propDefinition: [
19+
toggl,
20+
"clientName",
21+
],
22+
},
23+
notes: {
24+
propDefinition: [
25+
toggl,
26+
"notes",
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const response = await this.toggl.createClient({
32+
$,
33+
workspaceId: this.workspaceId,
34+
data: {
35+
name: this.name,
36+
notes: this.notes,
37+
wid: this.workspaceId,
38+
},
39+
});
40+
if (response.id) {
41+
$.export("$summary", `Successfully created client with ID: ${response.id}`);
42+
}
43+
return response;
44+
},
45+
};

0 commit comments

Comments
 (0)