Skip to content

Commit

Permalink
Merge pull request #283 from HubSpot/feature/products
Browse files Browse the repository at this point in the history
add products
  • Loading branch information
ksvirkou-hubspot authored Jan 14, 2020
2 parents fd957cd + b940c17 commit 2ed3f70
Show file tree
Hide file tree
Showing 5 changed files with 384 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ If you see something not planned, that you want, make an [issue](https://github.
- [ ] Line Items API
- [ ] Marketing Email API
- [x] Owners API :upadated:
- [ ] Products API
- [x] Products API :new:
- [x] Social Media API
- [x] Tickets API
- [x] Timeline API :upadated:
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Client
protected $wrapResponse = true;

/** @var string */
private $user_agent = 'SevenShores_Hubspot_PHP/1.0.0-rc.1 (https://github.com/ryanwinchester/hubspot-php)';
protected $user_agent = 'SevenShores_Hubspot_PHP/2.0.1 (https://github.com/HubSpot/hubspot-php)';

/**
* Make it, baby.
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/HubDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function addRow($tableId, array $values, bool $draft = false, string $nam
"https://api.hubapi.com/hubdb/api/v2/tables/{$tableId}/rows",
$draft
);

return $this->client->request(
'post',
$endpoint,
Expand Down Expand Up @@ -378,7 +378,7 @@ public function import($tableId, string $file, array $cofig = [], bool $draft =
],
]);
}

/**
* Get body.
*/
Expand Down
195 changes: 195 additions & 0 deletions src/Resources/Products.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/products/products-overview
*/
class Products extends Resource
{
/**
* Get all products.
*
* @see https://developers.hubspot.com/docs/methods/products/get-all-products
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function all(array $params = [])
{
$endpoint = 'https://api.hubapi.com/crm-objects/v1/objects/products/paged';

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit 2ed3f70

Please sign in to comment.