diff --git a/src/Benhawker/Pipedrive/Library/Deals.php b/src/Benhawker/Pipedrive/Library/Deals.php index 533c2d8..34ceb61 100644 --- a/src/Benhawker/Pipedrive/Library/Deals.php +++ b/src/Benhawker/Pipedrive/Library/Deals.php @@ -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 * @@ -91,7 +103,7 @@ public function add(array $data) return $this->curl->post('deals', $data); } - + /** * Adds a product to a deal * diff --git a/src/Benhawker/Pipedrive/Library/Filters.php b/src/Benhawker/Pipedrive/Library/Filters.php new file mode 100644 index 0000000..4156098 --- /dev/null +++ b/src/Benhawker/Pipedrive/Library/Filters.php @@ -0,0 +1,58 @@ +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); + } + +} diff --git a/src/Benhawker/Pipedrive/Library/Pipelines.php b/src/Benhawker/Pipedrive/Library/Pipelines.php new file mode 100644 index 0000000..bf19c48 --- /dev/null +++ b/src/Benhawker/Pipedrive/Library/Pipelines.php @@ -0,0 +1,47 @@ +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'); + } + +} diff --git a/src/Benhawker/Pipedrive/Library/Stages.php b/src/Benhawker/Pipedrive/Library/Stages.php new file mode 100644 index 0000000..08525a4 --- /dev/null +++ b/src/Benhawker/Pipedrive/Library/Stages.php @@ -0,0 +1,49 @@ +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'); + } + +} diff --git a/src/Benhawker/Pipedrive/Pipedrive.php b/src/Benhawker/Pipedrive/Pipedrive.php index 1fe7b18..a68a0a1 100644 --- a/src/Benhawker/Pipedrive/Pipedrive.php +++ b/src/Benhawker/Pipedrive/Pipedrive.php @@ -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 @@ -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); } /** @@ -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; + } }