zm-ruby-client 2.0.6 → 2.1.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/Gemfile +3 -2
- data/README.md +0 -1
- data/lib/zm/client/base/zimbra_attribute.rb +1 -1
- data/lib/zm/client/base.rb +1 -1
- data/lib/zm/client/connector/rest_account.rb +56 -41
- data/lib/zm/client/connector/soap_base.rb +33 -31
- data/lib/zm/client/folder/folder.rb +0 -5
- data/lib/zm/client/folder/folder_jsns_initializer.rb +2 -0
- data/lib/zm/client/folder/mod_document_folder.rb +3 -3
- data/lib/zm/client/version.rb +2 -2
- data/lib/zm/modules/common/zimbra-attrs.json +19 -2
- data/zm-ruby-client.gemspec +6 -2
- metadata +41 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7e939168149edeb472b2e33930cfbbe97a45d8bd7012a1200df9dfe7c635f47
|
4
|
+
data.tar.gz: 7508c98743481ad485843e3a611efe75d6d5328107e546fbbcabc7ab8fab29ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03ab31a3733a6add8cb01b88297536dcf6203cc29ec875e27cc0914b00357d993d0195597d0fa188c2bddc6e78835358d453538e8e5535e192d69d9d61fb929c
|
7
|
+
data.tar.gz: 22f3dbc7e82d70c4fc8311f36d181e0056d8c2c748a68c730c771053381b792e36802e878612a68d4b03150a50998f639b9c4027890a5453c06169809c2f0099
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -45,7 +45,7 @@ module Zm
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def is_calendarResource_scoped?
|
48
|
-
@is_calendarResource_scoped ||= objects_scope.include?('calendarResource')
|
48
|
+
@is_calendarResource_scoped ||= objects_scope.include?('calendarResource') || objects_scope.include?('account')
|
49
49
|
end
|
50
50
|
|
51
51
|
def is_cos_scoped?
|
data/lib/zm/client/base.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'faraday/multipart'
|
4
|
+
|
3
5
|
module Zm
|
4
6
|
module Client
|
5
7
|
class RestAccountConnector
|
@@ -7,8 +9,15 @@ module Zm
|
|
7
9
|
|
8
10
|
def initialize
|
9
11
|
@verbose = false
|
12
|
+
@timeout = 300
|
13
|
+
|
14
|
+
@ssl_options = {
|
15
|
+
verify: false,
|
16
|
+
verify_hostname: false,
|
17
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE
|
18
|
+
}
|
19
|
+
|
10
20
|
@cookies = nil
|
11
|
-
@follow_location = true
|
12
21
|
end
|
13
22
|
|
14
23
|
def verbose!
|
@@ -19,69 +28,75 @@ module Zm
|
|
19
28
|
@cookies = cookies
|
20
29
|
end
|
21
30
|
|
22
|
-
def download(
|
23
|
-
|
31
|
+
def download(download_url, dest_file_path)
|
32
|
+
url, path = split_url(download_url)
|
33
|
+
|
34
|
+
conn = Faraday.new(**http_options(url)) do |faraday|
|
35
|
+
faraday.response :logger, nil, { headers: true, bodies: true, errors: true } if @verbose
|
36
|
+
end
|
37
|
+
|
38
|
+
response = nil
|
24
39
|
|
25
40
|
File.open(dest_file_path, 'wb') do |f|
|
26
|
-
|
27
|
-
|
28
|
-
|
41
|
+
response = conn.get(path) do |request|
|
42
|
+
request.options.on_data = Proc.new do |chunk, _, _|
|
43
|
+
f.write chunk
|
44
|
+
end
|
29
45
|
end
|
30
|
-
|
31
|
-
curl.perform
|
32
46
|
end
|
33
47
|
|
34
|
-
if
|
48
|
+
if response.status >= 400
|
35
49
|
File.unlink(dest_file_path) if File.exist?(dest_file_path)
|
36
|
-
|
37
|
-
message = "Download failure: #{curl.body_str} (status=#{curl.status})"
|
38
|
-
close_curl(curl)
|
39
|
-
raise RestError, message
|
50
|
+
raise RestError, "Download failure: #{response.body} (status=#{response.status})"
|
40
51
|
end
|
41
|
-
|
42
|
-
dest_file_path
|
43
52
|
end
|
44
53
|
|
45
|
-
def upload(
|
46
|
-
|
54
|
+
def upload(upload_url, src_file_path)
|
55
|
+
url, path = split_url(upload_url)
|
56
|
+
|
57
|
+
conn = Faraday.new(**http_options(url)) do |faraday|
|
58
|
+
faraday.request :multipart
|
59
|
+
faraday.response :logger, nil, { headers: true, bodies: true, errors: true } if @verbose
|
60
|
+
end
|
47
61
|
|
48
|
-
|
62
|
+
payload = { file: Faraday::Multipart::FilePart.new(src_file_path, nil) }
|
63
|
+
response = conn.post(path, payload)
|
49
64
|
|
50
|
-
if
|
65
|
+
if response.status >= 400
|
51
66
|
messages = [
|
52
67
|
"Upload failure ! #{src_file_path}",
|
53
|
-
extract_title(
|
68
|
+
extract_title(response.body)
|
54
69
|
].compact
|
55
|
-
|
70
|
+
|
56
71
|
raise RestError, messages.join("\n")
|
57
72
|
end
|
58
73
|
|
59
|
-
|
60
|
-
close_curl(curl)
|
61
|
-
str
|
74
|
+
response.body
|
62
75
|
end
|
63
76
|
|
64
77
|
private
|
65
78
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
79
|
+
def split_url(url)
|
80
|
+
uri = URI(url)
|
81
|
+
url = "#{uri.scheme}://#{uri.host}:#{uri.port}"
|
82
|
+
path = [uri.path, uri.query].join('?')
|
83
|
+
|
84
|
+
[url, path]
|
70
85
|
end
|
71
86
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
87
|
+
def headers
|
88
|
+
{ 'Cookie' => @cookies, 'User-Agent' => 'ZmRubyClient' }
|
89
|
+
end
|
90
|
+
|
91
|
+
def http_options(url)
|
92
|
+
{
|
93
|
+
url: url,
|
94
|
+
headers: headers,
|
95
|
+
request: {
|
96
|
+
timeout: @timeout
|
97
|
+
},
|
98
|
+
ssl: @ssl_options
|
99
|
+
}
|
85
100
|
end
|
86
101
|
|
87
102
|
def extract_title(str)
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
require 'openssl'
|
5
|
-
require 'curb'
|
6
5
|
require 'uri'
|
7
6
|
|
8
7
|
require_relative 'soap_error'
|
@@ -14,14 +13,24 @@ module Zm
|
|
14
13
|
|
15
14
|
BASESPACE = 'urn:zimbra'
|
16
15
|
HTTP_HEADERS = {
|
17
|
-
'Content-Type' => 'application/json; charset=utf-8'
|
16
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
17
|
+
'User-Agent' => 'ZmRubyClient'
|
18
18
|
}.freeze
|
19
19
|
|
20
20
|
attr_reader :context
|
21
21
|
|
22
22
|
def initialize(scheme, host, port, soap_path)
|
23
23
|
@verbose = false
|
24
|
-
@
|
24
|
+
@timeout = 300
|
25
|
+
|
26
|
+
@ssl_options = {
|
27
|
+
verify: false,
|
28
|
+
verify_hostname: false,
|
29
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE
|
30
|
+
}
|
31
|
+
|
32
|
+
@soap_path = soap_path
|
33
|
+
@uri = URI::HTTP.new(scheme, nil, host, port, nil, nil, nil, nil, nil)
|
25
34
|
@context = SoapContext.new
|
26
35
|
end
|
27
36
|
|
@@ -30,7 +39,7 @@ module Zm
|
|
30
39
|
end
|
31
40
|
|
32
41
|
def invoke(soap_element, error_handler = SoapError)
|
33
|
-
|
42
|
+
do_request(envelope(soap_element), error_handler)[:Body]
|
34
43
|
end
|
35
44
|
|
36
45
|
def target_invoke(soap_element, target_id, error_handler = SoapError)
|
@@ -40,45 +49,38 @@ module Zm
|
|
40
49
|
resp
|
41
50
|
end
|
42
51
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def http_client!
|
53
|
+
@http_client = Faraday.new(
|
54
|
+
url: @uri.to_s,
|
55
|
+
headers: HTTP_HEADERS,
|
56
|
+
request: {
|
57
|
+
timeout: @timeout
|
58
|
+
},
|
59
|
+
ssl: @ssl_options
|
60
|
+
) do |faraday|
|
61
|
+
faraday.request :json
|
62
|
+
faraday.response :logger, nil, { headers: true, bodies: true, errors: true } if @verbose
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
57
|
-
|
58
|
-
curl = init_curl_client
|
59
|
-
logger.debug body.to_json
|
60
|
-
curl.http_post(body.to_json)
|
66
|
+
private
|
61
67
|
|
62
|
-
|
68
|
+
def http_client
|
69
|
+
@http_client || http_client!
|
70
|
+
end
|
71
|
+
|
72
|
+
def do_request(body, error_handler = SoapError)
|
73
|
+
response = http_client.post(@soap_path, body)
|
63
74
|
|
64
|
-
soapbody = JSON.parse(
|
75
|
+
soapbody = JSON.parse(response.body, symbolize_names: true)
|
65
76
|
|
66
|
-
if
|
67
|
-
close_curl(curl)
|
77
|
+
if response.status >= 400
|
68
78
|
raise(error_handler, soapbody)
|
69
79
|
end
|
70
80
|
|
71
|
-
close_curl(curl)
|
72
|
-
|
73
81
|
soapbody
|
74
82
|
end
|
75
83
|
|
76
|
-
def close_curl(curl)
|
77
|
-
curl.close
|
78
|
-
# force process to kill socket
|
79
|
-
GC.start
|
80
|
-
end
|
81
|
-
|
82
84
|
def envelope(soap_element)
|
83
85
|
{
|
84
86
|
Body: soap_element.to_hash,
|
@@ -13,8 +13,6 @@ module Zm
|
|
13
13
|
:grants, :retention_policies,
|
14
14
|
:name, :color, :rgb, :l, :url, :f, :view
|
15
15
|
|
16
|
-
# define_changed_attributes :name, :color, :rgb, :l, :url, :f, :view
|
17
|
-
|
18
16
|
alias nb_messages n
|
19
17
|
alias nb_items n
|
20
18
|
alias size s
|
@@ -29,8 +27,6 @@ module Zm
|
|
29
27
|
@retention_policies = FolderRetentionPoliciesCollection.new(self)
|
30
28
|
|
31
29
|
yield(self) if block_given?
|
32
|
-
|
33
|
-
extend(DocumentFolder) if view == Zm::Client::FolderView::DOCUMENT
|
34
30
|
end
|
35
31
|
|
36
32
|
def is_immutable?
|
@@ -66,7 +62,6 @@ module Zm
|
|
66
62
|
end
|
67
63
|
|
68
64
|
def color!
|
69
|
-
# @parent.sacc.invoke(jsns_builder.to_color) if color_changed? || rgb_changed?
|
70
65
|
@parent.sacc.invoke(jsns_builder.to_color)
|
71
66
|
|
72
67
|
true
|
@@ -11,11 +11,11 @@ module DocumentFolder
|
|
11
11
|
|
12
12
|
raise Zm::Client::RestError, 'failed to extract uuid' if uuid.nil?
|
13
13
|
|
14
|
-
jsns = { doc: { l:
|
14
|
+
jsns = { doc: { l: @id, upload: { id: uuid } } }
|
15
15
|
|
16
|
-
soap_request = SoapElement.mail(SoapMailConstants::SAVE_DOCUMENT_REQUEST).add_attributes(jsns)
|
16
|
+
soap_request = Zm::Client::SoapElement.mail(Zm::Client::SoapMailConstants::SAVE_DOCUMENT_REQUEST).add_attributes(jsns)
|
17
17
|
rep = @parent.sacc.invoke(soap_request)
|
18
18
|
|
19
|
-
DocumentJsnsInitializer.create(@parent, rep[:SaveDocumentResponse][:doc].first)
|
19
|
+
Zm::Client::DocumentJsnsInitializer.create(@parent, rep[:SaveDocumentResponse][:doc].first)
|
20
20
|
end
|
21
21
|
end
|