zm-ruby-client 2.0.7 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d742737b6d4f0eee51242127553458ed1a605d45971dc1486b02d93f467e984b
4
- data.tar.gz: 17588c912b95778bc6b7049b765a88fb81e2e24f4926d74ad0fb444c30d5a7dd
3
+ metadata.gz: b7e939168149edeb472b2e33930cfbbe97a45d8bd7012a1200df9dfe7c635f47
4
+ data.tar.gz: 7508c98743481ad485843e3a611efe75d6d5328107e546fbbcabc7ab8fab29ce
5
5
  SHA512:
6
- metadata.gz: 9afa511f00a2193b69470ac8cbc6c3ff85e3d6b27aa167cf50623be1942c9a6ab3691dc1ed860debbc07237d60fc5adb52f49ef01e1d4b69462e3ce1096be001
7
- data.tar.gz: b37f5333137c31c2eccec348ff8939e54cc53dd57eac3770a47cb1f188ed683853bfd0fa54301c510a35a35783033bd453f60bf278c43f05df5208595fb24501
6
+ metadata.gz: 03ab31a3733a6add8cb01b88297536dcf6203cc29ec875e27cc0914b00357d993d0195597d0fa188c2bddc6e78835358d453538e8e5535e192d69d9d61fb929c
7
+ data.tar.gz: 22f3dbc7e82d70c4fc8311f36d181e0056d8c2c748a68c730c771053381b792e36802e878612a68d4b03150a50998f639b9c4027890a5453c06169809c2f0099
data/Gemfile CHANGED
@@ -3,5 +3,6 @@ source 'https://rubygems.org'
3
3
  ruby ">= 2.7"
4
4
 
5
5
  gem 'addressable', '~> 2.8'
6
- gem 'curb', '~> 1.0'
7
- gem 'version_sorter', '~> 2.3'
6
+ gem 'faraday'
7
+ gem 'faraday-multipart'
8
+ gem 'version_sorter', '~> 2.3'
data/README.md CHANGED
@@ -11,7 +11,6 @@ OS: Linux distribution LTS
11
11
  Language: Ruby2.7+
12
12
 
13
13
  ```bash
14
- sudo apt install make gcc curl libcurl4-openssl-dev
15
14
  gem install zm-ruby-client
16
15
  ```
17
16
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'curb'
3
+ require 'faraday'
4
4
  require 'logger'
5
5
  require 'openssl'
6
6
 
@@ -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(url, dest_file_path)
23
- curl = init_curl_client(url)
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
- curl.on_body do |data|
27
- f << data
28
- data.size
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 curl.status.to_i >= 400
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(url, src_file_path)
46
- curl = init_curl_client(url)
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
- curl.http_post(Curl::PostField.file('file', src_file_path))
62
+ payload = { file: Faraday::Multipart::FilePart.new(src_file_path, nil) }
63
+ response = conn.post(path, payload)
49
64
 
50
- if curl.status.to_i >= 400
65
+ if response.status >= 400
51
66
  messages = [
52
67
  "Upload failure ! #{src_file_path}",
53
- extract_title(curl.body_str)
68
+ extract_title(response.body)
54
69
  ].compact
55
- close_curl(curl)
70
+
56
71
  raise RestError, messages.join("\n")
57
72
  end
58
73
 
59
- str = curl.body_str
60
- close_curl(curl)
61
- str
74
+ response.body
62
75
  end
63
76
 
64
77
  private
65
78
 
66
- def close_curl(curl)
67
- curl.close
68
- # force process to kill socket
69
- GC.start
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 init_curl_client(url)
73
- ::Curl::Easy.new(url) do |curl|
74
- curl.timeout = 300
75
- curl.enable_cookies = false
76
- curl.encoding = ''
77
- curl.ssl_verify_peer = false
78
- curl.ssl_verify_host = 0
79
- curl.multipart_form_post = true
80
- curl.verbose = verbose
81
- curl.follow_location = follow_location
82
- curl.verbose = @verbose
83
- curl.cookies = @cookies
84
- end
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
- @uri = URI::HTTP.new(scheme, nil, host, port, nil, soap_path, nil, nil, nil)
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
- curl_request(envelope(soap_element), error_handler)[:Body]
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
- private
44
-
45
- def init_curl_client
46
- ::Curl::Easy.new(@uri.to_s) do |curl|
47
- curl.timeout = 300
48
- curl.enable_cookies = false
49
- curl.encoding = ''
50
- curl.headers = HTTP_HEADERS
51
- curl.ssl_verify_peer = false
52
- curl.ssl_verify_host = 0
53
- curl.verbose = @verbose
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
- def curl_request(body, error_handler = SoapError)
58
- curl = init_curl_client
59
- logger.debug body.to_json
60
- curl.http_post(body.to_json)
66
+ private
61
67
 
62
- logger.debug curl.body_str
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(curl.body_str, symbolize_names: true)
75
+ soapbody = JSON.parse(response.body, symbolize_names: true)
65
76
 
66
- if curl.status.to_i >= 400
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
@@ -58,6 +58,8 @@ module Zm
58
58
  end
59
59
  end
60
60
 
61
+ item.extend(DocumentFolder) if item.view == Zm::Client::FolderView::DOCUMENT
62
+
61
63
  item
62
64
  end
63
65
  end
@@ -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: l, pload: { id: uuid } } }
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
@@ -9,8 +9,8 @@ module Zm
9
9
 
10
10
  module VERSION
11
11
  MAJOR = 2
12
- MINOR = 0
13
- TINY = 7
12
+ MINOR = 1
13
+ TINY = 0
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
16
16
  end
@@ -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 "bundler", ">= 1.15.0"
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.7
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-01-30 00:00:00.000000000 Z
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: curb
28
+ name: version_sorter
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
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: '1.0'
40
+ version: '2.3'
41
41
  - !ruby/object:Gem::Dependency
42
- name: version_sorter
42
+ name: faraday
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.3'
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.3'
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.5.4
358
+ rubygems_version: 3.1.6
327
359
  signing_key:
328
360
  specification_version: 4
329
361
  summary: zm-ruby-client