Initial build of API endpoints.
This commit is contained in:
51
includes/api/class-publications.php
Normal file
51
includes/api/class-publications.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package CleverOgre
|
||||||
|
* @subpackage OgreIssuu
|
||||||
|
* @version 0.1.0
|
||||||
|
* @since 0.1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OgreIssuu\Api;
|
||||||
|
|
||||||
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
|
use stdClass;
|
||||||
|
use lasselehtinen\Issuu\Issuu;
|
||||||
|
|
||||||
|
class Publications {
|
||||||
|
|
||||||
|
private Issuu $issuu;
|
||||||
|
|
||||||
|
public function __construct(Issuu $issuu) {
|
||||||
|
$this->issuu = $issuu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPublicationAssetsBySlug(string $slug, array $args = []):stdClass {
|
||||||
|
$args = wp_parse_args($args, [
|
||||||
|
'assetType' => '',
|
||||||
|
'size' => 10,
|
||||||
|
'page' => 1,
|
||||||
|
'documentPageNumber' => 0.0,
|
||||||
|
]);
|
||||||
|
if (!$args['documentPageNumber']) unset($args['documentPageNumber']);
|
||||||
|
|
||||||
|
return $this->issuu->getResponse(method: 'GET', endpoint: "publications/{$slug}/assets", queryParameters: $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPublicationEmbedBySlug(string $slug, array $args = []):stdClass {
|
||||||
|
$args = wp_parse_args($args, [
|
||||||
|
'responsive' => true,
|
||||||
|
'width' => '100%',
|
||||||
|
'height' => '100%',
|
||||||
|
'hideIssuuLogo' => false,
|
||||||
|
'hideShareButton' => false,
|
||||||
|
'showOtherPublications' => false,
|
||||||
|
'bgColor' => '',
|
||||||
|
'fullScreenShareBgColor' => '',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->issuu->getResponse(method: 'GET', endpoint: "publications/{$slug}/embed", queryParameters: $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
84
includes/class-api.php
Normal file
84
includes/class-api.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package CleverOgre
|
||||||
|
* @subpackage OgreIssuu
|
||||||
|
* @version 0.1.0
|
||||||
|
* @since 0.1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OgreIssuu;
|
||||||
|
|
||||||
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
|
use stdClass;
|
||||||
|
use Exception;
|
||||||
|
use lasselehtinen\Issuu\Issuu;
|
||||||
|
use lasselehtinen\Issuu\Publications;
|
||||||
|
use OgreIssuu\Api\Publications as ApiPublications;
|
||||||
|
|
||||||
|
class Api {
|
||||||
|
use Singleton;
|
||||||
|
|
||||||
|
private Issuu $client;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
if (!Settings::exists('token')) return;
|
||||||
|
$this->client = new Issuu(Settings::get('token'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_publications(array $args = []):stdClass {
|
||||||
|
if (!isset($this->client)) return null;
|
||||||
|
|
||||||
|
$args = wp_parse_args($args, [
|
||||||
|
'size' => 10,
|
||||||
|
'page' => 1,
|
||||||
|
'state' => 'ALL',
|
||||||
|
'q' => '',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$publications = new Publications($this->client);
|
||||||
|
try {
|
||||||
|
return $publications->list($args['size'], $args['page'], $args['state'], $args['q']);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log($e->getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_publication(string $slug):stdClass {
|
||||||
|
if (!isset($this->client)) return null;
|
||||||
|
|
||||||
|
$publications = new Publications($this->client);
|
||||||
|
try {
|
||||||
|
return $publications->getPublicationBySlug($slug);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log($e->getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_publication_assets(string $slug, array $args = []):stdClass {
|
||||||
|
if (!isset($this->client)) return null;
|
||||||
|
|
||||||
|
$publications = new ApiPublications($this->client);
|
||||||
|
try {
|
||||||
|
return $publications->getPublicationAssetsBySlug($slug, $args);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log($e->getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_publication_embed(string $slug, array $args = []):stdClass {
|
||||||
|
if (!isset($this->client)) return null;
|
||||||
|
|
||||||
|
$publications = new ApiPublications($this->client);
|
||||||
|
try {
|
||||||
|
return $publications->getPublicationEmbedBySlug($slug, $args);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log($e->getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -34,7 +34,10 @@ class Plugin extends PluginBase {
|
|||||||
parent::__construct(__FILE__);
|
parent::__construct(__FILE__);
|
||||||
|
|
||||||
$this->add_files([
|
$this->add_files([
|
||||||
|
'vendor/autoload.php',
|
||||||
'includes/class-settings.php',
|
'includes/class-settings.php',
|
||||||
|
'includes/api/class-publications.php',
|
||||||
|
'includes/class-api.php',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user