zoho_hub 0.1.19 → 0.1.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/zoho_hub.rb +1 -0
- data/lib/zoho_hub/connection.rb +13 -6
- data/lib/zoho_hub/errors.rb +3 -0
- data/lib/zoho_hub/records/attachment.rb +104 -0
- data/lib/zoho_hub/records/base_record.rb +16 -12
- data/lib/zoho_hub/records/potential.rb +7 -1
- data/lib/zoho_hub/version.rb +1 -1
- data/zoho_hub.gemspec +1 -1
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebb43093884ef3e4b2590191125e4b21084cf470cae45bdd57bfa3796f62ae2d
|
4
|
+
data.tar.gz: 168f9f71eba69af19fee9b086d7b39d5d267f262125f669a7aec118816fbc5b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a7c32dc1b4e7286884a5d06febe06d211e6784f61cff3688196029480b5e8e056aa5ae90b2976f95919c2c937d769cdb529c8e234a8db4be37bf3ebb8e50b6f
|
7
|
+
data.tar.gz: 37763d48728fa49b24f9aec36d3866717140292d5e1f59c02c18e74214f5ae5644474cfa54b93f18180a9385f9a4e693ee245eb2eb30153c39959798cae2a47f
|
data/.gitignore
CHANGED
data/lib/zoho_hub.rb
CHANGED
data/lib/zoho_hub/connection.rb
CHANGED
@@ -26,24 +26,30 @@ module ZohoHub
|
|
26
26
|
@refresh_token ||= refresh_token # do not overwrite if it's already set
|
27
27
|
end
|
28
28
|
|
29
|
-
def get(path, params = {})
|
29
|
+
def get(path, params = {}, &block)
|
30
30
|
log "GET #{path} with #{params}"
|
31
31
|
|
32
|
-
response = with_refresh
|
32
|
+
response = with_refresh do
|
33
|
+
adapter(&block).get(path, params)
|
34
|
+
end
|
33
35
|
response.body
|
34
36
|
end
|
35
37
|
|
36
|
-
def post(path, params = {})
|
38
|
+
def post(path, params = {}, &block)
|
37
39
|
log "POST #{path} with #{params}"
|
38
40
|
|
39
|
-
response = with_refresh
|
41
|
+
response = with_refresh do
|
42
|
+
adapter(&block).post(path, params)
|
43
|
+
end
|
40
44
|
response.body
|
41
45
|
end
|
42
46
|
|
43
|
-
def put(path, params = {})
|
47
|
+
def put(path, params = {}, &block)
|
44
48
|
log "PUT #{path} with #{params}"
|
45
49
|
|
46
|
-
response = with_refresh
|
50
|
+
response = with_refresh do
|
51
|
+
adapter(&block).put(path, params)
|
52
|
+
end
|
47
53
|
response.body
|
48
54
|
end
|
49
55
|
|
@@ -98,6 +104,7 @@ module ZohoHub
|
|
98
104
|
Faraday.new(url: base_url) do |conn|
|
99
105
|
conn.headers = authorization_header if access_token?
|
100
106
|
conn.use FaradayMiddleware::ParseJson
|
107
|
+
yield conn if block_given?
|
101
108
|
conn.response :json, parser_options: { symbolize_names: true }
|
102
109
|
conn.response :logger if ZohoHub.configuration.debug?
|
103
110
|
conn.adapter Faraday.default_adapter
|
data/lib/zoho_hub/errors.rb
CHANGED
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zoho_hub/records/base_record'
|
4
|
+
|
5
|
+
module ZohoHub
|
6
|
+
class Attachment < BaseRecord
|
7
|
+
attributes :id, :parent_id, :file_name, :link_url, :type, :created_time
|
8
|
+
attributes :parent, :attachment_url
|
9
|
+
|
10
|
+
# The translation from attribute name to the JSON field on Zoho. The default behaviour will be
|
11
|
+
# to Camel_Case the attribute so on this list we should only have exceptions to this rule.
|
12
|
+
attribute_translation(
|
13
|
+
id: :id,
|
14
|
+
link_url: :'$link_url',
|
15
|
+
type: :'$type'
|
16
|
+
)
|
17
|
+
|
18
|
+
def initialize(params)
|
19
|
+
attributes.each do |attr|
|
20
|
+
zoho_key = attr_to_zoho_key(attr)
|
21
|
+
|
22
|
+
send("#{attr}=", params[zoho_key] || params[attr])
|
23
|
+
end
|
24
|
+
|
25
|
+
@parent_id = params.dig(:Parent_Id, :id)
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def exists?(id, parent:)
|
30
|
+
!find(id, parent: parent).nil?
|
31
|
+
rescue RecordNotFound
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def find(id, parent:)
|
36
|
+
body = get(File.join(request_path, id.to_s), parent: parent)
|
37
|
+
response = build_response(body)
|
38
|
+
|
39
|
+
if response.empty?
|
40
|
+
raise RecordNotFound, "Couldn't find #{request_path.singularize} with 'id'=#{id}"
|
41
|
+
end
|
42
|
+
|
43
|
+
new(response.data)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get(path, parent:, **params)
|
47
|
+
# remove /search added by where method
|
48
|
+
path = path.sub('/search', '')
|
49
|
+
ZohoHub.connection.get(parent_module_path(path, parent), params)
|
50
|
+
end
|
51
|
+
|
52
|
+
def post(path, parent:, **params)
|
53
|
+
ZohoHub.connection.post(parent_module_path(path, parent), params) do |conn|
|
54
|
+
conn.request :multipart
|
55
|
+
conn.request :url_encoded
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def put(_path, _params = {})
|
60
|
+
raise NotImplementedError
|
61
|
+
end
|
62
|
+
|
63
|
+
def parent_module_path(path, parent)
|
64
|
+
File.join(
|
65
|
+
parent.class.request_path,
|
66
|
+
parent.id,
|
67
|
+
path
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def post(path, _params = {})
|
73
|
+
self.class.post(path, parent: parent, **to_params)
|
74
|
+
end
|
75
|
+
|
76
|
+
def put(_path, _params = {})
|
77
|
+
raise NotImplementedError
|
78
|
+
end
|
79
|
+
|
80
|
+
def save(*)
|
81
|
+
super
|
82
|
+
rescue => e
|
83
|
+
if e.message.include?('Attachment link already exists')
|
84
|
+
raise AttachmentLinkTakenError, e.message
|
85
|
+
else
|
86
|
+
raise e
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_params
|
91
|
+
{ attachmentUrl: attachment_url }
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def to_input(**)
|
97
|
+
to_params
|
98
|
+
end
|
99
|
+
|
100
|
+
def parent_module_path(path)
|
101
|
+
self.class.parent_module_path(path, parent)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -49,7 +49,7 @@ module ZohoHub
|
|
49
49
|
|
50
50
|
response = get(path, params)
|
51
51
|
|
52
|
-
data = response.nil? ? [] : response
|
52
|
+
data = response.nil? ? [] : response.fetch(:data, [])
|
53
53
|
|
54
54
|
data.map { |info| new(info) }
|
55
55
|
end
|
@@ -75,16 +75,16 @@ module ZohoHub
|
|
75
75
|
data.map { |info| new(info) }
|
76
76
|
end
|
77
77
|
|
78
|
-
def get(path, params = {})
|
79
|
-
ZohoHub.connection.get(path, params)
|
78
|
+
def get(path, params = {}, &block)
|
79
|
+
ZohoHub.connection.get(path, params, &block)
|
80
80
|
end
|
81
81
|
|
82
|
-
def post(path, params = {})
|
83
|
-
ZohoHub.connection.post(path, params.to_json)
|
82
|
+
def post(path, params = {}, &block)
|
83
|
+
ZohoHub.connection.post(path, params.to_json, &block)
|
84
84
|
end
|
85
85
|
|
86
|
-
def put(path, params = {})
|
87
|
-
ZohoHub.connection.put(path, params.to_json)
|
86
|
+
def put(path, params = {}, &block)
|
87
|
+
ZohoHub.connection.put(path, params.to_json, &block)
|
88
88
|
end
|
89
89
|
|
90
90
|
def exists?(id)
|
@@ -124,14 +124,11 @@ module ZohoHub
|
|
124
124
|
# Save the record to Zoho
|
125
125
|
# trigger: ['workflow', 'approval', 'blueprint']
|
126
126
|
def save(trigger:)
|
127
|
-
json = { data: [to_params] }
|
128
|
-
json[:trigger] = Array(trigger) if trigger
|
129
|
-
|
130
127
|
body = if new_record? # create new record
|
131
|
-
post(self.class.request_path,
|
128
|
+
post(self.class.request_path, to_input(trigger: trigger))
|
132
129
|
else # update existing record
|
133
130
|
path = File.join(self.class.request_path, id)
|
134
|
-
put(path,
|
131
|
+
put(path, to_input(trigger: trigger))
|
135
132
|
end
|
136
133
|
|
137
134
|
response = build_response(body)
|
@@ -144,6 +141,13 @@ module ZohoHub
|
|
144
141
|
response.data
|
145
142
|
end
|
146
143
|
|
144
|
+
def to_input(trigger:)
|
145
|
+
json = { data: [to_params] }
|
146
|
+
json[:trigger] = Array(trigger) if trigger
|
147
|
+
|
148
|
+
json
|
149
|
+
end
|
150
|
+
|
147
151
|
def new_record?
|
148
152
|
!id.present?
|
149
153
|
end
|
@@ -9,6 +9,9 @@ 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
|
12
15
|
|
13
16
|
DEFAULTS = {
|
14
17
|
currency: 'GBP',
|
@@ -23,7 +26,8 @@ module ZohoHub
|
|
23
26
|
code: :Project_Ref_No,
|
24
27
|
description: :Project_description,
|
25
28
|
employee_count: :Number_of_Employees,
|
26
|
-
use_proceeds: :use_proceeds
|
29
|
+
use_proceeds: :use_proceeds,
|
30
|
+
vat_registration: :Pick_List_15
|
27
31
|
)
|
28
32
|
|
29
33
|
def initialize(params)
|
@@ -37,6 +41,7 @@ module ZohoHub
|
|
37
41
|
@account_id ||= params.dig(:Account_Name, :id)
|
38
42
|
@contact_id ||= params.dig(:Contact_Name, :id)
|
39
43
|
@campaign_id ||= params.dig(:Campaign_Source, :id)
|
44
|
+
@accountant_id ||= params.dig(:Accountant_Name, :id)
|
40
45
|
end
|
41
46
|
|
42
47
|
def to_params
|
@@ -45,6 +50,7 @@ module ZohoHub
|
|
45
50
|
params[:Campaign_Source] = { id: @campaign_id } if @campaign_id
|
46
51
|
params[:Account_Name] = { id: @account_id } if @account_id
|
47
52
|
params[:Contact_Name] = { id: @contact_id } if @contact_id
|
53
|
+
params[:Accountant_Name] = { id: @accountant_id } if @accountant_id
|
48
54
|
|
49
55
|
params
|
50
56
|
end
|
data/lib/zoho_hub/version.rb
CHANGED
data/zoho_hub.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
spec.add_dependency 'activesupport', '~> 5
|
26
|
+
spec.add_dependency 'activesupport', '~> 5'
|
27
27
|
spec.add_dependency 'addressable', '~> 2.5'
|
28
28
|
spec.add_dependency 'faraday', '~> 0.15'
|
29
29
|
spec.add_dependency 'faraday_middleware', '~> 0.12'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zoho_hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Otero
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5
|
19
|
+
version: '5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '5
|
26
|
+
version: '5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: addressable
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -230,6 +230,7 @@ files:
|
|
230
230
|
- lib/zoho_hub/connection.rb
|
231
231
|
- lib/zoho_hub/errors.rb
|
232
232
|
- lib/zoho_hub/records/account.rb
|
233
|
+
- lib/zoho_hub/records/attachment.rb
|
233
234
|
- lib/zoho_hub/records/base_record.rb
|
234
235
|
- lib/zoho_hub/records/campaign.rb
|
235
236
|
- lib/zoho_hub/records/contact.rb
|
@@ -244,7 +245,7 @@ homepage: https://github.com/rikas/zoho_hub
|
|
244
245
|
licenses:
|
245
246
|
- MIT
|
246
247
|
metadata: {}
|
247
|
-
post_install_message:
|
248
|
+
post_install_message:
|
248
249
|
rdoc_options: []
|
249
250
|
require_paths:
|
250
251
|
- lib
|
@@ -259,8 +260,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
260
|
- !ruby/object:Gem::Version
|
260
261
|
version: '0'
|
261
262
|
requirements: []
|
262
|
-
|
263
|
-
|
263
|
+
rubyforge_project:
|
264
|
+
rubygems_version: 2.7.6
|
265
|
+
signing_key:
|
264
266
|
specification_version: 4
|
265
267
|
summary: Simple gem to connect to Zoho CRM API V2
|
266
268
|
test_files: []
|