From 93483bdfca7d9421d9822dafd8de6b25997c10b3 Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 13:44:50 -0400 Subject: [PATCH 01/13] add dotenv compat & composer.json --- CurlLib/curlwrap_v2.php | 50 +++++++++++++++++++++++----------- composer.json | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 composer.json diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index eea0407..0287354 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -8,51 +8,71 @@ * @author Agile CRM developers */ +// use a dotenv file if exists to set credentials -# Enter your domain name , agile email and agile api key -define("AGILE_DOMAIN", "YOUR_AGILE_DOMAIN"); # Example : define("domain","jim"); -define("AGILE_USER_EMAIL", "YOUR_AGILE_USER_EMAIL"); -define("AGILE_REST_API_KEY", "YOUR_AGILE_REST_API_KEY"); +if (function_exists('getenv')) { + if (getenv('AGILECRM_DEV')) { + define('AGILE_DOMAIN', getenv('AGILECRM_DEV_DOMAIN')); + define('AGILE_USER_EMAIL', getenv('AGILECRM_DEV_USER_EMAIL')); + define('AGILE_REST_API_KEY', getenv('AGILECRM_DEV_REST_API_KEY'); + } + else { + define('AGILE_DOMAIN', getenv('AGILECRM_DEV_DOMAIN')); + define('AGILE_USER_EMAIL', getenv('AGILECRM_DEV_USER_EMAIL'); + define('AGILE_REST_API_KEY', getenv('AGILECRM_DEV_REST_API_KEY'); + } +} + +// if the domain is not set, it is likely the others are unset as well +// attempt to use hardcoded credentials here +// HARDCODED DOMAIN, EMAIL, AND API KEY GO HERE + +if (!isset(AGILE_DOMAIN) || len(AGILE_DOMAIN < 1)) { + # Enter your domain name , agile email and agile api key + define('AGILE_DOMAIN', 'YOUR_AGILE_DOMAIN'); # Example : define('domain','jim'); + define('AGILE_USER_EMAIL', 'YOUR_AGILE_USER_EMAIL'); + define('AGILE_REST_API_KEY', 'YOUR_AGILE_REST_API_KEY'); +} function curl_wrap($entity, $data, $method, $content_type) { if ($content_type == NULL) { - $content_type = "application/json"; + $content_type = 'application/json'; } - $agile_url = "https://" . AGILE_DOMAIN . ".agilecrm.com/dev/api/" . $entity; + $agile_url = 'https://' . AGILE_DOMAIN . '.agilecrm.com/dev/api/' . $entity; $ch = curl_init(); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true); switch ($method) { - case "POST": + case 'POST': $url = $agile_url; curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); break; - case "GET": + case 'GET': $url = $agile_url; curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); break; - case "PUT": + case 'PUT': $url = $agile_url; curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); break; - case "DELETE": + case 'DELETE': $url = $agile_url; curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; default: break; } curl_setopt($ch, CURLOPT_HTTPHEADER, array( - "Content-type : $content_type;", 'Accept : application/json' + 'Content-type : $content_type;', 'Accept : application/json' )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, AGILE_USER_EMAIL . ':' . AGILE_REST_API_KEY); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..29368bb --- /dev/null +++ b/composer.json @@ -0,0 +1,59 @@ +{ + "name": "agilecrm/php-api", + "description": "This is the AgileCRM API PHP interface helper library", + "version": "3.0.0", + "type": "library", + "keywords": ["agilecrm", "api", "http"], + "homepage": "https://www.agilecrm.com", + "time": "2018-08-20", + "license": "MIT", + "authors": [ + { + "name": "Adam Panzer", + "email": "apanzerj@gmail.com", + "homepage": "http://cra.ptaculo.us", + "role": "Developer" + }, + { + "name": "Ghanshyam Raut", + "email": "ghanshyam.raut@agilecrm.com", + "homepage": "https://www.agilecrm.com", + "role": "Developer" + }, + { + "name": "Brad Chesney", + "email": "bradchesney79@gmail.com", + "homepage": "https://splashfinancial.com", + "role": "Developer" + } + ], + "support": { + "email": "care@agilecrm.com", + "issues": "https://github.com/agilecrm/php-api/issues", + "source": "https://github.com/agilecrm/php-api", + "docs": "https://www.agilecrm.com/api" + }, + "require": { + }, + "require-dev": { + }, + "autoload": { + "files": ["autoload.php"] + }, + "autoload-dev": { + "psr-0": { + "AgileCRM\\Tests": "Tester/" + } + }, + "target-dir": "", + "minimum-stability": "stable", + "repositories": "", + "config": { + "use-include-path": true + }, + "archive": {}, + "prefer-stable": true, + "scripts": {}, + "extra": "", + "bin": "" +} \ No newline at end of file From f3a507bb4b7194180e8f80bbc89f44a61465c645 Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 13:53:17 -0400 Subject: [PATCH 02/13] refine composer.json from template --- composer.json | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 29368bb..2bc56a7 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,6 @@ { "name": "agilecrm/php-api", "description": "This is the AgileCRM API PHP interface helper library", - "version": "3.0.0", "type": "library", "keywords": ["agilecrm", "api", "http"], "homepage": "https://www.agilecrm.com", @@ -45,15 +44,9 @@ "AgileCRM\\Tests": "Tester/" } }, - "target-dir": "", "minimum-stability": "stable", - "repositories": "", "config": { "use-include-path": true }, - "archive": {}, - "prefer-stable": true, - "scripts": {}, - "extra": "", - "bin": "" + "prefer-stable": true } \ No newline at end of file From 351086b20fdd47b5b3dc11a50c01786873cfcf8a Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 14:21:26 -0400 Subject: [PATCH 03/13] change autoload.php to index.php --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2bc56a7..f8a8620 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "require-dev": { }, "autoload": { - "files": ["autoload.php"] + "files": ["index.php"] }, "autoload-dev": { "psr-0": { From 3c3a3bb32251c86a0c7f8a35270cb32475df0675 Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 14:33:02 -0400 Subject: [PATCH 04/13] add install instructions to README.md --- README.md | 25 ++++++++++++++++++++++++- composer.json | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c50f29..75620c0 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ Table of contents **[Requirements](#requirements)** +**[Install](#install)** + **[Usage](#usage)** **[1 Contact](#1-contact)** @@ -131,6 +133,28 @@ $data = json_encode($data); - Two folder CurlLib and Tester - Can directly test Tester's any file after setting domain,email and api key of curlwrap_v2.php (CurlLib folder) +## Install + +### Simple + +Merely include, require, include_once, or require once the CurlLib/curlwrap_v2.php file as the index.php file shows. + +### Composer + +Modify your project composer.json to include these properties. + +```javascript + "repositories": [ + { + "type": "git", + "url": "https://github.com/agilecrm/php-api.git" + } + ], + "require": { + "agilecrm/php-api":"^3.1.0" + }, +``` + ## Usage @@ -720,5 +744,4 @@ echo $currentUser; ``` ---- - - The curlwrap_v*.php is based on https://gist.github.com/apanzerj/2920899 authored by [Adam Panzer](https://github.com/apanzerj). diff --git a/composer.json b/composer.json index f8a8620..0f5ba64 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "require-dev": { }, "autoload": { - "files": ["index.php"] + "files": ["CurlLib/curlwrap_v2.php"] }, "autoload-dev": { "psr-0": { From e775902c0c200124482e0d8d7ba111a280d2e910 Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 14:43:51 -0400 Subject: [PATCH 05/13] add an underscore to require_once --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75620c0..bdff0a1 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ $data = json_encode($data); ### Simple -Merely include, require, include_once, or require once the CurlLib/curlwrap_v2.php file as the index.php file shows. +Merely include, require, include_once, or require_once the CurlLib/curlwrap_v2.php file as the index.php file shows. ### Composer From f9638e234c45f1b2c35911ddad8447e25fd5e7a5 Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 14:50:13 -0400 Subject: [PATCH 06/13] add missing closing parenthesis --- CurlLib/curlwrap_v2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index 0287354..61bb5ef 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -14,7 +14,7 @@ if (getenv('AGILECRM_DEV')) { define('AGILE_DOMAIN', getenv('AGILECRM_DEV_DOMAIN')); define('AGILE_USER_EMAIL', getenv('AGILECRM_DEV_USER_EMAIL')); - define('AGILE_REST_API_KEY', getenv('AGILECRM_DEV_REST_API_KEY'); + define('AGILE_REST_API_KEY', getenv('AGILECRM_DEV_REST_API_KEY')); } else { define('AGILE_DOMAIN', getenv('AGILECRM_DEV_DOMAIN')); From cd1ad61d5bd52be6eae9e25bd0b4283b1511985b Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 14:55:56 -0400 Subject: [PATCH 07/13] add missing closing parenthesises --- CurlLib/curlwrap_v2.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index 61bb5ef..d70f645 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -18,8 +18,8 @@ } else { define('AGILE_DOMAIN', getenv('AGILECRM_DEV_DOMAIN')); - define('AGILE_USER_EMAIL', getenv('AGILECRM_DEV_USER_EMAIL'); - define('AGILE_REST_API_KEY', getenv('AGILECRM_DEV_REST_API_KEY'); + define('AGILE_USER_EMAIL', getenv('AGILECRM_DEV_USER_EMAIL')); + define('AGILE_REST_API_KEY', getenv('AGILECRM_DEV_REST_API_KEY')); } } From c4068c01503b75d107ce98817fc6e3ae347efa5f Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 15:04:51 -0400 Subject: [PATCH 08/13] change to code meant for checking constants --- CurlLib/curlwrap_v2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index d70f645..e9aef86 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -27,7 +27,7 @@ // attempt to use hardcoded credentials here // HARDCODED DOMAIN, EMAIL, AND API KEY GO HERE -if (!isset(AGILE_DOMAIN) || len(AGILE_DOMAIN < 1)) { +if (!defined(AGILE_DOMAIN) || strlen(trim(AGILE_DOMAIN)) < 1) { # Enter your domain name , agile email and agile api key define('AGILE_DOMAIN', 'YOUR_AGILE_DOMAIN'); # Example : define('domain','jim'); define('AGILE_USER_EMAIL', 'YOUR_AGILE_USER_EMAIL'); From 12b2720a3d7704cc577a23898295bb79a9fe83c8 Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 15:08:56 -0400 Subject: [PATCH 09/13] change check of defined constant to string of constant name --- CurlLib/curlwrap_v2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index e9aef86..cdebfd7 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -27,7 +27,7 @@ // attempt to use hardcoded credentials here // HARDCODED DOMAIN, EMAIL, AND API KEY GO HERE -if (!defined(AGILE_DOMAIN) || strlen(trim(AGILE_DOMAIN)) < 1) { +if (!defined('AGILE_DOMAIN') || strlen(trim(AGILE_DOMAIN)) < 1) { # Enter your domain name , agile email and agile api key define('AGILE_DOMAIN', 'YOUR_AGILE_DOMAIN'); # Example : define('domain','jim'); define('AGILE_USER_EMAIL', 'YOUR_AGILE_USER_EMAIL'); From 1a556d516913691721799d8cb7572d1254dc5e3f Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 15:31:28 -0400 Subject: [PATCH 10/13] change constants to variables for performance and support new dotenv logic --- CurlLib/curlwrap_v2.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index cdebfd7..3d8d862 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -10,16 +10,16 @@ // use a dotenv file if exists to set credentials -if (function_exists('getenv')) { +if (class_exists('Dotenv')) { if (getenv('AGILECRM_DEV')) { - define('AGILE_DOMAIN', getenv('AGILECRM_DEV_DOMAIN')); - define('AGILE_USER_EMAIL', getenv('AGILECRM_DEV_USER_EMAIL')); - define('AGILE_REST_API_KEY', getenv('AGILECRM_DEV_REST_API_KEY')); + $AGILE_DOMAIN = getenv('AGILECRM_DEV_DOMAIN')); + $AGILE_USER_EMAIL = getenv('AGILECRM_DEV_USER_EMAIL')); + $AGILE_REST_API_KEY = getenv('AGILECRM_DEV_REST_API_KEY')); } else { - define('AGILE_DOMAIN', getenv('AGILECRM_DEV_DOMAIN')); - define('AGILE_USER_EMAIL', getenv('AGILECRM_DEV_USER_EMAIL')); - define('AGILE_REST_API_KEY', getenv('AGILECRM_DEV_REST_API_KEY')); + $AGILE_DOMAIN = getenv('AGILECRM_DEV_DOMAIN')); + $AGILE_USER_EMAIL = getenv('AGILECRM_DEV_USER_EMAIL')); + $AGILE_REST_API_KEY = getenv('AGILECRM_DEV_REST_API_KEY')); } } @@ -27,19 +27,21 @@ // attempt to use hardcoded credentials here // HARDCODED DOMAIN, EMAIL, AND API KEY GO HERE -if (!defined('AGILE_DOMAIN') || strlen(trim(AGILE_DOMAIN)) < 1) { +if (!isset($AGILE_DOMAIN) || strlen(trim($AGILE_DOMAIN)) < 1) { # Enter your domain name , agile email and agile api key - define('AGILE_DOMAIN', 'YOUR_AGILE_DOMAIN'); # Example : define('domain','jim'); - define('AGILE_USER_EMAIL', 'YOUR_AGILE_USER_EMAIL'); - define('AGILE_REST_API_KEY', 'YOUR_AGILE_REST_API_KEY'); + $AGILE_DOMAIN = 'YOUR_AGILE_DOMAIN'); # Example : define('domain','jim'); + $AGILE_USER_EMAIL = 'YOUR_AGILE_USER_EMAIL'); + $AGILE_REST_API_KEY ='YOUR_AGILE_REST_API_KEY'); } + + function curl_wrap($entity, $data, $method, $content_type) { if ($content_type == NULL) { $content_type = 'application/json'; } - $agile_url = 'https://' . AGILE_DOMAIN . '.agilecrm.com/dev/api/' . $entity; + $agile_url = 'https://' . $AGILE_DOMAIN . '.agilecrm.com/dev/api/' . $entity; $ch = curl_init(); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); @@ -75,7 +77,7 @@ function curl_wrap($entity, $data, $method, $content_type) { 'Content-type : $content_type;', 'Accept : application/json' )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERPWD, AGILE_USER_EMAIL . ':' . AGILE_REST_API_KEY); + curl_setopt($ch, CURLOPT_USERPWD, $AGILE_USER_EMAIL . ':' . $AGILE_REST_API_KEY); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $output = curl_exec($ch); From 86adb375783877746b271a1876c05938bd0ec3fc Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 15:38:21 -0400 Subject: [PATCH 11/13] iron out last of composer SNAFUs --- CurlLib/curlwrap_v2.php | 13 +++---------- composer.json | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index 3d8d862..de4484f 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -11,16 +11,9 @@ // use a dotenv file if exists to set credentials if (class_exists('Dotenv')) { - if (getenv('AGILECRM_DEV')) { - $AGILE_DOMAIN = getenv('AGILECRM_DEV_DOMAIN')); - $AGILE_USER_EMAIL = getenv('AGILECRM_DEV_USER_EMAIL')); - $AGILE_REST_API_KEY = getenv('AGILECRM_DEV_REST_API_KEY')); - } - else { - $AGILE_DOMAIN = getenv('AGILECRM_DEV_DOMAIN')); - $AGILE_USER_EMAIL = getenv('AGILECRM_DEV_USER_EMAIL')); - $AGILE_REST_API_KEY = getenv('AGILECRM_DEV_REST_API_KEY')); - } + $AGILE_DOMAIN = getenv('AGILECRM_DOMAIN')); + $AGILE_USER_EMAIL = getenv('AGILECRM_USER_EMAIL')); + $AGILE_REST_API_KEY = getenv('AGILECRM_REST_API_KEY')); } // if the domain is not set, it is likely the others are unset as well diff --git a/composer.json b/composer.json index 0f5ba64..c641ef1 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "AgileCRM\\Tests": "Tester/" } }, - "minimum-stability": "stable", + "minimum-stability": "dev", "config": { "use-include-path": true }, From 21ef2a6053a24365a04f6df763f89fee47d2babf Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 15:40:57 -0400 Subject: [PATCH 12/13] remove extra closing parenthesises --- CurlLib/curlwrap_v2.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index de4484f..f33421d 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -11,9 +11,9 @@ // use a dotenv file if exists to set credentials if (class_exists('Dotenv')) { - $AGILE_DOMAIN = getenv('AGILECRM_DOMAIN')); - $AGILE_USER_EMAIL = getenv('AGILECRM_USER_EMAIL')); - $AGILE_REST_API_KEY = getenv('AGILECRM_REST_API_KEY')); + $AGILE_DOMAIN = getenv('AGILECRM_DOMAIN'); + $AGILE_USER_EMAIL = getenv('AGILECRM_USER_EMAIL'); + $AGILE_REST_API_KEY = getenv('AGILECRM_REST_API_KEY'); } // if the domain is not set, it is likely the others are unset as well From 8278458cf1ec3ca472d74c3c6b5e150afaef3f51 Mon Sep 17 00:00:00 2001 From: BradChesney79 Date: Mon, 20 Aug 2018 16:06:14 -0400 Subject: [PATCH 13/13] add back one set of double quotes to allow substitution --- CurlLib/curlwrap_v2.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index f33421d..cf17a11 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -27,8 +27,6 @@ $AGILE_REST_API_KEY ='YOUR_AGILE_REST_API_KEY'); } - - function curl_wrap($entity, $data, $method, $content_type) { if ($content_type == NULL) { $content_type = 'application/json'; @@ -67,7 +65,7 @@ function curl_wrap($entity, $data, $method, $content_type) { break; } curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-type : $content_type;', 'Accept : application/json' + "Content-type : $content_type;", 'Accept : application/json' )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, $AGILE_USER_EMAIL . ':' . $AGILE_REST_API_KEY);