zoho_hub 0.1.48 → 0.2.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +5 -2
  5. data/.ruby-version +1 -1
  6. data/.travis.yml +5 -2
  7. data/README.md +91 -7
  8. data/bin/console +6 -7
  9. data/bin/read +44 -0
  10. data/bin/setup +0 -2
  11. data/bin/zoho_hub +62 -0
  12. data/cache/.git_keep +0 -0
  13. data/lib/zoho_hub/auth.rb +37 -47
  14. data/lib/zoho_hub/base_record.rb +122 -0
  15. data/lib/zoho_hub/configuration.rb +3 -4
  16. data/lib/zoho_hub/connection.rb +10 -17
  17. data/lib/zoho_hub/{records → deprecated_and_only_for_reference_records}/account.rb +1 -1
  18. data/lib/zoho_hub/{records → deprecated_and_only_for_reference_records}/campaign.rb +0 -0
  19. data/lib/zoho_hub/{records → deprecated_and_only_for_reference_records}/contact.rb +3 -9
  20. data/lib/zoho_hub/deprecated_and_only_for_reference_records/funder.rb +9 -0
  21. data/lib/zoho_hub/{records → deprecated_and_only_for_reference_records}/potential.rb +1 -21
  22. data/lib/zoho_hub/deprecated_and_only_for_reference_records/product.rb +9 -0
  23. data/lib/zoho_hub/deprecated_and_only_for_reference_records/quote.rb +34 -0
  24. data/lib/zoho_hub/errors.rb +0 -3
  25. data/lib/zoho_hub/module_builder.rb +61 -0
  26. data/lib/zoho_hub/oauth_callback_server.rb +26 -0
  27. data/lib/zoho_hub/response.rb +1 -4
  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 +34 -0
  31. data/lib/zoho_hub/version.rb +1 -1
  32. data/lib/zoho_hub/views/variables.erb +72 -0
  33. data/lib/zoho_hub/with_attributes.rb +74 -0
  34. data/lib/zoho_hub/with_connection.rb +36 -0
  35. data/lib/zoho_hub.rb +21 -23
  36. data/zoho_hub.gemspec +14 -10
  37. metadata +80 -57
  38. data/lib/zoho_hub/records/adverse_criteria.rb +0 -43
  39. data/lib/zoho_hub/records/attachment.rb +0 -104
  40. data/lib/zoho_hub/records/base_record.rb +0 -189
  41. data/lib/zoho_hub/records/credit_score.rb +0 -36
  42. data/lib/zoho_hub/records/product.rb +0 -33
  43. data/lib/zoho_hub/records/quote.rb +0 -44
  44. data/lib/zoho_hub/records/sms_message.rb +0 -32
  45. data/lib/zoho_hub/records/vendor.rb +0 -34
@@ -6,7 +6,7 @@ module ZohoHub
6
6
  class Account < BaseRecord
7
7
  attributes :id, :name, :territories, :company_number, :employee_count, :company_type, :industry
8
8
  attributes :billing_city, :billing_code, :billing_country, :billing_street, :billing_state
9
- attributes :account_type, :industry_section, :region
9
+ attributes :account_type
10
10
 
11
11
  # This is the ID to be used when the borrower has no organisation (unlikely) or belongs to
12
12
  # multiple organisations.
@@ -4,18 +4,14 @@ require 'zoho_hub/records/base_record'
4
4
 
5
5
  module ZohoHub
6
6
  class Contact < BaseRecord
7
- attributes :id, :email, :salutation, :first_name, :mobile, :role, :last_name, :vendor_id
8
- attributes :account_id, :owner_id, :campaign_id, :status, :campaign_detail, :phone
9
- attributes :mailing_city, :mailing_zip, :mailing_country, :mailing_street, :mailing_state
10
- attributes :date_of_birth, :relationship_to_business
7
+ attributes :id, :email, :salutation, :first_name, :mobile, :role, :last_name
8
+ attributes :account_id, :owner_id, :campaign_id, :status, :campaign_detail
11
9
 
12
10
  attribute_translation(
13
11
  id: :id,
14
12
  role: :platform_cont_type,
15
13
  status: :platform_cont_status,
16
- use_proceeds: :use_proceeds,
17
- date_of_birth: :Date_of_Birth,
18
- relationship_to_business: :Relationship_to_business
14
+ use_proceeds: :use_proceeds
19
15
  )
20
16
 
21
17
  DEFAULTS = {
@@ -34,7 +30,6 @@ module ZohoHub
34
30
  @account_id ||= params.dig(:Account_Name, :id)
35
31
  @owner_id ||= params.dig(:Owner, :id)
36
32
  @campaign_id ||= params.dig(:Campaign_Lookup, :id)
37
- @vendor_id ||= params.dig(:Vendor_Name, :id)
38
33
  end
39
34
 
40
35
  def to_params
@@ -43,7 +38,6 @@ module ZohoHub
43
38
  params[:Account_Name] = { id: @account_id } if @account_id
44
39
  params[:Owner] = { id: @owner_id } if @owner_id
45
40
  params[:Campaign_Lookup] = { id: @campaign_id } if @campaign_id
46
- params[:Vendor_Name] = { id: @vendor_id } if @vendor_id
47
41
 
48
42
  params
49
43
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoHub
4
+ class Vendor < BaseRecord
5
+ def initialize(params)
6
+ puts Rainbow(params).red.bright
7
+ end
8
+ end
9
+ end
@@ -9,13 +9,6 @@ module ZohoHub
9
9
  attributes :currency, :territory, :employee_count, :turnover, :industry, :region
10
10
  attributes :review_outcome, :first_created, :last_modified, :preferred_term, :project_notes
11
11
  attributes :campaign_id, :account_id, :contact_id, :campaign_detail, :reviewers_comment
12
- attributes :accounting_software, :banking_provider, :turnover_figure
13
- attributes :guarantee_types, :home_ownership_status
14
- attributes :accountant_id, :vat_registration, :published_all_of_market
15
- attributes :credit_risk_band, :live_ccjs, :satisfied_ccjs
16
- attributes :state, :number_of_connections
17
- attributes :submitted_to_lender_panel, :last_attachment_uploaded, :funds_timeline
18
- attributes :cancellation_reason
19
12
 
20
13
  DEFAULTS = {
21
14
  currency: 'GBP',
@@ -30,18 +23,7 @@ module ZohoHub
30
23
  code: :Project_Ref_No,
31
24
  description: :Project_description,
32
25
  employee_count: :Number_of_Employees,
33
- use_proceeds: :use_proceeds,
34
- vat_registration: :Pick_List_15,
35
- live_ccjs: :Live_CCJs,
36
- satisfied_ccjs: :Satisfied_CCJs,
37
- published_all_of_market: :Published_to_All_of_Market,
38
- state: :State1,
39
- submitted_to_lender_panel: :Submitted_to_Lender_Panel1,
40
- number_of_connections: :Number_of_Connections,
41
- turnover_figure: :Turnover_figure,
42
- last_attachment_uploaded: :Last_Attachment_Uploaded,
43
- funds_timeline: :When_will_you_needs_the_funds,
44
- cancellation_reason: :If_Application_Cancelled_select_reason
26
+ use_proceeds: :use_proceeds
45
27
  )
46
28
 
47
29
  def initialize(params)
@@ -55,7 +37,6 @@ module ZohoHub
55
37
  @account_id ||= params.dig(:Account_Name, :id)
56
38
  @contact_id ||= params.dig(:Contact_Name, :id)
57
39
  @campaign_id ||= params.dig(:Campaign_Source, :id)
58
- @accountant_id ||= params.dig(:Accountant_Name, :id)
59
40
  end
60
41
 
61
42
  def to_params
@@ -64,7 +45,6 @@ module ZohoHub
64
45
  params[:Campaign_Source] = { id: @campaign_id } if @campaign_id
65
46
  params[:Account_Name] = { id: @account_id } if @account_id
66
47
  params[:Contact_Name] = { id: @contact_id } if @contact_id
67
- params[:Accountant_Name] = { id: @accountant_id } if @accountant_id
68
48
 
69
49
  params
70
50
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoHub
4
+ class Product < BaseRecord
5
+ def initialize(params)
6
+ puts Rainbow(params).red.bright
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zoho_hub/records/base_record'
4
+
5
+ module ZohoHub
6
+ class Quote < BaseRecord
7
+ attributes :id, :stage, :subject
8
+ attributes :potential_id
9
+
10
+ attribute_translation(
11
+ id: :id,
12
+ stage: :Quote_Stage
13
+ )
14
+
15
+ def initialize(params)
16
+ puts Rainbow(params).bright.red
17
+ attributes.each do |attr|
18
+ zoho_key = attr_to_zoho_key(attr)
19
+
20
+ send("#{attr}=", params[zoho_key] || params[attr])
21
+ end
22
+
23
+ @potential_id ||= params.dig(:Deal_Name, :id)
24
+ @lender_organisation_id ||= params.dig(:Account_Name, :id)
25
+ end
26
+
27
+ def to_params
28
+ params = super
29
+
30
+ params[:Deal_Name] = { id: @potential_id } if @potential_id
31
+ params[:Account_Name] = { id: @lender_organisation_id } if @lender_organisation_id
32
+ end
33
+ end
34
+ end
@@ -12,7 +12,4 @@ module ZohoHub
12
12
 
13
13
  class ZohoAPIError < StandardError
14
14
  end
15
-
16
- class AttachmentLinkTakenError < StandardError
17
- end
18
15
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zoho_hub/string_utils'
4
+
5
+ module ZohoHub
6
+ class ModuleBuilder
7
+ class << self
8
+ def build_from_cache
9
+ cached_module_definitions.map do |file|
10
+ json = MultiJson.load(File.read(file), symbolize_keys: true)
11
+
12
+ create_module(json)
13
+ end
14
+ end
15
+
16
+ def cached_module_definitions
17
+ Dir[File.join(ZohoHub.root, 'cache', 'modules', '**')]
18
+ end
19
+
20
+ def create_module(json)
21
+ fields = cached_module_fields(json[:api_name])
22
+
23
+ klass = Class.new(ZohoHub::BaseRecord) do
24
+ request_path json[:api_name]
25
+
26
+ translations = {}
27
+ fields.each do |field|
28
+ key = StringUtils.underscore(field[:api_name])
29
+
30
+ translations[key] = field[:api_name]
31
+ end
32
+
33
+ if translations.any?
34
+ attributes(*translations.keys)
35
+ attribute_translation(translations)
36
+ end
37
+
38
+ def initialize(params)
39
+ attributes.each do |attr|
40
+ zoho_key = attr_to_zoho_key(attr)
41
+
42
+ send("#{attr}=", params[zoho_key] || params[attr])
43
+ end
44
+ end
45
+ end
46
+
47
+ ZohoHub.const_set(StringUtils.camelize(json[:singular_label]), klass)
48
+ end
49
+
50
+ def cached_module_fields(module_name)
51
+ file = File.join(ZohoHub.root, 'cache', 'fields', "#{module_name}.json")
52
+
53
+ return [] unless File.exist?(file)
54
+
55
+ json_content = File.read(file)
56
+
57
+ MultiJson.load(json_content, symbolize_keys: true)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sinatra/base'
4
+
5
+ module ZohoHub
6
+ class OauthCallbackServer < Sinatra::Base
7
+ enable :logging
8
+
9
+ CALLBACK_PATH = 'oauth2callback'
10
+
11
+ before do
12
+ content_type :json
13
+ end
14
+
15
+ get "/#{CALLBACK_PATH}" do
16
+ grant_token = params[:code]
17
+
18
+ # This will trigger a post request to get both the token and the refresh token
19
+ @variables = ZohoHub::Auth.get_token(grant_token)
20
+
21
+ puts "Variables: #{@variables.inspect}"
22
+
23
+ erb :variables
24
+ end
25
+ end
26
+ end
@@ -7,9 +7,7 @@ module ZohoHub
7
7
  end
8
8
 
9
9
  def invalid_data?
10
- if data.is_a?(Array)
11
- return data.first[:code] == 'MANDATORY_NOT_FOUND'
12
- end
10
+ return false if data.is_a?(Array)
13
11
 
14
12
  data[:code] == 'INVALID_DATA'
15
13
  end
@@ -42,7 +40,6 @@ module ZohoHub
42
40
 
43
41
  def msg
44
42
  msg = data[:message]
45
- msg << ", error in #{data.dig(:details, :api_name)}" if data.dig(:code) == 'INVALID_DATA'
46
43
 
47
44
  if data.dig(:details, :expected_data_type)
48
45
  expected = data.dig(:details, :expected_data_type)
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zoho_hub/with_connection'
4
+ require 'zoho_hub/with_attributes'
5
+
6
+ module ZohoHub
7
+ module Settings
8
+ class Field
9
+ include WithConnection
10
+ include WithAttributes
11
+
12
+ REQUEST_PATH = 'settings/fields'
13
+
14
+ attributes :custom_field, :lookup, :convert_mapping, :visible, :field_label, :length,
15
+ :view_type, :read_only, :api_name, :unique, :data_type, :formula, :currency, :id,
16
+ :decimal_place, :pick_list_values, :auto_number
17
+
18
+ def self.all_for(module_name)
19
+ fields = all_json_for(module_name)
20
+ fields.map { |json| new(json) }
21
+ end
22
+
23
+ def self.all_json_for(module_name)
24
+ response = get(REQUEST_PATH, module: module_name)
25
+ response[:fields]
26
+ end
27
+
28
+ def initialize(json = {})
29
+ attributes.each { |attr| send("#{attr}=", json[attr]) }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zoho_hub/with_connection'
4
+ require 'zoho_hub/with_attributes'
5
+
6
+ require 'zoho_hub/settings/field'
7
+
8
+ module ZohoHub
9
+ module Settings
10
+ # Zoho CRM has standard modules such as, Leads, Accounts, Contacts, Deals, Forecasts,
11
+ # Activities, etc,. Using Zoho CRM REST API, you can retrieve the list of available modules.
12
+ #
13
+ # convertable: Describes if the user can convert the record into another type of record.
14
+ # For example: Convert Leads in to Deals.
15
+ # creatable: Checks if the user can create a record in the current module.
16
+ # generated_type: Describes the type of module which would be generated by the user. There are
17
+ # 4 types: default, web, custom, linking.
18
+ # api_supported: The modules which are currently not accessible by APIs have value as "false".
19
+ # If the modules are supported in the future, the value automatically changes
20
+ # to "true".
21
+ # modified_time: The date and time of changes made by the user.
22
+ #
23
+ # More details: https://www.zoho.com/crm/help/api/v2/#Modules-APIs
24
+ class Module
25
+ include WithConnection
26
+ include WithAttributes
27
+
28
+ REQUEST_PATH = 'settings/modules'
29
+
30
+ attributes :convertable, :editable, :deletable, :web_link, :singular_label, :modified_time,
31
+ :viewable, :api_supported, :creatable, :plural_label, :api_name, :modified_by,
32
+ :generated_type, :id, :module_name, :fields
33
+
34
+ def self.all
35
+ modules = all_json
36
+ modules.map { |json| new(json) }
37
+ end
38
+
39
+ def self.all_json
40
+ response = get(REQUEST_PATH)
41
+ response[:modules]
42
+ end
43
+
44
+ def initialize(json = {})
45
+ attributes.each { |attr| send("#{attr}=", json[attr]) }
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoHub
4
+ class StringUtils
5
+ class << self
6
+ def demodulize(text)
7
+ text.split('::').last
8
+ end
9
+
10
+ def pluralize(text)
11
+ "#{text}s"
12
+ end
13
+
14
+ def camelize(text)
15
+ result = text.split(/[_\s]/)
16
+
17
+ return result.first if result.size == 1
18
+
19
+ result.map(&:capitalize).join
20
+ end
21
+
22
+ def underscore(text)
23
+ return text unless text =~ /[A-Z-]/
24
+
25
+ result = text.dup
26
+ result.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
27
+ result.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
28
+ result.tr!('-', '_')
29
+ result.downcase!
30
+ result
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZohoHub
4
- VERSION = '0.1.48'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,72 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" dir="ltr">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Zoho CRM authentication</title>
6
+ <style media="screen">
7
+ body {
8
+ font-family: sans-serif;
9
+ padding: 20px 50px;
10
+ }
11
+
12
+ ul.variables {
13
+ padding: 20px;
14
+ background-color: #eaeaea;
15
+ font-family: monospace;
16
+ list-style: none;
17
+ line-height: 1.5em;
18
+ margin-bottom: 50px;
19
+ }
20
+
21
+ li.error {
22
+ color: #aa0000;
23
+ }
24
+
25
+ div.config {
26
+ padding: 20px;
27
+ background-color: #eaeaea;
28
+ font-family: monospace;
29
+ line-height: 1.5em;
30
+ }
31
+
32
+ pre {
33
+ margin: 0;
34
+ padding: 0;
35
+ }
36
+
37
+ code {
38
+ padding: 0;
39
+ margin: 0;
40
+ }
41
+ </style>
42
+ </head>
43
+
44
+ <body>
45
+ <h2>Here's what you have to add to your environment variables:</h2>
46
+
47
+ <ul class="variables">
48
+ <li>ZOHO_CLIENT_ID=<%= ZohoHub.configuration.client_id %></li>
49
+ <li>ZOHO_SECRET=<%= ZohoHub.configuration.secret %></li>
50
+ <li>ZOHO_API_DOMAIN=<%= @variables[:api_domain] %></li>
51
+ <% if @variables[:refresh_token] %>
52
+ <li>ZOHO_REFRESH_TOKEN=<%= @variables[:refresh_token] %></li>
53
+ <% else %>
54
+ <li class="error">
55
+ ZOHO_REFRESH_TOKEN=zoho didn't send the refresh token. Please review your configuration.
56
+ Check <a href="https://github.com/rikas/zoho_hub">the documentation</a> to understand why
57
+ this is important and how to solve the problem.
58
+ </li>
59
+ <% end %>
60
+ </ul>
61
+
62
+ <h2>Then you need a configuration block like this one:</h2>
63
+ <div class="config">
64
+ <pre><code>ZohoHub.configure do |config|
65
+ config.client_id = ENV['ZOHO_CLIENT_ID']
66
+ config.secret = ENV['ZOHO_SECRET']
67
+ config.api_domain = ENV['ZOHO_API_DOMAIN']
68
+ config.refresh_token = ENV['ZOHO_REFRESH_TOKEN']
69
+ end</code></pre>
70
+ </div>
71
+ </body>
72
+ </html>
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoHub
4
+ # Allows adding attributes to a class, as <tt>attr_accessors</tt> that can then be listed from the
5
+ # class or an instance of that class.
6
+ #
7
+ # === Example
8
+ #
9
+ # class User
10
+ # include ZohoHub::WithAttributes
11
+ #
12
+ # attributes :first_name, :last_name, :email
13
+ # end
14
+ #
15
+ # User.attributes # => [:first_name, :last_name, :email]
16
+ # User.new.attributes # => [:first_name, :last_name, :email]
17
+ #
18
+ # user = User.new
19
+ # user.first_name = 'Ricardo'
20
+ # user.last_name = 'Otero'
21
+ # user.first_name # => "Ricardo"
22
+ module WithAttributes
23
+ def self.included(base)
24
+ base.extend ClassMethods
25
+ end
26
+
27
+ module ClassMethods
28
+ def attributes(*attributes)
29
+ @attributes ||= []
30
+
31
+ return @attributes unless attributes
32
+
33
+ attr_accessor(*attributes)
34
+
35
+ @attributes += attributes
36
+ end
37
+
38
+ def attribute_translation(translation = nil)
39
+ @attribute_translation ||= {}
40
+
41
+ return @attribute_translation unless translation
42
+
43
+ @attribute_translation = translation
44
+ end
45
+
46
+ def zoho_key_translation
47
+ @attribute_translation.to_a.map(&:rotate).to_h
48
+ end
49
+ end
50
+
51
+ # Returns the list of attributes defined for the instance class.
52
+ def attributes
53
+ self.class.attributes
54
+ end
55
+
56
+ private
57
+
58
+ def attr_to_zoho_key(attr_name)
59
+ translations = self.class.attribute_translation
60
+
61
+ return translations[attr_name.to_sym] if translations.key?(attr_name.to_sym)
62
+
63
+ attr_name.to_s.split('_').map(&:capitalize).join('_').to_sym
64
+ end
65
+
66
+ def zoho_key_to_attr(zoho_key)
67
+ translations = self.class.zoho_key_translation
68
+
69
+ return translations[zoho_key.to_sym] if translations.key?(zoho_key.to_sym)
70
+
71
+ zoho_key.to_sym
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoHub
4
+ # Adds the ability to do API requests (GET / PUT and POST requests) when included in a class.
5
+ module WithConnection
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def get(path, params = {})
12
+ ZohoHub.connection.get(path, params)
13
+ end
14
+
15
+ def post(path, params = {})
16
+ ZohoHub.connection.post(path, params.to_json)
17
+ end
18
+
19
+ def put(path, params = {})
20
+ ZohoHub.connection.put(path, params.to_json)
21
+ end
22
+ end
23
+
24
+ def get(path, params = {})
25
+ self.class.get(path, params)
26
+ end
27
+
28
+ def post(path, params = {})
29
+ self.class.post(path, params)
30
+ end
31
+
32
+ def put(path, params = {})
33
+ self.class.put(path, params)
34
+ end
35
+ end
36
+ end
data/lib/zoho_hub.rb CHANGED
@@ -1,36 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/object/blank'
4
- require 'active_support/core_ext/string/inflections'
3
+ require 'backports/2.3.0/hash' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3.0')
5
4
 
6
5
  require 'zoho_hub/version'
7
6
  require 'zoho_hub/auth'
8
7
  require 'zoho_hub/configuration'
9
8
  require 'zoho_hub/connection'
10
9
  require 'zoho_hub/errors'
11
- require 'zoho_hub/records/contact'
12
- require 'zoho_hub/records/potential'
13
- require 'zoho_hub/records/campaign'
14
- require 'zoho_hub/records/account'
15
- require 'zoho_hub/records/quote'
16
- require 'zoho_hub/records/vendor'
17
- require 'zoho_hub/records/product'
18
- require 'zoho_hub/records/attachment'
19
- require 'zoho_hub/records/credit_score'
20
- require 'zoho_hub/records/adverse_criteria'
21
- require 'zoho_hub/records/sms_message'
10
+ require 'zoho_hub/base_record'
11
+ require 'zoho_hub/settings/module'
12
+ require 'zoho_hub/module_builder'
13
+
14
+ require 'multi_json'
22
15
 
23
16
  module ZohoHub
24
17
  module_function
25
18
 
19
+ def root
20
+ File.expand_path(File.join(__dir__, '..'))
21
+ end
22
+
26
23
  def configuration
27
24
  @configuration ||= Configuration.new
28
25
  end
29
26
 
30
- def connection
31
- @connection
27
+ def configure
28
+ yield(configuration)
32
29
  end
33
30
 
31
+ # Callback for when the token is refreshed.
34
32
  def on_refresh(&block)
35
33
  @connection.on_refresh_cb = block
36
34
  end
@@ -38,24 +36,24 @@ module ZohoHub
38
36
  def setup_connection(params = {})
39
37
  raise "ERROR: #{params[:error]}" if params[:error]
40
38
 
41
- connection_params = params.slice(:access_token, :expires_in, :api_domain, :refresh_token)
39
+ connection_params = params.dup.slice(:access_token, :expires_in, :api_domain, :refresh_token)
42
40
 
43
- @connection = Connection.new(**connection_params)
41
+ @connection = Connection.new(connection_params)
42
+ end
43
+
44
+ def connection
45
+ @connection
44
46
  end
45
47
 
46
48
  def refresh_token?
47
- return false unless connection.present?
49
+ return false unless connection
48
50
 
49
51
  connection.refresh_token?
50
52
  end
51
53
 
52
54
  def access_token?
53
- return false unless connection.present?
55
+ return false unless connection
54
56
 
55
57
  connection.access_token?
56
58
  end
57
-
58
- def configure
59
- yield(configuration)
60
- end
61
59
  end