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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13a8f6a25daf14d60d491a527f7b9b71920afe9e5df79cbb60bceeacdbdcd606
4
- data.tar.gz: f3e41e0e600c97ab87a0198bb69e305ba7e12e07d9235ae57ff2e5f6d8457e21
3
+ metadata.gz: b7e939168149edeb472b2e33930cfbbe97a45d8bd7012a1200df9dfe7c635f47
4
+ data.tar.gz: 7508c98743481ad485843e3a611efe75d6d5328107e546fbbcabc7ab8fab29ce
5
5
  SHA512:
6
- metadata.gz: 38457fc1f124a1970240edbe7ee900ba02b1c9a864306c03335318eff0c106b27a16cf6598bcc3b1f931904eff7f6de31834f125a69a4177cba07aef86ca6ea7
7
- data.tar.gz: 2d4491d26f0c59c8b2bc36c9f7f1ac183a3d00b06abf749005442dd67ef5fa17674f1fcd36a7bb4ae23c73a23a157f1f3a063427b938ddc7a9decda724967653
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
 
@@ -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?
@@ -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 = 6
12
+ MINOR = 1
13
+ TINY = 0
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
16
16
  end