Skip to content

Commit 6a4420e

Browse files
authored
Merging pull request #17012
* Added actions * Added actions
1 parent 80b68e3 commit 6a4420e

File tree

9 files changed

+299
-20
lines changed

9 files changed

+299
-20
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: "Get data for the challenge with the specified ID. [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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
GROUP_TYPES: [
3+
"party",
4+
"guilds",
5+
"privateGuilds",
6+
"publicGuilds",
7+
"tavern",
8+
],
9+
};

components/habitica/habitica.app.mjs

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

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
}

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)