Skip to content

Commit 39f8ece

Browse files
author
Edoardo Soloperto
committed
first commit
0 parents  commit 39f8ece

13 files changed

+491
-0
lines changed

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Hayashi Takuya
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
A simple wrapper for [ClickUp](https://clickup.com/) API (v2).
2+
3+
4+
## Install
5+
```bash
6+
composer require "edsol/clickup-php"
7+
```
8+
9+
## Team
10+
11+
### get all
12+
```php
13+
$this->team()->all();
14+
```
15+
### get all spaces
16+
```php
17+
$this->team("12345")->spaces();
18+
```
19+
20+
21+
22+
## Comment
23+
24+
### get Task comment
25+
```php
26+
$this->task("12345")->comments();
27+
```
28+
29+
### get List comment
30+
```php
31+
$this->list("12345")->comments();
32+
```
33+
34+
### create
35+
```php
36+
$this->task("12345")->createComment([
37+
"comment_text": "Task comment content",
38+
// "assignee": 183,
39+
// "notify_all": true
40+
]);
41+
```
42+
43+
## Folder
44+
45+
### get folder
46+
```php
47+
$this->folder("12345")->get();
48+
```
49+
50+
or
51+
52+
```php
53+
$this->folder()->get("12345");
54+
```
55+
56+
## Space
57+
58+
### get all spaces
59+
```php
60+
$this->space()->all();
61+
```
62+
or
63+
64+
```php
65+
$this->space()->get("12345");
66+
```
67+
68+
### get tasks
69+
```php
70+
$this->space("12345")->get();
71+
```

composer.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "edsol/php-clickup-api-client",
3+
"description": "ClickUp V2 API client (unofficial)",
4+
"keywords": [
5+
"ClickUp",
6+
"click-up",
7+
"api",
8+
"php"
9+
],
10+
"type": "library",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Edoardo Soloperto",
15+
"email": "edoardo.soloperto@gmail.com"
16+
}
17+
],
18+
"minimum-stability": "stable",
19+
"require": {
20+
"php": ">=5.6",
21+
"guzzlehttp/guzzle": "^6.3|^7.2"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"ClickUpClient\\": "src/"
26+
}
27+
},
28+
"require-dev": {
29+
"psy/psysh": "^0.9.8"
30+
}
31+
}

src/Client.php

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace ClickUpClient;
4+
5+
// define('DOT', '.');
6+
// define('DS', '/');
7+
8+
class Client
9+
{
10+
private $guzzleClient;
11+
private const MODELS_NAMESPACE = __NAMESPACE__ . "\\Models\\";
12+
private $models_match = [
13+
'TaskList' => 'list'
14+
];
15+
16+
public function __construct($apiToken)
17+
{
18+
$this->guzzleClient = new \GuzzleHttp\Client([
19+
'base_uri' => 'https://api.clickup.com/api/v2/',
20+
'headers' => [
21+
'Authorization' => $apiToken,
22+
],
23+
]);
24+
}
25+
26+
/**
27+
* client
28+
*
29+
* @return Client
30+
*/
31+
public function client()
32+
{
33+
return $this;
34+
}
35+
36+
/**
37+
* __call
38+
*
39+
* @param mixed $name
40+
* @param mixed $arguments
41+
* @return void
42+
*/
43+
public function __call(string $name, array $arguments)
44+
{
45+
if (class_exists(self::MODELS_NAMESPACE . ucfirst($name)) === false) {
46+
throw new \Exception("`$name` is not a method or object", 1);
47+
}
48+
$model = ucfirst($name);
49+
$model_namespaced = self::MODELS_NAMESPACE . $model;
50+
51+
if (array_key_exists($model, $this->models_match)) {
52+
$model = $this->models_match[$model];
53+
}
54+
55+
$object = new $model_namespaced($this, $arguments[0] ?? null);
56+
return $object;
57+
}
58+
59+
/**
60+
* @param string $method
61+
* @param array $params
62+
* @return mixed
63+
*/
64+
public function get($method, $params = [])
65+
{
66+
$response = $this->guzzleClient->request('GET', $method, ['query' => $params]);
67+
return json_decode($response->getBody(), true);
68+
}
69+
70+
/**
71+
* @param string $method
72+
* @param array $body
73+
* @return mixed
74+
*/
75+
public function post($method, $body = [])
76+
{
77+
$response = $this->guzzleClient->request('POST', $method, ['json' => $body]);
78+
return json_decode($response->getBody(), true);
79+
}
80+
81+
/**
82+
* delete
83+
*
84+
* @param mixed $method
85+
* @return int
86+
*/
87+
public function delete($method)
88+
{
89+
$response = $this->guzzleClient->request('DELETE', $method);
90+
return $response->getStatusCode();
91+
}
92+
93+
public function put($method, $body = [])
94+
{
95+
$response = $this->guzzleClient->request('PUT', $method, ['json' => $body]);
96+
return json_decode($response->getBody(), true);
97+
}
98+
}

src/Models/AbstractModel.php

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace ClickUpClient\Models;
4+
5+
use \ClickUpClient\Client;
6+
7+
abstract class AbstractModel
8+
{
9+
public $model;
10+
/* @var Client $client */
11+
public $client;
12+
public $id;
13+
14+
/* @var array $extra */
15+
private $extra;
16+
17+
/**
18+
* @param Client $client
19+
* @param array $array
20+
*/
21+
public function __construct(Client $client, string $id = null)
22+
{
23+
$this->setClient($client);
24+
if (!empty($id)) {
25+
$this->setId($id);
26+
}
27+
}
28+
29+
// abstract protected function fromArray($array);
30+
31+
/**
32+
* @return Client
33+
*/
34+
protected function client()
35+
{
36+
return $this->client;
37+
}
38+
39+
/**
40+
* setClient
41+
*
42+
* @param mixed $client
43+
* @return void
44+
*/
45+
private function setClient(Client $client)
46+
{
47+
$this->client = $client;
48+
}
49+
50+
/**
51+
* setModel
52+
*
53+
* @param string $model
54+
* @return void
55+
*/
56+
public function setModel(string $model)
57+
{
58+
$this->model = $model;
59+
}
60+
61+
/**
62+
* checkId
63+
*
64+
* @return void
65+
*/
66+
public function checkId()
67+
{
68+
if ($this->id === null) {
69+
throw new \Exception("An ID is required to make the request", 1);
70+
}
71+
}
72+
73+
/**
74+
* setId
75+
*
76+
* @param mixed $id
77+
* @return void
78+
*/
79+
public function setId(string $id)
80+
{
81+
$this->id = $id;
82+
}
83+
84+
public function get(string $id = null)
85+
{
86+
return $this->client()->get($this->model . DS . ($id ?? $this->id));
87+
}
88+
}

src/Models/Comment.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace ClickUpClient\Models;
4+
5+
use \ClickUpClient\CommentTrait;
6+
7+
class Comment extends AbstractModel
8+
{
9+
use CommentTrait;
10+
11+
public $model = 'comment';
12+
}

src/Models/Folder.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace ClickUpClient\Models;
4+
5+
class Folder extends AbstractModel
6+
{
7+
public $model = 'folder';
8+
9+
/**
10+
* get all list
11+
*
12+
* @return void
13+
*/
14+
public function lists()
15+
{
16+
$this->checkId();
17+
return $this->client()->get($this->model . DS . $this->id . DS . "list");
18+
}
19+
}

src/Models/Space.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace ClickUpClient\Models;
4+
5+
class Space extends AbstractModel
6+
{
7+
public $model = 'space';
8+
9+
/**
10+
* tags
11+
*
12+
* @return void
13+
*/
14+
public function tags()
15+
{
16+
return $this->client()->get($this->model . DS . $this->id . DS . "tag");
17+
}
18+
}

src/Models/Task.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace ClickUpClient\Models;
4+
5+
use \ClickUpClient\CommentTrait;
6+
use \ClickUpClient\MemberTrait;
7+
8+
class Task extends AbstractModel
9+
{
10+
use CommentTrait;
11+
use MemberTrait;
12+
13+
public $model = 'task';
14+
}

src/Models/TaskList.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace ClickUpClient\Models;
4+
5+
use \ClickUpClient\CommentTrait;
6+
use \ClickUpClient\MemberTrait;
7+
8+
class TaskList extends AbstractModel
9+
{
10+
use CommentTrait;
11+
use MemberTrait;
12+
public $model = 'list';
13+
}

0 commit comments

Comments
 (0)