Skip to content

Commit

Permalink
Merge pull request #333 from HubSpot/feature/v3
Browse files Browse the repository at this point in the history
Feature/v3
  • Loading branch information
ksvirkou-hubspot authored Oct 12, 2020
2 parents 8794b4a + 9f552ed commit a01ae4d
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 83 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ sudo: false

jobs:
include:
- php: 7.0
env: PHPUNIT_SUITE=All
- php: 7.1
env: PHPUNIT_SUITE=Unit
- php: 7.2
env: PHPUNIT_SUITE=Unit
env: PHPUNIT_SUITE=All
- php: 7.3
env: PHPUNIT_SUITE=Unit
- php: 7.4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ If you see something not planned, that you want, make an [issue](https://github.
- [ ] Conversations Live Chat Widget API (Front End)
- [x] CMS Blog API (Blogs) :upadated:
- [x] CMS Blog Authors API (BlogAuthors) :upadated:
- [ ] CMS Blog Comments API (Comments)
- [x] CMS Blog Comments API (BlogComments)
- [x] CMS Blog Post API (BlogPosts)
- [x] CMS Blog Topics API (BlogTopics)
- [ ] CMS Domains API
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.2",
"ext-json": "*",
"guzzlehttp/guzzle": "~6.0"
"guzzlehttp/guzzle": "~7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.13",
Expand Down
1 change: 0 additions & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function __construct(array $config = [], Client $client = null, array $cl
/**
* Return an instance of a Resource based on the method called.
*
* @param array $arguments
* @param mixed $args
*/
public function __call(string $name, $args): Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SevenShores\Hubspot\Resources;

class Comments extends Resource
class BlogComments extends Resource
{
/**
* Get all comments.
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/BlogPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function delete($id)
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function clonePost($id, string $name)
public function clone($id, string $name)
{
$endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$id}/clone";

Expand Down
9 changes: 3 additions & 6 deletions src/Resources/BlogTopics.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,17 @@ public function getById($id, array $params = [])
/**
* Create a new blog topic.
*
* @param string $name Name of the topic
* @param array $prorerties Blog topic's fields
* @param array $params Optional parametrs
* @param array $prorerties Blog topic's fields
* @param array $params Optional parametrs
*
* @see https://developers.hubspot.com/docs/methods/blog/v3/create-blog-topic
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function create($name, array $prorerties = [], $params = [])
public function create(array $prorerties, $params = [])
{
$endpoint = 'https://api.hubapi.com/blogs/v3/topics';

$prorerties['name'] = $name;

return $this->client->request(
'post',
$endpoint,
Expand Down
6 changes: 2 additions & 4 deletions src/Resources/ContactProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public function delete(string $name)
}

/**
* Get contact property groups.
*
* Returns all of the contact property groups for a given portal.
*
* @param bool $includeProperties if true returns all of the properties for each company property group
Expand All @@ -108,7 +106,7 @@ public function delete(string $name)
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getGroups(bool $includeProperties = false)
public function getAllGroups(bool $includeProperties = false)
{
$endpoint = 'https://api.hubapi.com/contacts/v2/groups';

Expand Down Expand Up @@ -176,7 +174,7 @@ public function updateGroup(string $groupName, array $properties)
{
$endpoint = "https://api.hubapi.com/contacts/v2/groups/named/{$groupName}";

$group['name'] = $groupName;
$properties['name'] = $groupName;

return $this->client->request('put', $endpoint, ['json' => $properties]);
}
Expand Down
31 changes: 21 additions & 10 deletions src/Resources/CrmPipelines.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,33 @@
*/
class CrmPipelines extends Resource
{
/**
* @var string
*/
protected $objectType;

public function __construct($client, string $objectType)
{
parent::__construct($client);

$this->objectType = $objectType;
}

/**
* Get all of the pipelines for the specified object type.
* This currently supports pipelines for deals and tickets.
*
* @param string $objectType | Currently supports tickets or deals only
* @param array $params | Array of optional parameter ['includeInactive' => 'EXCLUDE_DELETED' (default) | 'INCLUDE_DELETED']
* @param array $params | Array of optional parameter ['includeInactive' => 'EXCLUDE_DELETED' (default) | 'INCLUDE_DELETED']
*
* @throws \SevenShores\Hubspot\Exceptions\BadRequest
*
* @see https://developers.hubspot.com/docs/methods/pipelines/get_pipelines_for_object_type
*
* @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response
*/
public function all(string $objectType, array $params = [])
public function all(array $params = [])
{
$endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$objectType}";
$endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$this->objectType}";

return $this->client->request(
'get',
Expand All @@ -43,9 +54,9 @@ public function all(string $objectType, array $params = [])
*
* @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response
*/
public function create(string $objectType, array $properties)
public function create(array $properties)
{
$endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$objectType}";
$endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$this->objectType}";

return $this->client->request('post', $endpoint, ['json' => $properties]);
}
Expand All @@ -59,9 +70,9 @@ public function create(string $objectType, array $properties)
*
* @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response
*/
public function update(string $objectType, string $id, array $properties)
public function update(string $id, array $properties)
{
$endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$objectType}/{$id}";
$endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$this->objectType}/{$id}";

return $this->client->request('put', $endpoint, ['json' => $properties]);
}
Expand All @@ -75,9 +86,9 @@ public function update(string $objectType, string $id, array $properties)
*
* @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response
*/
public function delete(string $objectType, string $id)
public function delete(string $id)
{
$endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$objectType}/{$id}";
$endpoint = "https://api.hubapi.com/crm-pipelines/v1/pipelines/{$this->objectType}/{$id}";

return $this->client->request('delete', $endpoint);
}
Expand Down
23 changes: 19 additions & 4 deletions src/Resources/Deals.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ class Deals extends Resource
/**
* Create a deal.
*
* @param array $properties array of deal properties
* @param array $properties array of deal properties
* @param array $associations array of IDs for records that the new deal should be associated with
*
* @see https://developers.hubspot.com/docs/methods/deals/create_deal
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function create(array $properties)
public function create(array $properties, array $associations = [])
{
$endpoint = 'https://api.hubapi.com/deals/v1/deal';

return $this->client->request('post', $endpoint, ['json' => $properties]);
$data = ['properties' => $properties];

if (!empty($associations)) {
$data['associations'] = $associations;
}

return $this->client->request(
'post',
$endpoint,
['json' => $data]
);
}

/**
Expand All @@ -37,7 +48,11 @@ public function update($id, array $properties)
{
$endpoint = "https://api.hubapi.com/deals/v1/deal/{$id}";

return $this->client->request('put', $endpoint, ['json' => $properties]);
return $this->client->request(
'put',
$endpoint,
['json' => ['properties' => $properties]]
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/ObjectProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function delete(string $name)
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getGroups(bool $includeProperties = false)
public function getAllGroups(bool $includeProperties = false)
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/groups";

Expand Down
19 changes: 14 additions & 5 deletions tests/Integration/Abstraction/CrmPipelinesTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,28 @@ class CrmPipelinesTestCase extends EntityTestCase
*/
protected $resourceClass = CrmPipelines::class;

public function setUp()
{
if (empty($this->resource)) {
$this->resource = new $this->resourceClass($this->getClient(), $this->type);
}
sleep(1);

parent::setUp();
}

/** @test */
public function getAllPipelinesTest()
{
$response = $this->resource->all($this->type);
$response = $this->resource->all();

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

/** @test */
public function getAllPipelinesIncludingDeleted()
{
$response = $this->resource->all($this->type, ['includeInactive' => 'INCLUDE_DELETED']);
$response = $this->resource->all(['includeInactive' => 'INCLUDE_DELETED']);

$this->assertEquals(200, $response->getStatusCode());
}
Expand All @@ -51,7 +61,6 @@ public function createPipeline()
public function updatePipeline()
{
$response = $this->resource->update(
$this->type,
$this->entity->pipelineId,
$this->getData('Updated '.$this->type.' Pipeline')
);
Expand All @@ -71,12 +80,12 @@ public function deletePipeline()

protected function createEntity()
{
return $this->resource->create($this->type, $this->getData());
return $this->resource->create($this->getData());
}

protected function deleteEntity()
{
return $this->resource->delete($this->type, $this->entity->pipelineId);
return $this->resource->delete($this->entity->pipelineId);
}

protected function getData(string $label = null)
Expand Down
9 changes: 2 additions & 7 deletions tests/Integration/Abstraction/PropertyGroupsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

abstract class PropertyGroupsTestCase extends EntityTestCase
{
/**
* @var string
*/
protected $allGroupsMethod = 'getAllGroups';

/**
* @var bool
*/
Expand All @@ -17,7 +12,7 @@ abstract class PropertyGroupsTestCase extends EntityTestCase
/** @test */
public function all()
{
$response = $this->resource->{$this->allGroupsMethod}();
$response = $this->resource->getAllGroups();

$this->assertEquals(200, $response->getStatusCode());
$this->assertGreaterThanOrEqual(1, count($response->getData()));
Expand All @@ -27,7 +22,7 @@ public function all()
/** @test */
public function allWithProperties()
{
$response = $this->resource->{$this->allGroupsMethod}(true);
$response = $this->resource->getAllGroups(true);

$this->assertEquals(200, $response->getStatusCode());
$this->assertGreaterThanOrEqual(1, count($response->getData()));
Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/Resources/BlogCommentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace SevenShores\Hubspot\Tests\Integration\Resources;

use SevenShores\Hubspot\Http\Client;
use SevenShores\Hubspot\Resources\BlogComments;
use SevenShores\Hubspot\Resources\BlogPosts;
use SevenShores\Hubspot\Resources\Comments;
use SevenShores\Hubspot\Tests\Integration\Abstraction\BlogPostTestCase;

/**
Expand All @@ -14,14 +14,14 @@
class BlogCommentsTest extends BlogPostTestCase
{
/**
* @var Comments
* @var BlogComments
*/
protected $resource;

/**
* @var Comments:class
* @var BlogComments:class
*/
protected $resourceClass = Comments::class;
protected $resourceClass = BlogComments::class;

/**
* @var BlogPosts
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Resources/BlogPostsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function delete()
/** @test */
public function clonePost()
{
$response = $this->resource->clonePost($this->entity->id, 'Cloned post name');
$response = $this->resource->clone($this->entity->id, 'Cloned post name');

$this->assertEquals(201, $response->getStatusCode());

Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/Resources/BlogTopicsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public function delete()

protected function createEntity()
{
return $this->resource->create('Topic Test '.uniqid(), [
return $this->resource->create([
'name' => 'Topic Test '.uniqid(),
'description' => 'Topic Test '.uniqid().' Description',
]);
}
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/Resources/CompaniesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ protected function deleteAssociatedContacts($companyId, $contactIds = [])
{
foreach ($contactIds as $contactId) {
$this->resource->removeContact($contactId, $companyId);
sleep(1);
$this->contactsResource->delete($contactId);
}
}
Expand Down
5 changes: 0 additions & 5 deletions tests/Integration/Resources/ContactPropertyGroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
*/
class ContactPropertyGroupsTest extends PropertyGroupsTestCase
{
/**
* @var string
*/
protected $allGroupsMethod = 'getGroups';

/**
* @var bool
*/
Expand Down
Loading

0 comments on commit a01ae4d

Please sign in to comment.