|
1 | 1 | <?php
|
2 |
| -define("AGILE_DOMAIN", "your_agile_domain"); |
3 |
| -define("AGILE_USER_EMAIL", "your_agile_user_email"); |
4 |
| -define("AGILE_REST_API_KEY", "your_agile_api_key"); |
5 | 2 |
|
6 |
| -function curl_wrap($entity, $data, $method) |
7 |
| -{ |
8 |
| - $agile_url = "https://" . AGILE_DOMAIN . ".agilecrm.com/dev/api/" . $entity; |
9 |
| - $agile_php_url = "https://" . AGILE_DOMAIN . ".agilecrm.com/core/php/api/" . $entity . "?id=" . AGILE_REST_API_KEY; |
| 3 | +/** |
| 4 | + * Agile CRM \ Curl Wrap |
| 5 | + * |
| 6 | + * The Curl Wrap is the entry point to all services and actions. |
| 7 | + * |
| 8 | + * @author Agile CRM developers <Ghanshyam> |
| 9 | + */ |
| 10 | + |
| 11 | + |
| 12 | +# Enter your domain name , agile email and agile api key |
| 13 | +define("AGILE_DOMAIN", "ghanshyam"); # Example : define("domain","jim"); |
| 14 | +define( "AGILE_USER_EMAIL", "[email protected]"); |
| 15 | +define("AGILE_REST_API_KEY", "123456"); // Example : http://snag.gy/AEq23.jpg |
| 16 | + |
| 17 | +function curl_wrap($entity, $data, $method, $content_type) { |
| 18 | + if ($content_type == NULL) { |
| 19 | + $content_type = "application/json"; |
| 20 | + } |
| 21 | + |
| 22 | + $agile_url = "https://" . AGILE_DOMAIN . ".agilecrm.com/dev/api/" . $entity; |
10 | 23 |
|
11 | 24 | $ch = curl_init();
|
12 | 25 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
13 | 26 | curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
|
14 | 27 | curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
|
15 |
| - |
16 | 28 | switch ($method) {
|
17 | 29 | case "POST":
|
18 |
| - $url = ($entity == "tags" ? $agile_php_url : $agile_url); |
| 30 | + $url = $agile_url; |
19 | 31 | curl_setopt($ch, CURLOPT_URL, $url);
|
20 | 32 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
21 | 33 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
22 | 34 | break;
|
23 | 35 | case "GET":
|
24 |
| - $url = ($entity == "tags" ? $agile_php_url . '&email=' . $data->{'email'} : $agile_url); |
| 36 | + $url = $agile_url; |
25 | 37 | curl_setopt($ch, CURLOPT_URL, $url);
|
26 | 38 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
27 | 39 | break;
|
28 | 40 | case "PUT":
|
29 |
| - $url = ($entity == "tags" ? $agile_php_url : $agile_url); |
| 41 | + $url = $agile_url; |
30 | 42 | curl_setopt($ch, CURLOPT_URL, $url);
|
31 | 43 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
32 | 44 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
33 | 45 | break;
|
34 | 46 | case "DELETE":
|
35 |
| - $url = ($entity == "tags" ? $agile_php_url : $agile_url); |
| 47 | + $url = $agile_url; |
36 | 48 | curl_setopt($ch, CURLOPT_URL, $url);
|
37 | 49 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
|
38 | 50 | break;
|
39 | 51 | default:
|
40 | 52 | break;
|
41 | 53 | }
|
42 |
| - |
43 | 54 | curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
44 |
| - 'Content-type : application/json; charset : UTF-8;', |
45 |
| - 'Accept : application/json' |
| 55 | + "Content-type : $content_type;", 'Accept : application/json' |
46 | 56 | ));
|
47 | 57 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
48 | 58 | curl_setopt($ch, CURLOPT_USERPWD, AGILE_USER_EMAIL . ':' . AGILE_REST_API_KEY);
|
49 | 59 | curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
50 |
| - |
| 60 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
51 | 61 | $output = curl_exec($ch);
|
52 | 62 | curl_close($ch);
|
53 | 63 | return $output;
|
54 | 64 | }
|
55 |
| -?> |
|
0 commit comments