zoho_crm 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +274 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/zoho_crm/version.rb +5 -0
- data/lib/zoho_crm.rb +196 -0
- data/zoho_crm.gemspec +30 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9bd1f8b70b42d52cb21a3ed0b73fe988882479c0
|
4
|
+
data.tar.gz: 7684fee1463608e80503fd1b488a118084342a1b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff4963206663ad171ecb658de505c8d653587a2cae99bf1a193dd30bdd15f7e16bf50305370e659369fc0682747566f5f7ff3c097a4c4e00c4a5882229c02594
|
7
|
+
data.tar.gz: f5cd1b38f1b8e6b0f59aa052c9795a74ac7a4376ed2cfab95c71a68eeecd2fc712303295230c05c44cf8f0fafb9e94922d9cf7fe64d93564a5c12d57d8f4d682
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Ciaran Lofts
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,274 @@
|
|
1
|
+
# ZohoCrm
|
2
|
+
|
3
|
+
zoho_crm is a basic gem to interact with the Zoho API. Methods are only available for the Leads and Contacts Zoho modules. Communication is through instantiation of the main class **ZohoCRM::Client** which requires the user to have a Zoho username and password.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'zoho_crm'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install zoho_crm
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Instantiate a client:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = ZohoCrm::Client.new("zoho@email.com", "myzohopassword")
|
27
|
+
```
|
28
|
+
|
29
|
+
Generate a token:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
auth_token = client.authenticate_user
|
33
|
+
```
|
34
|
+
|
35
|
+
Now that we have a client and an authentication token, we can interact with the Zoho API.
|
36
|
+
|
37
|
+
The methods for the Contacts module are as follows:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
client.retrieve_contacts(auth_token, from_index, to_index)
|
41
|
+
```
|
42
|
+
|
43
|
+
The maximum number of records returned in one request is 200. For example, to retrieve the fist 200 contacts the method would be:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
client.retrieve_contacts("my_zoho_api_token", 1, 200)
|
47
|
+
```
|
48
|
+
|
49
|
+
Which returns a response in JSON format.
|
50
|
+
|
51
|
+
**data** is required to be supplied in the following format:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
data = {
|
55
|
+
first_name: "Roger",
|
56
|
+
last_name: "Jones",
|
57
|
+
email: "roger@jones.com"
|
58
|
+
}
|
59
|
+
```
|
60
|
+
**id** is the Zoho Contact ID which is part of the JSON response returned by the **retrieve_contacts** method.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
client.new_contact(auth_token, data)
|
64
|
+
```
|
65
|
+
|
66
|
+
Up to 200 new Contacts can be added in batches using the **multiple_new_contacts** method.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
client.multiple_new_contacts(auth_token, data)
|
70
|
+
```
|
71
|
+
|
72
|
+
Where **data** is an array of hashes
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
data = [
|
76
|
+
{email: "matt@craigs.com", first_name: "Matt", last_name: "Craigs"},
|
77
|
+
{email: "roger@jones.com", first_name: "Roger", last_name: "Jones"}
|
78
|
+
]
|
79
|
+
```
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
client.update_contact(auth_token, data, id)
|
83
|
+
```
|
84
|
+
|
85
|
+
To update an individual Contact.
|
86
|
+
|
87
|
+
Only the fields being updated need to be supplied in **data**. The other fields will remain untouched.
|
88
|
+
|
89
|
+
Up to 100 Contacts can be updated in batches using the **update_multiple_contacts** method.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
client.update_multiple_contacts(auth_token, data)
|
93
|
+
```
|
94
|
+
|
95
|
+
Where **data** is an array of hashes and the **ID** of the Contact must be given.
|
96
|
+
The **ID** is in the response from the **retrieve_contacts** method.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
data = [
|
100
|
+
{id: "1234001", email: "matt@craigs.com", first_name: "Matt", last_name: "Craigs"},
|
101
|
+
{id:"1234002", email: "roger@jones.com", first_name: "Roger", last_name: "Jones"}
|
102
|
+
]
|
103
|
+
```
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
client.delete_contact(auth_token, id)
|
107
|
+
```
|
108
|
+
|
109
|
+
Zoho requires **last_name** for Contacts. zoho_crm supported field names for the Contacts module are:
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
data = {
|
113
|
+
first_name: "Roger",
|
114
|
+
last_name: "Jones",
|
115
|
+
title: "CFO",
|
116
|
+
department: "Leveraged Loans",
|
117
|
+
phone: "1234",
|
118
|
+
mobile: "1234",
|
119
|
+
home_phone: "1234",
|
120
|
+
other_phone: "1234",
|
121
|
+
email: "roger@jones.com",
|
122
|
+
mailing_street: "Welland Mews",
|
123
|
+
mailing_city: "Welland Town",
|
124
|
+
mailing_state: "Wellandville"
|
125
|
+
mailing_zip: "ABC123"
|
126
|
+
mailing_country: "Welland Republic"
|
127
|
+
description: "a description"
|
128
|
+
}
|
129
|
+
```
|
130
|
+
|
131
|
+
Limitations of these fields can be found at https://www.zoho.com/crm/help/api/modules-fields.html#Contacts
|
132
|
+
|
133
|
+
The methods for the Leads module are as follows:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
client.retrieve_leads(auth_token, from_index, to_index)
|
137
|
+
```
|
138
|
+
|
139
|
+
The maximum number of records returned in one request is 200. For example, to retrieve the fist 200 leads the method would be:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
client.retrieve_leads("my_zoho_api_token", 1, 200)
|
143
|
+
```
|
144
|
+
|
145
|
+
Which returns a response in JSON format.
|
146
|
+
|
147
|
+
**data** is required to be supplied in the following format:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
data = {
|
151
|
+
first_name: "Roger",
|
152
|
+
last_name: "Jones",
|
153
|
+
email: "roger@jones.com"
|
154
|
+
}
|
155
|
+
```
|
156
|
+
**id** is the Zoho Lead ID which is part of the JSON response returned by the **retrieve_leads** method.
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
client.new_lead(auth_token, data)
|
160
|
+
```
|
161
|
+
|
162
|
+
Up to 200 new Leads can be added in batches using the **multiple_new_leads** method.
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
client.multiple_new_leads(auth_token, data)
|
166
|
+
```
|
167
|
+
|
168
|
+
Where **data** is an array of hashes
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
data = [
|
172
|
+
{email: "matt@craigs.com", first_name: "Matt", last_name: "Craigs", company: "Welland Capital"},
|
173
|
+
{email: "roger@jones.com", first_name: "Roger", last_name: "Jones", company: "Welland Capital"}
|
174
|
+
]
|
175
|
+
```
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
client.update_lead(auth_token, data, id)
|
179
|
+
```
|
180
|
+
|
181
|
+
To update an individual Lead.
|
182
|
+
|
183
|
+
Only the fields being updated need to be supplied in **data**. The other fields will remain untouched.
|
184
|
+
|
185
|
+
Up to 100 Leads can be updated in batches using the **update_multiple_leads** method.
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
client.update_multiple_leads(auth_token, data)
|
189
|
+
```
|
190
|
+
|
191
|
+
Where **data** is an array of hashes and the **ID** of the Lead must be given.
|
192
|
+
The **ID** is in the response from the **retrieve_leads** method.
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
data = [
|
196
|
+
{id: "1234001", email: "matt@craigs.com", first_name: "Matt", last_name: "Craigs", company: "Welland Capital"},
|
197
|
+
{id:"1234002", email: "roger@jones.com", first_name: "Roger", last_name: "Jones", company: "Welland Capital"}
|
198
|
+
]
|
199
|
+
```
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
client.delete_lead(auth_token, id)
|
203
|
+
```
|
204
|
+
|
205
|
+
Zoho requires **last_name** and **company** for Leads. The zoho_crm supported field names for the Leads module are:
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
data = {
|
209
|
+
first_name: "Roger",
|
210
|
+
last_name: "Jones",
|
211
|
+
title: "CFO",
|
212
|
+
company: "Welland Capital",
|
213
|
+
phone: "1234",
|
214
|
+
mobile: "1234",
|
215
|
+
email: "roger@jones.com",
|
216
|
+
street: "Welland Mews",
|
217
|
+
city: "Welland Town",
|
218
|
+
state: "Wellandville"
|
219
|
+
zip: "ABC123"
|
220
|
+
country: "Welland Republic"
|
221
|
+
description: "a description"
|
222
|
+
}
|
223
|
+
```
|
224
|
+
|
225
|
+
Limitations of these fields can be found at https://www.zoho.com/crm/help/api/modules-fields.html#Leads
|
226
|
+
|
227
|
+
The fields for both the Contacts and Leads modules can be obtained with the following method:
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
client.get_fields(auth_token, module_name)
|
231
|
+
```
|
232
|
+
|
233
|
+
Which returns a response in JSON format.
|
234
|
+
|
235
|
+
Where **module_name** is either:
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
"Contacts"
|
239
|
+
```
|
240
|
+
|
241
|
+
or
|
242
|
+
|
243
|
+
```ruby
|
244
|
+
"Leads"
|
245
|
+
```
|
246
|
+
|
247
|
+
If custom fields have been added to either the Contacts or Leads modules by a Zoho user then this will be indicated in the response from the **get_fields** method.
|
248
|
+
|
249
|
+
Provided a Zoho user has added custom fields, these can be populated using the **new_contact** , **new_lead** , **update_contact** and **update_lead** methods.
|
250
|
+
|
251
|
+
These can be added to **data** with the custom field name as a hash key in lower snake case. For example, if a Zoho user add custom fields **Gender** and **Football Team** then **data** would be:
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
data = {
|
255
|
+
gender: "Undisclosed",
|
256
|
+
football_team: "Welland FC"
|
257
|
+
}
|
258
|
+
```
|
259
|
+
|
260
|
+
N.B. It appears that zoho will only let 10 concurrent auth tokens be generated for each account. These auth tokens can be deleted manually in the 'My Account' section on Zoho.
|
261
|
+
|
262
|
+
## Development
|
263
|
+
|
264
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
265
|
+
|
266
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
267
|
+
|
268
|
+
## Contributing
|
269
|
+
|
270
|
+
1. Fork it ( https://github.com/cjlofts/zoho_crm/fork )
|
271
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
272
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
273
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
274
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "zoho_crm"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/zoho_crm.rb
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'zoho_crm/version'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module ZohoCrm
|
5
|
+
RateLimitExceeded = Class.new(StandardError)
|
6
|
+
class Client
|
7
|
+
|
8
|
+
AUTH_URL = "https://accounts.zoho.com/apiauthtoken/nb/create?SCOPE=ZohoCRM/crmapi&"
|
9
|
+
GET_LEADS = "https://crm.zoho.com/crm/private/json/Leads/getRecords?"
|
10
|
+
GET_CONTACTS = "https://crm.zoho.com/crm/private/json/Contacts/getRecords?"
|
11
|
+
NEW_LEAD = "https://crm.zoho.com/crm/private/xml/Leads/insertRecords?"
|
12
|
+
NEW_CONTACT = "https://crm.zoho.com/crm/private/xml/Contacts/insertRecords?"
|
13
|
+
UPDATE_LEAD = "http://crm.zoho.com/crm/private/xml/Leads/updateRecords?"
|
14
|
+
UPDATE_CONTACT = "http://crm.zoho.com/crm/private/xml/Contacts/updateRecords?"
|
15
|
+
DELETE_LEAD = "http://crm.zoho.com/crm/private/xml/Leads/deleteRecords?"
|
16
|
+
DELETE_CONTACT = "http://crm.zoho.com/crm/private/xml/Contacts/deleteRecords?"
|
17
|
+
GET_FIELDS = "https://crm.zoho.com/crm/private/json/"
|
18
|
+
NEW_CONTACTS = "https://crm.zoho.com/crm/private/xml/Contacts/insertRecords?"
|
19
|
+
NEW_LEADS = "https://crm.zoho.com/crm/private/xml/Leads/insertRecords?"
|
20
|
+
UPDATE_CONTACTS = "https://crm.zoho.com/crm/private/xml/Contacts/updateRecords?"
|
21
|
+
UPDATE_LEADS = "https://crm.zoho.com/crm/private/xml/Leads/updateRecords?"
|
22
|
+
|
23
|
+
def initialize(username, password)
|
24
|
+
@username = username
|
25
|
+
@password = password
|
26
|
+
end
|
27
|
+
|
28
|
+
def authenticate_user
|
29
|
+
token_url = AUTH_URL + "EMAIL_ID=#{@username}&PASSWORD=#{@password}"
|
30
|
+
response = HTTParty.post(token_url)
|
31
|
+
response_body = response.body
|
32
|
+
auth_info = Hash[response_body.split(" ").map { |str| str.split("=") }]
|
33
|
+
auth_info["AUTHTOKEN"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def retrieve_contacts(auth_token, from_index, to_index)
|
37
|
+
all_contacts = GET_CONTACTS + "authtoken=#{auth_token}&scope=crmapi&fromIndex=#{from_index}&toIndex=#{to_index}"
|
38
|
+
response = HTTParty.get(all_contacts)
|
39
|
+
raise_api_exception(response)
|
40
|
+
end
|
41
|
+
|
42
|
+
def retrieve_leads(auth_token, from_index, to_index)
|
43
|
+
all_leads = GET_LEADS + "authtoken=#{auth_token}&scope=crmapi&fromIndex=#{from_index}&toIndex=#{to_index}"
|
44
|
+
response = HTTParty.get(all_leads)
|
45
|
+
raise_api_exception(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
def new_contact(auth_token, data)
|
49
|
+
xml_data = format_contacts(data)
|
50
|
+
formatted_data = escape_xml(xml_data)
|
51
|
+
new_contact = NEW_CONTACT + "authtoken=#{auth_token}&scope=crmapi&xmlData=#{formatted_data}"
|
52
|
+
response = HTTParty.post(new_contact)
|
53
|
+
raise_api_exception(response)
|
54
|
+
end
|
55
|
+
|
56
|
+
def new_lead(auth_token, data)
|
57
|
+
xml_data = format_leads(data)
|
58
|
+
formatted_data = escape_xml(xml_data)
|
59
|
+
new_lead = NEW_LEAD + "authtoken=#{auth_token}&scope=crmapi&xmlData=#{formatted_data}"
|
60
|
+
response = HTTParty.post(new_lead)
|
61
|
+
raise_api_exception(response)
|
62
|
+
end
|
63
|
+
|
64
|
+
def update_contact(auth_token, data, id)
|
65
|
+
xml_data = format_contacts(data)
|
66
|
+
formatted_data = escape_xml(xml_data)
|
67
|
+
update_contact = UPDATE_CONTACT + "authtoken=#{auth_token}&scope=crmapi&newFormat=1&id=#{id}&xmlData=#{formatted_data}"
|
68
|
+
response = HTTParty.put(update_contact)
|
69
|
+
raise_api_exception(response)
|
70
|
+
end
|
71
|
+
|
72
|
+
def update_lead(auth_token, data, id)
|
73
|
+
xml_data = format_leads(data)
|
74
|
+
formatted_data = escape_xml(xml_data)
|
75
|
+
update_lead = UPDATE_LEAD + "authtoken=#{auth_token}&scope=crmapi&newFormat=1&id=#{id}&xmlData=#{formatted_data}"
|
76
|
+
response = HTTParty.put(update_lead)
|
77
|
+
raise_api_exception(response)
|
78
|
+
end
|
79
|
+
|
80
|
+
def delete_contact(auth_token, id)
|
81
|
+
delete_contact = DELETE_CONTACT + "authtoken=#{auth_token}&scope=crmapi&id=#{id}"
|
82
|
+
response = HTTParty.delete(delete_contact)
|
83
|
+
raise_api_exception(response)
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete_lead(auth_token, id)
|
87
|
+
delete_lead = DELETE_LEAD + "authtoken=#{auth_token}&scope=crmapi&id=#{id}"
|
88
|
+
response = HTTParty.delete(delete_lead)
|
89
|
+
raise_api_exception(response)
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_fields(auth_token, module_name)
|
93
|
+
name = module_name.capitalize
|
94
|
+
fields = GET_FIELDS + name + "/getFields?authtoken=#{auth_token}&scope=crmap"
|
95
|
+
response = HTTParty.get(fields)
|
96
|
+
raise_api_exception(response)
|
97
|
+
end
|
98
|
+
|
99
|
+
def multiple_new_contacts(auth_token, data)
|
100
|
+
xml_data = format_multiple_contacts(data)
|
101
|
+
formatted_data = escape_xml(xml_data)
|
102
|
+
new_contacts = NEW_CONTACTS + "newFormat=1&authtoken=#{auth_token}&scope=crmapi&xmlData=#{formatted_data}"
|
103
|
+
response = HTTParty.post(new_contacts)
|
104
|
+
raise_api_exception(response)
|
105
|
+
end
|
106
|
+
|
107
|
+
def multiple_new_leads(auth_token, data)
|
108
|
+
xml_data = format_multiple_leads(data)
|
109
|
+
formatted_data = escape_xml(xml_data)
|
110
|
+
new_leads = NEW_LEADS + "newFormat=1&authtoken=#{auth_token}&scope=crmapi&xmlData=#{formatted_data}"
|
111
|
+
response = HTTParty.post(new_leads)
|
112
|
+
raise_api_exception(response)
|
113
|
+
end
|
114
|
+
|
115
|
+
def update_multiple_contacts(auth_token, data)
|
116
|
+
xml_data = format_multiple_contacts(data)
|
117
|
+
formatted_data = escape_xml(xml_data)
|
118
|
+
update_contacts = UPDATE_CONTACTS + "authtoken=#{auth_token}&scope=crmapi&version=4&xmlData=#{formatted_data}"
|
119
|
+
response = HTTParty.post(update_contacts)
|
120
|
+
raise_api_exception(response)
|
121
|
+
end
|
122
|
+
|
123
|
+
def update_multiple_leads(auth_token, data)
|
124
|
+
xml_data = format_multiple_leads(data)
|
125
|
+
formatted_data = escape_xml(xml_data)
|
126
|
+
update_leads = UPDATE_LEADS + "authtoken=#{auth_token}&scope=crmapi&version=4&xmlData=#{formatted_data}"
|
127
|
+
response = HTTParty.post(update_leads)
|
128
|
+
raise_api_exception(response)
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def format_contacts(info)
|
134
|
+
data = "<Contacts><row no='1'>"
|
135
|
+
info.each do |key, value|
|
136
|
+
data += "<FL val='" + zohoify_key(key) + "'>" + value + "</FL>"
|
137
|
+
end
|
138
|
+
data += "</row></Contacts>"
|
139
|
+
end
|
140
|
+
|
141
|
+
def format_leads(info)
|
142
|
+
data = "<Leads><row no='1'>"
|
143
|
+
info.each do |key, value|
|
144
|
+
data += "<FL val='" + zohoify_key(key) + "'>" + value + "</FL>"
|
145
|
+
end
|
146
|
+
data += "</row></Leads>"
|
147
|
+
end
|
148
|
+
|
149
|
+
def format_multiple_contacts(info)
|
150
|
+
data = "<Contacts>"
|
151
|
+
row_num = 1
|
152
|
+
info.each do |record|
|
153
|
+
data += "<row no='#{row_num}'>"
|
154
|
+
record.each do |key, value|
|
155
|
+
data += "<FL val='" + zohoify_key(key) + "'>" + value + "</FL>"
|
156
|
+
end
|
157
|
+
data += "</row>"
|
158
|
+
row_num += 1
|
159
|
+
end
|
160
|
+
data += "</Contacts>"
|
161
|
+
end
|
162
|
+
|
163
|
+
def format_multiple_leads(info)
|
164
|
+
data = "<Leads>"
|
165
|
+
row_num = 1
|
166
|
+
info.each do |record|
|
167
|
+
data += "<row no='#{row_num}'>"
|
168
|
+
record.each do |key, value|
|
169
|
+
data += "<FL val='" + zohoify_key(key) + "'>" + value + "</FL>"
|
170
|
+
end
|
171
|
+
data += "</row>"
|
172
|
+
row_num += 1
|
173
|
+
end
|
174
|
+
data += "</Leads>"
|
175
|
+
end
|
176
|
+
|
177
|
+
def zohoify_key(key)
|
178
|
+
key.to_s.gsub("_", " ").split.map(&:capitalize).join(' ')
|
179
|
+
end
|
180
|
+
|
181
|
+
def escape_xml(data)
|
182
|
+
URI.escape(data)
|
183
|
+
end
|
184
|
+
|
185
|
+
def raise_api_exception(response)
|
186
|
+
if response["response"].nil?
|
187
|
+
response
|
188
|
+
elsif response["response"]["error"].nil?
|
189
|
+
response
|
190
|
+
else
|
191
|
+
raise RateLimitExceeded, "You've 'literally' exceeded your API rate limit" if response["response"]["error"]["message"] == "You crossed your license limit"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
end
|
data/zoho_crm.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zoho_crm/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zoho_crm"
|
8
|
+
spec.version = ZohoCrm::Client::VERSION
|
9
|
+
spec.authors = ["Ciaran Lofts"]
|
10
|
+
spec.email = ["ciaran@wishpond.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Light wrapper for the ZohoCRM API allowing users to interact with the Contacts and Leads modules}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.add_dependency 'httparty'
|
26
|
+
spec.add_development_dependency 'bundler', "~> 1.9"
|
27
|
+
spec.add_development_dependency 'rake', "~> 10.0"
|
28
|
+
spec.add_development_dependency 'rspec'
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zoho_crm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ciaran Lofts
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- ciaran@wishpond.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/zoho_crm.rb
|
86
|
+
- lib/zoho_crm/version.rb
|
87
|
+
- zoho_crm.gemspec
|
88
|
+
homepage: ''
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata:
|
92
|
+
allowed_push_host: https://rubygems.org
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.4.6
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Light wrapper for the ZohoCRM API allowing users to interact with the Contacts
|
113
|
+
and Leads modules
|
114
|
+
test_files: []
|