diff --git a/CurlLib/curlwrap_v2.php b/CurlLib/curlwrap_v2.php index eea0407..cf17a11 100644 --- a/CurlLib/curlwrap_v2.php +++ b/CurlLib/curlwrap_v2.php @@ -8,45 +8,58 @@ * @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 (class_exists('Dotenv')) { + $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 +// attempt to use hardcoded credentials here +// HARDCODED DOMAIN, EMAIL, AND API KEY GO HERE + +if (!isset($AGILE_DOMAIN) || strlen(trim($AGILE_DOMAIN)) < 1) { + # Enter your domain name , agile email and agile 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"; + $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; @@ -55,7 +68,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); diff --git a/README.md b/README.md index 2c50f29..bdff0a1 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 new file mode 100644 index 0000000..c641ef1 --- /dev/null +++ b/composer.json @@ -0,0 +1,52 @@ +{ + "name": "agilecrm/php-api", + "description": "This is the AgileCRM API PHP interface helper library", + "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": ["CurlLib/curlwrap_v2.php"] + }, + "autoload-dev": { + "psr-0": { + "AgileCRM\\Tests": "Tester/" + } + }, + "minimum-stability": "dev", + "config": { + "use-include-path": true + }, + "prefer-stable": true +} \ No newline at end of file