Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data structure for NPF Content Blocks #108

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add BlogInfo and integrate into Client
Funcke committed Mar 10, 2020
commit d96fb7c28a710c4df8f883abbb473fe0fc41e67b
27 changes: 20 additions & 7 deletions lib/Tumblr/API/Client.php
Original file line number Diff line number Diff line change
@@ -2,16 +2,20 @@

namespace Tumblr\API;

use Tumblr\API\NPF\Write\NPFScheme;
use Tumblr\API\NPF\Write\NPFReblogScheme;

use Tumblr\API\Write\NPFScheme;
use Tumblr\API\Write\NPFReblogScheme;
use Tumblr\API\Read\BlogInfo;
use Tumblr\API\RequestException;
/**
* A client to access the Tumblr API
*/
class Client
{

private string $apiKey;
/**
* @var string
* API Key for a registered user
*/
private $apiKey;

/**
* Create a new Client
@@ -277,13 +281,22 @@ public function getTaggedPosts($tag, $options = null)
* Get information about a given blog
*
* @param string $blogName the name of the blog to look up
* @return array the response array
* @return BlogInfo the response array
*/
public function getBlogInfo($blogName)
{
$path = $this->blogPath($blogName, '/info');

return $this->getRequest($path, null, true);
$result = $this->getRequest($path, null, true);
$info = new BlogInfo($result->blog->title, $result->blog->posts,
$result->blog->name, $result->blog->updated,
$result->blog->description, $result->blog->ask,
$result->blog->ask_anon, $result->blog->likes,
$result->blog->is_blocked_from_primary,
$result->blog->avatar,
$result->blog->theme,
$result->blog->timezone_offset);
return $info;
}

/**
7 changes: 1 addition & 6 deletions lib/Tumblr/API/NPF/Content/Attribution/AttributionObject.php
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
* @package Tumblr\API\NPF\Content\Attribution
*/
abstract class AttributionObject {
use \Tumblr\API\Read\ReadableTrait;
/**
* Type of attribution.
* Used by the API to further process and embed the declared attribution.
@@ -33,10 +34,4 @@ abstract class AttributionObject {
protected function __construct(string $type) {
$this->type = $type;
}

public function __get($property) {
if(\property_exists($this, $property)) {
return $this->$property;
}
}
}
7 changes: 1 addition & 6 deletions lib/Tumblr/API/NPF/Content/ContentBlock.php
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
namespace Tumblr\API\NPF\Content;

abstract class ContentBlock {
use \Tumblr\API\Read\ReadableTrait;
/**
* @var string
*/
@@ -12,12 +13,6 @@ protected function __construct(string $type) {
$this->type = $type;
}

public function __get($property) {
if(\property_exists($this, $property)) {
return $this->$property;
}
}

public function toJSON() {
return \get_object_vars($this);
}
32 changes: 0 additions & 32 deletions lib/Tumblr/API/NPF/Read/PostFormat.php

This file was deleted.

89 changes: 89 additions & 0 deletions lib/Tumblr/API/Read/BlogInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Tumblr\API\Read;

use Tumblr\API\Read\Theme;

class BlogInfo implements \JsonSerializable{
use \Tumblr\API\Read\ReadableTrait;
/**
* @var string
*/
protected $title;
/**
* @var int
*/
protected $posts;
/**
* @var string
*/
protected $name;
/**
* @var int
*/
protected $updated;
/**
* @var string
*/
protected $description;
/**
* @var bool
*/
protected $ask;
/**
* @var bool
*/
protected $ask_anon;
/**
* @var int
*/
protected $likes;
/**
* @var bool
*/
protected $is_blocked_from_primary;
/**
* @var array
*/
protected $avatar;
/**
* @var Theme
*/
protected $theme;
/**
* @var string
*/
protected $timezone_offset;

/**
* c'tor
* @param string $title Title of the blog
* @param int $posts Number of posts
* @param string $name Name of the blog
* @param int $updated Time in miliseconds since last update
* @param string $description Description of the blog
* @param bool $ask Status if blog allows questions
* @param bool $ask_anon Status if blog allows anonymous questions
* @param int $likes Number of likes this blog has created
* @param bool $is_blocked_from_primary Status if this blog is being blocked by primary activated account
* @param array $avatar Array with image objects of the avatars history
* @param Theme $theme Theme object with information of the theme used by the blog
* @param string $timezone_offset Offset from UTC time
*/
public function __construct($title = '', $posts = 0, $name = '', $updated = 0, $description = '',
$ask = false, $ask_anon = false, $likes = 0, $is_blocked_from_primary = false, $avatar = [],
$theme = NULL, $timezone_offset = '') {
$this->title = $title;
$this->posts = $posts;
$this->name = $name;
$this->updated = $updated;
$this->description = $description;
$this->ask = $ask;
$this->ask_anon = $ask_anon;
$this->likes = $likes;
$this->is_blocked_from_primary = $is_blocked_from_primary;
$this->avatar = $avatar;
$this->theme = $theme;
$this->timezone_offset = $timezone_offset;
}
}
51 changes: 51 additions & 0 deletions lib/Tumblr/API/Read/PostFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Tumblr\API\Read;

class PostFormat implements \JsonSerializable {
use \Tumblr\API\Read\ReadableTrait;
/**
* @var string
*/
protected $object_type;
/**
* @var string
*/
protected $type;
/**
* @var string
*/
protected $id;
/**
* @var string
*/
protected $tumblelog_uuid;
/**
* @var string
*/
protected $reblog_key;
/**
* @var array
*/
protected $trail;
/**
* @var array
*/
protected $content;
/**
* @var array
*/
protected $layout;

protected function __construct(string $object_type, string $type, $id, string $tumblelog_uuid,
string $reblog_key, array $trail = [], array $content = [], array $layout = []){
$this->object_type = $object_type;
$this->type = $type;
$this->id = $id;
$this->tumblelog_uuid = $tumblelog_uuid;
$this->reblog_key = $reblog_key;
$this->trail = $trail;
$this->content = $content;
$this->layout = $layout;
}
}
14 changes: 14 additions & 0 deletions lib/Tumblr/API/Read/ReadableTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace Tumblr\API\Read;

trait ReadableTrait{
public function __get($property) {
if(\property_exists($this, $property)) {
return $this->$property;
}
}

public function jsonSerialize() {
return \get_object_vars($this);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php

namespace Tumblr\API\NPF\Read;
namespace Tumblr\API\Read;

use Tumblr\API\NPF\Read\PostFormat;

class ReblogPostFormat extends PostFormat {
protected string $parent_post_id;
protected string $parent_tumblelog_uuid;
/**
* @var string
*/
protected $parent_post_id;
/**
* @var string
*/
protected $parent_tumblelog_uuid;

protected function __construct(string $object_type, string $type, $id, string $tumblelog_uuid,
string $reblog_key, array $trail = [], array $content = [], array $layout = [],
Loading