zoho_hub 0.1.29 → 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.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/.rspec +1 -0
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -1
- data/.travis.yml +5 -2
- data/README.md +91 -7
- data/bin/console +5 -6
- data/bin/read +44 -0
- data/bin/setup +0 -2
- data/bin/zoho_hub +62 -0
- data/cache/.git_keep +0 -0
- data/lib/zoho_hub/auth.rb +37 -47
- data/lib/zoho_hub/base_record.rb +122 -0
- data/lib/zoho_hub/configuration.rb +3 -4
- data/lib/zoho_hub/connection.rb +10 -17
- data/lib/zoho_hub/{records → deprecated_and_only_for_reference_records}/account.rb +0 -0
- data/lib/zoho_hub/{records → deprecated_and_only_for_reference_records}/campaign.rb +0 -0
- data/lib/zoho_hub/{records → deprecated_and_only_for_reference_records}/contact.rb +2 -4
- data/lib/zoho_hub/deprecated_and_only_for_reference_records/funder.rb +9 -0
- data/lib/zoho_hub/{records → deprecated_and_only_for_reference_records}/potential.rb +1 -14
- data/lib/zoho_hub/deprecated_and_only_for_reference_records/product.rb +9 -0
- data/lib/zoho_hub/deprecated_and_only_for_reference_records/quote.rb +34 -0
- data/lib/zoho_hub/errors.rb +0 -3
- data/lib/zoho_hub/module_builder.rb +61 -0
- data/lib/zoho_hub/oauth_callback_server.rb +26 -0
- data/lib/zoho_hub/response.rb +1 -7
- data/lib/zoho_hub/settings/field.rb +33 -0
- data/lib/zoho_hub/settings/module.rb +49 -0
- data/lib/zoho_hub/string_utils.rb +34 -0
- data/lib/zoho_hub/version.rb +1 -1
- data/lib/zoho_hub/views/variables.erb +72 -0
- data/lib/zoho_hub/with_attributes.rb +74 -0
- data/lib/zoho_hub/with_connection.rb +36 -0
- data/lib/zoho_hub.rb +20 -21
- data/zoho_hub.gemspec +21 -17
- metadata +104 -80
- data/lib/zoho_hub/records/adverse_criteria.rb +0 -43
- data/lib/zoho_hub/records/attachment.rb +0 -104
- data/lib/zoho_hub/records/base_record.rb +0 -189
- data/lib/zoho_hub/records/credit_score.rb +0 -36
- data/lib/zoho_hub/records/product.rb +0 -35
- data/lib/zoho_hub/records/quote.rb +0 -42
- data/lib/zoho_hub/records/vendor.rb +0 -34
@@ -4,8 +4,8 @@ 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
|
8
|
-
attributes :account_id, :owner_id, :campaign_id, :status, :campaign_detail
|
7
|
+
attributes :id, :email, :salutation, :first_name, :mobile, :role, :last_name
|
8
|
+
attributes :account_id, :owner_id, :campaign_id, :status, :campaign_detail
|
9
9
|
|
10
10
|
attribute_translation(
|
11
11
|
id: :id,
|
@@ -30,7 +30,6 @@ module ZohoHub
|
|
30
30
|
@account_id ||= params.dig(:Account_Name, :id)
|
31
31
|
@owner_id ||= params.dig(:Owner, :id)
|
32
32
|
@campaign_id ||= params.dig(:Campaign_Lookup, :id)
|
33
|
-
@vendor_id ||= params.dig(:Vendor_Name, :id)
|
34
33
|
end
|
35
34
|
|
36
35
|
def to_params
|
@@ -39,7 +38,6 @@ module ZohoHub
|
|
39
38
|
params[:Account_Name] = { id: @account_id } if @account_id
|
40
39
|
params[:Owner] = { id: @owner_id } if @owner_id
|
41
40
|
params[:Campaign_Lookup] = { id: @campaign_id } if @campaign_id
|
42
|
-
params[:Vendor_Name] = { id: @vendor_id } if @vendor_id
|
43
41
|
|
44
42
|
params
|
45
43
|
end
|
@@ -9,11 +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
|
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
12
|
|
18
13
|
DEFAULTS = {
|
19
14
|
currency: 'GBP',
|
@@ -28,13 +23,7 @@ module ZohoHub
|
|
28
23
|
code: :Project_Ref_No,
|
29
24
|
description: :Project_description,
|
30
25
|
employee_count: :Number_of_Employees,
|
31
|
-
use_proceeds: :use_proceeds
|
32
|
-
vat_registration: :Pick_List_15,
|
33
|
-
live_ccjs: :Live_CCJs,
|
34
|
-
satisfied_ccjs: :Satisfied_CCJs,
|
35
|
-
published_all_of_market: :Published_to_All_of_Market,
|
36
|
-
state: :State1,
|
37
|
-
number_of_connections: :Number_of_Connections
|
26
|
+
use_proceeds: :use_proceeds
|
38
27
|
)
|
39
28
|
|
40
29
|
def initialize(params)
|
@@ -48,7 +37,6 @@ module ZohoHub
|
|
48
37
|
@account_id ||= params.dig(:Account_Name, :id)
|
49
38
|
@contact_id ||= params.dig(:Contact_Name, :id)
|
50
39
|
@campaign_id ||= params.dig(:Campaign_Source, :id)
|
51
|
-
@accountant_id ||= params.dig(:Accountant_Name, :id)
|
52
40
|
end
|
53
41
|
|
54
42
|
def to_params
|
@@ -57,7 +45,6 @@ module ZohoHub
|
|
57
45
|
params[:Campaign_Source] = { id: @campaign_id } if @campaign_id
|
58
46
|
params[:Account_Name] = { id: @account_id } if @account_id
|
59
47
|
params[:Contact_Name] = { id: @contact_id } if @contact_id
|
60
|
-
params[:Accountant_Name] = { id: @accountant_id } if @accountant_id
|
61
48
|
|
62
49
|
params
|
63
50
|
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
|
data/lib/zoho_hub/errors.rb
CHANGED
@@ -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
|
data/lib/zoho_hub/response.rb
CHANGED
@@ -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
|
@@ -43,10 +41,6 @@ module ZohoHub
|
|
43
41
|
def msg
|
44
42
|
msg = data[:message]
|
45
43
|
|
46
|
-
if data.dig(:code) == 'INVALID_DATA'
|
47
|
-
msg << ", error in #{data.dig(:details, :api_name)}"
|
48
|
-
end
|
49
|
-
|
50
44
|
if data.dig(:details, :expected_data_type)
|
51
45
|
expected = data.dig(:details, :expected_data_type)
|
52
46
|
field = data.dig(:details, :api_name)
|
@@ -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
|
data/lib/zoho_hub/version.rb
CHANGED
@@ -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,35 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
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/
|
12
|
-
require 'zoho_hub/
|
13
|
-
require 'zoho_hub/
|
14
|
-
|
15
|
-
require '
|
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'
|
10
|
+
require 'zoho_hub/base_record'
|
11
|
+
require 'zoho_hub/settings/module'
|
12
|
+
require 'zoho_hub/module_builder'
|
13
|
+
|
14
|
+
require 'multi_json'
|
21
15
|
|
22
16
|
module ZohoHub
|
23
17
|
module_function
|
24
18
|
|
19
|
+
def root
|
20
|
+
File.expand_path(File.join(__dir__, '..'))
|
21
|
+
end
|
22
|
+
|
25
23
|
def configuration
|
26
24
|
@configuration ||= Configuration.new
|
27
25
|
end
|
28
26
|
|
29
|
-
def
|
30
|
-
|
27
|
+
def configure
|
28
|
+
yield(configuration)
|
31
29
|
end
|
32
30
|
|
31
|
+
# Callback for when the token is refreshed.
|
33
32
|
def on_refresh(&block)
|
34
33
|
@connection.on_refresh_cb = block
|
35
34
|
end
|
@@ -37,24 +36,24 @@ module ZohoHub
|
|
37
36
|
def setup_connection(params = {})
|
38
37
|
raise "ERROR: #{params[:error]}" if params[:error]
|
39
38
|
|
40
|
-
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)
|
41
40
|
|
42
41
|
@connection = Connection.new(connection_params)
|
43
42
|
end
|
44
43
|
|
44
|
+
def connection
|
45
|
+
@connection
|
46
|
+
end
|
47
|
+
|
45
48
|
def refresh_token?
|
46
|
-
return false unless connection
|
49
|
+
return false unless connection
|
47
50
|
|
48
51
|
connection.refresh_token?
|
49
52
|
end
|
50
53
|
|
51
54
|
def access_token?
|
52
|
-
return false unless connection
|
55
|
+
return false unless connection
|
53
56
|
|
54
57
|
connection.access_token?
|
55
58
|
end
|
56
|
-
|
57
|
-
def configure
|
58
|
-
yield(configuration)
|
59
|
-
end
|
60
59
|
end
|
data/zoho_hub.gemspec
CHANGED
@@ -19,23 +19,27 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
20
|
f.match(%r{^(test|spec|features)/})
|
21
21
|
end
|
22
|
-
spec.bindir = '
|
23
|
-
spec.executables =
|
22
|
+
spec.bindir = 'bin'
|
23
|
+
spec.executables = ['zoho_hub']
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
spec.
|
27
|
-
|
28
|
-
spec.add_dependency '
|
29
|
-
spec.add_dependency '
|
30
|
-
spec.add_dependency '
|
31
|
-
spec.add_dependency '
|
32
|
-
|
33
|
-
spec.
|
34
|
-
spec.
|
35
|
-
spec.
|
36
|
-
|
37
|
-
spec.add_development_dependency '
|
38
|
-
spec.add_development_dependency '
|
39
|
-
spec.add_development_dependency '
|
40
|
-
spec.add_development_dependency '
|
26
|
+
spec.required_ruby_version = '>= 2.1.0'
|
27
|
+
|
28
|
+
spec.add_dependency 'addressable'
|
29
|
+
spec.add_dependency 'backports' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3.0')
|
30
|
+
spec.add_dependency 'faraday'
|
31
|
+
spec.add_dependency 'faraday_middleware'
|
32
|
+
spec.add_dependency 'launchy'
|
33
|
+
spec.add_dependency 'multi_json'
|
34
|
+
spec.add_dependency 'rainbow'
|
35
|
+
spec.add_dependency 'sinatra'
|
36
|
+
|
37
|
+
spec.add_development_dependency 'bundler'
|
38
|
+
spec.add_development_dependency 'dotenv'
|
39
|
+
spec.add_development_dependency 'pry-byebug'
|
40
|
+
spec.add_development_dependency 'rake'
|
41
|
+
spec.add_development_dependency 'rspec'
|
42
|
+
spec.add_development_dependency 'rubocop'
|
43
|
+
spec.add_development_dependency 'rubocop-rspec'
|
44
|
+
spec.add_development_dependency 'simplecov'
|
41
45
|
end
|