Initial build of API endpoints.
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user