From 15b9d144c39d95d999f73e926c3fae173681dda7 Mon Sep 17 00:00:00 2001 From: ksvirkou Date: Tue, 14 Jan 2020 16:55:58 +0300 Subject: [PATCH 1/3] update Blogs --- src/Resources/BlogAuthors.php | 100 +++++++++++------- src/Resources/Blogs.php | 27 +++-- .../Integration/Resources/BlogAuthorsTest.php | 60 ++++------- tests/Integration/Resources/BlogsTest.php | 28 ++--- 4 files changed, 117 insertions(+), 98 deletions(-) diff --git a/src/Resources/BlogAuthors.php b/src/Resources/BlogAuthors.php index 831c46de..11918ec6 100644 --- a/src/Resources/BlogAuthors.php +++ b/src/Resources/BlogAuthors.php @@ -4,36 +4,25 @@ class BlogAuthors extends Resource { - /** - * Create a new blog author. - * - * @param array $params optional Parameters - * - * @return \SevenShores\Hubspot\Http\Response - */ - public function create($params = []) - { - $endpoint = 'https://api.hubapi.com/blogs/v3/blog-authors'; - - $options['json'] = $params; - - return $this->client->request('post', $endpoint, $options); - } - /** * Get all blog authors. * * @param array $params optional parameters + * + * @see https://developers.hubspot.com/docs/methods/blog/v3/list-blog-authors * * @return \SevenShores\Hubspot\Http\Response */ - public function all($params = []) + public function all(array $params = []) { $endpoint = 'https://api.hubapi.com/blogs/v3/blog-authors'; - $queryString = build_query_string($params); - - return $this->client->request('get', $endpoint, [], $queryString); + return $this->client->request( + 'get', + $endpoint, + [], + build_query_string($params) + ); } /** @@ -42,61 +31,96 @@ public function all($params = []) * @param string $q Search query * @param array $params optional parameters * + * @see https://developers.hubspot.com/docs/methods/blog/v3/search-blog-authors + * * @return \SevenShores\Hubspot\Http\Response */ - public function search($q = '', $params = []) + public function search($q = '', array $params = []) { $endpoint = 'https://api.hubapi.com/blogs/v3/blog-authors/search'; $params['q'] = $q; - $queryString = build_query_string($params); - - return $this->client->request('get', $endpoint, [], $queryString); + return $this->client->request( + 'get', + $endpoint, + [], + build_query_string($params) + ); } /** - * Update a blog author. + * Get a specific blog author. * - * @param int $id unique identifier for a blog author - * @param array $params fields to update + * @param int $id unique identifier for a blog author + * + * @see https://developers.hubspot.com/docs/methods/blog/v3/get-blog-author-by-id * * @return \SevenShores\Hubspot\Http\Response */ - public function update($id, $params = []) + public function getById($id, array $params = []) { $endpoint = "https://api.hubapi.com/blogs/v3/blog-authors/{$id}"; - $options['json'] = $params; + return $this->client->request( + 'get', + $endpoint, + [], + build_query_string($params) + ); + } + + /** + * Create a new blog author. + * + * @param array $options optional Parameters + * + * @see https://developers.hubspot.com/docs/methods/blog/v3/create-blog-author + * + * @return \SevenShores\Hubspot\Http\Response + */ + public function create(array $options = [], array $params = []) + { + $endpoint = 'https://api.hubapi.com/blogs/v3/blog-authors'; - return $this->client->request('put', $endpoint, $options); + return $this->client->request( + 'post', + $endpoint, + ['json' => $options], + build_query_string($params) + ); } /** - * Delete a blog author. + * Update a blog author. * - * @param int $id unique identifier for the blog author to delete + * @param int $id unique identifier for a blog author + * @param array $params fields to update + * + * @see https://developers.hubspot.com/docs/methods/blog/v3/update-blog-author * * @return \SevenShores\Hubspot\Http\Response */ - public function delete($id) + public function update($id, array $params = []) { $endpoint = "https://api.hubapi.com/blogs/v3/blog-authors/{$id}"; - return $this->client->request('delete', $endpoint); + return $this->client->request('put', $endpoint, ['json' => $params]); } /** - * Get a specific blog author. + * Delete a blog author. * - * @param int $id unique identifier for a blog author + * @param int $id unique identifier for the blog author to delete * + * @see https://developers.hubspot.com/docs/methods/blog/v3/delete-blog-author + * * @return \SevenShores\Hubspot\Http\Response */ - public function getById($id) + public function delete($id) { $endpoint = "https://api.hubapi.com/blogs/v3/blog-authors/{$id}"; - return $this->client->request('get', $endpoint); + return $this->client->request('delete', $endpoint); } } diff --git a/src/Resources/Blogs.php b/src/Resources/Blogs.php index f5854da0..9bcbfac3 100644 --- a/src/Resources/Blogs.php +++ b/src/Resources/Blogs.php @@ -9,21 +9,28 @@ class Blogs extends Resource * * @param array $params Optional parameters ['limit', 'offset', 'created', 'deleted_at', 'name'] * + * @see https://developers.hubspot.com/docs/methods/blogv2/get_blogs + * * @return \SevenShores\Hubspot\Http\Response */ - public function all($params = []) + public function all(array $params = []) { $endpoint = 'https://api.hubapi.com/content/api/v2/blogs'; - $queryString = build_query_string($params); - - return $this->client->request('get', $endpoint, [], $queryString); + return $this->client->request( + 'get', + $endpoint, + [], + build_query_string($params) + ); } /** * Get information about a specific blog. * - * @param string $id + * @param int $id + * + * @see https://developers.hubspot.com/docs/methods/blogv2/get_blogs_blog_id * * @return \SevenShores\Hubspot\Http\Response */ @@ -37,7 +44,9 @@ public function getById($id) /** * Get previous versions of the blog. * - * @param string $id blog id + * @param int $id blog id + * + * @see https://developers.hubspot.com/docs/methods/blogv2/get_blogs_blog_id_versions * * @return \SevenShores\Hubspot\Http\Response */ @@ -51,8 +60,10 @@ public function versions($id) /** * Get a previous version of the blog. * - * @param string $id blog id - * @param string $version_id version id + * @param int $id blog id + * @param int $version_id version id + * + * @see https://developers.hubspot.com/docs/methods/blogv2/get_blogs_blog_id_versions_version_id * * @return \SevenShores\Hubspot\Http\Response */ diff --git a/tests/Integration/Resources/BlogAuthorsTest.php b/tests/Integration/Resources/BlogAuthorsTest.php index 20d4a07c..cbce6b11 100644 --- a/tests/Integration/Resources/BlogAuthorsTest.php +++ b/tests/Integration/Resources/BlogAuthorsTest.php @@ -2,28 +2,21 @@ namespace SevenShores\Hubspot\Tests\Integration\Resources; -use SevenShores\Hubspot\Http\Client; use SevenShores\Hubspot\Resources\BlogAuthors; +use SevenShores\Hubspot\Tests\Integration\Abstraction\EntityTestCase; /** * @internal * @coversNothing */ -class BlogAuthorsTest extends \PHPUnit_Framework_TestCase +class BlogAuthorsTest extends EntityTestCase { - private $blogAuthors; - - public function setUp() - { - parent::setUp(); - $this->blogAuthors = new BlogAuthors(new Client(['key' => getenv('HUBSPOT_TEST_API_KEY')])); - sleep(1); - } + protected $resourceClass = BlogAuthors::class; /** @test */ public function allWithNoParams() { - $response = $this->blogAuthors->all(); + $response = $this->resource->all(); $this->assertEquals(200, $response->getStatusCode()); } @@ -31,7 +24,7 @@ public function allWithNoParams() /** @test */ public function allWithParams() { - $response = $this->blogAuthors->all([ + $response = $this->resource->all([ 'limit' => 2, 'offset' => 3, ]); @@ -44,7 +37,7 @@ public function allWithParams() /** @test */ public function searchWithoutQueryAndParams() { - $response = $this->blogAuthors->search(); + $response = $this->resource->search(); $this->assertEquals(200, $response->getStatusCode()); } @@ -52,7 +45,7 @@ public function searchWithoutQueryAndParams() /** @test */ public function searchWithQueryAndWithoutParams() { - $response = $this->blogAuthors->search('john-smith'); + $response = $this->resource->search('john-smith'); $this->assertEquals(200, $response->getStatusCode()); } @@ -60,7 +53,7 @@ public function searchWithQueryAndWithoutParams() /** @test */ public function searchWithQueryAndParams() { - $response = $this->blogAuthors->search('john-smith', [ + $response = $this->resource->search('john-smith', [ 'limit' => 5, ]); @@ -71,9 +64,7 @@ public function searchWithQueryAndParams() /** @test */ public function getById() { - $author = $this->createBlogAuthor(); - - $response = $this->blogAuthors->getById($author->id); + $response = $this->resource->getById($this->entity->id); $this->assertEquals(200, $response->getStatusCode()); } @@ -81,21 +72,13 @@ public function getById() /** @test */ public function create() { - $response = $this->blogAuthors->create([ - 'fullName' => 'John Smith '.uniqid(), - 'email' => 'john.smith'.uniqid().'@example.com', - 'username' => 'john-smith', - ]); - - $this->assertEquals(201, $response->getStatusCode()); + $this->assertEquals(201, $this->entity->getStatusCode()); } /** @test */ public function update() { - $author = $this->createBlogAuthor(); - - $response = $this->blogAuthors->update($author->id, [ + $response = $this->resource->update($this->entity->id, [ 'bio' => 'Lorem ipsum dolor sit amet.', 'website' => 'http://example.com', ]); @@ -106,26 +89,23 @@ public function update() /** @test */ public function delete() { - $author = $this->createBlogAuthor(); - - $response = $this->blogAuthors->delete($author->id); + $response = $this->resource->delete($this->entity->id); $this->assertEquals(204, $response->getStatusCode()); + + $this->entity = null; } - // Lots of tests need an existing object to modify. - private function createBlogAuthor() - { - sleep(1); - - $response = $this->blogAuthors->create([ + protected function createEntity() { + return $this->resource->create([ 'fullName' => 'John Smith '.uniqid(), 'email' => 'john.smith'.uniqid().'@example.com', 'username' => 'john-smith', ]); + } - $this->assertEquals(201, $response->getStatusCode()); - - return $response; + protected function deleteEntity() { + $this->resource->delete($this->entity->id); } + } diff --git a/tests/Integration/Resources/BlogsTest.php b/tests/Integration/Resources/BlogsTest.php index 39a73713..a0ffaea5 100644 --- a/tests/Integration/Resources/BlogsTest.php +++ b/tests/Integration/Resources/BlogsTest.php @@ -11,19 +11,22 @@ */ class BlogsTest extends \PHPUnit_Framework_TestCase { - private $blogs; + /** + * @var Blogs + */ + protected $resource; public function setUp() { parent::setUp(); - $this->blogs = new Blogs(new Client(['key' => getenv('HUBSPOT_TEST_API_KEY')])); + $this->resource = new Blogs(new Client(['key' => getenv('HUBSPOT_TEST_API_KEY')])); sleep(1); } /** @test */ public function allWithNoParams() { - $response = $this->blogs->all(); + $response = $this->resource->all(); $this->assertEquals(200, $response->getStatusCode()); } @@ -31,7 +34,7 @@ public function allWithNoParams() /** @test */ public function allWithParams() { - $response = $this->blogs->all(['limit' => 1]); + $response = $this->resource->all(['limit' => 1]); $this->assertEquals(200, $response->getStatusCode()); $this->assertNotNull($response->objects[0]->created); @@ -40,7 +43,7 @@ public function allWithParams() /** @test */ public function allWithParamsAndArrayAccess() { - $response = $this->blogs->all(['limit' => 1]); + $response = $this->resource->all(['limit' => 1]); $this->assertEquals(200, $response->getStatusCode()); $this->assertNotNull($response['objects'][0]['created']); @@ -49,9 +52,9 @@ public function allWithParamsAndArrayAccess() /** @test */ public function getById() { - $blogs = $this->blogs->all(['limit' => 1]); + $blogs = $this->resource->all(['limit' => 1]); - $response = $this->blogs->getById($blogs->objects[0]->id); + $response = $this->resource->getById($blogs->objects[0]->id); $this->assertEquals(200, $response->getStatusCode()); } @@ -59,16 +62,17 @@ public function getById() /** @test */ public function versionsGetVersion() { - $this->markTestSkipped(); // TODO: fix test - $blogs = $this->blogs->all(['limit' => 1]); + $blogs = $this->resource->all(['limit' => 1]); - $listResponse = $this->blogs->versions($blogs->objects[0]->id); - $getResponse = $this->blogs->getVersion( + $listResponse = $this->resource->versions($blogs->objects[0]->id); + + $this->assertEquals(200, $listResponse->getStatusCode()); + + $getResponse = $this->resource->getVersion( $blogs->objects[0]->id, $listResponse->getData()[0]->version_id ); - $this->assertEquals(200, $listResponse->getStatusCode()); $this->assertEquals(200, $getResponse->getStatusCode()); } } From 547534b39100d460c028092aede8002e7e103509 Mon Sep 17 00:00:00 2001 From: ksvirkou Date: Tue, 14 Jan 2020 16:58:24 +0300 Subject: [PATCH 2/3] update Blogs --- tests/Integration/Resources/BlogAuthorsTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Integration/Resources/BlogAuthorsTest.php b/tests/Integration/Resources/BlogAuthorsTest.php index cbce6b11..fad14ee1 100644 --- a/tests/Integration/Resources/BlogAuthorsTest.php +++ b/tests/Integration/Resources/BlogAuthorsTest.php @@ -107,5 +107,4 @@ protected function createEntity() { protected function deleteEntity() { $this->resource->delete($this->entity->id); } - } From 65a6a36ef640305c2b0794e4ab7dc5c3d6db42f3 Mon Sep 17 00:00:00 2001 From: ksvirkou Date: Tue, 14 Jan 2020 17:39:20 +0300 Subject: [PATCH 3/3] update Blogs tests --- tests/Integration/Resources/BlogsTest.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tests/Integration/Resources/BlogsTest.php b/tests/Integration/Resources/BlogsTest.php index a0ffaea5..88e0b8ef 100644 --- a/tests/Integration/Resources/BlogsTest.php +++ b/tests/Integration/Resources/BlogsTest.php @@ -58,21 +58,4 @@ public function getById() $this->assertEquals(200, $response->getStatusCode()); } - - /** @test */ - public function versionsGetVersion() - { - $blogs = $this->resource->all(['limit' => 1]); - - $listResponse = $this->resource->versions($blogs->objects[0]->id); - - $this->assertEquals(200, $listResponse->getStatusCode()); - - $getResponse = $this->resource->getVersion( - $blogs->objects[0]->id, - $listResponse->getData()[0]->version_id - ); - - $this->assertEquals(200, $getResponse->getStatusCode()); - } }