Added User API endpoints.
This commit is contained in:
57
includes/api/class-user.php
Normal file
57
includes/api/class-user.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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 User {
|
||||
|
||||
private Issuu $issuu;
|
||||
|
||||
public function __construct(Issuu $issuu) {
|
||||
$this->issuu = $issuu;
|
||||
}
|
||||
|
||||
private static function parse_args(array $args, array $defaults):array {
|
||||
return array_filter(
|
||||
wp_parse_args($args, $defaults),
|
||||
function ($value, $key) use ($defaults) {
|
||||
return $value !== $defaults[$key];
|
||||
},
|
||||
ARRAY_FILTER_USE_BOTH
|
||||
);
|
||||
}
|
||||
|
||||
public function getUserProfile():stdClass {
|
||||
return $this->issuu->getResponse(method: 'GET', endpoint: "user/me");
|
||||
}
|
||||
|
||||
public function getUserFeatures():stdClass {
|
||||
return $this->issuu->getResponse(method: 'GET', endpoint: "user/features");
|
||||
}
|
||||
|
||||
public function getPublicationEmbedBySlug(string $slug, array $args = []):stdClass {
|
||||
$args = self::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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ use Exception;
|
||||
use lasselehtinen\Issuu\Issuu;
|
||||
use lasselehtinen\Issuu\Publications;
|
||||
use OgreIssuu\Api\Publications as ApiPublications;
|
||||
use OgreIssuu\Api\User;
|
||||
|
||||
class Api {
|
||||
use Singleton;
|
||||
@@ -26,6 +27,18 @@ class Api {
|
||||
$this->client = new Issuu(Settings::get('token'));
|
||||
}
|
||||
|
||||
public function get_user():?stdClass {
|
||||
if (!isset($this->client)) return null;
|
||||
|
||||
$user = new User($this->client);
|
||||
try {
|
||||
return $user->getUserProfile();
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_publications(array $args = []):?stdClass {
|
||||
if (!isset($this->client)) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user