From 3f5b125732362835e7a7ba43d69d36ded4747623 Mon Sep 17 00:00:00 2001 From: ksvirkou Date: Thu, 27 Aug 2020 20:31:10 +0300 Subject: [PATCH 1/3] review Pages + test --- src/Resources/Pages.php | 193 +++++++++++++--------- tests/Integration/Resources/PagesTest.php | 77 ++++++--- tests/unit/Support/QueryBuilderTest.php | 3 - 3 files changed, 168 insertions(+), 105 deletions(-) diff --git a/src/Resources/Pages.php b/src/Resources/Pages.php index 84156388..5429d69f 100644 --- a/src/Resources/Pages.php +++ b/src/Resources/Pages.php @@ -9,15 +9,15 @@ class Pages extends Resource * * @param array $params optional Parameters * + * @see https://legacydocs.hubspot.com/docs/methods/pages/post_pages + * * @return \SevenShores\Hubspot\Http\Response */ - public function create($params) + public function create(array $params) { $endpoint = 'https://api.hubapi.com/content/api/v2/pages'; - $options['json'] = $params; - - return $this->client->request('post', $endpoint, $options); + return $this->client->request('post', $endpoint, ['json' => $params]); } /** @@ -25,185 +25,208 @@ public function create($params) * * @param array $params optional parameters * + * @see https://legacydocs.hubspot.com/docs/methods/pages/get_pages + * * @return \SevenShores\Hubspot\Http\Response */ - public function all($params = []) + public function all(array $params = []) { $endpoint = 'https://api.hubapi.com/content/api/v2/pages'; - $queryString = build_query_string($params); - - return $this->client->request('get', $endpoint, [], $queryString); + return $this->client->request( + 'get', + $endpoint, + [], + build_query_string($params) + ); } /** * Update a page. * - * @param int $page_id the page id - * @param array $params the page fields to update + * @param int $pageId the page id + * @param array $params the page fields to update + * + * @see https://legacydocs.hubspot.com/docs/methods/pages/put_pages_page_id * * @return \SevenShores\Hubspot\Http\Response */ - public function update($page_id, $params) + public function update($pageId, array $params) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}"; - - $options['json'] = $params; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}"; - return $this->client->request('put', $endpoint, $options); + return $this->client->request('put', $endpoint, ['json' => $params]); } /** * Delete a page. * - * @param int $page_id + * @param int $pageId + * + * @see https://legacydocs.hubspot.com/docs/methods/pages/delete_pages_page_id * * @return \SevenShores\Hubspot\Http\Response */ - public function delete($page_id) + public function delete($pageId) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}"; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}"; return $this->client->request('delete', $endpoint); } /** - * Get a specific page. + * Get a Page by ID. * - * @param int $page_id + * @param int $pageId + * + * @see https://legacydocs.hubspot.com/docs/methods/pages/get_pages_page_id * * @return \SevenShores\Hubspot\Http\Response */ - public function getById($page_id) + public function getById($pageId) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}"; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}"; return $this->client->request('get', $endpoint); } /** - * Updates the auto-save buffer. + * Clone the page. * - * @param int $page_id The page ID - * @param array $params the auto-save buffer fields to update + * @param int $pageId The page ID + * @param string $name The cloned page name + * + * @see https://legacydocs.hubspot.com/docs/methods/pages/post_pages_page_id_clone * * @return \SevenShores\Hubspot\Http\Response */ - public function updateAutoSaveBuffer($page_id, $params) + public function clonePage($pageId, $name) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/buffer"; - - $options['json'] = $params; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}/clone"; - return $this->client->request('put', $endpoint, $options); + return $this->client->request('post', $endpoint, ['json' => ['name' => $name]]); } /** - * Gets the current contents of the auto-save buffer. + * Either publishes or cancels publishing based on the POSTed JSON. * - * @param int $page_id The page ID + * Allowable actions are: "push-buffer-live", "schedule-publish", "cancel-publish". + * "push-buffer-live": copies the current contents of the auto-save buffer into the live object. + * "schedule-publish": which pushes the buffer live and then sets up the content for publishing at + * the existing publish_date time. + * "cancel-publish": cancels a previous schedule-publish action. + * + * @param int $pageId The page ID + * @param string $action The publish action + * + * @see https://legacydocs.hubspot.com/docs/methods/pages/post_pages_page_id_publish_action * * @return \SevenShores\Hubspot\Http\Response */ - public function getAutoSaveBufferContents($page_id) + public function publishAction($pageId, string $action) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/buffer"; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}/publish-action"; - return $this->client->request('get', $endpoint); + return $this->client->request( + 'post', + $endpoint, + ['json' => ['action' => $action]] + ); } /** - * Clone the page. + * Gets the current contents of the auto-save buffer. + * + * @param int $pageId The page ID * - * @param int $page_id The page ID - * @param string $name The cloned page name + * @see https://legacydocs.hubspot.com/docs/methods/pages/get_pages_page_id_buffer * * @return \SevenShores\Hubspot\Http\Response */ - public function clonePage($page_id, $name) + public function getAutoSaveBufferContents($pageId) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/clone"; - - $options['json'] = ['name' => $name]; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}/buffer"; - return $this->client->request('post', $endpoint, $options); + return $this->client->request('get', $endpoint); } /** - * Determine if the auto-save buffer differs from the live page. + * Updates the auto-save buffer. * - * @param int $page_id The page ID + * @param int $pageId The page ID + * @param array $params the auto-save buffer fields to update + * + * @see https://legacydocs.hubspot.com/docs/methods/pages/put_pages_page_id_buffer * * @return \SevenShores\Hubspot\Http\Response */ - public function hasBufferedChanges($page_id) + public function updateAutoSaveBuffer($pageId, array $params = []) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/has-buffered-changes"; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}/buffer"; - return $this->client->request('get', $endpoint); + return $this->client->request('put', $endpoint, ['json' => $params]); } /** - * Either publishes or cancels publishing based on the POSTed JSON. + * Determine if the auto-save buffer differs from the live page. * - * Allowable actions are: "push-buffer-live", "schedule-publish", "cancel-publish". - * "push-buffer-live": copies the current contents of the auto-save buffer into the live object. - * "schedule-publish": which pushes the buffer live and then sets up the content for publishing at - * the existing publish_date time. - * "cancel-publish": cancels a previous schedule-publish action. + * @param int $pageId The page ID * - * @param int $page_id The page ID - * @param string $action The publish action + * @see https://legacydocs.hubspot.com/docs/methods/pages/get_pages_page_id_has_buffered_changes * * @return \SevenShores\Hubspot\Http\Response */ - public function publishAction($page_id, $action) + public function hasBufferedChanges($pageId) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/publish-action"; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}/has-buffered-changes"; - $options['json'] = ['action' => $action]; - - return $this->client->request('post', $endpoint, $options); + return $this->client->request('get', $endpoint); } /** * Copies the contents of the auto-save buffer into the live page. * - * @param int $page_id The page ID + * @param int $pageId The page ID + * + * @see https://legacydocs.hubspot.com/docs/methods/pages/post_pages_page_id_push_buffer_live * * @return \SevenShores\Hubspot\Http\Response */ - public function pushBufferLive($page_id) + public function pushBufferLive($pageId) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/push-buffer-live"; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}/push-buffer-live"; return $this->client->request('post', $endpoint); } /** - * Restores a previously deleted page. + * Validates the auto-save buffer version of the page. + * + * @param int $pageId The page ID * - * @param int $page_id The page ID + * @see https://legacydocs.hubspot.com/docs/methods/pages/post_pages_page_id_validate_buffer * * @return \SevenShores\Hubspot\Http\Response */ - public function restoreDeleted($page_id) + public function validateBuffer($pageId) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/restore-deleted"; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}/validate-buffer"; return $this->client->request('post', $endpoint); } /** - * Validates the auto-save buffer version of the page. + * Restores a previously deleted page. + * + * @param int $pageId The page ID * - * @param int $page_id The page ID + * @see https://legacydocs.hubspot.com/docs/methods/pages/post_pages_page_id_restore_deleted * * @return \SevenShores\Hubspot\Http\Response */ - public function validateBuffer($page_id) + public function restoreDeleted($pageId) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/validate-buffer"; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}/restore-deleted"; return $this->client->request('post', $endpoint); } @@ -211,13 +234,15 @@ public function validateBuffer($page_id) /** * List previous versions of the page. * - * @param int $page_id The page ID + * @param int $pageId The page ID + * + * @see https://legacydocs.hubspot.com/docs/methods/pages/get_pages_page_id_versions * * @return \SevenShores\Hubspot\Http\Response */ - public function versions($page_id) + public function versions($pageId) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/versions"; + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}/versions"; return $this->client->request('get', $endpoint); } @@ -225,17 +250,21 @@ public function versions($page_id) /** * Restore a previous version of the page. * - * @param int $page_id The page ID - * @param int $version_id The version ID + * @param int $pageId The page ID + * @param int $versionId The version ID + * + * @see https://legacydocs.hubspot.com/docs/methods/pages/post_pages_page_id_versions_restore * * @return \SevenShores\Hubspot\Http\Response */ - public function restoreVersion($page_id, $version_id) + public function restoreVersion($pageId, $versionId) { - $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/versions/restore"; - - $options['json'] = compact('version_id'); + $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$pageId}/versions/restore"; - return $this->client->request('post', $endpoint, $options); + return $this->client->request( + 'post', + $endpoint, + ['json' => ['version_id' => $versionId]] + ); } } diff --git a/tests/Integration/Resources/PagesTest.php b/tests/Integration/Resources/PagesTest.php index 69403657..7e376ad8 100644 --- a/tests/Integration/Resources/PagesTest.php +++ b/tests/Integration/Resources/PagesTest.php @@ -2,44 +2,81 @@ namespace SevenShores\Hubspot\Tests\Integration\Resources; -use SevenShores\Hubspot\Http\Client; -use SevenShores\Hubspot\Resources\Pages; +use SevenShores\Hubspot\Tests\Integration\Abstraction\EntityTestCase; /** * @internal * @coversNothing */ -class PagesTest extends \PHPUnit_Framework_TestCase +class PagesTest extends EntityTestCase { - private $pages; + /** + * @var null|SevenShores\Hubspot\Resources\Resource::class + */ + protected $resourceClass = 'SevenShores\Hubspot\Resources\Pages'; - public function setUp() + /** @test */ + public function create() { - parent::setUp(); - $this->pages = new Pages(new Client(['key' => getenv('HUBSPOT_TEST_API_KEY')])); - sleep(1); + $this->assertEquals(201, $this->entity->getStatusCode()); } /** @test */ - public function clonePage() + public function update() { - $post = $this->createPage(); - $response = $this->pages->clonePage($post->id, 'New page name'); - $this->assertEquals(201, $response->getStatusCode()); + $response = $this->resource->update( + $this->entity->id, + ['name' => 'Updated '.$this->entity->name] + ); + + $this->assertEquals(200, $response->getStatusCode()); } - // Lots of tests need an existing object to modify. - private function createPage() + /** @test */ + public function getById() { - sleep(1); + $response = $this->resource->getById($this->entity->id); - $response = $this->pages->create([ - 'name' => 'My Super Awesome Post '.uniqid(), - 'content_group_id' => 351076997, - ]); + $this->assertEquals(200, $response->getStatusCode()); + } + + /** @test */ + public function delete() + { + $response = $this->deleteEntity(); + + $this->assertEquals(204, $response->getStatusCode()); + + $this->entity = null; + } + + /** @test */ + public function all() + { + $response = $this->resource->all(); + + $this->assertEquals(200, $response->getStatusCode()); + } + + /** @test */ + public function clonePage() + { + $response = $this->resource->clonePage($this->entity->id, 'New page name'); $this->assertEquals(201, $response->getStatusCode()); - return $response; + $this->resource->delete($response->id); + } + + protected function createEntity() + { + return $this->resource->create([ + 'name' => 'My Super Awesome Post(AutoTest)', + ]); + } + + protected function deleteEntity() + { + return $this->resource->delete($this->entity->id); } } diff --git a/tests/unit/Support/QueryBuilderTest.php b/tests/unit/Support/QueryBuilderTest.php index b7c03f82..2182c1d3 100644 --- a/tests/unit/Support/QueryBuilderTest.php +++ b/tests/unit/Support/QueryBuilderTest.php @@ -11,9 +11,6 @@ class QueryBuilderTest extends \PHPUnit_Framework_TestCase /** * @test * @dataProvider buildDataProvider - * - * @param array $params - * @param string $result */ public function build(array $params, string $result) { From 388df234e81b372356e5b018fab37ee4105fcd36 Mon Sep 17 00:00:00 2001 From: ksvirkou Date: Fri, 28 Aug 2020 12:18:56 +0300 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 679df0f4..e4edeb2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - *nothing of note yet here* +## [2.0.5] + +### Changed +- removing list contacts by email address +- minor changes + ## [2.0.3] ### Added From 89248fc2bef38cd6f3e5588419011d9b94663927 Mon Sep 17 00:00:00 2001 From: ksvirkou Date: Fri, 28 Aug 2020 12:25:39 +0300 Subject: [PATCH 3/3] unrelesed --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4edeb2c..df98d9bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [Unreleased] -- *nothing of note yet here* +## [Unreleased](https://github.com/HubSpot/hubspot-php/compare/v2.0.5...HEAD) ## [2.0.5]