diff --git a/README.md b/README.md index a8b1cd1..68bfab6 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,67 @@ PipeDrive-api-php -============ +================= -PHP API client library for the PipeDrive CRM +PHP API client library for the PipeDrive CRM. Only some basic functionality required for my current project has been added. However the basic blocks are to make use of the whole API including file uploading. -Recommend you install this library through composer. https://packagist.org/packages/benhawker/pipedrive +Recommend you install this library through composer: https://packagist.org/packages/benhawker/pipedrive + + composer require benhawker/pipedrive dev-master API Docs can be found here: https://developers.pipedrive.com/v1 -Example: - +Example: +-------- + ```php -use Benhawker\Pipedrive\Pipedrive; +use Benhawker\Pipedrive\Pipedrive; + +$pipedrive = new Pipedrive('0deceea867202fcf3889cd507ef93a91789f7e3a'); + +/** + * Add company. + */ +$organization['name'] = 'Explorer'; -$pipedrive = new Pipedrive('0deceea867202fcf3889cd507ef93a91789f7e3a'); +$organization = $pipedrive->organizations()->add($organization); -//add user -$person['name'] = 'John Smith'; +/** + * Add customer. + */ +$person['name'] = 'John Smith'; +$person['org_id'] = $organization['data']['id']; -$person = $pipedrive->persons()->add($person); +$person = $pipedrive->persons()->add($person); -//add note to user -$note['content'] = 'example note'; -$note['person_id'] = $person['data']['id']; +/** + * Add note to customer. + */ +$note['content'] = 'example note'; +$note['person_id'] = $person['data']['id']; -$pipedrive->notes()->add($note); +$pipedrive->notes()->add($note); -//add deal to user -deal['title'] = 'example title'; -$deal['stage_id'] = 8; -$deal['person_id'] = $person['data']['id']; +/** + * Add deal to customer. + */ +$deal['title'] = 'example title'; +$deal['stage_id'] = 8; +$deal['person_id'] = $person['data']['id']; -$pipedrive->deals()->add($deal); +$pipedrive->deals()->add($deal); -//add activity -$activity = array( - 'subject' => 'Example send brochure', - 'type' => 'send-brochure', - 'person_id' => 17686, - 'user_id' => 190870, - 'deal_id' => 88, - 'due_date' => date('Y-m-d') - ); +/** + * Add activity. + */ +$activity = array( + 'subject' => 'Example send brochure', + 'type' => 'send-brochure', + 'person_id' => 17686, + 'user_id' => 190870, + 'deal_id' => 88, + 'due_date' => date('Y-m-d') +); $pipedrive->activities()->add($activity); ``` diff --git a/src/Benhawker/Pipedrive/Library/Activities.php b/src/Benhawker/Pipedrive/Library/Activities.php index cf93df3..a97d608 100644 --- a/src/Benhawker/Pipedrive/Library/Activities.php +++ b/src/Benhawker/Pipedrive/Library/Activities.php @@ -21,7 +21,7 @@ class Activities protected $curl; /** - * Initialise the object load master class + * Initialize the object load master class */ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) { @@ -32,12 +32,11 @@ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) /** * Adds a activity * - * @param array $data activity detials - * @return array returns detials of the activity + * @param array $data activity details + * @return array returns details of the activity */ public function add(array $data) { - //if there is no subject or type set chuck error as both of the fields are required if (!isset($data['subject']) or !isset($data['type'])) { throw new PipedriveMissingFieldError('You must include both a "subject" and "type" field when inserting a note'); diff --git a/src/Benhawker/Pipedrive/Library/Curl.php b/src/Benhawker/Pipedrive/Library/Curl.php index 8ed21fc..3e9fdb5 100644 --- a/src/Benhawker/Pipedrive/Library/Curl.php +++ b/src/Benhawker/Pipedrive/Library/Curl.php @@ -30,7 +30,7 @@ class Curl public $curl; /** - * Initialise the cURL session and set headers + * Initialize the cURL session and set headers */ public function __construct($url, $apiKey) { @@ -38,7 +38,7 @@ public function __construct($url, $apiKey) $this->url = $url; $this->apiKey = $apiKey; - //Intialise cURL session + //Initialize cURL session $this->curl = curl_init(); //Set up options for cURL session $this->setOpt(CURLOPT_USERAGENT, self::USER_AGENT) @@ -67,7 +67,7 @@ public function __destruct() public function get($method, $data = array()) { //set cURL transfer option for get request - // and get ouput + // and get output return $this->createEndPoint($method, $data) ->setOpt(CURLOPT_CUSTOMREQUEST, 'GET') ->setopt(CURLOPT_HTTPGET, true) @@ -83,7 +83,7 @@ public function get($method, $data = array()) public function post($method, array $data) { //set cURL transfer option for post request - // and get ouput + // and get output return $this->createEndPoint($method) ->setOpt(CURLOPT_CUSTOMREQUEST, 'POST') ->setOpt(CURLOPT_POST, true) @@ -100,7 +100,7 @@ public function post($method, array $data) public function put($method, array $data) { //set cURL transfer option for post request - // and get ouput + // and get output return $this->createEndPoint($method) ->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT') ->setOpt(CURLOPT_POSTFIELDS, http_build_query($data)) @@ -116,7 +116,7 @@ public function put($method, array $data) public function delete($method) { //set cURL transfer option for delete request - // and get ouput + // and get output return $this->createEndPoint($method) ->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE') ->exec(); @@ -125,7 +125,7 @@ public function delete($method) /** * Execute current cURL session * - * @return array decoded json ouput + * @return array decoded json output */ protected function exec() { @@ -203,9 +203,9 @@ protected function createEndPoint($method, $data = array()) protected function postfields($data) { if (is_array($data)) { - //if mulitdimensional array + //if multidimensional array if ($this->isArrayMultiDim($data)) { - // build bultidimensial query + // build multidimensional query $data = $this->httpBuildMultiQuery($data); } else { //loop through array @@ -232,7 +232,7 @@ protected function postfields($data) } /** - * Build multidimenianl query + * Build multidimensional query * from: https://github.com/php-curl-class/php-curl-class * * @param array $data post data diff --git a/src/Benhawker/Pipedrive/Library/DealFields.php b/src/Benhawker/Pipedrive/Library/DealFields.php index 3c8f50e..54fc819 100644 --- a/src/Benhawker/Pipedrive/Library/DealFields.php +++ b/src/Benhawker/Pipedrive/Library/DealFields.php @@ -25,7 +25,7 @@ class DealFields protected $curl; /** - * Initialise the object load master class + * Initialize the object load master class */ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) { @@ -42,7 +42,7 @@ public function getAll() { return $this->curl->get('dealFields'); } - + /** * Returns a deal field * @@ -57,7 +57,7 @@ public function getById($id) /** * Adds a dealField * - * @param array $data deal field detials + * @param array $data deal field details * @return array returns details of the deal field */ public function add(array $data) diff --git a/src/Benhawker/Pipedrive/Library/Deals.php b/src/Benhawker/Pipedrive/Library/Deals.php index 533c2d8..20d77ea 100644 --- a/src/Benhawker/Pipedrive/Library/Deals.php +++ b/src/Benhawker/Pipedrive/Library/Deals.php @@ -23,7 +23,7 @@ class Deals protected $curl; /** - * Initialise the object load master class + * Initialize the object load master class */ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) { @@ -35,7 +35,7 @@ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) * Returns a deal * * @param int $id pipedrive deals id - * @return array returns detials of a deal + * @return array returns details of a deal */ public function getById($id) { @@ -46,7 +46,7 @@ public function getById($id) * Returns a deal / deals * * @param string $name pipedrive deals title - * @return array returns detials of a deal + * @return array returns details of a deal */ public function getByName($name, $personId=null, $orgId=null) { @@ -79,8 +79,8 @@ public function products(array $data) /** * Adds a deal * - * @param array $data deal detials - * @return array returns detials of the deal + * @param array $data deal details + * @return array returns details of the deal */ public function add(array $data) { @@ -91,13 +91,13 @@ public function add(array $data) return $this->curl->post('deals', $data); } - + /** * Adds a product to a deal * * @param int $dealId deal id - * @param array $data deal and product detials - * @return array returns detials of the deal-product + * @param array $data deal and product details + * @return array returns details of the deal-product * @throws PipedriveMissingFieldError */ public function addProduct($dealId, array $data) @@ -122,8 +122,8 @@ public function addProduct($dealId, array $data) * Updates a deal * * @param int $dealId pipedrives deal Id - * @param array $data new detials of deal - * @return array returns detials of a deal + * @param array $data new details of deal + * @return array returns details of a deal */ public function update($dealId, array $data = array()) { @@ -135,7 +135,7 @@ public function update($dealId, array $data = array()) * * @param int $dealId deal id * @param int $stageId stage id - * @return array returns detials of the deal + * @return array returns details of the deal */ public function moveStage($dealId, $stageId) { diff --git a/src/Benhawker/Pipedrive/Library/Notes.php b/src/Benhawker/Pipedrive/Library/Notes.php index 4034a99..3b00e08 100644 --- a/src/Benhawker/Pipedrive/Library/Notes.php +++ b/src/Benhawker/Pipedrive/Library/Notes.php @@ -20,7 +20,7 @@ class Notes protected $curl; /** - * Initialise the object load master class + * Initialize the object load master class */ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) { @@ -31,8 +31,8 @@ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) /** * Adds a note * - * @param array $data note detials - * @return array returns detials of the note + * @param array $data note details + * @return array returns details of the note */ public function add(array $data) { @@ -41,7 +41,7 @@ public function add(array $data) throw new PipedriveMissingFieldError('You must include a "content" field when inserting a note'); } - //if there is no deal, person, organisation id set throw error as one of the fields is required + //if there is no deal, person, organization id set throw error as one of the fields is required if (!isset($data['deal_id']) && !isset($data['person_id']) && !isset($data['org_id'])) { throw new PipedriveMissingFieldError('You must include one of the following "deal_id", "person_id", "org_id" field when inserting a note'); } diff --git a/src/Benhawker/Pipedrive/Library/Organizations.php b/src/Benhawker/Pipedrive/Library/Organizations.php index ac21d59..faaaa50 100644 --- a/src/Benhawker/Pipedrive/Library/Organizations.php +++ b/src/Benhawker/Pipedrive/Library/Organizations.php @@ -5,8 +5,8 @@ /** * Pipedrive Organizations Methods * - * Organizations are companies and other kinds of organizations you are making - * Deals with. Persons can be associated with organizations so that each + * Organizations are companies and other kinds of organizations you are making + * Deals with. Persons can be associated with organizations so that each * organization can contain one or more Persons. * */ @@ -17,9 +17,9 @@ class Organizations * @var Curl Object */ protected $curl; - + /** - * Initialise the object load master class + * Initialize the object load master class */ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) { @@ -31,7 +31,7 @@ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) * Returns a organization * * @param int $id pipedrive organizations id - * @return array returns detials of a organization + * @return array returns details of a organization */ public function getById($id) { @@ -43,26 +43,26 @@ public function getById($id) * * @param string $name pipedrive organizations name * @param array $data (start, limit) - * @return array returns detials of a organization + * @return array returns details of a organization */ public function getByName($name, array $data = array()) { $data['term'] = $name; return $this->curl->get('organizations/find', $data); } - - + + /** * Returns all organizations * * @param array $data (filter_id, start, limit, sort_by, sort_mode) - * @return array returns detials of all organizations + * @return array returns details of all organizations */ public function getAll(array $data = array()) { return $this->curl->get('organizations/', $data); } - + /** * Lists deals associated with a organization. * @@ -82,8 +82,8 @@ public function deals(array $data) * Updates an organization * * @param int $organizationId pipedrives organization Id - * @param array $data new detials of organization - * @return array returns detials of a organization + * @param array $data new details of organization + * @return array returns details of a organization */ public function update($organizationId, array $data = array()) { @@ -93,8 +93,8 @@ public function update($organizationId, array $data = array()) /** * Adds a organization * - * @param array $data organizations detials - * @return array returns detials of a organization + * @param array $data organizations details + * @return array returns details of a organization */ public function add(array $data) { @@ -110,7 +110,7 @@ public function add(array $data) * Deletes an organization * * @param int $organizationId pipedrives organization Id - * @return array returns detials of a organization + * @return array returns details of a organization */ public function delete($organizationId) { diff --git a/src/Benhawker/Pipedrive/Library/Persons.php b/src/Benhawker/Pipedrive/Library/Persons.php index e87f39b..bb00181 100644 --- a/src/Benhawker/Pipedrive/Library/Persons.php +++ b/src/Benhawker/Pipedrive/Library/Persons.php @@ -19,7 +19,7 @@ class Persons protected $curl; /** - * Initialise the object load master class + * Initialize the object load master class */ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) { @@ -31,7 +31,7 @@ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) * Returns a person * * @param int $id pipedrive persons id - * @return array returns detials of a person + * @return array returns details of a person */ public function getById($id) { @@ -42,7 +42,7 @@ public function getById($id) * Returns a person / people * * @param string $name pipedrive persons name - * @return array returns detials of a person + * @return array returns details of a person */ public function getByName($name) { @@ -85,8 +85,8 @@ public function products(array $data) * Updates a person * * @param int $personId pipedrives person Id - * @param array $data new detials of person - * @return array returns detials of a person + * @param array $data new details of person + * @return array returns details of a person */ public function update($personId, array $data = array()) { @@ -96,8 +96,8 @@ public function update($personId, array $data = array()) /** * Adds a person * - * @param array $data persons detials - * @return array returns detials of a person + * @param array $data persons details + * @return array returns details of a person */ public function add(array $data) { @@ -113,7 +113,7 @@ public function add(array $data) * Deletes a person * * @param int $personId pipedrives person Id - * @return array returns detials of a person + * @return array returns details of a person */ public function delete($personId) { diff --git a/src/Benhawker/Pipedrive/Library/Products.php b/src/Benhawker/Pipedrive/Library/Products.php index 8afca4b..1619689 100644 --- a/src/Benhawker/Pipedrive/Library/Products.php +++ b/src/Benhawker/Pipedrive/Library/Products.php @@ -10,7 +10,7 @@ * have a price in N different currencies, and secondly, each Product can * have N variations of itself, each having N prices different currencies. * Note that only one price per variation per currency is supported. - * Products can be instantiated to Deals. In the context of instatiation, + * Products can be instantiated to Deals. In the context of instantiation, * a custom price, quantity, duration and discount can be applied. */ class Products @@ -22,7 +22,7 @@ class Products protected $curl; /** - * Initialise the object load master class + * Initialize the object load master class */ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) { @@ -33,8 +33,8 @@ public function __construct(\Benhawker\Pipedrive\Pipedrive $master) /** * Returns a product / products * - * @param string $name pipedrive prodeuct name - * @return array returns detials of a product + * @param string $name pipedrive product name + * @return array returns details of a product */ public function getByName($name) { diff --git a/src/Benhawker/Pipedrive/Pipedrive.php b/src/Benhawker/Pipedrive/Pipedrive.php index 1fe7b18..5bd0616 100644 --- a/src/Benhawker/Pipedrive/Pipedrive.php +++ b/src/Benhawker/Pipedrive/Pipedrive.php @@ -1,6 +1,6 @@ apiKey = $apiKey; $this->protocol = $protocol; $this->host = $host; @@ -115,7 +115,7 @@ public function __construct($apiKey = '', $protocol = 'https', $host = 'api.pipe //add curl library and pass the API Url & key to the object $this->curl = new Library\Curl($url, $apiKey); - //add pipedrive classes to the assoicated property + //add pipedrive classes to the associated property $this->persons = new Library\Persons($this); $this->deals = new Library\Deals($this); $this->activities = new Library\Activities($this);