Skip to content

Commit f020c70

Browse files
committed
Merge branch 'release/1.2.5'
2 parents 3827143 + 441380b commit f020c70

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Psy Shell v0.9.9 (PHP 7.3.11 — cli) by Justin Hileman
130130
=> Spinen\ClickUp\Api\Client {#2363}
131131
```
132132

133-
The `$clickup` instance will work exaclty like all of the examples below, so if you are not using Laravel, then you can use the package once you bootstrap the client.
133+
The `$clickup` instance will work exactly like all of the examples below, so if you are not using Laravel, then you can use the package once you bootstrap the client.
134134

135135

136136
## Authentication
@@ -139,7 +139,7 @@ ClickUp has 2 ways to authenticate when making API calls... 1) OAuth token or 2)
139139

140140
### OAuth
141141

142-
There is a middleware named `clickup` that you can apply to any route that verifies that the user has a `clickup_token`, and if the user does not, then it redirects the user to ClickUp's OAuth page with the `client_id` where the user selectes the team(s) to link with your applciation. Upon selecting the team(s), the user is rediected to `/clickup/sso/<user_id>?code=<OAuth Code>` where the system converts the `code` to a token & saves it to the user. Upon saving the `clickup_token`, the user is redirected to the inital page that was proteted by the middleware.
142+
There is a middleware named `clickup` that you can apply to any route that verifies that the user has a `clickup_token`, and if the user does not, then it redirects the user to ClickUp's OAuth page with the `client_id` where the user selects the team(s) to link with your application. Upon selecting the team(s), the user is redirected to `/clickup/sso/<user_id>?code=<OAuth Code>` where the system converts the `code` to a token & saves it to the user. Upon saving the `clickup_token`, the user is redirected to the initial page that was protected by the middleware.
143143

144144
> NOTE: You will need to have the `auth` middleware on the routes as the `User` is needed to see if there is a `clickup_token`.
145145
@@ -159,7 +159,7 @@ Psy Shell v0.9.9 (PHP 7.3.11 — cli) by Justin Hileman
159159
160160
### Personal Token
161161

162-
If you do not what to use the OAuth flow, then you can allow the user to provide you a personal token that you can save on the `User`.
162+
If you do not want to use the OAuth flow, then you can allow the user to provide you a personal token that you can save on the `User`.
163163

164164
```bash
165165
$ php artisan tinker

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.4
1+
1.2.5

src/Api/Client.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ public function request($path, $data = [], $method = 'GET'): ?array
219219
*/
220220
public function setConfigs(array $configs): self
221221
{
222-
$this->configs = $configs;
222+
// Replace empty strings with nulls in config values
223+
$this->configs = array_map(function($value) {
224+
return $value === "" ? null : $value;
225+
}, $configs);
223226

224227
return $this;
225228
}
@@ -241,8 +244,9 @@ public function setToken($token): self
241244
/**
242245
* URL to ClickUp
243246
*
244-
* If path is passed in, then append it to the end. By default, it will use the url
245-
* in the configs, but if an url is passed in as second parameter, then it is used.
247+
* If path is passed in, then append it to the end. By default, it will use the url
248+
* in the configs, but if a url is passed in as a second parameter then it is used.
249+
* If no url is found it will use the hard-coded v2 ClickUp API URL.
246250
*
247251
* @param string|null $path
248252
* @param string|null $url
@@ -251,6 +255,8 @@ public function setToken($token): self
251255
*/
252256
public function uri($path = null, $url = null): string
253257
{
254-
return rtrim(($url ?: $this->configs['url']), '/') . (Str::startsWith($path, '?') ? null : '/') . ltrim($path, '/');
258+
$url = $url ?? $this->configs['url'] ?? 'https://api.clickup.com/api/v2';
259+
260+
return rtrim($url, '/') . (Str::startsWith($path, '?') ? null : '/') . ltrim($path, '/');
255261
}
256262
}

tests/Api/ClientTest.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function it_can_be_constructed()
8181
/**
8282
* @test
8383
*/
84-
public function it_expects_the_first_argument_tobe_an_array()
84+
public function it_expects_the_first_argument_to_be_an_array()
8585
{
8686
$this->expectException(TypeError::class);
8787

@@ -91,7 +91,7 @@ public function it_expects_the_first_argument_tobe_an_array()
9191
/**
9292
* @test
9393
*/
94-
public function it_expects_the_second_argument_tobe_a_guzzle()
94+
public function it_expects_the_second_argument_to_be_a_guzzle()
9595
{
9696
$this->expectException(TypeError::class);
9797

@@ -150,6 +150,34 @@ public function it_allows_setting_the_configs()
150150
$this->assertInstanceOf(Client::class, $return);
151151
}
152152

153+
/**
154+
* @test
155+
*/
156+
public function it_sets_url_to_default_value_if_not_passed_in()
157+
{
158+
$this->client->setConfigs(
159+
[
160+
'url' => null,
161+
]
162+
);
163+
164+
$this->assertEquals('https://api.clickup.com/api/v2/', $this->client->uri());
165+
}
166+
167+
/**
168+
* @test
169+
*/
170+
public function it_sets_url_to_default_value_if_its_an_empty_string()
171+
{
172+
$this->client->setConfigs(
173+
[
174+
'url' => "",
175+
]
176+
);
177+
178+
$this->assertEquals('https://api.clickup.com/api/v2/', $this->client->uri());
179+
}
180+
153181
/**
154182
* @test
155183
*/
@@ -201,8 +229,8 @@ public function it_builds_correct_uri()
201229
$this->assertEquals('http://some/place/resource', $this->client->uri('/resource'), 'no double slash');
202230
$this->assertEquals('http://some/place/resource/', $this->client->uri('resource/'), 'leaves end slash');
203231
$this->assertEquals(
204-
'http://some/place?paramater=value',
205-
$this->client->uri('?paramater=value'),
232+
'http://some/place?parameter=value',
233+
$this->client->uri('?parameter=value'),
206234
'query string'
207235
);
208236
$this->assertEquals(

0 commit comments

Comments
 (0)