diff --git a/src/APnutI.php b/src/APnutI.php index 6bd0719..c0caf29 100644 --- a/src/APnutI.php +++ b/src/APnutI.php @@ -648,16 +648,18 @@ class APnutI string $text, int $reply_to, bool $is_nsfw = false, - bool $auto_crop = false + bool $auto_crop = false, + array $raw = [] ): Post { - return createPost($text, $reply_to, $is_nsfw, $auto_crop); + return createPost($text, $reply_to, $is_nsfw, $auto_crop, $raw); } public function createPost( string $text, bool $is_nsfw = false, bool $auto_crop = false, - ?int $reply_to = null + ?int $reply_to = null, + array $raw = [] ): Post { $text = $auto_crop ? substr($text, 0, $this->getMaxPostLength()) : $text; $parameters = [ @@ -665,7 +667,25 @@ class APnutI 'reply_to' => $reply_to, 'is_nsfw' => $is_nsfw, ]; - return new Post($this->post('posts', $parameters), $this); + if (!empty($raw)) { + $parameters['raw'] = $parameters; + } + return new Post($this->post('/posts', $parameters, 'application/json'), $this); + } + + public function createPostWithParameters( + string $text, + array $params = [], + bool $auto_crop = false, + ): Post { + $text = $auto_crop ? substr($text, 0, $this->getMaxPostLength()) : $text; + $parameters = [ + 'text' => $text, + ]; + $parameters = array_merge($parameters, $params); + $this->logger->debug('Post with params'); + $this->logger->debug(json_encode($parameters)); + return new Post($this->post('/posts', $parameters, 'application/json'), $this); } protected function fetchPnutSystemConfig() @@ -713,7 +733,7 @@ class APnutI 'client_secret' => $this->client_secret, 'grant_type' => 'client_credentials' ]; - $resp = $this->post('oauth/access_token', $params); + $resp = $this->post('/oauth/access_token', $params); if (!empty($resp['access_token'])) { $this->logger->info(json_encode($resp)); return $resp['access_token']; diff --git a/src/Entities/Poll.php b/src/Entities/Poll.php index 7301964..ccd6fd7 100644 --- a/src/Entities/Poll.php +++ b/src/Entities/Poll.php @@ -190,6 +190,29 @@ class Poll return new Poll($resp, $api); } + public static function makePollNoticeRaw(int $poll_id, string $poll_token) + { + /*return [ + 'type' => 'io.pnut.core.poll-notice', + 'value' => [ + '+io.pnut.core.poll' => [ + 'poll_id' => $poll_id, + 'poll_token' => $poll_token + ] + ] + ];*/ + return [ + 'io.pnut.core.poll-notice' => [ + [ + '+io.pnut.core.poll' => [ + 'poll_id' => $poll_id, + 'poll_token' => $poll_token + ] + ] + ] + ]; + } + public function __toString(): string { if (!empty($this->user)) { diff --git a/src/Entities/Post.php b/src/Entities/Post.php index 5e010be..eace9e0 100644 --- a/src/Entities/Post.php +++ b/src/Entities/Post.php @@ -9,7 +9,7 @@ use APnutI\Entities\PostContent; class Post { - public DateTime $created_at; + public \DateTime $created_at; public int $id; public bool $is_deleted = false; public bool $is_nsfw = false; @@ -30,7 +30,11 @@ class Post public function __construct(array $data, APnutI $api) { $this->api = $api; + $this->api->logger->debug('constructing post'); + $this->api->logger->debug(json_encode($data)); + $this->api->logger->debug('Created string: ' . $data['created_at']); $this->created_at = new \DateTime($data['created_at']); + $this->api->logger->debug(json_encode($this->created_at)); $this->id = (int)$data['id']; if (!empty($data['is_deleted'])) { $this->is_deleted = (bool)$data['is_deleted']; @@ -46,7 +50,7 @@ class Post } #file_put_contents(__DIR__."/post_log.log", json_encode($data['user']), FILE_APPEND | LOCK_EX); if (!empty($data['user'])) { - $this->user = new User($data['user']); + $this->user = new User($data['user'], $api); } #file_put_contents(__DIR__."/post_log.log", json_encode($this->user), FILE_APPEND | LOCK_EX); $this->thread_id = (int)$data['thread_id']; diff --git a/src/Entities/PostContent.php b/src/Entities/PostContent.php new file mode 100644 index 0000000..ad64a56 --- /dev/null +++ b/src/Entities/PostContent.php @@ -0,0 +1,22 @@ +text = $data['text']; + if (!empty($data['html'])) { + $this->html = $data['html']; + } + $this->entities = $data['entities']; + if (!empty($data['links_not_parsed'])) { + $this->links_not_parsed = (bool)$data['links_not_parsed']; + } + } +} diff --git a/src/Entities/PostContents.php b/src/Entities/PostContents.php deleted file mode 100644 index acc56b6..0000000 --- a/src/Entities/PostContents.php +++ /dev/null @@ -1,18 +0,0 @@ -bookmarks = (int)$data['bookmarks']; - $this->replies = (int)$data['replies']; - $this->reposts = (int)$data['reposts']; - $this->threads = (int)$data['threads']; - } -} diff --git a/src/Entities/PostCounts.php b/src/Entities/PostCounts.php index ad64a56..acc56b6 100644 --- a/src/Entities/PostCounts.php +++ b/src/Entities/PostCounts.php @@ -1,22 +1,18 @@ text = $data['text']; - if (!empty($data['html'])) { - $this->html = $data['html']; - } - $this->entities = $data['entities']; - if (!empty($data['links_not_parsed'])) { - $this->links_not_parsed = (bool)$data['links_not_parsed']; - } + $this->bookmarks = (int)$data['bookmarks']; + $this->replies = (int)$data['replies']; + $this->reposts = (int)$data['reposts']; + $this->threads = (int)$data['threads']; } }