Skip to content

Commit bf65796

Browse files
committed
Merge branch 'minor-refactoring' of https://github.com/mpociot/laravel-notion-api into mpociot-minor-refactoring
2 parents 424d503 + b4c2c7d commit bf65796

File tree

9 files changed

+103
-143
lines changed

9 files changed

+103
-143
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"FiveamCode\\LaravelNotionApi\\LaravelNotionApiServiceProvider"
6060
],
6161
"aliases": {
62-
"LaravelNotionApi": "FiveamCode\\LaravelNotionApi\\LaravelNotionApiFacade"
62+
"Notion": "FiveamCode\\LaravelNotionApi\\NotionFacade"
6363
}
6464
}
6565
}

composer.lock

Lines changed: 66 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/config.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<?php
22

3-
/*
4-
* You can place your custom package configuration in here.
5-
*/
63
return [
4+
/**
5+
* The default Notion API version to use.
6+
*/
7+
'version' => 'v1',
8+
9+
/**
10+
* Your Notion API token.
11+
*/
712
'notion-api-token' => env('NOTION_API_TOKEN', '')
813
];

src/Exceptions/LaravelNotionAPIException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class LaravelNotionAPIException extends \Exception
1919
*/
2020
protected array $payload = [];
2121

22-
/**
22+
/**w
2323
* Handy method to create a *Exception with payload.
2424
*
2525
* @param string $message

src/LaravelNotionApiServiceProvider.php

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,10 @@ class LaravelNotionApiServiceProvider extends ServiceProvider
1111
*/
1212
public function boot()
1313
{
14-
/*
15-
* Optional methods to load your package assets
16-
*/
17-
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-notion-api');
18-
// $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-notion-api');
19-
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
20-
// $this->loadRoutesFrom(__DIR__.'/routes.php');
21-
2214
if ($this->app->runningInConsole()) {
2315
$this->publishes([
2416
__DIR__.'/../config/config.php' => config_path('laravel-notion-api.php'),
2517
], 'config');
26-
27-
// Publishing the views.
28-
/*$this->publishes([
29-
__DIR__.'/../resources/views' => resource_path('views/vendor/laravel-notion-api'),
30-
], 'views');*/
31-
32-
// Publishing assets.
33-
/*$this->publishes([
34-
__DIR__.'/../resources/assets' => public_path('vendor/laravel-notion-api'),
35-
], 'assets');*/
36-
37-
// Publishing the translation files.
38-
/*$this->publishes([
39-
__DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-notion-api'),
40-
], 'lang');*/
41-
42-
// Registering package commands.
43-
// $this->commands([]);
4418
}
4519
}
4620

@@ -52,9 +26,9 @@ public function register()
5226
// Automatically apply the package configuration
5327
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-notion-api');
5428

55-
// Register the main class to use with the facade
56-
$this->app->singleton('laravel-notion-api', function () {
57-
return new LaravelNotionApi;
29+
30+
$this->app->singleton(Notion::class, function () {
31+
return new Notion(config('laravel-notion-api.notion-api-token'), config('laravel-notion-api.version'));
5832
});
5933
}
6034
}

src/Notion.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,14 @@ class Notion
2929
* @param string|null $version
3030
* @param string|null $token
3131
*/
32-
public function __construct(string $version = null, string $token = null)
32+
public function __construct(string $token, string $version = "v1")
3333
{
34-
if ($token !== null) {
35-
$this->setToken($token);
36-
} elseif ($token === null) {
37-
38-
// check if Notion integration token is set in config
39-
$token = config('laravel-notion-api.notion-api-token');
40-
41-
if ($token !== null)
42-
$this->setToken($token);
43-
}
34+
$this->setToken($token);
4435

4536
$this->validVersions = collect(["v1"]);
4637

47-
if ($version !== null) {
48-
$this->setVersion($version);
49-
} else {
50-
$this->v1();
51-
}
38+
$this->setVersion($version);
39+
5240
}
5341

5442
/**

src/LaravelNotionApiFacade.php renamed to src/NotionFacade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* @see \FiveamCode\LaravelNotionApi\Skeleton\SkeletonClass
99
*/
10-
class LaravelNotionApiFacade extends Facade
10+
class NotionFacade extends Facade
1111
{
1212
/**
1313
* Get the registered name of the component.
@@ -16,6 +16,6 @@ class LaravelNotionApiFacade extends Facade
1616
*/
1717
protected static function getFacadeAccessor()
1818
{
19-
return 'laravel-notion-api';
19+
return Notion::class;
2020
}
2121
}

tests/EndpointDatabaseTest.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
use Carbon\Carbon;
66
use FiveamCode\LaravelNotionApi\Entities\Database;
77
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
8-
use FiveamCode\LaravelNotionApi\Notion;
9-
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
10-
use Illuminate\Support\Facades\File;
118
use Illuminate\Support\Facades\Http;
129
use Orchestra\Testbench\TestCase;
1310

@@ -22,6 +19,17 @@
2219
class EndpointDatabaseTest extends TestCase
2320
{
2421

22+
protected function getPackageProviders($app)
23+
{
24+
return ['FiveamCode\LaravelNotionApi\LaravelNotionApiServiceProvider'];
25+
}
26+
27+
protected function getPackageAliases($app)
28+
{
29+
return [
30+
'Notion' => \FiveamCode\LaravelNotionApi\NotionFacade::class
31+
];
32+
}
2533

2634
/** @test */
2735
public function it_returns_a_list_of_database_objects()
@@ -36,10 +44,7 @@ public function it_returns_a_list_of_database_objects()
3644
)
3745
]);
3846

39-
$notion = new Notion();
40-
$notion->v1()->setToken("secret_*");
41-
42-
$result = $notion->databases()->all();
47+
$result = \Notion::databases()->all();
4348

4449
$this->assertIsIterable($result);
4550
$this->assertCount(2, $result);
@@ -58,10 +63,7 @@ public function it_returns_an_empty_list()
5863
)
5964
]);
6065

61-
$notion = new Notion();
62-
$notion->v1()->setToken("secret_*");
63-
64-
$result = $notion->databases()->all();
66+
$result = \Notion::databases()->all();
6567

6668
// TODO check class here
6769
$this->assertIsIterable($result);
@@ -80,14 +82,11 @@ public function it_throws_a_notion_exception_bad_request()
8082
['Headers']
8183
)
8284
]);
83-
$notion = new Notion();
84-
$notion->v1()->setToken("secret_*");
85-
8685

8786
$this->expectException(NotionException::class);
8887
$this->expectExceptionMessage("Bad Request");
8988

90-
$result = $notion->databases()->all();
89+
\Notion::databases()->all();
9190
}
9291

9392
/** @test */
@@ -103,10 +102,7 @@ public function it_returns_database_entity_with_filled_properties()
103102
)
104103
]);
105104

106-
$notion = new Notion();
107-
$notion->v1()->setToken("secret_*");
108-
109-
$databaseResult = $notion->databases()->find("668d797c-76fa-4934-9b05-ad288df2d136");
105+
$databaseResult = \Notion::databases()->find("668d797c-76fa-4934-9b05-ad288df2d136");
110106

111107
$this->assertInstanceOf(Database::class, $databaseResult);
112108

@@ -134,13 +130,10 @@ public function it_throws_a_notion_exception_not_found()
134130
)
135131
]);
136132

137-
$notion = new Notion();
138-
$notion->v1()->setToken("secret_*");
139-
140133
$this->expectException(NotionException::class);
141134
$this->expectExceptionMessage("Not found");
142-
$databaseResult = $notion->databases()->find("b55c9c91-384d-452b-81db-d1ef79372b79");
143135

136+
\Notion::databases()->find("b55c9c91-384d-452b-81db-d1ef79372b79");
144137
}
145138

146139
}

tests/NotionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
namespace FiveamCode\LaravelNotionApi\Tests;
44

55
use Orchestra\Testbench\TestCase;
6-
use FiveamCode\LaravelNotionApi\Notion;
6+
use FiveamCode\LaravelNotionApi\Notion;
77

88
class NotionTest extends TestCase
99
{
1010

1111
/** @test */
1212
public function it_returns_notion_instance_with_set_token_and_connection()
1313
{
14-
$notion = new Notion();
14+
$notion = new Notion("secret_*");
1515
$notion->v1()->setToken("secret_*");
1616

1717
$this->assertInstanceOf(Notion::class, $notion);

0 commit comments

Comments
 (0)