Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions components/habitica/.gitignore

This file was deleted.

79 changes: 79 additions & 0 deletions components/habitica/actions/create-challenge/create-challenge.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import app from "../../habitica.app.mjs";

export default {
key: "habitica-create-challenge",
name: "Create Challenge",
description: "Creates a challenge. [See the documentation](https://habitica.com/apidoc/#api-Challenge-CreateChallenge)",
version: "0.0.1",
type: "action",
props: {
app,
type: {
propDefinition: [
app,
"type",
],
},
group: {
propDefinition: [
app,
"group",
(c) => ({
type: c.type,
}),
],
},
name: {
propDefinition: [
app,
"name",
],
},
shortName: {
propDefinition: [
app,
"shortName",
],
},
summary: {
propDefinition: [
app,
"summary",
],
},
description: {
propDefinition: [
app,
"description",
],
},
official: {
propDefinition: [
app,
"official",
],
},
prize: {
propDefinition: [
app,
"prize",
],
},
},
async run({ $ }) {
const response = await this.app.createChallenge({
$,
data: {
group: this.group,
name: this.name,
shortName: this.shortName,
summary: this.summary,
description: this.description,
official: this.official,
prize: this.prize,
},
});
$.export("$summary", "Successfully created challenge with ID: " + response.data._id);
return response;
},
};
26 changes: 26 additions & 0 deletions components/habitica/actions/delete-challenge/delete-challenge.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import app from "../../habitica.app.mjs";

export default {
key: "habitica-delete-challenge",
name: "Delete Challenge",
description: "Delete the challenge with the specified ID. [See the documentation](https://habitica.com/apidoc/#api-Challenge-DeleteChallenge)",
version: "0.0.1",
type: "action",
props: {
app,
challengeId: {
propDefinition: [
app,
"challengeId",
],
},
},
async run({ $ }) {
const response = await this.app.deleteChallenge({
$,
challengeId: this.challengeId,
});
$.export("$summary", "Successfully deleted the challenge with ID: " + this.challengeId);
return response;
},
};
26 changes: 26 additions & 0 deletions components/habitica/actions/get-challenge/get-challenge.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import app from "../../habitica.app.mjs";

export default {
key: "habitica-get-challenge",
name: "Get Challenge",
description: "Description for get-challenge. [See the documentation](https://habitica.com/apidoc/#api-Challenge-GetChallenge)",
version: "0.0.1",
type: "action",
props: {
app,
challengeId: {
propDefinition: [
app,
"challengeId",
],
},
},
async run({ $ }) {
const response = await this.app.getChallenge({
$,
challengeId: this.challengeId,
});
$.export("$summary", "Successfully retrieved the challenge with ID: " + this.challengeId);
return response;
},
};
13 changes: 0 additions & 13 deletions components/habitica/app/habitica.app.ts

This file was deleted.

147 changes: 147 additions & 0 deletions components/habitica/habitica.app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "habitica",
propDefinitions: {
group: {
type: "string",
label: "Group",
description: "ID of the groups to which the challenge belongs",
async options({ type }) {
const response = await this.getGroups({
type,
});
const groups = response.data;
return groups.map(({
name, _id,
}) => ({
label: name,
value: _id,
}));
},
},
name: {
type: "string",
label: "Name",
description: "Full name of the challenge",
},
shortName: {
type: "string",
label: "Short Name",
description: "A shortened name for the challenge, to be used as a tag",
},
summary: {
type: "string",
label: "Summary",
description: "A short summary advertising the main purpose of the challenge",
optional: true,
},
description: {
type: "string",
label: "Description",
description: "A detailed description of the challenge",
optional: true,
},
official: {
type: "boolean",
label: "Official",
description: "Whether or not a challenge is an official Habitica challenge",
optional: true,
},
prize: {
type: "string",
label: "Prize",
description: "Number of gems offered as a prize to challenge winne",
optional: true,
},
type: {
type: "string",
label: "Type",
description: "Type of the group",
},
challengeId: {
type: "string",
label: "Challenge ID",
description: "ID of the challenge to update",
async options({ page }) {
const response = await this.getChallenges({
params: {
page: page,
},
});
const challenges = response.data;
return challenges.map(({
name, _id,
}) => ({
label: name,
value: _id,
}));
},
},
},
methods: {
_baseUrl() {
return "https://habitica.com/api/v3";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"x-client": "3a326108-1895-4c23-874e-37668c75f2ad-Pipedream",
"x-api-user": `${this.$auth.user_id}`,
"x-api-key": `${this.$auth.api_token}`,
},
});
},
async createChallenge(args = {}) {
return this._makeRequest({
path: "/challenges",
method: "post",
...args,
});
},
async deleteChallenge({
challengeId, ...args
}) {
return this._makeRequest({
path: `/challenges/${challengeId}`,
method: "delete",
...args,
});
},
async getChallenge({
challengeId, ...args
}) {
return this._makeRequest({
path: `/challenges/${challengeId}`,
...args,
});
},
async getGroups({
type, ...args
}) {
return this._makeRequest({
path: "/groups",
params: {
type: type,
},
...args,
});
},
async getChallenges(args = {}) {
return this._makeRequest({
path: "/challenges/user",
...args,
});
},
},
};
8 changes: 5 additions & 3 deletions components/habitica/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "@pipedream/habitica",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream Habitica Components",
"main": "dist/app/habitica.app.mjs",
"main": "habitica.app.mjs",
"keywords": [
"pipedream",
"habitica"
],
"files": ["dist"],
"homepage": "https://pipedream.com/apps/habitica",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
Loading
Loading