zoho_hub 0.1.18 → 0.1.23

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84262876f36fb21c0f0cb89d56d8dd531fef6828d72f54f38463861964cb5366
4
- data.tar.gz: 494f4ced565252a8ee0cd04cfc982cf53c1bcaf2468227f9919ab24ee24856a2
3
+ metadata.gz: 326c1af1960621d802fc5d5e107402fa23045503b9b9b4fe3de22ba172b3a1ad
4
+ data.tar.gz: a5bfe6be91c71486af9cc75425167294d2d67098de39753a5da88308e1f26368
5
5
  SHA512:
6
- metadata.gz: 2196186030ca801f3ef0a9c3df47418cefab10b90a01ea3a477c4e411161e4adeea38a11428cd1d418af9039780604e5a8f53f8e286bb545a1dc23a6e99b7912
7
- data.tar.gz: 582a600fb2751d0ee756b97f88cfe653643a6d37be0208564ba5b6b6d3c2e49ea76bbd3afdd074ca29181b485058b3b46675dbdd181ed73f0a134daa359270d4
6
+ metadata.gz: b91c01210a1be51bb5231cf033db3d503f61d4132ea9c189bfa5aad8a97f79cd53aebbe0e5c8f13a17522667ca728080cf085c880e3da738da59fdb218b0fa4d
7
+ data.tar.gz: 95256c0bf960cc1812e069ea8627a1034a9be10d90c57917b69fd1ba0849bb7faa0cfc1e37f9e6e1421172b7bf9017ce65c35b3204d99dbe7b250307d3c002d3
@@ -15,6 +15,7 @@ require 'zoho_hub/records/account'
15
15
  require 'zoho_hub/records/quote'
16
16
  require 'zoho_hub/records/vendor'
17
17
  require 'zoho_hub/records/product'
18
+ require 'zoho_hub/records/attachment'
18
19
 
19
20
  module ZohoHub
20
21
  module_function
@@ -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 { adapter.get(path, params) }
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 { adapter.post(path, params) }
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 { adapter.put(path, params) }
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
@@ -12,4 +12,7 @@ module ZohoHub
12
12
 
13
13
  class ZohoAPIError < StandardError
14
14
  end
15
+
16
+ class AttachmentLinkTakenError < StandardError
17
+ end
15
18
  end
@@ -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[:data]
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, json)
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, json)
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
@@ -4,7 +4,7 @@ require 'zoho_hub/records/base_record'
4
4
 
5
5
  module ZohoHub
6
6
  class Quote < BaseRecord
7
- attributes :id, :stage, :subject, :potential_id, :owner_id, :product_id, :account_id
7
+ attributes :id, :stage, :subject, :potential_id, :owner_id, :product_id, :account_id, :extra_info
8
8
 
9
9
  attribute_translation(
10
10
  id: :id,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZohoHub
4
- VERSION = '0.1.18'
4
+ VERSION = '0.1.23'
5
5
  end
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.18
4
+ version: 0.1.23
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: 2019-04-03 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -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
- rubygems_version: 3.0.2
263
- signing_key:
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: []