zoho_hub 0.1.25 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +42 -0
  3. data/.gitignore +1 -1
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +17 -8
  6. data/.ruby-version +1 -1
  7. data/README.md +477 -8
  8. data/bin/console +8 -5
  9. data/bin/read +48 -0
  10. data/bin/setup +0 -2
  11. data/bin/zoho_hub +43 -0
  12. data/examples/models/campaign.rb +13 -0
  13. data/{lib/zoho_hub/records → examples/models}/potential.rb +5 -8
  14. data/examples/models/quote.rb +30 -0
  15. data/lib/zoho_hub.rb +24 -20
  16. data/lib/zoho_hub/auth.rb +19 -20
  17. data/lib/zoho_hub/base_record.rb +228 -0
  18. data/lib/zoho_hub/cli/callback_server.rb +94 -0
  19. data/lib/zoho_hub/cli/read_modules.rb +122 -0
  20. data/lib/zoho_hub/configuration.rb +3 -4
  21. data/lib/zoho_hub/connection.rb +32 -19
  22. data/lib/zoho_hub/errors.rb +14 -2
  23. data/lib/zoho_hub/modules/attachment.rb +41 -0
  24. data/lib/zoho_hub/notifications.rb +54 -0
  25. data/lib/zoho_hub/oauth_callback_server.rb +22 -0
  26. data/lib/zoho_hub/reflection/module_builder.rb +57 -0
  27. data/lib/zoho_hub/response.rb +42 -25
  28. data/lib/zoho_hub/settings/field.rb +33 -0
  29. data/lib/zoho_hub/settings/module.rb +49 -0
  30. data/lib/zoho_hub/string_utils.rb +38 -0
  31. data/lib/zoho_hub/validations/base_validation.rb +14 -0
  32. data/lib/zoho_hub/validations/validate_length.rb +19 -0
  33. data/lib/zoho_hub/validations/validate_picklist.rb +22 -0
  34. data/lib/zoho_hub/version.rb +1 -1
  35. data/lib/zoho_hub/views/variables.erb +79 -0
  36. data/lib/zoho_hub/with_attributes.rb +101 -0
  37. data/lib/zoho_hub/with_connection.rb +44 -0
  38. data/lib/zoho_hub/with_validations.rb +66 -0
  39. data/zoho_hub.gemspec +23 -17
  40. metadata +145 -74
  41. data/.travis.yml +0 -5
  42. data/lib/zoho_hub/records/account.rb +0 -43
  43. data/lib/zoho_hub/records/attachment.rb +0 -104
  44. data/lib/zoho_hub/records/base_record.rb +0 -189
  45. data/lib/zoho_hub/records/campaign.rb +0 -14
  46. data/lib/zoho_hub/records/contact.rb +0 -47
  47. data/lib/zoho_hub/records/product.rb +0 -35
  48. data/lib/zoho_hub/records/quote.rb +0 -42
  49. data/lib/zoho_hub/records/vendor.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fb0e65b3b5261334de8e0132b49ba57069ac73795e0b8fbafd953525c321946
4
- data.tar.gz: cffbddbec5d01c1128465494a536973ae4f0bd557e8d55581128bc51b89b8a5e
3
+ metadata.gz: f91e364b7e8432a5047a03f6fa2426201c502368c036bc604566de53de2e65fb
4
+ data.tar.gz: fc574d26b030f7d69025cc6004cb127a8eb7296ed9bba34566ac0c6de2c0b6fd
5
5
  SHA512:
6
- metadata.gz: 274a760138b2cc5f6799b07a30f8a68aaa0ed3fb9f0c118d53835ad10d8d31d1aae3298ec4a84d339a4bde4508643fd1d71ba7cfd4a583636c95784fef3268bd
7
- data.tar.gz: 76422df68817cc51a1bc2e8bb2f95c5cdedf845ff2cfa322a7c6ddddd0d55d62cc8f18b4c820800d729de4320f3277e6dc65d3d2e1160e23c78fc14fcc8ac38d
6
+ metadata.gz: b4931bbcc3fcf425eae35d1b5a5eeca9c27112503e0444198504a2ab65667638f0a070808d8299d00ed7cd1ed03f71d63b0d0ad645cd22e0ef9823902b5028b5
7
+ data.tar.gz: 8898cf446859177ef26d0a73a066e7f5f0f7ede6fc2401833d4900f2524bc0a9d204890c0006ad59d79f822f8a0e1df7b0bd75f8ca9d60126829960aaad4eea5
@@ -0,0 +1,42 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ lint:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - uses: ruby/setup-ruby@v1
11
+ with:
12
+ ruby-version: "2.5"
13
+ bundler-cache: true
14
+ - name: rubocop version
15
+ timeout-minutes: 1
16
+ run: bundle exec rubocop --version
17
+ - name: rubocop
18
+ timeout-minutes: 5
19
+ run: bundle exec rubocop -c .rubocop.yml
20
+
21
+ test:
22
+ runs-on: ubuntu-latest
23
+ continue-on-error: ${{ matrix.experimental }}
24
+ strategy:
25
+ fail-fast: false
26
+ matrix:
27
+ ruby: ["2.5", "2.6", "2.7", "3.0"]
28
+ experimental: [false]
29
+ include:
30
+ - ruby: "jruby"
31
+ experimental: true
32
+ - ruby: "truffleruby"
33
+ experimental: true
34
+ steps:
35
+ - uses: actions/checkout@v2
36
+ - uses: ruby/setup-ruby@v1
37
+ with:
38
+ ruby-version: ${{matrix.ruby}}
39
+ bundler-cache: true
40
+ - name: Run tests
41
+ timeout-minutes: 5
42
+ run: ${{matrix.env}} bundle exec rspec
data/.gitignore CHANGED
@@ -7,8 +7,8 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /cache/*
10
11
  Gemfile.lock
11
- /cache/
12
12
 
13
13
  # rspec failure tracking
14
14
  .rspec_status
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --format documentation
2
2
  --color
3
3
  --require spec_helper
4
+ --order rand
data/.rubocop.yml CHANGED
@@ -3,10 +3,21 @@ require: rubocop-rspec
3
3
  AllCops:
4
4
  TargetRubyVersion: 2.5.1
5
5
 
6
+ Gemspec/RequiredRubyVersion:
7
+ Enabled: false
8
+
9
+ Lint:
10
+ Exclude:
11
+ - bin/*
12
+
6
13
  # Don't force top level comments in every class
7
14
  Style/Documentation:
8
15
  Enabled: false
9
16
 
17
+ # Safe navigation is not available in older ruby versions
18
+ Style/SafeNavigation:
19
+ Enabled: false
20
+
10
21
  # A good line length is 100 chars
11
22
  Metrics/LineLength:
12
23
  Max: 100
@@ -21,6 +32,12 @@ Metrics/ClassLength:
21
32
  Metrics/MethodLength:
22
33
  Max: 20
23
34
 
35
+ Metrics/CyclomaticComplexity:
36
+ Max: 10
37
+
38
+ Metrics/PerceivedComplexity:
39
+ Max: 10
40
+
24
41
  Metrics/AbcSize:
25
42
  Max: 30
26
43
 
@@ -29,11 +46,3 @@ RSpec/ExampleLength:
29
46
 
30
47
  RSpec/MultipleExpectations:
31
48
  Max: 10
32
-
33
- RSpec/RepeatedExample:
34
- Exclude:
35
- - 'spec/policies/**/*'
36
-
37
- RSpec/RepeatedDescription:
38
- Exclude:
39
- - 'spec/policies/**/*'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.1
1
+ 2.5.8
data/README.md CHANGED
@@ -1,6 +1,48 @@
1
1
  # ZohoHub
2
2
 
3
- https://www.zoho.com/crm/help/api-diff/
3
+ [![Build Status](https://travis-ci.com/rikas/zoho_hub.svg?branch=master)](https://travis-ci.com/rikas/zoho_hub)
4
+ [![Gem Version](https://badge.fury.io/rb/zoho_hub.svg)](https://badge.fury.io/rb/zoho_hub)
5
+
6
+ Simple wrapper around Zoho CRM version2, using
7
+ [OAuth 2.0 protocol](https://www.zoho.com/crm/help/developer/api/oauth-overview.html) for authentication.
8
+
9
+ This gem reads your Module configuration and builds the corresponding classes for you, using some
10
+ reflection mechanisms. You should then be able to use simple classes with an API close to
11
+ ActiveRecord, to do CRUD operations.
12
+
13
+ **NOTE: this gem is WIP, please try to use it and open an issue if you run into limitations / problems**
14
+
15
+ ## Table of Contents
16
+
17
+ - [ZohoHub](#zohohub)
18
+ - [Table of Contents](#table-of-contents)
19
+ - [Installation](#installation)
20
+ - [Setup process](#setup-process)
21
+ - [1. Register your application](#1-register-your-application)
22
+ - [1.1 Zoho Accounts URL](#11-zoho-accounts-url)
23
+ - [1.2 Authorized Redirect URI](#12-authorized-redirect-uri)
24
+ - [2. Configure ZohoHub with your credentials](#2-configure-zohohub-with-your-credentials)
25
+ - [3. Authorization request](#3-authorization-request)
26
+ - [3.1 Redirection based authentication](#31-redirection-based-authentication)
27
+ - [3.2 Self-Client Authorization](#32-self-client-authorization)
28
+ - [3.3 More on scopes](#33-more-on-scopes)
29
+ - [3.4 Offline access](#34-offline-access)
30
+ - [4. Access token](#4-access-token)
31
+ - [5. Refresh token](#5-refresh-token)
32
+ - [6. Basic ZohoHub flow](#6-basic-zohohub-flow)
33
+ - [7. BaseRecord and record classes](#7-baserecord-and-record-classes)
34
+ - [7.1 Reflection](#71-reflection)
35
+ - [7.2 Subclassing BaseRecord](#72-subclassing-baserecord)
36
+ - [8 Notifications](#8-notifications)
37
+ - [8.1 Enable notifications](#81-enable-notifications)
38
+ - [8.2 List notifications](#82-list-notifications)
39
+ - [8.3 Caveats](#83-caveats)
40
+ - [Tips and suggestions](#tips-and-suggestions)
41
+ - [Examples](#examples)
42
+ - [Setup auth token and request CurrentUser](#setup-auth-token-and-request-currentuser)
43
+ - [Development](#development)
44
+ - [Contributing](#contributing)
45
+ - [License](#license)
4
46
 
5
47
  ## Installation
6
48
 
@@ -18,9 +60,438 @@ Or install it yourself as:
18
60
 
19
61
  $ gem install zoho_hub
20
62
 
21
- ## Usage
63
+ ## Setup process
64
+
65
+ ### 1. Register your application
66
+
67
+ If you want to access your Zoho CRM account from your application you first need to create your
68
+ application as described here: https://www.zoho.com/crm/help/developer/api/register-client.html.
69
+
70
+ This will give you a **Client ID** and a **secret**, that you'll use in
71
+ [step 2](#2-configure-zohohub-with-your-credentials).
72
+
73
+ #### 1.1 Zoho Accounts URL
74
+
75
+ Registration and authorization requests are made to Zoho's domain-specific Accounts URL which
76
+ varies depending on your region:
77
+
78
+ * China: https://accounts.zoho.com.cn
79
+ * EU: https://accounts.zoho.eu
80
+ * India: https://accounts.zoho.in
81
+ * US: https://accounts.zoho.com
82
+
83
+ ZohoHub uses the EU Account URL by default, but this can be overriden in a `ZohoHub.configure` block
84
+ via the `api_domain` method ([step 2](#2-configure-zohohub-with-your-credentials).)
85
+
86
+ #### 1.2 Authorized Redirect URI
87
+
88
+ Per Zoho's API documentation, providing a **redirect URI** is optional. Doing so allows a user of
89
+ your application to be redirected back to your app (to the **redirect URI**) with a **grant token**
90
+ upon successful authentication.
91
+
92
+ If you don't provide a **redirect URI**, you'll need to use the
93
+ [self-client option](https://www.zoho.com/crm/help/developer/api/auth-request.html#self-client) for
94
+ authorization (see [3.2](#32-self-client-authorization).)
95
+
96
+ ---
97
+
98
+ ### 2. Configure ZohoHub with your credentials
99
+
100
+ > **Note:** Treat these credentials like an important password. It is *strongly* recommended to not
101
+ > paste them anywhere in plain text. Do *not* add them to version control; keep them out of your
102
+ > code directly by referencing them via environment variables. Use something like the dotenv gem or
103
+ > encrypted credentials in Rails to keep them as secret and secure as possible.
104
+
105
+ You need to have a configuration block like the one below (in Rails add a `zoho_hub.rb` in your
106
+ `config/initializers` directory):
107
+
108
+ ```ruby
109
+ ZohoHub.configure do |config|
110
+ config.client_id = 'YOUR_ZOHO_CLIENT_ID' # obtained in 1.
111
+ config.secret = 'YOUR_ZOHO_SECRET' # obtained in 1.
112
+ config.redirect_uri = 'YOUR_ZOHO_OAUTH_REDIRECT_URL'
113
+ config.api_domain = 'https://accounts.zoho.com' # can be omitted if in the EU
114
+ # config.debug = true # this will be VERY verbose, but helps to identify bugs / problems
115
+ end
116
+ ```
117
+
118
+ ---
119
+
120
+ ### 3. Authorization request
121
+
122
+ In order to access data in Zoho CRM you need to authorize ZohoHub to access your account. To do so
123
+ you have to request a specific URL with the right **scope** and **access_type**. Successful
124
+ authorization will provide a **grant token** which will be used to generate **access** and
125
+ **refresh tokens**.
126
+
127
+ #### 3.1 Redirection based authentication
128
+
129
+ To get the right URL you can use this simple line of code:
130
+
131
+ ```ruby
132
+ ZohoHub::Auth.auth_url
133
+ # => "https://accounts.zoho.eu/oauth/v2/auth?access_type=offline&client_id=&redirect_uri=&response_type=code&scope=ZohoCRM.modules.custom.all,ZohoCRM.settings.all,ZohoCRM.modules.contacts.all,ZohoCRM.modules.all"
134
+ ```
135
+
136
+ If you request this generated URL you should see a screen like this one, where you have to click on
137
+ "Accept":
138
+
139
+ ![](https://duaw26jehqd4r.cloudfront.net/items/1h1i3C1N0k0i02092F0S/Screen%20Shot%202018-11-25%20at%2019.18.38.png)
140
+
141
+ You will then be redirected to the **redirect URI** you provided with additional query parameters
142
+ as follows (the value after `code=` is the **grant token**):
143
+
144
+ ```
145
+ {redirect_uri}?code={grant_token}&location=us&accounts-server=https%3A%2F%2Faccounts.zoho.com
146
+ ```
147
+
148
+ #### 3.2 Self-Client Authorization
149
+
150
+ If you don't have a **redirect URI** or you want your application to be able to authorize with Zoho
151
+ programmatically (without a user required to be present and click the "Accept" prompt), Zoho
152
+ provides a
153
+ [self-client option](https://www.zoho.com/crm/help/developer/api/auth-request.html#self-client)
154
+ for authentication which will provide a **grant token**.
155
+
156
+ #### 3.3 More on scopes
157
+
158
+ You can change the default scope (what data can be accessed by your application). This is the list
159
+ provided as the default scope:
160
+
161
+ ```
162
+ ZohoCRM.modules.custom.all
163
+ ZohoCRM.settings.all
164
+ ZohoCRM.modules.contacts.all
165
+ ZohoCRM.modules.all
166
+ ```
167
+
168
+ To get the URL for a different scope you can provide a `scope` argument:
169
+
170
+ ```ruby
171
+ ZohoHub::Auth.auth_url(scope: ['ZohoCRM.modules.custom.all', 'ZohoCRM.modules.all'])
172
+ # => "https://accounts.zoho.eu/oauth/v2/auth?access_type=offline&client_id=&redirect_uri=&response_type=code&scope=ZohoCRM.modules.custom.all,ZohoCRM.modules.all"
173
+ ```
174
+
175
+ Refer to
176
+ [Zoho's API documentation on scopes](https://www.zoho.com/crm/help/developer/api/oauth-overview.html#scopes)
177
+ for detailed information.
178
+
179
+ #### 3.4 Offline access
180
+
181
+ By design the **access tokens** returned by the OAuth flow expire after a period of time (1 hour by
182
+ default), as a safety mechanism. This means that any application that wants to work with a user's
183
+ data needs the user to have recently gone through the OAuth flow, aka be online.
184
+
185
+ When you request offline access the Zoho API returns a **refresh token**. **Refresh tokens** give
186
+ your application the ability to request data on behalf of the user when the user is not present and
187
+ in front of your application.
188
+
189
+ **By default `ZohoHub::Auth.auth_url` will request offline access**
190
+
191
+ You can force "online" access by using `#auth_url` with a `access_type` argument:
192
+
193
+ ```ruby
194
+ ZohoHub::Auth.auth_url(access_type: 'online')
195
+ # => "https://accounts.zoho.eu/oauth/v2/auth?access_type=online&client_id=&redirect_uri=&response_type=code&scope=ZohoCRM.modules.custom.all,ZohoCRM.settings.all,ZohoCRM.modules.contacts.all,ZohoCRM.modules.all"
196
+ ```
197
+
198
+ ---
199
+
200
+ ### 4. Access token
201
+
202
+ See Zoho's API documentation for generating an initial **access token**:
203
+ https://www.zoho.com/crm/help/developer/api/access-refresh.html
204
+
205
+ To use an **access token** in a manual request, include it as a request header as
206
+ `Authorization: Zoho-oauthtoken {access_token}` (without the braces.)
207
+
208
+ To use an **access token** with ZohoHub, pass it to the `ZohoHub.setup_connection` method as the
209
+ `access_token` parameter.
210
+
211
+ ---
212
+
213
+ ### 5. Refresh token
214
+
215
+ This gem automatically refresh the access token.
216
+
217
+ If you want automatic refresh, use the refresh_token argument as in the next chapter.
218
+
219
+ ---
220
+
221
+ ### 6. Basic ZohoHub flow
222
+
223
+ Once ZohoHub has been configured with your credentials (section 2) and you have a fresh **access
224
+ token**, setup a ZohoHub connection:
225
+
226
+ ```ruby
227
+ ZohoHub.setup_connection access_token: 'ACCESS_TOKEN',
228
+ expires_in: 'EXPIRES_IN_SEC',
229
+ api_domain: 'API_DOMAIN',
230
+ refresh_token: 'REFRESH_TOKEN'
231
+ ```
232
+
233
+ Now you can issue requests to Zoho's API with the Connection object, e.g.:
234
+
235
+ ```ruby
236
+ # request a (paginated) list of all Lead records
237
+ ZohoHub.connection.get 'Leads'
238
+ ```
239
+
240
+ A successful request will receive a response like the sample here:
241
+ https://www.zoho.com/crm/help/developer/api/get-records.html.
242
+
243
+ ---
244
+
245
+ ### 7. BaseRecord and record classes
246
+
247
+ At this point, ZohoHub is starting to do some of the heavy lifting, but using `ZohoHub.connection`
248
+ still gets tedious after just a handful of requests. But we can improve that by allowing ZohoHub
249
+ to build our record classes or by manually defining them ourselves.
250
+
251
+ #### 7.1 Reflection
252
+
253
+ TODO
254
+
255
+ #### 7.2 Subclassing BaseRecord
256
+
257
+ See `lib/zoho_hub/base_record.rb` and any of the classes in `examples/models/` for reference.
258
+
259
+ For any Zoho module with which you want to interact via ZohoHub, make a class of the same name that
260
+ inherits from `ZohoHub::BaseRecord`. For example, to build a class for the Leads module:
261
+
262
+ ```ruby
263
+ # lead.rb
264
+
265
+ class Lead < ZohoHub::BaseRecord
266
+ ...
267
+ end
268
+ ```
269
+
270
+ Specify this module's fields as attributes:
271
+
272
+ ```ruby
273
+ # lead.rb
274
+
275
+ class Lead < ZohoHub::BaseRecord
276
+ attributes :id, :first_name, :last_name, :phone, :email, :source, # etc.
277
+ end
278
+ ```
279
+
280
+ Now you can issue requests more easily with your record class, e.g.:
281
+
282
+ ```ruby
283
+ # Request a (paginated) list of all Lead records
284
+ Lead.all
285
+
286
+ # Get the Lead instance with a specific ID
287
+ Lead.find('78265000003433063')
288
+ ```
289
+
290
+ And even create new Lead entries in Zoho:
291
+
292
+ ```ruby
293
+ lead = Lead.new(
294
+ first_name: 'First name',
295
+ last_name: 'Last name',
296
+ phone: '+35197736281',
297
+ email: 'myemail@gmail.com',
298
+ source: 'Homepage'
299
+ )
300
+
301
+ # Creates the new lead
302
+ lead.save
303
+
304
+ # Or in one step:
305
+ lead = Lead.create(first_name: 'First name', ...)
306
+ ```
307
+
308
+ Updating records:
309
+
310
+ ```ruby
311
+ Lead.update(id: lead.id, first_name: "...", last_name: "...")
312
+
313
+ # Or
314
+ lead.update(first_name: "...", last_name: "...")
315
+
316
+ # Or update up to 100 records in one call:
317
+ leads = [{ id: id1, phone: "123" }, { id: id2, first_name: "..." }]
318
+ Lead.update_all(leads)
319
+ ```
320
+
321
+ Blueprint transition:
322
+
323
+ ```ruby
324
+ Lead.blueprint_transition(lead.id, transition_id)
325
+
326
+ # Or
327
+ lead.blueprint_transition(transition_id)
328
+ ```
329
+
330
+ Adding notes:
331
+
332
+ ```ruby
333
+ Lead.add_note(id: lead.id, title: 'Note title', content: 'Note content')
334
+ ```
335
+
336
+ Related records:
337
+
338
+ ```ruby
339
+ Product.all_related(parent_module: 'Lead', parent_id: lead.id)
340
+ Product.add_related(
341
+ parent_module: 'Lead',
342
+ parent_id: lead.id,
343
+ related_id: product.id
344
+ )
345
+ Product.remove_related(
346
+ parent_module: 'Lead',
347
+ parent_id: lead.id,
348
+ related_id: product.id
349
+ )
350
+ Product.update_related(...)
351
+ ```
352
+
353
+ Attachments (`ZohoHub::Attachment` is defined in the gem):
354
+
355
+ ```ruby
356
+ Lead.related_attachments(parent_id: lead.id)
357
+ # -> Array of Attachments
358
+
359
+ attachment = Lead.download_attachment(parent_id: lead.id, attachment_id:attachment.id)
360
+ # -> Attachment (attachment.file contains the file as a Tempfile)
361
+
362
+ #NB: Lead.upload_attachment not implemented yet
363
+ ```
364
+
365
+ ## 8 Notifications
366
+ Zoho allows you to receive a notification when a record of a module changes. Supported operation types are create, delete, edit, all.
367
+
368
+ ### 8.1 Enable notifications
369
+ In order to receive notifications, you have to enable them first.
370
+ ```ruby
371
+ # Enable notifications for a given channel:
372
+ notification_url = 'https://example.org/api/notifications' # Zoho will send notifications by POST to this url
373
+ token = '123abc' # Zoho will send this token back to you, so you can ensure that the notification is from Zoho
374
+ channel_id = 1 # Choose a channel to handle the response
375
+ events = %w[Leads.create Deals.edit Contacts.delete Sales_Orders.all] # Which events to receive notifications for
376
+ channel_expiry = (DateTime.now + 1.day).iso8601 # choose a date when the channel should expire. 24h is the maximum, default is one hour
377
+
378
+ ZohoHub::Notifications.enable(notification_url, channel_id, events, channel_expiry, token)
379
+ ```
380
+
381
+ After enabling notifications, Zoho will execute a POST request to the provided notification_url every time the requested event occurs.
382
+
383
+ For a list of an in-depth description of the response, check the [Zoho documentation](https://www.zoho.com/crm/developer/docs/api/notifications/overview.html)
384
+
385
+ ### 8.2 List notifications
386
+ You can also retrieve all notifications that are currently enabled and that you are receiving uppdates for.
387
+
388
+ ```ruby
389
+ # Get all enabled notifications
390
+ ZohoHub::Notifications.all
391
+ ```
392
+
393
+ ### 8.3 Caveats
394
+
395
+ * Zoho does not notify you when records are merged.
396
+ * Since Zoho does not tell you what changed, you will have to request the record by yourself. Due to this you can miss changes, when they occur quickly after another. This is especially important for status changes, as you might miss state changes.
397
+
398
+ ## Tips and suggestions
399
+
400
+ * Using a tool such as Postman or curl to issue HTTP requests and verify responses in isolation
401
+ can be a great sanity check during setup.
402
+ * Downloading ZohoHub code (as opposed to the gem) and running `bin/console` is a great way to
403
+ learn how the code works and test aspects of setup and Zoho's API in isolation.
404
+ * [The Zoho API Documentation](https://www.zoho.com/crm/help/developer/api/overview.html) is your
405
+ friend - especially the sample HTTP requests and responses in the various sections under "Rest
406
+ API" on the left.
407
+ * If you're manually implementing your record classes (rather than using the reflection mechanism),
408
+ the files in `/examples/models/` can help you get started.
409
+ * Requests can be issued to Zoho CRM's
410
+ [Sandbox](https://help.zoho.com/portal/kb/articles/using-sandbox)
411
+ by configuring `https://crmsandbox.zoho.com/crm` (or regional equivalent) as the `api_domain`.
412
+
413
+ ## Examples
414
+
415
+ ### Setup auth token and request CurrentUser
416
+
417
+ > This example assumes use of the dotenv gem and is written directly into
418
+ > ZohoHub's root directory (rather than using ZohoHub as a gem) for simplicity.
419
+
420
+ 1. Edit `bin/console` to comment out refreshing the token and setting up the connection:
421
+
422
+ ```ruby
423
+ # bin/console
424
+
425
+ ...
426
+ # puts 'Refreshing token...'
427
+ # token_params = ZohoHub::Auth.refresh_token(ENV['ZOHO_REFRESH_TOKEN'])
428
+ # ZohoHub.setup_connection(token_params)
429
+ ...
430
+ ```
431
+
432
+ 2. [Register your application](#1-register-your-application) to obtain a **client ID** and
433
+ **secret**. (Leave the [Zoho API Credentials page](https://accounts.zoho.com/developerconsole) open;
434
+ you'll need it in step 5.)
435
+ 3. Determine your [Zoho Accounts URL](#11-zoho-accounts-url).
436
+ 4. Add your registration and account URL information to a `.env` file:
437
+
438
+ ```
439
+ # .env
440
+
441
+ ZOHO_CLIENT_ID=YOUR_CLIENT_ID
442
+ ZOHO_SECRET=YOUR_SECRET
443
+ ZOHO_API_DOMAIN=YOUR_ZOHO_ACCOUNTS_URL
444
+ ```
445
+
446
+ 5. On the [Zoho API Credentials page](https://accounts.zoho.com/developerconsole) from step 1, click
447
+ the three vertical dots and select `Self client`.
448
+ 6. Paste this into the `Scope` field: `ZohoCRM.users.ALL`, choose an expiration time, and click
449
+ `View Code`; this is your **Grant token**.
450
+ 7. Run the ZohoHub console from your terminal: `bin/console`
451
+ 8. Issue a token request with the **grant token** (notice the quotes around the token value):
452
+
453
+ ```ruby
454
+ ZohoHub::Auth.get_token('paste_your_grant_token_here')
455
+ ```
456
+
457
+ This should return a response with an **access token**, e.g.:
458
+
459
+ ```ruby
460
+ => {:access_token=>"ACCESS_TOKEN_VALUE",
461
+ :expires_in_sec=>3600,
462
+ :api_domain=>"https://www.zohoapis.com",
463
+ :token_type=>"Bearer"
464
+ }
465
+ ```
466
+
467
+ exit the console with `exit`.
468
+
469
+ 9. Add the access token to your `.env` file:
470
+
471
+ ```
472
+ # .env
473
+
474
+ ZOHO_CLIENT_ID=YOUR_CLIENT_ID
475
+ ZOHO_SECRET=YOUR_SECRET
476
+ ZOHO_API_DOMAIN=YOUR_ZOHO_ACCOUNTS_URL
477
+ ZOHO_ACCESS_TOKEN=YOUR_ACCESS_TOKEN
478
+ ```
479
+
480
+ 10. Edit `bin/console` to add a new `setup_connection` after the previously commented out one:
481
+
482
+ ```ruby
483
+ # bin/console
484
+
485
+ ...
486
+ # ZohoHub.setup_connection(token_params)
487
+
488
+ ZohoHub.setup_connection(access_token: ENV['ZOHO_ACCESS_TOKEN'])
489
+ ...
490
+ ```
491
+
492
+ 11. Start the console again: `bin/console`.
22
493
 
23
- TODO: Write usage instructions here
494
+ 12. Issue a request for the current user: `ZohoHub.connection.get 'users?type=CurrentUser'`
24
495
 
25
496
  ## Development
26
497
 
@@ -28,10 +499,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
28
499
  the tests. You can also run `bin/console` for an interactive prompt that will allow you to
29
500
  experiment.
30
501
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new
32
- version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
33
- will create a git tag for the version, push git commits and tags, and push the `.gem` file
34
- to [rubygems.org](https://rubygems.org).
502
+ To install this gem onto your local machine, run `bundle exec rake install`.
35
503
 
36
504
  ## Contributing
37
505
 
@@ -39,4 +507,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/rikas/
39
507
 
40
508
  ## License
41
509
 
42
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
510
+ The gem is available as open source under the terms of the
511
+ [MIT License](https://opensource.org/licenses/MIT).