Skip to content

Commit

Permalink
Merge pull request #25 from basecrm/adding-resources
Browse files Browse the repository at this point in the history
New resources support
  • Loading branch information
Erwin Fedasz authored Aug 30, 2017
2 parents e272796 + 50171a4 commit 2a75f29
Show file tree
Hide file tree
Showing 16 changed files with 1,201 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## CHANGELOG

### v1.3.0 (2017-08-28)

**Features and Improvements**
* Support for resources: Lead Source, Deal Source, Product, Order, Line Item

### v1.2.1 (2016-06-29)

**Bug Fixes**
Expand Down
73 changes: 72 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ $deal['value'] = 10.10;
$deal['value'] = "10.10";
```

### Deal Source

```php
$client = new \BaseCRM\Client(['accessToken' => '<YOUR_PERSONAL_ACCESS_TOKEN>');
$client->dealSources // => \BaseCRM\DealSourcesService
```

Actions:
* Retrieve all deal sources - `client->dealSources->all`
* Create a deal source - `client->dealSources->create`
* Retrieve a single deal source - `client->dealSources->get`
* Update a deal source - `client->dealSources->update`
* Delete a deal source - `client->dealSources->destroy`

### Lead

```php
Expand All @@ -260,6 +274,35 @@ Actions:
* Update a lead - `client->leads->update`
* Delete a lead - `client->leads->destroy`

### Lead Source

```php
$client = new \BaseCRM\Client(['accessToken' => '<YOUR_PERSONAL_ACCESS_TOKEN>');
$client->leadSources // => \BaseCRM\LeadSourcesService
```

Actions:
* Retrieve all lead sources - `client->leadSources->all`
* Create a lead source - `client->leadSources->create`
* Retrieve a single lead source - `client->leadSources->get`
* Update a lead source - `client->leadSources->update`
* Delete a lead source - `client->leadSources->destroy`

### Line Item

```php
$client = new \BaseCRM\Client(['accessToken' => '<YOUR_PERSONAL_ACCESS_TOKEN>');
$client->lineItems // => \BaseCRM\LineItemsService
```

Actions:
* Retrieve all line items - `client->lineItems->all`
* Create a line item - `client->lineItems->create`
* Retrieve a single line item- `client->lineItems->get`
* Update a line item - `client->lineItems->update`
* Delete a line item - `client->lineItems->destroy`


### LossReason

```php
Expand Down Expand Up @@ -288,6 +331,20 @@ Actions:
* Update a note - `client->notes->update`
* Delete a note - `client->notes->destroy`

### Order

```php
$client = new \BaseCRM\Client(['accessToken' => '<YOUR_PERSONAL_ACCESS_TOKEN>');
$client->orders // => \BaseCRM\OrdersService
```

Actions:
* Retrieve all orders - `client->orders->all`
* Create an order - `client->orders->create`
* Retrieve a single order - `client->orders->get`
* Update an order - `client->orders->update`
* Delete an order - `client->orders->destroy`

### Pipeline

```php
Expand All @@ -298,7 +355,21 @@ $client->pipelines // => \BaseCRM\PipelinesService
Actions:
* Retrieve all pipelines - `client->pipelines->all`

### Source
### Product

```php
$client = new \BaseCRM\Client(['accessToken' => '<YOUR_PERSONAL_ACCESS_TOKEN>');
$client->products // => \BaseCRM\ProductsService
```

Actions:
* Retrieve all products - `client->products->all`
* Create a product - `client->products->create`
* Retrieve a single product - `client->products->get`
* Update a product - `client->products->update`
* Delete a product - `client->products->destroy`

### Source (Deprecated! Use Lead Source, Deal Source instead)

```php
$client = new \BaseCRM\Client(['accessToken' => '<YOUR_PERSONAL_ACCESS_TOKEN>');
Expand Down
40 changes: 40 additions & 0 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,34 @@ class Client
*/
public $deals;

/**
* @var \BaseCRM\DealSourcesService Access all DealSources related actions.
* @see \BaseCRM\DealSourcesService
* @see \BaseCRM\DealSource
*/
public $dealSources;

/**
* @var \BaseCRM\LeadsService Access all Leads related actions.
* @see \BaseCRM\LeadsService
* @see \BaseCRM\Lead
*/
public $leads;

/**
* @var \BaseCRM\LeadSourcesService Access all LeadSources related actions.
* @see \BaseCRM\LeadSourcesService
* @see \BaseCRM\LeadSource
*/
public $leadSources;

/**
* @var \BaseCRM\LineItemsService Access all LineItems related actions.
* @see \BaseCRM\LineItemsService
* @see \BaseCRM\LineItem
*/
public $lineItems;

/**
* @var \BaseCRM\LossReasonsService Access all LossReasons related actions.
* @see \BaseCRM\LossReasonsService
Expand All @@ -71,13 +92,27 @@ class Client
*/
public $notes;

/**
* @var \BaseCRM\OrdersService Access all Orders related actions.
* @see \BaseCRM\OrdersService
* @see \BaseCRM\Order
*/
public $orders;

/**
* @var \BaseCRM\PipelinesService Access all Pipelines related actions.
* @see \BaseCRM\PipelinesService
* @see \BaseCRM\Pipeline
*/
public $pipelines;

/**
* @var \BaseCRM\ProductsService Access all Products related actions.
* @see \BaseCRM\ProductsService
* @see \BaseCRM\Product
*/
public $products;

/**
* @var \BaseCRM\SourcesService Access all Sources related actions.
* @see \BaseCRM\SourcesService
Expand Down Expand Up @@ -153,10 +188,15 @@ public function __construct(array $config = [])
$this->associatedContacts = new AssociatedContactsService($this->httpClient);
$this->contacts = new ContactsService($this->httpClient);
$this->deals = new DealsService($this->httpClient);
$this->dealSources = new DealSourcesService($this->httpClient);
$this->leads = new LeadsService($this->httpClient);
$this->leadSources = new LeadSourcesService($this->httpClient);
$this->lineItems = new LineItemsService($this->httpClient);
$this->lossReasons = new LossReasonsService($this->httpClient);
$this->notes = new NotesService($this->httpClient);
$this->orders = new OrdersService($this->httpClient);
$this->pipelines = new PipelinesService($this->httpClient);
$this->products = new ProductsService($this->httpClient);
$this->sources = new SourcesService($this->httpClient);
$this->stages = new StagesService($this->httpClient);
$this->tags = new TagsService($this->httpClient);
Expand Down
6 changes: 3 additions & 3 deletions lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

class Configuration
{
// @version 1.1.1 Current stable version.
const VERSION = "1.2.0";
// @version 1.3.0 Current stable version.
const VERSION = "1.3.0";

const PRODUCTION_URL = "https://api.getbase.com";
const URL_REGEXP = "/\b(?:(?:https?|http):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i";
Expand Down Expand Up @@ -72,7 +72,7 @@ public function isValid()
if (preg_match('/\s/', $this->accessToken))
{
$msg = 'Provided access token is invalid '
. 'as it contains disallowed chracters. '
. 'as it contains disallowed characters. '
. 'Please double-check your access token.';
throw new Errors\ConfigurationError($msg);
}
Expand Down
128 changes: 128 additions & 0 deletions lib/DealSourcesService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
// WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
namespace BaseCRM;

/**
* BaseCRM\DealSourcesService
*
* Class used to make actions related to DealSource resource.
*
* @package BaseCRM
*/
class DealSourcesService
{
// @var array Allowed attribute names.
protected static $keysToPersist = ['name', 'resource_type'];

protected $httpClient;

/**
* Instantiate a new DealSourcesService instance.
*
* @param BaseCRM\HttpClient $httpClient Http client.
*/
public function __construct(HttpClient $httpClient)
{
$this->httpClient = $httpClient;
}

/**
* Retrieve all sources
*
* get '/deal_sources'
*
* Returns all deal sources available to the user according to the parameters provided
*
* @param array $options Search options
*
* @return array The list of DealSources for the first page, unless otherwise specified.
*/
public function all($options = [])
{
list($code, $deal_sources) = $this->httpClient->get("/deal_sources", $options);
return $deal_sources;
}

/**
* Create a new source
*
* post '/deal_sources'
*
* Creates a new source
* <figure class="notice">
* Source's name **must** be unique
* </figure>
*
* @param array $dealSource This array's attributes describe the object to be created.
*
* @return array The resulting object representing created resource.
*/
public function create(array $dealSource)
{
$attributes = array_intersect_key($dealSource, array_flip(self::$keysToPersist));

list($code, $createdDealSource) = $this->httpClient->post("/deal_sources", $attributes);
return $createdDealSource;
}

/**
* Retrieve a single source
*
* get '/deal_sources/{id}'
*
* Returns a single source available to the user by the provided id
* If a source with the supplied unique identifier does not exist it returns an error
*
* @param integer $id Unique identifier of a DealSource
*
* @return array Searched DealSource.
*/
public function get($id)
{
list($code, $deal_source) = $this->httpClient->get("/deal_sources/{$id}");
return $deal_source;
}

/**
* Update a source
*
* put '/deal_sources/{id}'
*
* Updates source information
* If the specified source does not exist, the request will return an error
* <figure class="notice">
* If you want to update a source, you **must** make sure source's name is unique
* </figure>
*
* @param integer $id Unique identifier of a DealSource
* @param array $dealSource This array's attributes describe the object to be updated.
*
* @return array The resulting object representing updated resource.
*/
public function update($id, array $dealSource)
{
$attributes = array_intersect_key($dealSource, array_flip(self::$keysToPersist));

list($code, $updatedDealSource) = $this->httpClient->put("/deal_sources/{$id}", $attributes);
return $updatedDealSource;
}

/**
* Delete a source
*
* delete '/deal_sources/{id}'
*
* Delete an existing source
* If the specified source does not exist, the request will return an error
* This operation cannot be undone
*
* @param integer $id Unique identifier of a DealSource
*
* @return boolean Status of the operation.
*/
public function destroy($id)
{
list($code, $payload) = $this->httpClient->delete("/deal_sources/{$id}");
return $code == 204;
}
}
Loading

0 comments on commit 2a75f29

Please sign in to comment.