zoho_hub 0.1.20 → 0.1.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +15 -11
- data/lib/zoho_hub/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bef57cd4ee9e81ead51f5bffec15c05428ece527014bf0d1cc8b68e1674f1e4
|
4
|
+
data.tar.gz: 1821d02482af55ee1e8f646372b2ee3d502a2aefe7320d7cffae25c70483894f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1169d827f96c290e368b0cb79a5390ef670eb939f94fc14eee26f5d678f25c5c03bcaa827354dce5b34a5961406a5482a72777a2b496a0619363553b094cc40
|
7
|
+
data.tar.gz: 22d127612237d82e84c79aa9f8602df456bfd4a06d3e1ff7a3b469242aca12974b15e8e924bf983910746d3324411fa230db9306e4af0e27c69665f00533e484
|
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
|
@@ -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
|
data/lib/zoho_hub/version.rb
CHANGED
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.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Otero
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-08 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
|