Skip to content

Commit a82fcbf

Browse files
committed
Implemented blog methods
1 parent ae61299 commit a82fcbf

File tree

4 files changed

+184
-2
lines changed

4 files changed

+184
-2
lines changed

Api.php

+99-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
/**
66
* @author Tijs Verkoyen <[email protected]>
7-
* @version 1.0.0
7+
* @version 1.0.1
88
* @copyright Copyright (c) 2008, Tijs Verkoyen. All rights reserved.
99
* @license BSD License
1010
*/
1111
class Api
1212
{
1313
// current version
14-
const VERSION = '1.0.0';
14+
const VERSION = '1.0.1';
1515

1616
/**
1717
* The API key to use for authentication
@@ -327,4 +327,101 @@ public function coreAppleRemoveDevice($token)
327327
// make the call
328328
$this->doCall('core.apple.removeDevice', $parameters, 'POST');
329329
}
330+
331+
/**
332+
* Get the comments
333+
*
334+
* @param string[optional] $status The type of comments to get. Possible values are: published, moderation, spam.
335+
* @param int[optional] $limit The maximum number of items to retrieve.
336+
* @param int[optional] $offset The offset.
337+
* @return mixed
338+
*/
339+
public function blogCommentsGet($status = null, $limit = null, $offset = null)
340+
{
341+
// build parameters
342+
$parameters = null;
343+
if ($status !== null) {
344+
$parameters['status'] = (string) $status;
345+
}
346+
if ($limit !== null) {
347+
$parameters['limit'] = (int) $limit;
348+
}
349+
if ($offset !== null) {
350+
$parameters['offset'] = (int) $offset;
351+
}
352+
353+
// make the call
354+
return $this->doCall('blog.comments.get', $parameters);
355+
}
356+
357+
/**
358+
* Get a single comment.
359+
*
360+
* @param string $id
361+
* @return mixed
362+
*/
363+
public function blogCommentsGetById($id)
364+
{
365+
// build parameters
366+
$parameters['id'] = (string) $id;
367+
368+
// make the call
369+
return $this->doCall('blog.comments.getById', $parameters);
370+
}
371+
372+
/**
373+
* Update a comment
374+
*
375+
* @param string $id The id of the comment.
376+
* @param string[optional] $status The new status for the comment. Possible values are: published, moderation, spam.
377+
* @param string[optional] $text The new text for the comment.
378+
* @param string[optional] $authorName The new author for the comment.
379+
* @param string[optional] $authorEmail The new email for the comment.
380+
* @param string[optional] $authorWebsite The new website for the comment.
381+
*/
382+
public function blogCommentsUpdate(
383+
$id,
384+
$status = null,
385+
$text = null,
386+
$authorName = null,
387+
$authorEmail = null,
388+
$authorWebsite = null
389+
) {
390+
// build parameters
391+
$parameters['id'] = (string) $id;
392+
if ($status !== null) {
393+
$parameters['status'] = (string) $status;
394+
}
395+
if ($text !== null) {
396+
$parameters['text'] = (string) $text;
397+
}
398+
if ($authorName !== null) {
399+
$parameters['authorName'] = (string) $authorName;
400+
}
401+
if ($authorEmail !== null) {
402+
$parameters['authorEmail'] = (string) $authorEmail;
403+
}
404+
if ($authorWebsite !== null) {
405+
$parameters['authorWebsite'] = (string) $authorWebsite;
406+
}
407+
408+
// make the call
409+
$this->doCall('blog.comments.update', $parameters, 'POST');
410+
}
411+
412+
/**
413+
* Update the status for multiple comments at once.
414+
*
415+
* @param array $ids The ids of the commen(s to update.
416+
* @param string $status The new status for the comment. Possible values are: published, moderation, spam.
417+
*/
418+
public function blogCommentsUpdateStatus(array $ids, $status)
419+
{
420+
// build parameters
421+
$parameters['id'] = $ids;
422+
$parameters['status'] = (string) $status;
423+
424+
// make the call
425+
$this->doCall('blog.comments.updateStatus', $parameters, 'POST');
426+
}
330427
}

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog since 1.0.0
2+
3+
* Implemented blog methods.

tests/ApiTest.php

+78
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,82 @@ public function testCoreAppleRemoveDevice()
103103
$var = $this->api->coreAppleRemoveDevice(APPLE_DEVICE_TOKEN);
104104
$this->assertNull($var);
105105
}
106+
107+
/**
108+
* tests Api->blogCommentsGet()
109+
*/
110+
public function testBlogCommentsGet()
111+
{
112+
$var = $this->api->blogCommentsGet();
113+
$this->assertArrayHasKey('comments', $var);
114+
foreach ($var['comments'] as $row) {
115+
$this->assertArrayHasKey('comment', $row);
116+
$this->assertArrayHasKey('article', $row['comment']);
117+
$this->assertArrayHasKey('@attributes', $row['comment']['article']);
118+
$this->assertArrayHasKey('id', $row['comment']['article']['@attributes']);
119+
$this->assertArrayHasKey('lang', $row['comment']['article']['@attributes']);
120+
$this->assertArrayHasKey('title', $row['comment']['article']);
121+
$this->assertArrayHasKey('url', $row['comment']['article']);
122+
$this->assertArrayHasKey('@attributes', $row['comment']);
123+
$this->assertArrayHasKey('id', $row['comment']['@attributes']);
124+
$this->assertArrayHasKey('created_on', $row['comment']['@attributes']);
125+
$this->assertArrayHasKey('status', $row['comment']['@attributes']);
126+
$this->assertArrayHasKey('text', $row['comment']);
127+
$this->assertArrayHasKey('url', $row['comment']);
128+
$this->assertArrayHasKey('author', $row['comment']);
129+
$this->assertArrayHasKey('@attributes', $row['comment']['author']);
130+
$this->assertArrayHasKey('email', $row['comment']['author']['@attributes']);
131+
$this->assertArrayHasKey('name', $row['comment']['author']);
132+
$this->assertArrayHasKey('website', $row['comment']['author']);
133+
}
134+
}
135+
136+
/**
137+
* Tests Api->blogCommentsGetById()
138+
*/
139+
public function testBlogCommentsGetById()
140+
{
141+
$var = $this->api->blogCommentsGetById(40);
142+
$this->assertArrayHasKey('comments', $var);
143+
$this->assertArrayHasKey('comment', $var['comments'][0]);
144+
$this->assertArrayHasKey('article', $var['comments'][0]['comment']);
145+
$this->assertArrayHasKey('@attributes', $var['comments'][0]['comment']['article']);
146+
$this->assertArrayHasKey('id', $var['comments'][0]['comment']['article']['@attributes']);
147+
$this->assertArrayHasKey('lang', $var['comments'][0]['comment']['article']['@attributes']);
148+
$this->assertArrayHasKey('title', $var['comments'][0]['comment']['article']);
149+
$this->assertArrayHasKey('url', $var['comments'][0]['comment']['article']);
150+
$this->assertArrayHasKey('@attributes', $var['comments'][0]['comment']);
151+
$this->assertArrayHasKey('id', $var['comments'][0]['comment']['@attributes']);
152+
$this->assertArrayHasKey('created_on', $var['comments'][0]['comment']['@attributes']);
153+
$this->assertArrayHasKey('status', $var['comments'][0]['comment']['@attributes']);
154+
$this->assertArrayHasKey('text', $var['comments'][0]['comment']);
155+
$this->assertArrayHasKey('url', $var['comments'][0]['comment']);
156+
$this->assertArrayHasKey('author', $var['comments'][0]['comment']);
157+
$this->assertArrayHasKey('@attributes', $var['comments'][0]['comment']['author']);
158+
$this->assertArrayHasKey('email', $var['comments'][0]['comment']['author']['@attributes']);
159+
$this->assertArrayHasKey('name', $var['comments'][0]['comment']['author']);
160+
$this->assertArrayHasKey('website', $var['comments'][0]['comment']['author']);
161+
}
162+
163+
/**
164+
* Tests Api->blogCommentsUpdate()
165+
*/
166+
public function testBlogCommentsUpdate()
167+
{
168+
$authorName = 'John Doe';
169+
170+
$var = $this->api->blogCommentsUpdate(40, null, null, $authorName);
171+
$this->assertNull($var);
172+
$var = $this->api->blogCommentsGetById(40);
173+
$this->assertEquals($authorName, $var['comments'][0]['comment']['author']['name']);
174+
}
175+
176+
/**
177+
* Tests Api->blogCommentsUpdateStatus()
178+
*/
179+
public function testBlogCommentsUpdateStatus()
180+
{
181+
$var = $this->api->blogCommentsUpdateStatus(array(39, 40), 'published');
182+
$this->assertNull($var);
183+
}
106184
}

tests/index.php

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
// $response = $api->coreGetInfo();
1515
// $response = $api->coreAppleAddDevice(APPLE_DEVICE_TOKEN);
1616
// $response = $api->coreAppleRemoveDevice(APPLE_DEVICE_TOKEN);
17+
// $response = $api->blogCommentsGet();
18+
// $response = $api->blogCommentsGetById(40);
19+
// $response = $api->blogCommentsUpdate(40, null, 'FooBar');
20+
// $response = $api->blogCommentsUpdateStatus(array(39, 40), 'published');
1721
} catch (Exception $e) {
1822
var_dump($e);
1923
}

0 commit comments

Comments
 (0)