diff --git a/includes/api/class-publications.php b/includes/api/class-publications.php new file mode 100644 index 0000000..dd29539 --- /dev/null +++ b/includes/api/class-publications.php @@ -0,0 +1,51 @@ +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); + } + +} diff --git a/includes/class-api.php b/includes/class-api.php new file mode 100644 index 0000000..c1a36f8 --- /dev/null +++ b/includes/class-api.php @@ -0,0 +1,84 @@ +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; + } + } + +} diff --git a/ogre-issuu.php b/ogre-issuu.php index 08964c6..d5dc2a2 100644 --- a/ogre-issuu.php +++ b/ogre-issuu.php @@ -34,7 +34,10 @@ class Plugin extends PluginBase { parent::__construct(__FILE__); $this->add_files([ + 'vendor/autoload.php', 'includes/class-settings.php', + 'includes/api/class-publications.php', + 'includes/class-api.php', ]); }