diff --git a/src/Facades/WordPress.php b/src/Facades/WordPress.php index 4f84c38..9b434ad 100644 --- a/src/Facades/WordPress.php +++ b/src/Facades/WordPress.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Facade; use Storipress\WordPress\Requests\Category; use Storipress\WordPress\Requests\Post; +use Storipress\WordPress\Requests\Storipress; use Storipress\WordPress\Requests\Tag; use Storipress\WordPress\Requests\User; @@ -15,6 +16,7 @@ * @method static Category category() * @method static Tag tag() * @method static User user() + * @method static Storipress storipress() * @method static \Storipress\WordPress\WordPress setSite(string $site) * @method static \Storipress\WordPress\WordPress site() * @method static \Storipress\WordPress\WordPress setUsername(string $username) diff --git a/src/Objects/StoripressResponse.php b/src/Objects/StoripressResponse.php new file mode 100644 index 0000000..3429da1 --- /dev/null +++ b/src/Objects/StoripressResponse.php @@ -0,0 +1,12 @@ +request('post', '/connect', [ + 'storipress_client' => $client, + ]); + + if (is_array($data)) { + throw new UnexpectedValueException(); + } + + return StoripressResponse::from($data); + } + + /** + * @throws HttpException + * @throws UnexpectedValueException + */ + public function disconnect(string $client): StoripressResponse + { + $data = $this->request('post', '/disconnect', [ + 'storipress_client' => $client, + ]); + + if (is_array($data)) { + throw new UnexpectedValueException(); + } + + return StoripressResponse::from($data); + } + + public function getUrl(string $path): string + { + return sprintf('%s/wp-json/storipress/%s/%s', + rtrim($this->app->site(), '/'), + self::VERSION, + ltrim($path, '/') + ); + } +} diff --git a/src/Requests/Tag.php b/src/Requests/Tag.php index d0e090f..610f8a2 100644 --- a/src/Requests/Tag.php +++ b/src/Requests/Tag.php @@ -104,7 +104,7 @@ public function delete(int $tagId): bool $uri = sprintf('/tags/%d', $tagId); return $this->request('delete', $uri, [ - 'force' => true + 'force' => true, ]); } } diff --git a/src/WordPress.php b/src/WordPress.php index 36a2732..55f8cfb 100644 --- a/src/WordPress.php +++ b/src/WordPress.php @@ -5,6 +5,7 @@ use Illuminate\Http\Client\Factory; use Storipress\WordPress\Requests\Category; use Storipress\WordPress\Requests\Post; +use Storipress\WordPress\Requests\Storipress; use Storipress\WordPress\Requests\Tag; use Storipress\WordPress\Requests\User; @@ -18,6 +19,8 @@ class WordPress protected readonly User $user; + protected readonly Storipress $storipress; + protected string $site; protected string $username; @@ -34,6 +37,8 @@ public function __construct( $this->category = new Category($this); $this->user = new User($this); + + $this->storipress = new Storipress($this); } public function instance(): static @@ -96,4 +101,9 @@ public function user(): User { return $this->user; } + + public function storipress(): Storipress + { + return $this->storipress; + } }