Skip to content

Commit

Permalink
Merge pull request #11 from lpg2709/dev
Browse files Browse the repository at this point in the history
Dev into master
  • Loading branch information
lpg2709 authored Nov 18, 2023
2 parents fdf5262 + 4df68a9 commit 94cfa72
Show file tree
Hide file tree
Showing 136 changed files with 110 additions and 52 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish Package to npmjs
run-name: NPM publish
on:
push:
branches:
- main
tags:
- v*.*.*
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.1] - 2023-11-18 -

## [1.2.0] - 2023-05-06 - xxxxxxxxxxxxxxxxxxxxxxxxxxxx
### Added

- Github Actions for publish :)

### Changed

- Better parameters evaluation

### Fixed

- The 204 JSON parsing issue: Pull request [#8](https://github.com/lpg2709/clickup_api/pull/8) from [@aduyng](https://github.com/aduyng)
- Typo in the example directory name - Pull request [#9](https://github.com/lpg2709/clickup_api/pull/9) by [@alexander-mart](https://github.com/mordygparency)
- Parameters empty on url
- `view_id` is required on `get_chat_view_comments`
- `team_id` is required on `get_custom_roles`
- `task_id`is required on `create_checklist`
- Better handle of `task_ids` on `get_tasks_time_in_status`

## [1.2.0] - 2023-05-06 - fdf5262bb0cadf69376d07b03e56b18a6822bfb0

### Added

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ To view the examples, you can access the [github](https://github.com/lpg2709/cli

## Changes log

All changes by version can be see on [CHANGELOG.md](https://github.com/lpg2709/clickup_api/blob/master/CHANGELOG) on [github](https://github.com/lpg2709/clickup_api)
All changes by version can be see on [CHANGELOG.md](https://raw.githubusercontent.com/lpg2709/clickup_api/master/CHANGELOG.md) on [github](https://github.com/lpg2709/clickup_api)

## Contributing

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async function main(){
const clickup = new clickup_api("access_token");

var param = {
"task_ids": "123",
"task_ids": ["123", "321"],
// "custom_task_ids": "0",
// "team_id": "123",
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "clickup_api",
"version": "1.2.0",
"version": "1.2.1",
"description": "No oficial module for ClickUp API",
"main": "src/index.js",
"contributors": [
"InSandBox <47696299+InSandBox@users.noreply.github.com>",
"J Paul Fortey <paul@f4tey.co.uk>",
"Carlos Souza <51545352+csouza1995@users.noreply.github.com>",
"accountantKev <50839401+accountantKev@users.noreply.github.com>",
"mordygparency <https://github.com/mordygparency>"
"mordygparency <https://github.com/mordygparency>",
"alexander-mart <https://github.com/mordygparency>"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
4 changes: 2 additions & 2 deletions src/components/Comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ Comments.prototype.get_chat_view_comments = function (view_id, params) {
var token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, []);
var res = await Requests.https_clickupapi_get(`/api/v2/view/${view_id}/comment?${Object.keys(params).length > 1 ? param : ""}`, token);
let param = genParams(params, ["view_id"], ["view_id"]);
var res = await Requests.https_clickupapi_get(`/api/v2/view/${view_id}/comment${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ var Roles = function(token){
*/
Roles.prototype.get_custom_roles = function(team_id, params){
var token = this.token;
let param = genParams(params, ["include_members"]);
let param = genParams(params, ["team_id"], ["team_id"]);
return new Promise(async function (resolve, reject) {
try {
var res = await Requests.https_clickupapi_get(`/team/${team_id}/customroles${params.length > 1 ? param : ""}`, token);
var res = await Requests.https_clickupapi_get(`/team/${team_id}/customroles${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand Down
4 changes: 2 additions & 2 deletions src/components/TaskCheckList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ TaskCheckList.prototype.create_checklist = function (task_id, params, data) {
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, []);
var res = await Requests.https_clickupapi_post(`/api/v2/task/${task_id}/checklist?${Object.keys(params).length > 1 ? param : ""}`, data, token);
let param = genParams(params, ["task_id"], ["task_id"]);
var res = await Requests.https_clickupapi_post(`/api/v2/task/${task_id}/checklist${param}`, data, token);
resolve(res);
} catch (err) {
reject(err);
Expand Down
16 changes: 8 additions & 8 deletions src/components/TaskRelationships.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ TaskRelationships.prototype.add_dependency = function (task_id, params, data) {
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, []);
var res = await Requests.https_clickupapi_post(`/api/v2/task/${task_id}/dependency?${Object.keys(params).length > 1 ? param : ""}`, data, token);
let param = genParams(params, ["task_id"], ["task_id"]);
var res = await Requests.https_clickupapi_post(`/api/v2/task/${task_id}/dependency${param}`, data, token);
resolve(res);
} catch (err) {
reject(err);
Expand All @@ -31,8 +31,8 @@ TaskRelationships.prototype.delete_dependency = function (task_id, params) {
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, ["depends_on", "dependency_of"]);
var res = await Requests.https_clickupapi_delete(`/api/v2/task/${task_id}/dependency?${Object.keys(params).length > 1 ? param : ""}`, token);
let param = genParams(params, ["task_id","depends_on", "dependency_of"], ["task_id"]);
var res = await Requests.https_clickupapi_delete(`/api/v2/task/${task_id}/dependency${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand All @@ -49,8 +49,8 @@ TaskRelationships.prototype.add_task_link = function (task_id, links_to, params)
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, []);
var res = await Requests.https_clickupapi_post(`/api/v2/task/${task_id}/link/${links_to}?${Object.keys(params).length > 1 ? param : ""}`, token);
let param = genParams(params, ["task_id", "links_to"], ["task_id", "links_to"]);
var res = await Requests.https_clickupapi_post(`/api/v2/task/${task_id}/link/${links_to}${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand All @@ -67,8 +67,8 @@ TaskRelationships.prototype.delete_task_link = function (task_id, links_to, para
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, []);
var res = await Requests.https_clickupapi_delete(`/api/v2/task/${task_id}/link/${links_to}?${Object.keys(params).length > 1 ? param : ""}`, token);
let param = genParams(params, ["task_id", "links_to"], ["task_id", "links_to"]);
var res = await Requests.https_clickupapi_delete(`/api/v2/task/${task_id}/link/${links_to}${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand Down
27 changes: 17 additions & 10 deletions src/components/Tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ Tasks.prototype.get_task = function (params) {
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, ["task_id"]);
var res = await Requests.https_clickupapi_get(`/api/v2/task/${params.task_id}/?${params.length > 1 ? param : ""}`, token);
let param = genParams(params, ["task_id"], ["task_id"]);
var res = await Requests.https_clickupapi_get(`/api/v2/task/${params.task_id}${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand All @@ -75,8 +75,8 @@ Tasks.prototype.get_tasks = function (params) {
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, ["list_id", "archived"]);
var res = await Requests.https_clickupapi_get(`/api/v2/list/${params.list_id}/task?${params.length > 1 ? param : ""}`, token);
let param = genParams(params, ["list_id"], ["list_id"]);
var res = await Requests.https_clickupapi_get(`/api/v2/list/${params.list_id}/task${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand All @@ -92,8 +92,8 @@ Tasks.prototype.get_filtered_team_tasks = function (params) {
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, ["team_Id", "page"]);
var res = await Requests.https_clickupapi_get(`/api/v2/team/${params.team_id}/task?${params.length > 1 ? param : ""}`, token);
let param = genParams(params, ["team_Id"], ["team_Id"]);
var res = await Requests.https_clickupapi_get(`/api/v2/team/${params.team_id}/task${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand All @@ -109,8 +109,8 @@ Tasks.prototype.get_tasks_time_in_status = function (params) {
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, ["task_id"]);
var res = await Requests.https_clickupapi_get(`/api/v2/task/${params.task_id}/time_in_status?${params.length > 1 ? param : ""}`, token);
let param = genParams(params, ["task_id"], ["task_id"]);
var res = await Requests.https_clickupapi_get(`/api/v2/task/${params.task_id}/time_in_status${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand All @@ -123,11 +123,18 @@ Tasks.prototype.get_tasks_time_in_status = function (params) {
* @param {JSON} params Request parameters in JSON format
*/
Tasks.prototype.get_bulk_tasks_time_in_status = function (params) {
// If thers some bug, is because i can't test in my plan :(
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, ["task_ids"]);
var res = await Requests.https_clickupapi_get(`/api/v2/task/bulk_time_in_status/task_ids?${params.task_ids}&${params.length > 1 ? param : ""}`, token);
let param = genParams(params, ["task_ids"], ["task_ids"]);
let tasks_ids = "?";
params["task_ids"].forEach((e) => {
tasks_ids += `task_ids=${e}&`;
})
tasks_ids = tasks_ids.slice(0, -1);
param = param.replace("?", "");
var res = await Requests.https_clickupapi_get(`/api/v2/task/bulk_time_in_status/task_ids${tasks_ids}${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand Down
4 changes: 2 additions & 2 deletions src/components/TimeTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ TimeTracking.prototype.get_time_entries_within_date_range = function (params) {
token = this.token;
return new Promise(async function (resolve, reject) {
try {
let param = genParams(params, ["team_id"]);
var res = await Requests.https_clickupapi_get(`/api/v2/team/${params.team_id}/time_entries?${Object.keys(params).length > 1 ? param : ""}`, token);
let param = genParams(params, ["team_id"], ["team_id"]);
var res = await Requests.https_clickupapi_get(`/api/v2/team/${params.team_id}/time_entries${param}`, token);
resolve(res);
} catch (err) {
reject(err);
Expand Down
1 change: 0 additions & 1 deletion src/components/Users.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const Requests = require("../utils/requests");
const genParams = require("../utils/params");

var Users = function (token) {
this.token = token;
Expand Down
40 changes: 22 additions & 18 deletions src/utils/params.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
module.exports = function (params, required) {
var requiredCount = 0;
module.exports = function (params, required, path_params) {
var requiredCount = 0;

required.forEach(function(elem){
if (params[elem] === undefined) {
console.log(`Error: ${elem} required, see ClickUp documentation`);
requiredCount++;
}
});

if (requiredCount !== 0){
return;
required.forEach(function(elem){
if (params[elem] === undefined) {
console.log(`Error: ${elem} required, see ClickUp documentation`);
requiredCount++;
}
});

if (requiredCount !== 0){
return;
}

var paramsName = Object.keys(params);
var str = "";
var paramsName = Object.keys(params);
var str = "";
let first = true;

for(let i in paramsName){
for(let i in paramsName){
if(first)
str += "?"; first = false;
if(!path_params.includes(paramsName[i]))
str += paramsName[i]+"="+params[paramsName[i]]+"&";
}
str = str.slice(0,-1);
str = encodeURI(str);
}
str = str.slice(0,-1);
str = encodeURI(str);

return str;
return str;
}
12 changes: 10 additions & 2 deletions src/utils/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,21 @@ module.exports = {
if (res.statusCode != 204) {
reject(res.statusCode);
}

// 204 should not return any data, but if it does, we'll parse it
res.on('data', function (chunk) {
str += chunk;
});

res.on('end', function () {
resolve(JSON.parse(str));
let parsedJSON = null;
try {
parsedJSON = JSON.parse(str);
}
catch (e) {
// ignore the error for now
}

resolve(parsedJSON);
});

res.on('error', function (err) {
Expand Down

0 comments on commit 94cfa72

Please sign in to comment.