Skip to content

Commit

Permalink
Merge pull request #287 from HubSpot/feature/LineItems
Browse files Browse the repository at this point in the history
Feature/line items
  • Loading branch information
ksvirkou-hubspot authored Jan 15, 2020
2 parents 7c662c0 + 00bc960 commit 876ced6
Show file tree
Hide file tree
Showing 8 changed files with 476 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
* @method \SevenShores\Hubspot\Resources\Forms forms()
* @method \SevenShores\Hubspot\Resources\HubDB hubDB()
* @method \SevenShores\Hubspot\Resources\Keywords keywords()
* @method \SevenShores\Hubspot\Resources\LineItems lineItems()
* @method \SevenShores\Hubspot\Resources\Pages pages()
* @method \SevenShores\Hubspot\Resources\Products products()
* @method \SevenShores\Hubspot\Resources\SocialMedia socialMedia()
* @method \SevenShores\Hubspot\Resources\Tickets tickets()
* @method \SevenShores\Hubspot\Resources\Timeline timeline()
Expand Down
44 changes: 22 additions & 22 deletions src/Resources/BlogAuthors.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BlogAuthors extends Resource
* 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
Expand All @@ -32,7 +32,7 @@ public function all(array $params = [])
* @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 = '', array $params = [])
Expand All @@ -42,18 +42,18 @@ public function search($q = '', array $params = [])
$params['q'] = $q;

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

/**
* Get a specific blog author.
*
* @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
Expand All @@ -63,18 +63,18 @@ public function getById($id, array $params = [])
$endpoint = "https://api.hubapi.com/blogs/v3/blog-authors/{$id}";

return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
'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
Expand All @@ -84,19 +84,19 @@ public function create(array $options = [], array $params = [])
$endpoint = 'https://api.hubapi.com/blogs/v3/blog-authors';

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

/**
* Update a blog author.
*
* @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
Expand All @@ -114,7 +114,7 @@ public function update($id, array $params = [])
* @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 delete($id)
Expand Down
2 changes: 0 additions & 2 deletions src/Resources/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,6 @@ public function search(string $query, array $params = [])
}

/**
* @deprecated
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function statistics()
Expand Down
195 changes: 195 additions & 0 deletions src/Resources/LineItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?php

namespace SevenShores\Hubspot\Resources;

/**
* @see https://developers.hubspot.com/docs/methods/line-items/line-items-overview
*/
class LineItems extends Resource
{
/**
* Get all line items.
*
* @see https://developers.hubspot.com/docs/methods/line-items/get-all-line-items
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function all(array $params = [])
{
$endpoint = 'https://api.hubapi.com/crm-objects/v1/objects/line_items/paged';

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

/**
* Get a line item by ID.
*
* @param int $id
*
* @see https://developers.hubspot.com/docs/methods/line-items/get_line_item_by_id
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getById($id, array $params = [])
{
$endpoint = "https://api.hubapi.com/crm-objects/v1/objects/line_items/{$id}";

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

/**
* Get a group of line items by ID.
*
* @see https://developers.hubspot.com/docs/methods/line-items/batch-get-line-items
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getBatchByIds(array $ids, array $params = [])
{
$endpoint = 'https://api.hubapi.com/crm-objects/v1/objects/line_items/batch-read';

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

/**
* Create a line item.
*
* @see https://developers.hubspot.com/docs/methods/line-items/create-line-item
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function create(array $properties)
{
$endpoint = 'https://api.hubapi.com/crm-objects/v1/objects/line_items';

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

/**
* Create a group of line items.
*
* @see https://developers.hubspot.com/docs/methods/line-items/batch-create-line-items
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function createBatch(array $lineItems)
{
$endpoint = 'https://api.hubapi.com/crm-objects/v1/objects/line_items/batch-create';

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

/**
* Update a line item.
*
* @param int $id
*
* @see https://developers.hubspot.com/docs/methods/line-items/update-line-item
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function update($id, array $properties)
{
$endpoint = "https://api.hubapi.com/crm-objects/v1/objects/line_items/{$id}";

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

/**
* Update a group of line items.
*
* @see https://developers.hubspot.com/docs/methods/line-items/batch-update-line-items
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function updateBatch(array $lineItems)
{
$endpoint = 'https://api.hubapi.com/crm-objects/v1/objects/line_items/batch-update';

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

/**
* Delete a line item.
*
* @param int $id
*
* @see https://developers.hubspot.com/docs/methods/line-items/delete-line-item
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function delete($id)
{
$endpoint = "https://api.hubapi.com/crm-objects/v1/objects/line_items/{$id}";

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

/**
* Delete a group of line items.
*
* @see https://developers.hubspot.com/docs/methods/line-items/batch-delete-line-items
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function deleteBatch(array $ids)
{
$endpoint = 'https://api.hubapi.com/crm-objects/v1/objects/line_items/batch-delete';

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

/**
* Get a log of changes for line items.
*
* @see https://developers.hubspot.com/docs/methods/line-items/get-line-item-changes
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getLineItemChanges(array $params = [])
{
$endpoint = 'https://api.hubapi.com/crm-objects/v1/change-log/line_items';

return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}
}
16 changes: 16 additions & 0 deletions tests/Integration/Abstraction/ProductData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace SevenShores\Hubspot\Tests\Integration\Abstraction;

trait ProductData
{
protected function getData(string $name = 'A new product'): array
{
return [
['name' => 'name', 'value' => $name],
['name' => 'description', 'value' => 'A description of this product.'],
['name' => 'price', 'value' => 27.50],
['name' => 'recurringbillingfrequency', 'value' => 'quarterly'],
];
}
}
8 changes: 5 additions & 3 deletions tests/Integration/Resources/BlogAuthorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,21 @@ public function delete()
$response = $this->resource->delete($this->entity->id);

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

$this->entity = null;
}

protected function createEntity() {
protected function createEntity()
{
return $this->resource->create([
'fullName' => 'John Smith '.uniqid(),
'email' => 'john.smith'.uniqid().'@example.com',
'username' => 'john-smith',
]);
}

protected function deleteEntity() {
protected function deleteEntity()
{
$this->resource->delete($this->entity->id);
}
}
Loading

0 comments on commit 876ced6

Please sign in to comment.