-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3ff390
commit fb67857
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace OvaStudio\IpsApi\Endpoints; | ||
|
||
use OvaStudio\IpsApi\Endpoints\Forums\Posts; | ||
|
||
class Forums extends AbstractEndpoint | ||
{ | ||
public function posts() : Posts | ||
{ | ||
return new Posts($this->api); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace OvaStudio\IpsApi\Endpoints\Forums; | ||
|
||
use OvaStudio\IpsApi\Endpoints\AbstractEndpoint; | ||
use OvaStudio\IpsApi\IpsApi; | ||
use stdClass; | ||
|
||
class Posts extends AbstractEndpoint | ||
{ | ||
private const ENDPOINT = 'forums/posts'; | ||
|
||
private int $author; | ||
private ?string $author_name; | ||
private bool $anonymous = false; | ||
|
||
public function __construct(IpsApi $api) | ||
{ | ||
parent::__construct($api); | ||
|
||
$this->withAuthor(config('services.ips.default_user', 1)); | ||
} | ||
|
||
public function withAuthor(int $author, ?string $author_name = null) : static | ||
{ | ||
$this->author = $author; | ||
$this->author_name = $author_name; | ||
|
||
return $this; | ||
} | ||
|
||
public function anonymousMode(bool $anonymous = true) : static | ||
{ | ||
$this->anonymous = $anonymous; | ||
|
||
return $this; | ||
} | ||
|
||
public function create(int $topic, string $post) : stdClass | ||
{ | ||
$data = [ | ||
'topic' => $topic, | ||
'author' => $this->author, | ||
'post' => $post, | ||
]; | ||
|
||
if ($data['author'] === 0) | ||
$data['author_name'] = $this->author_name; | ||
|
||
if ($this->anonymous) | ||
$data['anonymous'] = 1; | ||
|
||
$response = $this->api->client->post(self::ENDPOINT, [ | ||
'form_params' => $data | ||
]); | ||
|
||
return json_decode($response->getBody()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace OvaStudio\IpsApi\Tests\Feature\Endpoints; | ||
|
||
use OvaStudio\IpsApi\IpsApi; | ||
use OvaStudio\IpsApi\Tests\TestCase; | ||
|
||
class ForumsPostsTest extends TestCase | ||
{ | ||
public function test_post_create() | ||
{ | ||
$post = (new IpsApi())->forums()->posts()->create(2928, '<p>Test</p>'); | ||
|
||
self::assertTrue(true); | ||
self::assertNotNull($post->id); | ||
} | ||
} |