From b495880da69cd6b42c65b0f9df9473e5efc02045 Mon Sep 17 00:00:00 2001 From: Aurimas Pauga Date: Wed, 6 Jul 2016 12:16:51 +0300 Subject: [PATCH 1/4] login (using username and password) to pipedrive --- src/Benhawker/Pipedrive/Pipedrive.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Benhawker/Pipedrive/Pipedrive.php b/src/Benhawker/Pipedrive/Pipedrive.php index 1fe7b18..7cc88e8 100644 --- a/src/Benhawker/Pipedrive/Pipedrive.php +++ b/src/Benhawker/Pipedrive/Pipedrive.php @@ -125,6 +125,33 @@ public function __construct($apiKey = '', $protocol = 'https', $host = 'api.pipe $this->products = new Library\Products($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); + } + /** * Returns the Pipedrive cURL Session * From 0feda39dba067668b9fe65c29bfefc783c84b353 Mon Sep 17 00:00:00 2001 From: Aurimas Pauga Date: Wed, 6 Jul 2016 12:46:57 +0300 Subject: [PATCH 2/4] Filters object & deals getByFilter method --- src/Benhawker/Pipedrive/Library/Deals.php | 14 ++++- src/Benhawker/Pipedrive/Library/Filters.php | 58 +++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/Benhawker/Pipedrive/Library/Filters.php 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); + } + +} From 5f05cedf5b3b4303f7b3cd9f26bb2d7994cc2820 Mon Sep 17 00:00:00 2001 From: Aurimas Pauga Date: Wed, 6 Jul 2016 13:19:31 +0300 Subject: [PATCH 3/4] filters object to pipedrive object --- src/Benhawker/Pipedrive/Pipedrive.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Benhawker/Pipedrive/Pipedrive.php b/src/Benhawker/Pipedrive/Pipedrive.php index 7cc88e8..6e21060 100644 --- a/src/Benhawker/Pipedrive/Pipedrive.php +++ b/src/Benhawker/Pipedrive/Pipedrive.php @@ -92,6 +92,11 @@ class Pipedrive * @var Products Object */ protected $products; + /** + * Placeholder attritube for the pipedrive filters class + * @var Filters Object + */ + protected $filters; /** * Set up API url and load library classes @@ -123,6 +128,7 @@ 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); } /** @@ -231,4 +237,14 @@ public function products() { return $this->products; } + + /** + * Returns the Pipedrive Filters Object + * + * @return Filters Object + */ + public function filters() + { + return $this->filters; + } } From 9cb2f5d5f1e88c3eba5bcff84cbfe4fa99d0bceb Mon Sep 17 00:00:00 2001 From: Aurimas Pauga Date: Wed, 6 Jul 2016 15:16:29 +0300 Subject: [PATCH 4/4] Pipelines & Stages objects --- src/Benhawker/Pipedrive/Library/Pipelines.php | 47 ++++++++++++++++++ src/Benhawker/Pipedrive/Library/Stages.php | 49 +++++++++++++++++++ src/Benhawker/Pipedrive/Pipedrive.php | 32 ++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 src/Benhawker/Pipedrive/Library/Pipelines.php create mode 100644 src/Benhawker/Pipedrive/Library/Stages.php 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 6e21060..a68a0a1 100644 --- a/src/Benhawker/Pipedrive/Pipedrive.php +++ b/src/Benhawker/Pipedrive/Pipedrive.php @@ -97,6 +97,16 @@ class Pipedrive * @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 @@ -129,6 +139,8 @@ public function __construct($apiKey = '', $protocol = 'https', $host = 'api.pipe $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); } /** @@ -247,4 +259,24 @@ 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; + } }