Skip to content

Commit

Permalink
add storipress request
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrisbee committed Nov 16, 2023
1 parent e1bca76 commit 4a6e5f3
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Facades/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/Objects/StoripressResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Storipress\WordPress\Objects;

class StoripressResponse extends WordPressObject
{
public bool $success;

public ?string $message;

public ?int $code;
}
60 changes: 60 additions & 0 deletions src/Requests/Storipress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Storipress\WordPress\Requests;

use Storipress\WordPress\Exceptions\HttpException;
use Storipress\WordPress\Exceptions\UnexpectedValueException;
use Storipress\WordPress\Objects\StoripressResponse;

/**
* Storipress plugin's API endpoints
*/
class Storipress extends Request
{
public const VERSION = 'v1';

/**
* @throws HttpException
* @throws UnexpectedValueException
*/
public function connect(string $client): StoripressResponse
{
$data = $this->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, '/')
);
}
}
2 changes: 1 addition & 1 deletion src/Requests/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function delete(int $tagId): bool
$uri = sprintf('/tags/%d', $tagId);

return $this->request('delete', $uri, [
'force' => true
'force' => true,
]);
}
}
10 changes: 10 additions & 0 deletions src/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,6 +19,8 @@ class WordPress

protected readonly User $user;

protected readonly Storipress $storipress;

protected string $site;

protected string $username;
Expand All @@ -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
Expand Down Expand Up @@ -96,4 +101,9 @@ public function user(): User
{
return $this->user;
}

public function storipress(): Storipress
{
return $this->storipress;
}
}

0 comments on commit 4a6e5f3

Please sign in to comment.