Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
84 changes: 84 additions & 0 deletions components/everhour/actions/create-task/create-task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { STATUS_OPTIONS } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import everhour from "../../everhour.app.mjs";

export default {
key: "everhour-create-task",
name: "Create Task",
description: "Creates a new task in Everhour. [See the documentation](https://everhour.docs.apiary.io/)",
version: "0.0.1",
type: "action",
props: {
everhour,
projectId: {
propDefinition: [
everhour,
"projectId",
],
},
name: {
type: "string",
label: "Task Name",
description: "The name of the task to be created.",
},
sectionId: {
propDefinition: [
everhour,
"sectionId",
({ projectId }) => ({
projectId,
}),
],
},
tags: {
propDefinition: [
everhour,
"tags",
],
optional: true,
},
position: {
type: "integer",
label: "Position",
description: "The position of the task",
optional: true,
},
description: {
type: "string",
label: "Description",
description: "A description of the task",
optional: true,
},
dueOn: {
type: "string",
label: "Due Date",
description: "The due date of the task. **Format: YYYY-MM-DD**",
optional: true,
},
status: {
type: "string",
label: "Status",
description: "The status of the task",
options: STATUS_OPTIONS,
optional: true,
},
},
async run({ $ }) {
const response = await this.everhour.createTask({
$,
projectId: this.projectId,
data: {
name: this.name,
section: this.sectionId,
tags: this.tags && parseObject(this.tags),
position: this.position,
description: this.description,
dueOn: this.dueOn,
status: this.status,
},
});

$.export("$summary", `Successfully created task with ID: ${response.id}`);
return response;
},
};
52 changes: 52 additions & 0 deletions components/everhour/actions/start-timer/start-timer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import everhour from "../../everhour.app.mjs";

export default {
key: "everhour-start-timer",
name: "Start Timer",
description: "Begins a new timer for a task. [See the documentation](https://everhour.docs.apiary.io/#reference/0/timers/start-timer)",
version: "0.0.1",
type: "action",
props: {
everhour,
projectId: {
propDefinition: [
everhour,
"projectId",
],
},
taskId: {
propDefinition: [
everhour,
"taskId",
({ projectId }) => ({
projectId,
}),
],
},
userDate: {
type: "string",
label: "User Date",
description: "Date string to associate with the timer. Format as 'YYYY-MM-DD'",
optional: true,
},
comment: {
type: "string",
label: "Comment",
description: "An optional comment to associate with the timer",
optional: true,
},
},
async run({ $ }) {
const response = await this.everhour.startTimer({
$,
data: {
task: this.taskId,
userDate: this.userDate,
comment: this.comment,
},
});

$.export("$summary", `Successfully started a timer for task ID: ${this.taskId}`);
return response;
},
};
17 changes: 17 additions & 0 deletions components/everhour/actions/stop-timer/stop-timer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import everhour from "../../everhour.app.mjs";

export default {
key: "everhour-stop-timer",
name: "Stop Timer",
description: "Halts the current running timer. [See the documentation](https://everhour.docs.apiary.io/#reference/timers/stop-timer)",
version: "0.0.1",
type: "action",
props: {
everhour,
},
async run({ $ }) {
const response = await this.everhour.stopTimer();
$.export("$summary", "Successfully stopped the timer");
return response;
},
};
12 changes: 12 additions & 0 deletions components/everhour/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const LIMIT = 100;

export const STATUS_OPTIONS = [
{
label: "Open",
value: "open",
},
{
label: "Close",
value: "close",
},
];
24 changes: 24 additions & 0 deletions components/everhour/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
173 changes: 169 additions & 4 deletions components/everhour/everhour.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,176 @@
import { axios } from "@pipedream/platform";
import { LIMIT } from "./common/constants.mjs";

export default {
type: "app",
app: "everhour",
propDefinitions: {},
propDefinitions: {
projectId: {
type: "string",
label: "Project ID",
description: "The ID of the project",
async options({ page }) {
const projects = await this.listProjects({
params: {
limit: LIMIT,
page: page + 1,
},
});

return projects.map(({
name: label, id: value,
}) => ({
label,
value,
}));
},
},
sectionId: {
type: "string",
label: "Section ID",
description: "The section id of the task",
async options({ projectId }) {
const sections = await this.listSections({
projectId,
});

return sections.map(({
name: label, id: value,
}) => ({
label,
value,
}));
},
},
tags: {
type: "string[]",
label: "Tag IDs",
description: "The tag ids of the task",
async options() {
const tags = await this.listTags();

return tags.map(({
name: label, id: value,
}) => ({
label,
value,
}));
},
},
labels: {
type: "string[]",
label: "Tags",
description: "An array of tags associated with the task",
async options({ projectId }) {
const sections = await this.listSections({
projectId,
});

return sections.map(({
name: label, id: value,
}) => ({
label,
value,
}));
},
},
taskId: {
type: "string",
label: "Task ID",
description: "The ID of the task",
async options({ projectId }) {
const tasks = await this.getProjectTasks({
projectId,
});
return tasks.map(({
name: label, id: value,
}) => ({
label,
value,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.everhour.com";
},
_headers() {
return {
"X-Api-Key": `${this.$auth.api_token}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
listProjects(opts = {}) {
return this._makeRequest({
path: "/projects",
...opts,
});
},
listSections({
projectId, opts,
}) {
return this._makeRequest({
path: `/projects/${projectId}/sections`,
...opts,
});
},
listTags() {
return this._makeRequest({
path: "/tags",
});
},
getProjectTasks({
projectId, ...opts
}) {
return this._makeRequest({
path: `/projects/${projectId}/tasks`,
...opts,
});
},
createTask({
projectId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/projects/${projectId}/tasks`,
...opts,
});
},
startTimer(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/timers",
...opts,
});
},
stopTimer(opts = {}) {
return this._makeRequest({
method: "DELETE",
path: "/timers/current",
...opts,
});
},
createWebhook(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/hooks",
...opts,
});
},
deleteWebhook(webhookId) {
return this._makeRequest({
method: "DELETE",
path: `/hooks/${webhookId}`,
});
},
},
};
18 changes: 18 additions & 0 deletions components/everhour/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@pipedream/everhour",
"version": "0.1.0",
"description": "Pipedream Everhour Components",
"main": "everhour.app.mjs",
"keywords": [
"pipedream",
"everhour"
],
"homepage": "https://pipedream.com/apps/everhour",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
Loading
Loading