You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Zoho CRM library is a specialized XML wrapper for make request to zoho API, base on another vendor from [vaish](https://github.com/vaish/zohocrm-php), but this have some overpower :p.
4
+
The Zoho CRM library is a simple wrapper around Zoho API
5
5
6
-
I often found myself repeating the same pattern for XML manipulation with this API over and over. This library implements that pattern.
7
-
8
-
At it's heart, the library maps XML string to entity classes elements for interact like PHP value objects.
9
-
10
-
The following assumptions are made:
11
-
12
-
* XML namespaces are used everywhere using psr-0 for autoload class, same with composer.
13
-
* All XML elements map to entities PHP classes.
14
-
* Elements are represented by classes entities. A class(entity) extends of `Zoho\CRM\Wrapper\Element`, this gives you the ability to access the inherited method "deserializeXml()" for conver the values of xml into the object.
15
-
16
-
This is not your average XML library. The intention is not to make this super
17
-
simple, but rather very powerful for complex XML applications.
6
+
At MC we work a lot with Zoho and we found ourself repeting the same patter over and over that's why we build this library.
18
7
19
8
Installation
20
9
------------
@@ -28,7 +17,6 @@ Let's start
28
17
The first thing that you have to do is use the namespaces for access to all the classes of the package, then, there are two fases for begin with the interaction:
29
18
30
19
1. Wrap values from array to entity, this have restrictions for the names of the fields, continue reading
31
-
2. If you already have your entity with values, just jump to [Mapping XML to entities elements](#mapping-xml-to-entities-elements)
32
20
33
21
```php
34
22
<?php
@@ -47,134 +35,50 @@ $request = array(
47
35
'phone' => '809789654'
48
36
);
49
37
50
-
// From array values to xml valid entity string
38
+
// From array we need to clean its keys
51
39
$lead = new Lead();
52
-
$xmlstr = $lead->serializeXml($request);
53
-
```
54
-
At this part you have an **xvseL** (xml valid string entity Lead), this is nothing more than and entity Lead prepared for be parse to object, something like this:
The above values of the **$request** array can be taken from POST if you are using forms in landing page :D, just be sure that all the keys(name of the field on html) in the array have to be valid properties in the entity Lead of zoho, default properties can be found on documentation [here](https://www.zoho.com/crm/help/api/modules-fields.html#Leads) or make sure that those properties exist in your account if you custom your Lead on Zoho; the following convention are made:
67
43
68
44
- Name of fields are not CamelCase.
69
45
- Name with space between words, space is substituted by an "_".
70
46
- Need to clean(unset) from the array all the values that are not part of the entity, if you dont wanna make this, create another clean array.
71
47
72
-
73
-
Mapping XML to entities elements
74
-
--------------------------------
75
-
76
-
Normally when writing an entity class parser using this tool, there will be a number of elements that make sense to create using classes for.
77
-
78
-
A great example would be the `Lead` entity, is part by default of the package, can be found inside `Zoho\CRM\Entities\Lead` element:
79
-
80
-
```php
81
-
class Lead
82
-
{
83
-
/**
84
-
* Zoho CRM user to whom the Lead is assigned.
85
-
*
86
-
* @var string
87
-
*/
88
-
private $Lead_Owner;
89
-
90
-
/**
91
-
* Salutation for the lead
92
-
*
93
-
* @var string
94
-
*/
95
-
private $Salutation;
96
-
97
-
/**
98
-
* First name of the lead
99
-
*
100
-
* @var string
101
-
*/
102
-
private $First_Name;
103
-
104
-
/**
105
-
* The job position of the lead
106
-
*
107
-
* @var string
108
-
*/
109
-
private $Title;
110
-
111
-
/* etc, others fields... */
112
-
}
113
-
```
114
-
115
-
You can use this entity like a been, and make your own implementation of XML assings, but if you wanna use this for mapping xml, it recommended extends the entity of `Zoho\CRM\Wrapper\Element`, something like this:
116
-
117
-
```php
118
-
use Zoho\CRM\Wrapper\Element;
119
-
120
-
class Lead extends Element
121
-
{
122
-
/* ...fields... */
123
-
}
124
-
```
125
-
126
-
Now for load the **xvseL** into the object Lead just call the method of the parent `deserializeXml(string $xvsel)`:
// Nice, now you have the entity with the values loaded from a string, F**k yeah..!
144
-
/* Remember that you can set more parameters to the entity
145
-
$lead->Lead_Owner = 'Test Owner Martinez';
146
-
$lead->Lead_Source = 'http://someweirdsite.xxx';
147
-
$lead->Member = '0001'; // This can be setted too :D
148
-
*/
149
-
echo 'Success, continue using your entity, the xvsel was parsed great...!';
150
-
}else
151
-
echo 'The xml could not be parsed, please check the syntax';
152
-
}
153
48
```
154
49
Now the next part is interact with zoho api using the client, first thing, create a `ZohoClient` with your authtoken valid: **Set the module**, for now just Leads, on future or contributing the [missing modules](https://www.zoho.com/crm/help/api/modules-fields.html)
155
50
156
51
```php
157
52
use Zoho\CRM\ZohoClient;
158
53
159
-
$ZohoClient = new ZohoClient('YOUR_TOKEN'); // Make the connection to zoho api
54
+
55
+
$ZohoClient = new ZohoClient(); // Make the connection to zoho api
$ZohoClient->setModule('Leads'); // Set the module
171
75
```
172
76
173
-
The last part if make the call, `$validXML` content returned by `mapEntity(Lead $lead)` is gonna be the xml that will be send to zoho, this is the final string created before the call to ws
77
+
The last part if make the call, `$data` content returned by `cleanParams(Lead $lead)` is gonna be the array that will be send to zoho, this is the final json string created before the call to ws
174
78
175
79
Now make the call to ws and get the response object:
The object Response returned in located in `Zoho\CRM\Request`, contain the code, message, method, module, records, record id, uri and xml returned by zoho, this can be accessed by getters.
0 commit comments