Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This makes it easier for people to install with the PHP package manager, composer #19

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions CurlLib/curlwrap_v2.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,58 @@
* @author Agile CRM developers <Ghanshyam>
*/

// 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;
Expand All @@ -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);
Expand Down
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Table of contents

**[Requirements](#requirements)**

**[Install](#install)**

**[Usage](#usage)**

**[1 Contact](#1-contact)**
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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).
52 changes: 52 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"homepage": "http://cra.ptaculo.us",
"role": "Developer"
},
{
"name": "Ghanshyam Raut",
"email": "[email protected]",
"homepage": "https://www.agilecrm.com",
"role": "Developer"
},
{
"name": "Brad Chesney",
"email": "[email protected]",
"homepage": "https://splashfinancial.com",
"role": "Developer"
}
],
"support": {
"email": "[email protected]",
"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
}