Skip to content

Commit

Permalink
Merge pull request #266 from HubSpot/feature/crmobjectproperties
Browse files Browse the repository at this point in the history
new resource ObjectProperties
  • Loading branch information
ksvirkou-hubspot authored Dec 20, 2019
2 parents 2be5ee4 + 4c975e3 commit b1f8dd7
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @method \SevenShores\Hubspot\Resources\EcommerceBridge ecommerceBridge()
* @method \SevenShores\Hubspot\Resources\Webhooks webhooks()
* @method \SevenShores\Hubspot\Resources\OAuth2 oAuth2()
* @method \SevenShores\Hubspot\Resources\ObjectProperties objectProperties()
*/
class Factory
{
Expand Down Expand Up @@ -73,7 +74,7 @@ public function __call($name, $args)
{
$resource = 'SevenShores\\Hubspot\\Resources\\'.ucfirst($name);

return new $resource($this->client);
return new $resource($this->client, ...$args);
}

/**
Expand Down
196 changes: 196 additions & 0 deletions src/Resources/ObjectProperties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?php

namespace SevenShores\Hubspot\Resources;

/**
*
* @see https://developers.hubspot.com/docs/methods/crm-properties/crm-properties-overview
*/
class ObjectProperties extends Resource
{
/**
*
* @var string
*/
protected $objectType;

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

$this->objectType = $objectType;
}

/**
* Get an Object Property.
*
* @param string $name the name of the property
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function get($name)
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/properties/named/{$name}";

return $this->client->request('get', $endpoint);
}

/**
* Get all object properties.
*
* @see https://developers.hubspot.com/docs/methods/crm-properties/get-properties
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function all()
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/properties";

return $this->client->request('get', $endpoint);
}

/**
* Create a new object property.
*
* @see https://developers.hubspot.com/docs/methods/crm-properties/create-property
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function create(array $property)
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/properties";

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

/**
* Update an object property
*
* Update a specified contact property.
*
* @see https://developers.hubspot.com/docs/methods/crm-properties/update-property
*
* @param string $name
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function update($name, array $property)
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/properties/named/{$name}";

$property['name'] = $name;

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

/**
* Delete an object property.
*
*
* @see https://developers.hubspot.com/docs/methods/crm-properties/delete-property
*
* @param string $name
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function delete($name)
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/properties/named/{$name}";

return $this->client->request('delete', $endpoint);
}

/**
* Get all object property groups.
*
* @see https://developers.hubspot.com/docs/methods/crm-properties/get-property-groups
*
* @param bool $includeProperties
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getGroups($includeProperties = false)
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/groups";

$queryString = '';
if ($includeProperties) {
$queryString = build_query_string(['includeProperties' => 'true']);
}

return $this->client->request('get', $endpoint, [], $queryString);
}

/**
* Get an object property group.
*
* @see https://developers.hubspot.com/docs/methods/crm-properties/get-property-groups
*
* @param bool $includeProperties
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getGroup($name, $includeProperties = false)
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/groups/named/{$name}";

$queryString = '';
if ($includeProperties) {
$queryString = build_query_string(['includeProperties' => 'true']);
}

return $this->client->request('get', $endpoint, [], $queryString);
}

/**
* Create an object property group.
*
* @see https://developers.hubspot.com/docs/methods/crm-properties/create-property-group
*
* @param array $group Group properties
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function createGroup(array $group)
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/groups";

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

/**
* Update an object property group.
*
* @see https://developers.hubspot.com/docs/methods/crm-properties/udpate-property-group
*
* @param string $name
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function updateGroup($name, array $group)
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/groups/named/{$name}";

$group['name'] = $name;

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

/**
* Delete a property group.
*
* Delete an existing contact property group.
*
* @see https://developers.hubspot.com/docs/methods/crm-properties/delete-property-group
*
* @param string $name
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function deleteGroup($name)
{
$endpoint = "https://api.hubapi.com/properties/v2/{$this->objectType}/groups/named/{$name}";

return $this->client->request('delete', $endpoint);
}
}
25 changes: 25 additions & 0 deletions tests/Integration/Resources/ObjectPropertiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace SevenShores\Hubspot\Tests\Integration\Resources;

use SevenShores\Hubspot\Tests\Integration\Abstraction\PropertiesTestCase;
use SevenShores\Hubspot\Factory;

/**
* @internal
* @coversNothing
*/
class ObjectPropertiesTest extends PropertiesTestCase
{
/**
* @var string
*/
protected $groupName = 'productinformation';

public function setUp()
{
$this->resource = Factory::create(getenv('HUBSPOT_TEST_API_KEY'))->objectProperties('products');
sleep(1);
$this->entity = $this->createEntity();
}
}
33 changes: 33 additions & 0 deletions tests/Integration/Resources/ObjectPropertyGroupsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace SevenShores\Hubspot\Tests\Integration\Resources;

use SevenShores\Hubspot\Tests\Integration\Abstraction\PropertyGroupsTestCase;
use SevenShores\Hubspot\Factory;

/**
* @internal
* @coversNothing
*/
class ObjectPropertyGroupsTest extends PropertyGroupsTestCase
{
/**
* @var string
*/
protected $allGroupsMethod = 'getGroups';

public function setUp()
{
$this->resource = Factory::create(getenv('HUBSPOT_TEST_API_KEY'))->objectProperties('products');
sleep(1);
$this->entity = $this->createEntity();
}

/** @test */
public function get()
{
$response = $this->resource->getGroup($this->entity->name);

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

0 comments on commit b1f8dd7

Please sign in to comment.