Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Benhawker/Pipedrive/Library/Deals.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ public function getById($id)
return $this->curl->get('deals/' . $id);
}

/**
* Returns a deal / deals filtered by filter id
*
* @param int $filterId pipedrive deals filter id
* @return array returns detials of a deal
*/
public function getByFilter($filterId) {
$filterId = (int) $filterId;
$params = array("filter_id" => $filterId);
return $this->curl->get("deals", $params);
}

/**
* Returns a deal / deals
*
Expand Down Expand Up @@ -91,7 +103,7 @@ public function add(array $data)

return $this->curl->post('deals', $data);
}

/**
* Adds a product to a deal
*
Expand Down
58 changes: 58 additions & 0 deletions src/Benhawker/Pipedrive/Library/Filters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Benhawker\Pipedrive\Library;


/**
* Pipedrive Filters Methods
*
* Each filter is essentially a set of data validation conditions. A filter of
* the same kind can be applied when fetching list of Deals, Persons,
* Organizations, Products or Deals in the context of a Pipeline.
* When applied, only items matching the conditions of the filter are returned.
* Detailed definitions of filter conditions and additional functionality is
* not yet available.
*
*/
class Filters {

/**
* Hold the pipedrive cURL session
* @var \Benhawker\Pipedrive\Library\Curl Curl Object
*/
protected $curl;

/**
* Initialise the object load master class
*/
public function __construct(\Benhawker\Pipedrive\Pipedrive $master) {
//associate curl class
$this->curl = $master->curl();
}

/**
* Returns a filter
*
* @param int $id Pipedrive filter id
* @return array returns detials of a filter
*/
public function getById($id) {
$id = (int) $id;
return $this->curl->get('filters/' . $id);
}

/**
* Returns a filter / filters
*
* @param string $type ["deals", "org", "people", "products"]
* @return array returns detials of a filters
*/
public function getByType($type = false) {
$params = array();
if ($type != false) {
$params["type"] = $type;
}
return $this->curl->get("filters", $params);
}

}
47 changes: 47 additions & 0 deletions src/Benhawker/Pipedrive/Library/Pipelines.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Benhawker\Pipedrive\Library;

/**
* Pipedrive Pipelines Methods
*
* Pipelines are essentially ordered collections of Stages.
*
*/
class Pipelines {

/**
* Hold the pipedrive cURL session
* @var \Benhawker\Pipedrive\Library\Curl Curl Object
*/
protected $curl;

/**
* Initialise the object load master class
*/
public function __construct(\Benhawker\Pipedrive\Pipedrive $master) {
//associate curl class
$this->curl = $master->curl();
}

/**
* Returns data about a specific pipeline. Also returns the summary of the
* deals in this pipeline across its stages.
*
* @param int $id pipedrive persons id
* @return array returns detials of a pipeline
*/
public function getById($id) {
return $this->curl->get('pipelines/' . $id);
}

/**
* Returns data about all pipelines
*
* @return array returns detials of a pipelines
*/
public function get() {
return $this->curl->get('pipelines');
}

}
49 changes: 49 additions & 0 deletions src/Benhawker/Pipedrive/Library/Stages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Benhawker\Pipedrive\Library;

/**
* Pipedrive Stages Methods
*
* Stage is a logical component of a Pipeline, and essentially a bucket that
* can hold a number of Deals. In the context of the Pipeline a stage belongs
* to, it has an order number which defines the order of stages in that
* Pipeline.
*
*/
class Stages {

/**
* Hold the pipedrive cURL session
* @var \Benhawker\Pipedrive\Library\Curl Curl Object
*/
protected $curl;

/**
* Initialise the object load master class
*/
public function __construct(\Benhawker\Pipedrive\Pipedrive $master) {
//associate curl class
$this->curl = $master->curl();
}

/**
* Returns data about a specific stage
*
* @param int $id pipedrive stage id
* @return array returns detials of a stage
*/
public function getById($id) {
return $this->curl->get('stages/' . $id);
}

/**
* Returns data about all stages
*
* @return array returns detials of all stages
*/
public function get() {
return $this->curl->get('stages');
}

}
75 changes: 75 additions & 0 deletions src/Benhawker/Pipedrive/Pipedrive.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ class Pipedrive
* @var Products Object
*/
protected $products;
/**
* Placeholder attritube for the pipedrive filters class
* @var Filters Object
*/
protected $filters;
/**
* Placeholder attritube for the pipedrive pipelines class
* @var Pipelines Object
*/
protected $pipelines;
/**
* Placeholder attritube for the pipedrive stages class
* @var Filters Object
*/
protected $stages;

/**
* Set up API url and load library classes
Expand Down Expand Up @@ -123,6 +138,36 @@ public function __construct($apiKey = '', $protocol = 'https', $host = 'api.pipe
$this->dealFields = new Library\DealFields($this);
$this->organizations = new Library\Organizations($this);
$this->products = new Library\Products($this);
$this->filters = new Library\Filters($this);
$this->pipelines = new Library\Pipelines($this);
$this->stages = new Library\Stages($this);
}

/**
* Sets ApiKey using username and password
*
* @param string $username Username of pipedrive user
* @param string $password Password of pipedrive user
* @return Api Key
* @throws Exceptions\PipedriveException
*/
public function login($username, $password) {
$params = array("email" => $username, "password" => $password);
$response = $this->curl()->post("authorizations", $params);
$errorMessage = "Wrong email/password combination.";

//Handle response
if (isset($response["success"]) && $response["success"] == true) {
if (isset($response["data"]) && isset($response["data"][0]) && isset($response["data"][0]["api_token"])) {
$this->apiKey = $response["data"][0]["api_token"];
//Reinitalize class constructor in case of some actions must be made with new ApiKey
$this->__construct($this->apiKey, $this->protocol, $this->host, $this->version);
return $this->apiKey;
}
} else if (isset($response["error"]) && $response["error"]) {
$errorMessage = $response["error"];
}
throw new Exceptions\PipedriveException($errorMessage);
}

/**
Expand Down Expand Up @@ -204,4 +249,34 @@ public function products()
{
return $this->products;
}

/**
* Returns the Pipedrive Filters Object
*
* @return Filters Object
*/
public function filters()
{
return $this->filters;
}

/**
* Returns the Pipedrive Pipelines Object
*
* @return Pipelines Object
*/
public function pipelines()
{
return $this->pipelines;
}

/**
* Returns the Pipedrive Stages Object
*
* @return Stages Object
*/
public function stages()
{
return $this->stages;
}
}