Skip to content

Commit

Permalink
Merge pull request #284 from HubSpot/review/blogs
Browse files Browse the repository at this point in the history
Review/blogs
  • Loading branch information
ksvirkou-hubspot authored Jan 14, 2020
2 parents 2ed3f70 + 65a6a36 commit 7c662c0
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 109 deletions.
100 changes: 62 additions & 38 deletions src/Resources/BlogAuthors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

/**
Expand All @@ -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);
}
}
27 changes: 19 additions & 8 deletions src/Resources/Blogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand Down
59 changes: 19 additions & 40 deletions tests/Integration/Resources/BlogAuthorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,29 @@

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());
}

/** @test */
public function allWithParams()
{
$response = $this->blogAuthors->all([
$response = $this->resource->all([
'limit' => 2,
'offset' => 3,
]);
Expand All @@ -44,23 +37,23 @@ public function allWithParams()
/** @test */
public function searchWithoutQueryAndParams()
{
$response = $this->blogAuthors->search();
$response = $this->resource->search();

$this->assertEquals(200, $response->getStatusCode());
}

/** @test */
public function searchWithQueryAndWithoutParams()
{
$response = $this->blogAuthors->search('john-smith');
$response = $this->resource->search('john-smith');

$this->assertEquals(200, $response->getStatusCode());
}

/** @test */
public function searchWithQueryAndParams()
{
$response = $this->blogAuthors->search('john-smith', [
$response = $this->resource->search('john-smith', [
'limit' => 5,
]);

Expand All @@ -71,31 +64,21 @@ 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());
}

/** @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',
]);
Expand All @@ -106,26 +89,22 @@ 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);
}
}
Loading

0 comments on commit 7c662c0

Please sign in to comment.