zm-ruby-client 2.0.7 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/README.md +0 -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/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
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
|
data/lib/zm/client/version.rb
CHANGED
data/zm-ruby-client.gemspec
CHANGED
@@ -25,8 +25,12 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.require_paths = ['lib']
|
26
26
|
|
27
27
|
s.add_dependency('addressable', ['~> 2.8'])
|
28
|
-
s.add_dependency('curb', ['~> 1.0'])
|
29
28
|
s.add_dependency('version_sorter', ['~> 2.3'])
|
30
29
|
|
31
|
-
s.add_dependency
|
30
|
+
# s.add_dependency('faraday', ['>= 2.8.1'])
|
31
|
+
s.add_runtime_dependency 'faraday', '~> 2.8', '>= 2.8.1'
|
32
|
+
# s.add_dependency('faraday-multipart', ['1.0.4'])
|
33
|
+
s.add_runtime_dependency 'faraday-multipart', '~> 1.0', '>= 1.0.4'
|
34
|
+
|
35
|
+
s.add_runtime_dependency 'bundler', '~> 1.15', '>= 1.15.0'
|
32
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zm-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxime Désécot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -25,37 +25,66 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: version_sorter
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.3'
|
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: '2.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: faraday
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
47
|
+
version: '2.8'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.8.1
|
48
51
|
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
55
|
- - "~>"
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
57
|
+
version: '2.8'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.8.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: faraday-multipart
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.0'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.0.4
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.0'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.0.4
|
55
81
|
- !ruby/object:Gem::Dependency
|
56
82
|
name: bundler
|
57
83
|
requirement: !ruby/object:Gem::Requirement
|
58
84
|
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '1.15'
|
59
88
|
- - ">="
|
60
89
|
- !ruby/object:Gem::Version
|
61
90
|
version: 1.15.0
|
@@ -63,6 +92,9 @@ dependencies:
|
|
63
92
|
prerelease: false
|
64
93
|
version_requirements: !ruby/object:Gem::Requirement
|
65
94
|
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.15'
|
66
98
|
- - ">="
|
67
99
|
- !ruby/object:Gem::Version
|
68
100
|
version: 1.15.0
|
@@ -323,7 +355,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
323
355
|
- !ruby/object:Gem::Version
|
324
356
|
version: 1.8.11
|
325
357
|
requirements: []
|
326
|
-
rubygems_version: 3.
|
358
|
+
rubygems_version: 3.1.6
|
327
359
|
signing_key:
|
328
360
|
specification_version: 4
|
329
361
|
summary: zm-ruby-client
|