-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, '/') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters