Skip to content

Commit eb3fc32

Browse files
committed
Added actions
1 parent 27ae00a commit eb3fc32

File tree

8 files changed

+309
-27
lines changed

8 files changed

+309
-27
lines changed

components/habitica/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import app from "../../habitica.app.mjs";
2+
3+
export default {
4+
key: "habitica-create-challenge",
5+
name: "Create Challenge",
6+
description: "Creates a challenge. [See the documentation](https://habitica.com/apidoc/#api-Challenge-CreateChallenge)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
type: {
12+
propDefinition: [
13+
app,
14+
"type",
15+
],
16+
},
17+
group: {
18+
propDefinition: [
19+
app,
20+
"group",
21+
(c) => ({
22+
type: c.type,
23+
}),
24+
],
25+
},
26+
name: {
27+
propDefinition: [
28+
app,
29+
"name",
30+
],
31+
},
32+
shortName: {
33+
propDefinition: [
34+
app,
35+
"shortName",
36+
],
37+
},
38+
summary: {
39+
propDefinition: [
40+
app,
41+
"summary",
42+
],
43+
},
44+
description: {
45+
propDefinition: [
46+
app,
47+
"description",
48+
],
49+
},
50+
official: {
51+
propDefinition: [
52+
app,
53+
"official",
54+
],
55+
},
56+
prize: {
57+
propDefinition: [
58+
app,
59+
"prize",
60+
],
61+
},
62+
},
63+
async run({ $ }) {
64+
const response = await this.app.createChallenge({
65+
$,
66+
data: {
67+
group: this.group,
68+
name: this.name,
69+
shortName: this.shortName,
70+
summary: this.summary,
71+
description: this.description,
72+
official: this.official,
73+
prize: this.prize,
74+
},
75+
});
76+
$.export("$summary", "Successfully created challenge with ID: " + response.data._id);
77+
return response;
78+
},
79+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import app from "../../habitica.app.mjs";
2+
3+
export default {
4+
key: "habitica-delete-challenge",
5+
name: "Delete Challenge",
6+
description: "Delete the challenge with the specified ID. [See the documentation](https://habitica.com/apidoc/#api-Challenge-DeleteChallenge)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
challengeId: {
12+
propDefinition: [
13+
app,
14+
"challengeId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.app.deleteChallenge({
20+
$,
21+
challengeId: this.challengeId,
22+
});
23+
$.export("$summary", "Successfully deleted the challenge with ID: " + this.challengeId);
24+
return response;
25+
},
26+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import app from "../../habitica.app.mjs";
2+
3+
export default {
4+
key: "habitica-get-challenge",
5+
name: "Get Challenge",
6+
description: "Description for get-challenge. [See the documentation](https://habitica.com/apidoc/#api-Challenge-GetChallenge)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
challengeId: {
12+
propDefinition: [
13+
app,
14+
"challengeId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.app.getChallenge({
20+
$,
21+
challengeId: this.challengeId,
22+
});
23+
$.export("$summary", "Successfully retrieved the challenge with ID: " + this.challengeId);
24+
return response;
25+
},
26+
};

components/habitica/app/habitica.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "habitica",
6+
propDefinitions: {
7+
group: {
8+
type: "string",
9+
label: "Group",
10+
description: "ID of the groups to which the challenge belongs",
11+
async options({ type }) {
12+
const response = await this.getGroups({
13+
type,
14+
});
15+
const groups = response.data;
16+
return groups.map(({
17+
name, _id,
18+
}) => ({
19+
label: name,
20+
value: _id,
21+
}));
22+
},
23+
},
24+
name: {
25+
type: "string",
26+
label: "Name",
27+
description: "Full name of the challenge",
28+
},
29+
shortName: {
30+
type: "string",
31+
label: "Short Name",
32+
description: "A shortened name for the challenge, to be used as a tag",
33+
},
34+
summary: {
35+
type: "string",
36+
label: "Summary",
37+
description: "A short summary advertising the main purpose of the challenge",
38+
optional: true,
39+
},
40+
description: {
41+
type: "string",
42+
label: "Description",
43+
description: "A detailed description of the challenge",
44+
optional: true,
45+
},
46+
official: {
47+
type: "boolean",
48+
label: "Official",
49+
description: "Whether or not a challenge is an official Habitica challenge",
50+
optional: true,
51+
},
52+
prize: {
53+
type: "string",
54+
label: "Prize",
55+
description: "Number of gems offered as a prize to challenge winne",
56+
optional: true,
57+
},
58+
type: {
59+
type: "string",
60+
label: "Type",
61+
description: "Type of the group",
62+
},
63+
challengeId: {
64+
type: "string",
65+
label: "Challenge ID",
66+
description: "ID of the challenge to update",
67+
async options({ page }) {
68+
const response = await this.getChallenges({
69+
params: {
70+
page: page,
71+
},
72+
});
73+
const challenges = response.data;
74+
return challenges.map(({
75+
name, _id,
76+
}) => ({
77+
label: name,
78+
value: _id,
79+
}));
80+
},
81+
},
82+
},
83+
methods: {
84+
_baseUrl() {
85+
return "https://habitica.com/api/v3";
86+
},
87+
async _makeRequest(opts = {}) {
88+
const {
89+
$ = this,
90+
path,
91+
headers,
92+
...otherOpts
93+
} = opts;
94+
return axios($, {
95+
...otherOpts,
96+
url: this._baseUrl() + path,
97+
headers: {
98+
...headers,
99+
"x-client": "3a326108-1895-4c23-874e-37668c75f2ad-Pipedream",
100+
"x-api-user": `${this.$auth.user_id}`,
101+
"x-api-key": `${this.$auth.api_token}`,
102+
},
103+
});
104+
},
105+
async createChallenge(args = {}) {
106+
return this._makeRequest({
107+
path: "/challenges",
108+
method: "post",
109+
...args,
110+
});
111+
},
112+
async deleteChallenge({
113+
challengeId, ...args
114+
}) {
115+
return this._makeRequest({
116+
path: `/challenges/${challengeId}`,
117+
method: "delete",
118+
...args,
119+
});
120+
},
121+
async getChallenge({
122+
challengeId, ...args
123+
}) {
124+
return this._makeRequest({
125+
path: `/challenges/${challengeId}`,
126+
...args,
127+
});
128+
},
129+
async getGroups({
130+
type, ...args
131+
}) {
132+
return this._makeRequest({
133+
path: "/groups",
134+
params: {
135+
type: type,
136+
},
137+
...args,
138+
});
139+
},
140+
async getChallenges(args = {}) {
141+
return this._makeRequest({
142+
path: "/challenges/user",
143+
...args,
144+
});
145+
},
146+
},
147+
};

components/habitica/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/habitica",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Habitica Components",
5-
"main": "dist/app/habitica.app.mjs",
5+
"main": "habitica.app.mjs",
66
"keywords": [
77
"pipedream",
88
"habitica"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/habitica",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1517
}
1618
}

0 commit comments

Comments
 (0)