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.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/.rspec +1 -0
- data/.rubocop.yml +5 -2
- data/.ruby-version +1 -1
- data/.travis.yml +5 -2
- data/README.md +91 -7
- data/bin/console +6 -7
- 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 +1 -1
- 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 +3 -9
- 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 -21
- 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 -4
- 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 +21 -23
- data/zoho_hub.gemspec +14 -10
- metadata +80 -57
- 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 -33
- data/lib/zoho_hub/records/quote.rb +0 -44
- data/lib/zoho_hub/records/sms_message.rb +0 -32
- data/lib/zoho_hub/records/vendor.rb +0 -34
data/zoho_hub.gemspec
CHANGED
@@ -19,20 +19,24 @@ 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 '
|
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'
|
32
36
|
|
33
37
|
spec.add_development_dependency 'bundler'
|
34
|
-
spec.add_development_dependency 'dotenv'
|
35
|
-
spec.add_development_dependency 'pry-byebug'
|
38
|
+
spec.add_development_dependency 'dotenv'
|
39
|
+
spec.add_development_dependency 'pry-byebug'
|
36
40
|
spec.add_development_dependency 'rake'
|
37
41
|
spec.add_development_dependency 'rspec'
|
38
42
|
spec.add_development_dependency 'rubocop'
|
metadata
CHANGED
@@ -1,99 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zoho_hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Otero
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: addressable
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: faraday_middleware
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: launchy
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: multi_json
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rainbow
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sinatra
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
103
|
+
version: '0'
|
90
104
|
type: :runtime
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - "
|
108
|
+
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: bundler
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,30 +126,30 @@ dependencies:
|
|
112
126
|
name: dotenv
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
|
-
- - "
|
129
|
+
- - ">="
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
131
|
+
version: '0'
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
|
-
- - "
|
136
|
+
- - ">="
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: pry-byebug
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
|
-
- - "
|
143
|
+
- - ">="
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
145
|
+
version: '0'
|
132
146
|
type: :development
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
|
-
- - "
|
150
|
+
- - ">="
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: rake
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -209,7 +223,8 @@ dependencies:
|
|
209
223
|
description: Simple gem to connect to Zoho CRM API V2
|
210
224
|
email:
|
211
225
|
- oterosantos@gmail.com
|
212
|
-
executables:
|
226
|
+
executables:
|
227
|
+
- zoho_hub
|
213
228
|
extensions: []
|
214
229
|
extra_rdoc_files: []
|
215
230
|
files:
|
@@ -223,32 +238,39 @@ files:
|
|
223
238
|
- README.md
|
224
239
|
- Rakefile
|
225
240
|
- bin/console
|
241
|
+
- bin/read
|
226
242
|
- bin/setup
|
243
|
+
- bin/zoho_hub
|
244
|
+
- cache/.git_keep
|
227
245
|
- lib/zoho_hub.rb
|
228
246
|
- lib/zoho_hub/auth.rb
|
247
|
+
- lib/zoho_hub/base_record.rb
|
229
248
|
- lib/zoho_hub/configuration.rb
|
230
249
|
- lib/zoho_hub/connection.rb
|
250
|
+
- lib/zoho_hub/deprecated_and_only_for_reference_records/account.rb
|
251
|
+
- lib/zoho_hub/deprecated_and_only_for_reference_records/campaign.rb
|
252
|
+
- lib/zoho_hub/deprecated_and_only_for_reference_records/contact.rb
|
253
|
+
- lib/zoho_hub/deprecated_and_only_for_reference_records/funder.rb
|
254
|
+
- lib/zoho_hub/deprecated_and_only_for_reference_records/potential.rb
|
255
|
+
- lib/zoho_hub/deprecated_and_only_for_reference_records/product.rb
|
256
|
+
- lib/zoho_hub/deprecated_and_only_for_reference_records/quote.rb
|
231
257
|
- lib/zoho_hub/errors.rb
|
232
|
-
- lib/zoho_hub/
|
233
|
-
- lib/zoho_hub/
|
234
|
-
- lib/zoho_hub/records/attachment.rb
|
235
|
-
- lib/zoho_hub/records/base_record.rb
|
236
|
-
- lib/zoho_hub/records/campaign.rb
|
237
|
-
- lib/zoho_hub/records/contact.rb
|
238
|
-
- lib/zoho_hub/records/credit_score.rb
|
239
|
-
- lib/zoho_hub/records/potential.rb
|
240
|
-
- lib/zoho_hub/records/product.rb
|
241
|
-
- lib/zoho_hub/records/quote.rb
|
242
|
-
- lib/zoho_hub/records/sms_message.rb
|
243
|
-
- lib/zoho_hub/records/vendor.rb
|
258
|
+
- lib/zoho_hub/module_builder.rb
|
259
|
+
- lib/zoho_hub/oauth_callback_server.rb
|
244
260
|
- lib/zoho_hub/response.rb
|
261
|
+
- lib/zoho_hub/settings/field.rb
|
262
|
+
- lib/zoho_hub/settings/module.rb
|
263
|
+
- lib/zoho_hub/string_utils.rb
|
245
264
|
- lib/zoho_hub/version.rb
|
265
|
+
- lib/zoho_hub/views/variables.erb
|
266
|
+
- lib/zoho_hub/with_attributes.rb
|
267
|
+
- lib/zoho_hub/with_connection.rb
|
246
268
|
- zoho_hub.gemspec
|
247
269
|
homepage: https://github.com/rikas/zoho_hub
|
248
270
|
licenses:
|
249
271
|
- MIT
|
250
272
|
metadata: {}
|
251
|
-
post_install_message:
|
273
|
+
post_install_message:
|
252
274
|
rdoc_options: []
|
253
275
|
require_paths:
|
254
276
|
- lib
|
@@ -256,15 +278,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
256
278
|
requirements:
|
257
279
|
- - ">="
|
258
280
|
- !ruby/object:Gem::Version
|
259
|
-
version:
|
281
|
+
version: 2.1.0
|
260
282
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
261
283
|
requirements:
|
262
284
|
- - ">="
|
263
285
|
- !ruby/object:Gem::Version
|
264
286
|
version: '0'
|
265
287
|
requirements: []
|
266
|
-
|
267
|
-
|
288
|
+
rubyforge_project:
|
289
|
+
rubygems_version: 2.7.6
|
290
|
+
signing_key:
|
268
291
|
specification_version: 4
|
269
292
|
summary: Simple gem to connect to Zoho CRM API V2
|
270
293
|
test_files: []
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'zoho_hub/records/base_record'
|
4
|
-
|
5
|
-
module ZohoHub
|
6
|
-
class AdverseCriteria < BaseRecord
|
7
|
-
request_path 'Adverse_Criteria'
|
8
|
-
|
9
|
-
attributes :id, :account_id, :date_decided, :date_paid
|
10
|
-
attributes :status, :amount, :currency, :court
|
11
|
-
attributes :case_reference, :entity_details, :data_source
|
12
|
-
|
13
|
-
attribute_translation(
|
14
|
-
id: :id,
|
15
|
-
case_reference: :Name,
|
16
|
-
status: :CCJ_Status,
|
17
|
-
amount: :CCJ_Amount,
|
18
|
-
data_source: :CCJ_Data_Source,
|
19
|
-
date_paid: :Date_paid,
|
20
|
-
date_decided: :Date_decided,
|
21
|
-
entity_details: :Entity_details
|
22
|
-
)
|
23
|
-
|
24
|
-
def initialize(params)
|
25
|
-
attributes.each do |attr|
|
26
|
-
zoho_key = attr_to_zoho_key(attr)
|
27
|
-
|
28
|
-
send("#{attr}=", params[zoho_key] || params[attr])
|
29
|
-
end
|
30
|
-
|
31
|
-
# Setup values as they come from the Zoho API if needed
|
32
|
-
@account_id ||= params.dig(:Account, :id)
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_params
|
36
|
-
params = super
|
37
|
-
|
38
|
-
params[:Account] = { id: @account_id } if @account_id
|
39
|
-
|
40
|
-
params
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,104 +0,0 @@
|
|
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
|
@@ -1,189 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'zoho_hub/response'
|
4
|
-
|
5
|
-
module ZohoHub
|
6
|
-
class BaseRecord
|
7
|
-
class << self
|
8
|
-
def request_path(name = nil)
|
9
|
-
@request_path = name if name
|
10
|
-
@request_path ||= to_s.demodulize.pluralize
|
11
|
-
@request_path
|
12
|
-
end
|
13
|
-
|
14
|
-
def attributes(*attributes)
|
15
|
-
@attributes ||= []
|
16
|
-
|
17
|
-
return @attributes unless attributes
|
18
|
-
|
19
|
-
attr_accessor(*attributes)
|
20
|
-
|
21
|
-
@attributes += attributes
|
22
|
-
end
|
23
|
-
|
24
|
-
def attribute_translation(translation = nil)
|
25
|
-
@attribute_translation ||= {}
|
26
|
-
|
27
|
-
return @attribute_translation unless translation
|
28
|
-
|
29
|
-
@attribute_translation = translation
|
30
|
-
end
|
31
|
-
|
32
|
-
def zoho_key_translation
|
33
|
-
@attribute_translation.to_a.map(&:rotate).to_h
|
34
|
-
end
|
35
|
-
|
36
|
-
def find(id)
|
37
|
-
body = get(File.join(request_path, id.to_s))
|
38
|
-
response = build_response(body)
|
39
|
-
|
40
|
-
if response.empty?
|
41
|
-
raise RecordNotFound, "Couldn't find #{request_path.singularize} with 'id'=#{id}"
|
42
|
-
end
|
43
|
-
|
44
|
-
new(response.data)
|
45
|
-
end
|
46
|
-
|
47
|
-
def where(params)
|
48
|
-
path = File.join(request_path, 'search')
|
49
|
-
|
50
|
-
response = get(path, params)
|
51
|
-
|
52
|
-
data = response.nil? ? [] : response.fetch(:data, [])
|
53
|
-
|
54
|
-
data.map { |info| new(info) }
|
55
|
-
end
|
56
|
-
|
57
|
-
def find_by(params)
|
58
|
-
records = where(params)
|
59
|
-
records.first
|
60
|
-
end
|
61
|
-
|
62
|
-
def create(params)
|
63
|
-
new(params).save
|
64
|
-
end
|
65
|
-
|
66
|
-
def all(options = {})
|
67
|
-
options[:page] ||= 1
|
68
|
-
options[:per_page] ||= 200
|
69
|
-
|
70
|
-
body = get(request_path, options)
|
71
|
-
response = build_response(body)
|
72
|
-
|
73
|
-
data = response.nil? ? [] : response.data
|
74
|
-
|
75
|
-
data.map { |info| new(info) }
|
76
|
-
end
|
77
|
-
|
78
|
-
def get(path, params = {}, &block)
|
79
|
-
ZohoHub.connection.get(path, params, &block)
|
80
|
-
end
|
81
|
-
|
82
|
-
def post(path, params = {}, &block)
|
83
|
-
ZohoHub.connection.post(path, params.to_json, &block)
|
84
|
-
end
|
85
|
-
|
86
|
-
def put(path, params = {}, &block)
|
87
|
-
ZohoHub.connection.put(path, params.to_json, &block)
|
88
|
-
end
|
89
|
-
|
90
|
-
def exists?(id)
|
91
|
-
!find(id).nil?
|
92
|
-
rescue RecordNotFound
|
93
|
-
false
|
94
|
-
end
|
95
|
-
|
96
|
-
alias exist? exists?
|
97
|
-
|
98
|
-
def build_response(body)
|
99
|
-
response = Response.new(body)
|
100
|
-
|
101
|
-
raise InvalidTokenError, response.msg if response.invalid_token?
|
102
|
-
raise RecordInvalid, response.msg if response.invalid_data?
|
103
|
-
|
104
|
-
response
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def attributes
|
109
|
-
self.class.attributes
|
110
|
-
end
|
111
|
-
|
112
|
-
def get(path, params = {})
|
113
|
-
self.class.get(path, params)
|
114
|
-
end
|
115
|
-
|
116
|
-
def post(path, params = {})
|
117
|
-
self.class.post(path, params)
|
118
|
-
end
|
119
|
-
|
120
|
-
def put(path, params = {})
|
121
|
-
self.class.put(path, params)
|
122
|
-
end
|
123
|
-
|
124
|
-
# Save the record to Zoho
|
125
|
-
# trigger: ['workflow', 'approval', 'blueprint']
|
126
|
-
def save(trigger:)
|
127
|
-
body = if new_record? # create new record
|
128
|
-
post(self.class.request_path, to_input(trigger: trigger))
|
129
|
-
else # update existing record
|
130
|
-
path = File.join(self.class.request_path, id)
|
131
|
-
put(path, to_input(trigger: trigger))
|
132
|
-
end
|
133
|
-
|
134
|
-
response = build_response(body)
|
135
|
-
|
136
|
-
id = response.data.dig(:details, :id)
|
137
|
-
|
138
|
-
return id if id
|
139
|
-
|
140
|
-
# Invalid errors
|
141
|
-
response.data
|
142
|
-
end
|
143
|
-
|
144
|
-
def to_input(trigger:)
|
145
|
-
json = { data: [to_params] }
|
146
|
-
json[:trigger] = Array(trigger) if trigger
|
147
|
-
|
148
|
-
json
|
149
|
-
end
|
150
|
-
|
151
|
-
def new_record?
|
152
|
-
!id.present?
|
153
|
-
end
|
154
|
-
|
155
|
-
def to_params
|
156
|
-
params = {}
|
157
|
-
|
158
|
-
attributes.each do |attr|
|
159
|
-
key = attr_to_zoho_key(attr)
|
160
|
-
|
161
|
-
params[key] = send(attr)
|
162
|
-
end
|
163
|
-
|
164
|
-
params
|
165
|
-
end
|
166
|
-
|
167
|
-
def build_response(body)
|
168
|
-
self.class.build_response(body)
|
169
|
-
end
|
170
|
-
|
171
|
-
private
|
172
|
-
|
173
|
-
def attr_to_zoho_key(attr_name)
|
174
|
-
translations = self.class.attribute_translation
|
175
|
-
|
176
|
-
return translations[attr_name.to_sym] if translations.key?(attr_name.to_sym)
|
177
|
-
|
178
|
-
attr_name.to_s.split('_').map(&:capitalize).join('_').to_sym
|
179
|
-
end
|
180
|
-
|
181
|
-
def zoho_key_to_attr(zoho_key)
|
182
|
-
translations = self.class.zoho_key_translation
|
183
|
-
|
184
|
-
return translations[zoho_key.to_sym] if translations.key?(zoho_key.to_sym)
|
185
|
-
|
186
|
-
zoho_key.to_sym
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'zoho_hub/records/base_record'
|
4
|
-
|
5
|
-
module ZohoHub
|
6
|
-
class CreditScore < BaseRecord
|
7
|
-
request_path 'Credit_Scores'
|
8
|
-
|
9
|
-
attributes :id, :account_id, :credit_data_source, :credit_score_band
|
10
|
-
attributes :score_description, :credit_score_number, :credit_limit, :currency
|
11
|
-
|
12
|
-
attribute_translation(
|
13
|
-
id: :id,
|
14
|
-
credit_score_number: :Name
|
15
|
-
)
|
16
|
-
|
17
|
-
def initialize(params)
|
18
|
-
attributes.each do |attr|
|
19
|
-
zoho_key = attr_to_zoho_key(attr)
|
20
|
-
|
21
|
-
send("#{attr}=", params[zoho_key] || params[attr])
|
22
|
-
end
|
23
|
-
|
24
|
-
# Setup values as they come from the Zoho API if needed
|
25
|
-
@account_id ||= params.dig(:Account_Name, :id)
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_params
|
29
|
-
params = super
|
30
|
-
|
31
|
-
params[:Account_Name] = { id: @account_id } if @account_id
|
32
|
-
|
33
|
-
params
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|