onlyoffice_api 0.10.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/onlyoffice_api/onlyoffice_api_instance.rb +65 -0
  3. data/lib/onlyoffice_api.rb +1 -0
  4. data/lib/teamlab/config.rb +5 -2
  5. data/lib/teamlab/modules/calendar.rb +2 -2
  6. data/lib/teamlab/modules/community.rb +2 -2
  7. data/lib/teamlab/modules/crm/crm_common.rb +19 -1
  8. data/lib/teamlab/modules/crm/crm_contacts.rb +31 -0
  9. data/lib/teamlab/modules/crm/crm_invoices.rb +14 -0
  10. data/lib/teamlab/modules/crm/crm_opportunities.rb +7 -0
  11. data/lib/teamlab/modules/crm/crm_tags.rb +9 -0
  12. data/lib/teamlab/modules/crm.rb +2 -2
  13. data/lib/teamlab/modules/feed.rb +2 -2
  14. data/lib/teamlab/modules/files.rb +34 -20
  15. data/lib/teamlab/modules/group.rb +2 -2
  16. data/lib/teamlab/modules/mail.rb +2 -2
  17. data/lib/teamlab/modules/mailserver.rb +2 -2
  18. data/lib/teamlab/modules/people/people_reassign.rb +4 -1
  19. data/lib/teamlab/modules/people/people_remove.rb +27 -0
  20. data/lib/teamlab/modules/people.rb +30 -6
  21. data/lib/teamlab/modules/portals.rb +8 -2
  22. data/lib/teamlab/modules/project.rb +2 -2
  23. data/lib/teamlab/modules/projects/projects_comments.rb +16 -0
  24. data/lib/teamlab/modules/projects/projects_discussions.rb +14 -0
  25. data/lib/teamlab/modules/projects/projects_milestones.rb +37 -0
  26. data/lib/teamlab/modules/projects/projects_projects.rb +7 -12
  27. data/lib/teamlab/modules/projects/projects_reports.rb +7 -0
  28. data/lib/teamlab/modules/projects/projects_settings.rb +11 -0
  29. data/lib/teamlab/modules/settings.rb +2 -2
  30. data/lib/teamlab/request.rb +25 -8
  31. data/lib/teamlab/responce/custom_exceptions.rb +6 -0
  32. data/lib/teamlab/response.rb +56 -5
  33. data/lib/teamlab/version.rb +1 -1
  34. metadata +35 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58536681a16a0e9cd5d20506a8d6549f87747914d0252cd5c6fed30165eaa022
4
- data.tar.gz: 1ea712d7ee0f71a79f1a8390dd6ce31e06f1ad250ac044ada511562ccbb4b746
3
+ metadata.gz: c892bbb1d17d3dc5973b02ff35819d2ac24c25562128e34a511b85f2a853b765
4
+ data.tar.gz: 3370a41ebc3b2b591836eaf2b4cc5d49fa4f5bd05665016a07e7fad2a20d654c
5
5
  SHA512:
6
- metadata.gz: 5c835194dba1d3d8edb26e3559065fcabed8698a4242ed825ecbf2119447af11f59705315e11cf03c295f8d7e2ab8449b61a18822f8a237ce8d8ef31ce90d950
7
- data.tar.gz: 2ff09f5ab0e21ee974ecb7b5dedee3c929ac620686ed47bf02c6aa4fbcdd454a8c97562ffdbf9ec61f084a8f7364faba7565c599da0385fff7d1b12953c71ab2
6
+ metadata.gz: 27bd8ba09090aaa9220498757d732dcc37037d34fc4cb42eb14a82995dbbf93eee528535f0a8750f27ac019d3df1650827423fe18de4054e13579d16c64a31ba
7
+ data.tar.gz: 9ff12209da0b8d4316470f1f71653ce2d31574d2359c1d21e05ece096fd3345f4606e07373a909ac8abffaab49a4f62c2b4b92eaf2194adcb94e5966fe606099
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../teamlab/config'
4
+
5
+ module Teamlab
6
+ # Class for multiuser instance
7
+ class OnlyofficeApiInstance
8
+ def initialize(params = {})
9
+ @config = Config.new(params)
10
+ auth_response = Teamlab::Request.new(@config, 'authentication').post('', userName: @config.username, password: @config.password).body
11
+ raise "Cannot get response token for #{auth_response}" if auth_response['response'].nil? || auth_response['response']['token'].nil?
12
+
13
+ @config.token = auth_response['response']['token']
14
+ @config.headers = { 'authorization' => @config.token }
15
+ end
16
+
17
+ def people
18
+ @people ||= Teamlab::People.new(@config)
19
+ end
20
+
21
+ def group
22
+ @group ||= Teamlab::Group.new(@config)
23
+ end
24
+
25
+ def settings
26
+ @settings ||= Teamlab::Settings.new(@config)
27
+ end
28
+
29
+ def files
30
+ @files ||= Teamlab::Files.new(@config)
31
+ end
32
+
33
+ def project
34
+ @project ||= Teamlab::Project.new(@config)
35
+ end
36
+
37
+ def portal
38
+ @portal ||= Teamlab::Portal.new(@config)
39
+ end
40
+
41
+ def crm
42
+ @crm ||= Teamlab::Crm.new(@config)
43
+ end
44
+
45
+ def community
46
+ @community ||= Teamlab::Community.new(@config)
47
+ end
48
+
49
+ def calendar
50
+ @calendar ||= Teamlab::Calendar.new(@config)
51
+ end
52
+
53
+ def mail
54
+ @mail ||= Teamlab::Mail.new(@config)
55
+ end
56
+
57
+ def mailserver
58
+ @mailserver ||= Teamlab::MailServer.new(@config)
59
+ end
60
+
61
+ def feed
62
+ @feed ||= Teamlab::Feed.new(@config)
63
+ end
64
+ end
65
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'onlyoffice_api/onlyoffice_api_instance'
3
4
  require_relative 'teamlab/version'
4
5
  require_relative 'teamlab/config'
5
6
  require_relative 'teamlab/request'
@@ -8,7 +8,7 @@ module Teamlab
8
8
  def self.configure(&block)
9
9
  @config ||= Config.new
10
10
  yield @config if block
11
- auth_response = Teamlab::Request.new('authentication').post('', userName: @config.username, password: @config.password).body
11
+ auth_response = Teamlab::Request.new(nil, 'authentication').post('', userName: @config.username, password: @config.password).body
12
12
  raise "Cannot get response token for #{auth_response}" if auth_response['response'].nil? || auth_response['response']['token'].nil?
13
13
 
14
14
  @config.token = auth_response['response']['token']
@@ -24,8 +24,11 @@ module Teamlab
24
24
  # @return [Net::HTTP::Proxy] connection proxy
25
25
  attr_accessor :proxy
26
26
 
27
- def initialize
27
+ def initialize(params = {})
28
28
  default_configuration
29
+ @server = params[:server]
30
+ @username = params[:username]
31
+ @password = params[:password]
29
32
  end
30
33
 
31
34
  def default_configuration
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Teamlab
4
4
  class Calendar
5
- def initialize
6
- @request = Teamlab::Request.new('calendar')
5
+ def initialize(config = nil)
6
+ @request = Teamlab::Request.new(config, 'calendar')
7
7
  end
8
8
 
9
9
  def get_default_access
@@ -13,8 +13,8 @@ module Teamlab
13
13
  include CommunityForums
14
14
  include CommunityWiki
15
15
 
16
- def initialize
17
- @request = Teamlab::Request.new('community')
16
+ def initialize(config = nil)
17
+ @request = Teamlab::Request.new(config, 'community')
18
18
  end
19
19
  end
20
20
  end
@@ -23,7 +23,7 @@ module Teamlab
23
23
  @request.get(%w[currency rates], {})
24
24
  end
25
25
 
26
- def set_currency_rate(from = 'EUR', to = 'USD', rate = '1.0')
26
+ def create_currency_rate(from = 'EUR', to = 'USD', rate = '1.0')
27
27
  @request.post(%w[currency rates], fromCurrency: from, toCurrency: to, rate: rate)
28
28
  end
29
29
 
@@ -31,6 +31,14 @@ module Teamlab
31
31
  @request.get(['currency', 'rates', id.to_s], {})
32
32
  end
33
33
 
34
+ # Get currency rate by currencies
35
+ # @param from_currency [String] rate from currency
36
+ # @param to_currency [String] rate to currency
37
+ # @return [Hash] currency rate data
38
+ def get_currency_rate_by_currency(from_currency, to_currency)
39
+ @request.get(['currency', 'rates', from_currency.to_s, to_currency.to_s])
40
+ end
41
+
34
42
  def delete_currency_rate_by_id(id)
35
43
  @request.delete(['currency', 'rates', id.to_s], {})
36
44
  end
@@ -38,5 +46,15 @@ module Teamlab
38
46
  def set_is_portal_configured(options = {})
39
47
  @request.put(%w[settings], options)
40
48
  end
49
+
50
+ # Update currency rate object
51
+ # @param id [String] id of rate currency
52
+ # @param from [String] rate from currency
53
+ # @param to [String] rate to currency
54
+ # @param rate [String] currency rate
55
+ # @return [Hash] currency and rate data
56
+ def update_currency_rate(id, from, to, rate)
57
+ @request.put(['currency', 'rates', id.to_s], fromCurrency: from, toCurrency: to, rate: rate)
58
+ end
41
59
  end
42
60
  end
@@ -139,6 +139,13 @@ module Teamlab
139
139
  @request.get(['contact', 'company', company_id.to_s, 'person'])
140
140
  end
141
141
 
142
+ # Returns the detailed information about the contacts Email, Phone, Web Site/Social Networks and Address information with the ID
143
+ # @param contact_id [String] Contact ID
144
+ # @return [Hash] Contact information
145
+ def get_contact_information(contact_id)
146
+ @request.get(['contact', contact_id.to_s, 'data'])
147
+ end
148
+
142
149
  def get_contact_information_by_type(contact_id, info_type)
143
150
  @request.get(['contact', contact_id.to_s, 'data', info_type.to_s])
144
151
  end
@@ -192,6 +199,13 @@ module Teamlab
192
199
  @request.put(['contact', contact_id.to_s, 'access'], options)
193
200
  end
194
201
 
202
+ # Returns access rights to the contact with the ID specified in the request
203
+ # @param contact_id [String] Contact ID
204
+ # @return [Array] List of contacts
205
+ def get_contact_access_rights(contact_id)
206
+ @request.get(['contact', contact_id.to_s, 'access'])
207
+ end
208
+
195
209
  def update_company(company_id, company_name, options = {})
196
210
  @request.put(['contact', 'company', company_id.to_s], { companyName: company_name.to_s }.merge(options))
197
211
  end
@@ -239,5 +253,22 @@ module Teamlab
239
253
  def remove_contact_from_project(contact_id, project_id)
240
254
  @request.delete(['contact', contact_id.to_s, 'project', project_id.to_s])
241
255
  end
256
+
257
+ # Adds the address information to the contact with the selected ID
258
+ # @param contact_id [String] Contact ID
259
+ # @param address [Hash] Contact address parameters: street, city, state, zip, country, isPrimary
260
+ # @return [Hash] Contact information
261
+ def add_address_info(contact_id, address = {})
262
+ @request.post(['contact', contact_id.to_s, 'addressdata'], { address: address })
263
+ end
264
+
265
+ # Updates the address information with the parameters specified in the request for the contact with the selected ID
266
+ # @param contact_id [String] Contact ID
267
+ # @param info_id [String] Contact information record ID
268
+ # @param address [Hash] Contact address parameters: street, city, state, zip, country, isPrimary
269
+ # @return [Hash] Contact information
270
+ def update_address_info(contact_id, info_id, address = {})
271
+ @request.put(['contact', contact_id.to_s, 'addressdata', info_id.to_s], { address: address })
272
+ end
242
273
  end
243
274
  end
@@ -117,5 +117,19 @@ module Teamlab
117
117
  def get_invoice_item_by_id(invoice_item_id)
118
118
  @request.get(['invoiceitem', invoice_item_id])
119
119
  end
120
+
121
+ # Returns the existence of an invoice with the number specified in the request
122
+ # @param number [String] Invoice number
123
+ # @return [Boolean] Invoice existence
124
+ def check_invoice_existence_by_number(number)
125
+ @request.get(%w[invoice bynumber exist], number: number)
126
+ end
127
+
128
+ # Returns the detailed information about an invoice with the number specified in the request
129
+ # @param number [String] Invoice number
130
+ # @return [Hash] Invoice data
131
+ def get_invoice_by_number(number)
132
+ @request.get(%w[invoice bynumber], number: number)
133
+ end
120
134
  end
121
135
  end
@@ -23,6 +23,13 @@ module Teamlab
23
23
  @request.get(['opportunity', opportunity_id.to_s, 'contact'])
24
24
  end
25
25
 
26
+ # Returns a list of all the opportunities for the contact with the ID specified in the request
27
+ # @param contact_id [String, Integer] Contact ID
28
+ # @return [Array] List of opportunities
29
+ def get_contact_opportunities(contact_id)
30
+ @request.get(['opportunity', 'bycontact', contact_id.to_s])
31
+ end
32
+
26
33
  def create_opportunity(stage_id, title, responsible_id, options = {})
27
34
  options[:bidCurrencyAbbr] ||= 'USD'
28
35
  @request.post(%w[opportunity], { stageId: stage_id, title: title, responsibleid: responsible_id }.merge(options))
@@ -50,5 +50,14 @@ module Teamlab
50
50
  def add_contact_tag_to_group(entity_type, entity_id, tag)
51
51
  @request.post([entity_type.to_s, entity_id.to_s, 'tag', 'group'], tagName: tag)
52
52
  end
53
+
54
+ # Deletes the selected tag from the entity (company or person) specified in the request and from all the related contacts
55
+ # @param entity_type [String, Symbol] Entity type
56
+ # @param entity_id [String] Entity ID
57
+ # @param tag [String] Tag name
58
+ # @return [String] Tag name
59
+ def delete_contact_tag_of_group(entity_type, entity_id, tag)
60
+ @request.delete([entity_type.to_s, entity_id, 'tag', 'group'], tagName: tag)
61
+ end
53
62
  end
54
63
  end
@@ -25,8 +25,8 @@ module Teamlab
25
25
  include CrmTasks
26
26
  include CrmUserFields
27
27
 
28
- def initialize
29
- @request = Teamlab::Request.new('crm')
28
+ def initialize(config = nil)
29
+ @request = Teamlab::Request.new(config, 'crm')
30
30
  end
31
31
  end
32
32
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Teamlab
4
4
  class Feed
5
- def initialize
6
- @request = Teamlab::Request.new('feed')
5
+ def initialize(config = nil)
6
+ @request = Teamlab::Request.new(config, 'feed')
7
7
  end
8
8
 
9
9
  # TODO: find out how it should work api.onlyoffice.com missing documentation
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
4
+
3
5
  module Teamlab
4
6
  class Files
5
- def initialize
6
- @request = Teamlab::Request.new('files')
7
+ def initialize(config = nil)
8
+ @request = Teamlab::Request.new(config, 'files')
7
9
  end
8
10
 
9
11
  # region File Creation
@@ -25,15 +27,15 @@ module Teamlab
25
27
  end
26
28
 
27
29
  def create_txt(folder_id, title, content)
28
- @request.post([folder_id.to_s, 'text'], title: title.to_s, content: content.to_s)
30
+ @request.post([escape_folder_id(folder_id), 'text'], title: title.to_s, content: content.to_s)
29
31
  end
30
32
 
31
33
  def create_html(folder_id, title, content)
32
- @request.post([folder_id.to_s, 'html'], title: title.to_s, content: content.to_s)
34
+ @request.post([escape_folder_id(folder_id), 'html'], title: title.to_s, content: content.to_s)
33
35
  end
34
36
 
35
37
  def create_file(folder_id, title)
36
- @request.post([folder_id.to_s, 'file'], title: title.to_s)
38
+ @request.post([escape_folder_id(folder_id), 'file'], title: title.to_s)
37
39
  end
38
40
 
39
41
  # endregion
@@ -52,13 +54,13 @@ module Teamlab
52
54
  @request.get(['file', fileid.to_s, 'checkconversion'])
53
55
  end
54
56
 
55
- def move_to_folder(dest_folder_id, options = {})
56
- @request.put(%w[fileops move], { destFolderId: dest_folder_id }.merge(options))
57
+ def move_to_folder(folder_id, options = {})
58
+ @request.put(%w[fileops move], { destFolderId: escape_folder_id(folder_id) }.merge(options))
57
59
  end
58
60
  alias move_files move_to_folder
59
61
 
60
- def copy_to_folder(dest_folder_id, options = {})
61
- @request.put(%w[fileops copy], { destFolderId: dest_folder_id }.merge(options))
62
+ def copy_to_folder(folder_id, options = {})
63
+ @request.put(%w[fileops copy], { destFolderId: escape_folder_id(folder_id) }.merge(options))
62
64
  end
63
65
 
64
66
  def delete(options = {})
@@ -135,27 +137,27 @@ module Teamlab
135
137
  end
136
138
 
137
139
  def get_folder(folder_id, options = {})
138
- @request.get([folder_id.to_s], options)
140
+ @request.get([escape_folder_id(folder_id)], options)
139
141
  end
140
142
 
141
143
  def get_folder_info(folder_id)
142
- @request.get(['folder', folder_id.to_s])
144
+ @request.get(['folder', escape_folder_id(folder_id)])
143
145
  end
144
146
 
145
147
  def get_folder_path(folder_id)
146
- @request.get(['folder', folder_id.to_s, 'path'])
148
+ @request.get(['folder', escape_folder_id(folder_id), 'path'])
147
149
  end
148
150
 
149
151
  def new_folder(folder_id, title)
150
- @request.post(['folder', folder_id.to_s], title: title)
152
+ @request.post(['folder', escape_folder_id(folder_id)], title: title)
151
153
  end
152
154
 
153
155
  def rename_folder(folder_id, title)
154
- @request.put(['folder', folder_id.to_s], title: title)
156
+ @request.put(['folder', escape_folder_id(folder_id)], title: title)
155
157
  end
156
158
 
157
159
  def delete_folder(folder_id)
158
- @request.delete(['folder', folder_id.to_s])
160
+ @request.delete(['folder', escape_folder_id(folder_id)])
159
161
  end
160
162
 
161
163
  # endregion
@@ -167,7 +169,7 @@ module Teamlab
167
169
  end
168
170
 
169
171
  def get_folder_sharing(folder_id)
170
- @request.get(['folder', folder_id.to_s, 'share'])
172
+ @request.get(['folder', escape_folder_id(folder_id), 'share'])
171
173
  end
172
174
 
173
175
  def share_file(file_id, user_id, access_type, options = {})
@@ -175,7 +177,7 @@ module Teamlab
175
177
  end
176
178
 
177
179
  def share_folder(folder_id, user_id, access_type, options = {})
178
- @request.put(['folder', folder_id.to_s, 'share'], { share: { shareTo: user_id, Access: access_type } }.merge(options))
180
+ @request.put(['folder', escape_folder_id(folder_id), 'share'], { share: { shareTo: user_id, Access: access_type } }.merge(options))
179
181
  end
180
182
 
181
183
  def removes_sharing_rights(options = {})
@@ -224,15 +226,15 @@ module Teamlab
224
226
  end
225
227
 
226
228
  def upload_to_folder(folder_id, file)
227
- @request.post([folder_id.to_s, 'upload'], somefile: File.new(file))
229
+ @request.post([escape_folder_id(folder_id), 'upload'], somefile: File.new(file))
228
230
  end
229
231
 
230
232
  def insert_file(folder_id, file, title: File.basename(file), keep_convert_status: false)
231
- @request.post([folder_id.to_s, 'insert'], file: File.new(file), title: title, keepConvertStatus: keep_convert_status)
233
+ @request.post([escape_folder_id(folder_id), 'insert'], file: File.new(file), title: title, keepConvertStatus: keep_convert_status)
232
234
  end
233
235
 
234
236
  def chunked_upload(folder_id, filename, file_size)
235
- @request.post([folder_id.to_s, 'upload', 'create_session'], fileName: filename, fileSize: file_size)
237
+ @request.post([escape_folder_id(folder_id), 'upload', 'create_session'], fileName: filename, fileSize: file_size)
236
238
  end
237
239
 
238
240
  # endregion
@@ -252,5 +254,17 @@ module Teamlab
252
254
  def check_overwrite(set_value = true)
253
255
  @request.put(%w[updateifexist], set: set_value)
254
256
  end
257
+
258
+ # Sometimes folder id require escaping
259
+ # Because for example for folders from connected account will have id like this:
260
+ # ```
261
+ # sbox-193828-|New_Folder__474b010d-ad5f-49ff-8b3a-5b2583c1fbcc
262
+ # ```
263
+ # And this need escaping
264
+ # @param [Integer, String] id to escape
265
+ # @return [String] result after escape
266
+ def escape_folder_id(id)
267
+ CGI.escape(id.to_s)
268
+ end
255
269
  end
256
270
  end
@@ -6,8 +6,8 @@ module Teamlab
6
6
  class Group
7
7
  include GroupHelper
8
8
 
9
- def initialize
10
- @request = Teamlab::Request.new('group')
9
+ def initialize(config = nil)
10
+ @request = Teamlab::Request.new(config, 'group')
11
11
  end
12
12
 
13
13
  def get_groups
@@ -25,8 +25,8 @@ module Teamlab
25
25
  include MailSettings
26
26
  include MailTags
27
27
 
28
- def initialize
29
- @request = Teamlab::Request.new('mail')
28
+ def initialize(config = nil)
29
+ @request = Teamlab::Request.new(config, 'mail')
30
30
  end
31
31
 
32
32
  # @return [Teamlab::Response] Returns all Mail running operations (only complex)
@@ -11,8 +11,8 @@ module Teamlab
11
11
  include MailserverDomains
12
12
  include MailserverMailboxes
13
13
 
14
- def initialize
15
- @request = Teamlab::Request.new('mailserver')
14
+ def initialize(config = nil)
15
+ @request = Teamlab::Request.new(config, 'mailserver')
16
16
  end
17
17
  end
18
18
  end
@@ -7,18 +7,21 @@ module Teamlab
7
7
  # @param from_user_id [String] guid of user from whom reassign
8
8
  # @param to_user_id [String] guid of user to whom reassign
9
9
  # @param delete_profile [True, False] Delete profile when reassignment will be finished
10
+ # @return [Hash] reassign progress data
10
11
  def start_reassign_user_data(from_user_id, to_user_id, delete_profile = true)
11
12
  @request.post(%w[reassign start], fromUserId: from_user_id, toUserId: to_user_id, deleteProfile: delete_profile)
12
13
  end
13
14
 
14
15
  # Returns the progress of the started reassign process
15
16
  # @param from_user_id [String] User ID (guid) whose data is reassigned
16
- def get_reassign_progress(from_user_id)
17
+ # @return [Hash] reassign progress data
18
+ def reassign_progress(from_user_id)
17
19
  @request.get(%w[reassign progress], userId: from_user_id)
18
20
  end
19
21
 
20
22
  # Terminate reassign process
21
23
  # @param user_id [String] User ID (guid) whose data is reassigned
24
+ # @return [Void]
22
25
  def terminate_reassign(user_id)
23
26
  @request.put(%w[reassign terminate], userId: user_id)
24
27
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Teamlab
4
+ # Module for people removing process
5
+ module PeopleRemove
6
+ # Start a remove process
7
+ # @param userId [String] guid of user to remove
8
+ # @return [Hash] remove progress data
9
+ def start_remove(user_id)
10
+ @request.post(%w[remove start], userId: user_id)
11
+ end
12
+
13
+ # Returns the progress of the started remove process
14
+ # @param userId [String] guid of user to remove
15
+ # @return [Hash] remove progress data
16
+ def remove_progress(user_id)
17
+ @request.get(%w[remove progress], userId: user_id)
18
+ end
19
+
20
+ # Terminate remove process
21
+ # @param userId [String] guid of user to remove
22
+ # @return [Void]
23
+ def terminate_remove(user_id)
24
+ @request.put(%w[remove terminate], userId: user_id)
25
+ end
26
+ end
27
+ end
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'people/people_reassign'
4
+ require_relative 'people/people_remove'
4
5
  module Teamlab
5
6
  class People
6
7
  include PeopleReassign
8
+ include PeopleRemove
7
9
 
8
- def initialize
9
- @request = Teamlab::Request.new('people')
10
+ def initialize(config = nil)
11
+ @request = Teamlab::Request.new(config, 'people')
10
12
  end
11
13
 
12
14
  def get_people
@@ -45,10 +47,6 @@ module Teamlab
45
47
  @request.post(nil, { isVisitor: is_visitor, email: email, firstname: firstname, lastname: lastname }.merge(options))
46
48
  end
47
49
 
48
- def active(options = {})
49
- @request.post(['active'], options) # TODO: need some fixing
50
- end
51
-
52
50
  def update_contacts(user_id, contacts = {})
53
51
  @request.post([user_id, 'contacts'], contacts)
54
52
  end
@@ -100,5 +98,31 @@ module Teamlab
100
98
  def unlink_account(provider)
101
99
  @request.delete([%w[thirdparty unlinkaccount]], provider: provider)
102
100
  end
101
+
102
+ # Return the detailed information about the profile of the user with the email specified in the request
103
+ # @param email [String] User email
104
+ # @return [Hash] result user search by email
105
+ def get_user_by_email(email)
106
+ @request.get(['email'], email: email)
107
+ end
108
+
109
+ # Get user photos
110
+ # @param userid [String] User ID
111
+ # @return [Hash] result user photos
112
+ def get_user_photoes(user_id)
113
+ @request.get([user_id, 'photo'])
114
+ end
115
+
116
+ # Send instructions for delete user own profile
117
+ # @return [Void] send `Deletion of your profile` letter
118
+ def send_delete_instruction
119
+ @request.put(%w[self delete])
120
+ end
121
+
122
+ # Join to affiliate programme
123
+ # @return [String] link to affiliate programme
124
+ def join_to_affiliate_programme
125
+ @request.put(%w[self joinaffiliate])
126
+ end
103
127
  end
104
128
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Teamlab
4
4
  class Portal
5
- def initialize
6
- @request = Teamlab::Request.new('portal')
5
+ def initialize(config = nil)
6
+ @request = Teamlab::Request.new(config, 'portal')
7
7
  end
8
8
 
9
9
  def invite_user_url
@@ -13,5 +13,11 @@ module Teamlab
13
13
  def invite_visitor_url
14
14
  @request.get(%w[users invite visitor])
15
15
  end
16
+
17
+ # Deletes the current portal immediately
18
+ # WARNING: Do not test this method in specs in this project
19
+ def delete_portal
20
+ @request.delete(%w[deleteportalimmediately])
21
+ end
16
22
  end
17
23
  end
@@ -30,8 +30,8 @@ module Teamlab
30
30
  include ProjectsTemplates
31
31
  include ProjectsTime
32
32
 
33
- def initialize
34
- @request = Teamlab::Request.new('project')
33
+ def initialize(config = nil)
34
+ @request = Teamlab::Request.new(config, 'project')
35
35
  end
36
36
  end
37
37
  end
@@ -30,5 +30,21 @@ module Teamlab
30
30
  def delete_comment(comment_id)
31
31
  @request.delete(['comment', comment_id.to_s])
32
32
  end
33
+
34
+ # Adds a project comment with the parameters specified in the request
35
+ # @param entity_id [String] Entity ID
36
+ # @param content [String] Comment text
37
+ # @param type [String, Symbol] Comment type (message or task)
38
+ # @return [Hash] Comment information
39
+ def add_project_comment(entity_id, content, type, options = {})
40
+ @request.post(%w[comment], { entityid: entity_id, content: content, type: type.to_s }.merge(options))
41
+ end
42
+
43
+ # Get a preview of a project comment with the ID specified in the request
44
+ # @param htmltext [String] Comment text in the HTML format
45
+ # @return [Hash] Comment information
46
+ def get_a_comment_preview(htmltext, options = {})
47
+ @request.post(%w[comment preview], { htmltext: htmltext }.merge(options))
48
+ end
33
49
  end
34
50
  end
@@ -39,8 +39,22 @@ module Teamlab
39
39
  @request.put(['message', message_id.to_s, 'subscribe'])
40
40
  end
41
41
 
42
+ # Returns a list of all the subscribers of the discussion with the selected message
43
+ # @param message_id [Integer, String] Message ID
44
+ # @return [Array] List of subscibers
45
+ def discussion_subscribers(message_id)
46
+ @request.get(['message', message_id.to_s, 'subscribes'])
47
+ end
48
+
42
49
  def delete_message(message_id)
43
50
  @request.delete(['message', message_id.to_s])
44
51
  end
52
+
53
+ # Returns a preview of the discussion message
54
+ # @param [String] Message text in the HTML format
55
+ # @return [Hash] Message preview
56
+ def preview_of_discussion_message(htmltext)
57
+ @request.post(%w[message discussion preview], htmltext: htmltext)
58
+ end
45
59
  end
46
60
  end
@@ -31,6 +31,36 @@ module Teamlab
31
31
  @request.get(['milestone', year.to_s, month.to_s, day.to_s])
32
32
  end
33
33
 
34
+ # Returns a list of all the milestones within a project with the ID specified in the request
35
+ # @param project_id [Symbol, String] Project ID
36
+ # @return [Array] List of milestones
37
+ def milestones_by_project_id(project_id)
38
+ @request.get([project_id.to_s, 'milestone'])
39
+ end
40
+
41
+ # Returns a list of all the milestones within a project with the ID and status specified in the request
42
+ # @param project_id [Symbol, String] Project ID
43
+ # @param status [Symbol, String] Milestone status
44
+ # @return [Array] List of milestones
45
+ def milestones_by_project_id_and_status(project_id, status)
46
+ @request.get([project_id.to_s, 'milestone', status.to_s])
47
+ end
48
+
49
+ # Adds a new milestone using the parameters (project ID, milestone title, deadline, etc) specified in the request
50
+ # @param project_id [Symbol, String] Project ID
51
+ # @param title [String] Milestone title
52
+ # @param deadline [String] Milestone deadline
53
+ # @param responsible_id [String] Milestone responsible
54
+ # @param options [Hash] options to create a Milestone with
55
+ # @option isKey [Boolean] Specifies if this is a key milestone or not
56
+ # @option isNotify [Boolean] Reminds me 48 hours before the milestone due date
57
+ # @option description [String] Milestone description
58
+ # @option notifyResponsible [Boolean] Notifies the responsible about the milestone actions or not
59
+ # @return [Hash] Added milestone
60
+ def add_milestone(project_id, title, deadline, responsible_id, options = {})
61
+ @request.post([project_id.to_s, 'milestone'], { title: title, deadline: deadline, responsible: responsible_id }.merge(options))
62
+ end
63
+
34
64
  def update_milestone(id, title, deadline, options = {})
35
65
  @request.put(['milestone', id.to_s], { title: title, deadline: deadline }.merge(options))
36
66
  end
@@ -42,5 +72,12 @@ module Teamlab
42
72
  def delete_milestone(id)
43
73
  @request.delete(['milestone', id.to_s])
44
74
  end
75
+
76
+ # Deletes the milestones with the IDs specified in the request
77
+ # @param ids [Array] Milestone IDs
78
+ # @return [Array] Deleted milestones
79
+ def delete_milestones(ids)
80
+ @request.delete(['milestone'], { ids: ids })
81
+ end
45
82
  end
46
83
  end
@@ -35,10 +35,6 @@ module Teamlab
35
35
  @request.get([project_id.to_s, 'files'])
36
36
  end
37
37
 
38
- def get_milestones(project_id)
39
- @request.get([project_id.to_s, 'milestone'])
40
- end
41
-
42
38
  def search_all_projects(query)
43
39
  @request.get(['@search', query.to_s])
44
40
  end
@@ -47,18 +43,10 @@ module Teamlab
47
43
  @request.get([project_id.to_s, '@search', query.to_s])
48
44
  end
49
45
 
50
- def get_milestones_with_status(project_id, status)
51
- @request.get([project_id.to_s, 'milestone', status.to_s])
52
- end
53
-
54
46
  def create_project(title, description, responsible_id, tags, private, options = {})
55
47
  @request.post('', { title: title, description: description, responsibleid: responsible_id, tags: tags, private: private }.merge(options))
56
48
  end
57
49
 
58
- def add_milestone(project_id, title, deadline, responsible_id, options = {})
59
- @request.post([project_id.to_s, 'milestone'], { title: title, deadline: deadline, responsible: responsible_id }.merge(options))
60
- end
61
-
62
50
  def update_project(id, title, responsible_id, options = {})
63
51
  @request.put([id.to_s], { title: title, responsibleId: responsible_id }.merge(options))
64
52
  end
@@ -78,5 +66,12 @@ module Teamlab
78
66
  def delete_project(id)
79
67
  @request.delete([id.to_s])
80
68
  end
69
+
70
+ # Deletes the projects with the IDs specified in the request from the portal
71
+ # @param ids [Array] List of project IDs
72
+ # @return [Array] Deleted projects
73
+ def delete_projects(ids)
74
+ @request.delete('', { projectids: ids })
75
+ end
81
76
  end
82
77
  end
@@ -11,6 +11,13 @@ module Teamlab
11
11
  @request.put(['report', report_id.to_s], { name: name }.merge(options))
12
12
  end
13
13
 
14
+ # Returns a project report template with the ID specified in the request
15
+ # @param report_id [Symbol, String] Report template ID
16
+ # @return [Hash] Project report template
17
+ def report_template(report_id)
18
+ @request.get(['report', report_id.to_s])
19
+ end
20
+
14
21
  def delete_report_template(report_id)
15
22
  @request.delete(['report', report_id.to_s])
16
23
  end
@@ -7,5 +7,16 @@ module Teamlab
7
7
  def projects_settings
8
8
  @request.get(%w[settings])
9
9
  end
10
+
11
+ # Updates the project settings with the parameters specified in the request
12
+ # @param options [Hash] options to change Projects module settings
13
+ # @option everebodyCanCreate [Boolean] Specifies if all the portal users can create projects or not
14
+ # @option hideEntitiesInPausedProjects [Boolean] Specifies if the entities will be hidden in the paused projects or not
15
+ # @option startModule [String] Module type: Projects, Tasks, Discussions, TimeTracking
16
+ # @option folderId [String] Folder ID
17
+ # @return [Hash] Updated settings
18
+ def update_projects_settings(options = {})
19
+ @request.put(%w[settings], options)
20
+ end
10
21
  end
11
22
  end
@@ -5,8 +5,8 @@ module Teamlab
5
5
  # @return [String] id of global admin of portal
6
6
  GLOBAL_ADMIN_ID = '00000000-0000-0000-0000-000000000000'
7
7
 
8
- def initialize
9
- @request = Teamlab::Request.new('settings')
8
+ def initialize(config = nil)
9
+ @request = Teamlab::Request.new(config, 'settings')
10
10
  end
11
11
 
12
12
  def get_settings
@@ -9,7 +9,8 @@ module Teamlab
9
9
  class Request
10
10
  include HTTParty
11
11
 
12
- def initialize(api_additive)
12
+ def initialize(config, api_additive)
13
+ @config = config
13
14
  @api_additive = api_additive.to_s
14
15
  end
15
16
 
@@ -49,8 +50,24 @@ module Teamlab
49
50
  response
50
51
  end
51
52
 
53
+ def server
54
+ @config&.server || Teamlab.config.server
55
+ end
56
+
57
+ def api_path
58
+ @config&.api_path || Teamlab.config.api_path
59
+ end
60
+
61
+ def headers
62
+ @config&.headers || Teamlab.config.headers
63
+ end
64
+
65
+ def proxy
66
+ @config&.proxy || Teamlab.config.proxy
67
+ end
68
+
52
69
  def generate_request_url(command)
53
- Teamlab.config.server + Teamlab.config.api_path + @api_additive + command
70
+ server + api_path + @api_additive + command
54
71
  end
55
72
 
56
73
  def parse_args(args, type)
@@ -58,7 +75,7 @@ module Teamlab
58
75
  opts = {}
59
76
  opts[:body] = args.last.instance_of?(Hash) ? args.pop : {}
60
77
  opts[:body].delete_if { |_key, value| value == [] }
61
- opts[:headers] = Teamlab.config.headers
78
+ opts[:headers] = headers
62
79
  opts = init_proxy(opts)
63
80
  opts[:query] = opts.delete(:body) if type == :get
64
81
  [command, opts]
@@ -67,12 +84,12 @@ module Teamlab
67
84
  # @param opts [Hash] options to init
68
85
  # @return [Hash] options
69
86
  def init_proxy(opts)
70
- return opts unless Teamlab.config.proxy
87
+ return opts unless proxy
71
88
 
72
- opts[:http_proxyaddr] ||= Teamlab.config.proxy.proxy_address
73
- opts[:http_proxyport] ||= Teamlab.config.proxy.proxy_port
74
- opts[:http_proxyuser] ||= Teamlab.config.proxy.proxy_user
75
- opts[:http_proxypass] ||= Teamlab.config.proxy.proxy_pass
89
+ opts[:http_proxyaddr] ||= proxy.proxy_address
90
+ opts[:http_proxyport] ||= proxy.proxy_port
91
+ opts[:http_proxyuser] ||= proxy.proxy_user
92
+ opts[:http_proxypass] ||= proxy.proxy_pass
76
93
  opts
77
94
  end
78
95
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Teamlab
4
+ # Exception if in response no JSON body
5
+ class NoJsonInResponce < StandardError; end
6
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'responce/custom_exceptions'
4
+
3
5
  module Teamlab
4
6
  class Response
5
7
  attr_reader :body, :error, :code, :success
@@ -9,7 +11,7 @@ module Teamlab
9
11
  @success = @code < 400
10
12
  err_msg = generate_err_msg(http_response) if @code >= 400
11
13
  if @success
12
- @body = http_response.to_hash
14
+ handle_success_responce(http_response)
13
15
  else
14
16
  raise TimeoutError, 'Portal is warming up' if http_response.parsed_response.include?('portal is being warmed')
15
17
  raise "Error #{@code}\n#{err_msg}" if @code >= 400
@@ -21,10 +23,10 @@ module Teamlab
21
23
 
22
24
  def generate_err_msg(http_response)
23
25
  "API request failed\n\noriginal request:\n"\
24
- "#{http_response.request.http_method} #{http_response.request.path}\nbody: "\
25
- "#{JSON.pretty_generate(http_response.request.options[:body])}"\
26
- "\n\nresponse:\n"\
27
- "#{prettify_response(http_response.parsed_response)}"
26
+ "#{http_response.request.http_method} #{http_response.request.path}\nbody: "\
27
+ "#{JSON.pretty_generate(http_response.request.options[:body])}"\
28
+ "\n\nresponse:\n"\
29
+ "#{prettify_response(http_response.parsed_response)}"
28
30
  end
29
31
 
30
32
  def prettify_response(msg)
@@ -37,5 +39,54 @@ module Teamlab
37
39
  def data
38
40
  @body['response']
39
41
  end
42
+
43
+ # Check if responce is succeed, has nil error and has hash body
44
+ # @param [Symbol] current api method
45
+ # @return [Boolean] result of responce check
46
+ def correct?(command)
47
+ result = @success && @error.nil? && @body.is_a?(Hash)
48
+ raise("Response should be always successful for #{command}") unless @success
49
+ raise("Response should not contain errors for #{command}") unless @error.nil?
50
+ raise("Response should be Hash for #{command}") unless @body.is_a?(Hash)
51
+
52
+ result
53
+ end
54
+
55
+ private
56
+
57
+ # Sometime in strange situation, like maybe nginx errors
58
+ # API requests return not JSON, but html or other data
59
+ # @param [Teamlab::Responce] responce to check
60
+ # @return [Nil] is body responce correct and raise exception in any other situation
61
+ def check_responce_body(responce)
62
+ return if stream_data_request?(responce)
63
+
64
+ JSON.parse(responce.body)
65
+ rescue JSON::ParserError => e
66
+ request_info = "#{responce.request.http_method} #{responce.request.uri}"
67
+ raise NoJsonInResponce, "Request `#{request_info}` responce body is not a json\n "\
68
+ "Parsing error: \n#{e}\n"
69
+ end
70
+
71
+ # Handle success responce
72
+ # @param [Teamlab::Responce] responce to handle
73
+ # @return [nil] if everything is fine or exception
74
+ def handle_success_responce(responce)
75
+ check_responce_body(responce)
76
+ @body = responce.to_hash
77
+ end
78
+
79
+ # Check if request for stream data
80
+ # Those request has no body, but data stream in responce
81
+ # @param [Teamlab::Responce] responce to check
82
+ # @return [Boolean] result of check
83
+ def stream_data_request?(responce)
84
+ calendar_ical_request_regexp = %r{.*/calendar/\d*/ical/\S*}
85
+ uri = responce.request.uri.to_s
86
+
87
+ return true if calendar_ical_request_regexp.match?(uri)
88
+
89
+ false
90
+ end
40
91
  end
41
92
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Teamlab
4
- VERSION = '0.10.0'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlyoffice_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-04-29 00:00:00.000000000 Z
14
+ date: 2022-02-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty
@@ -27,20 +27,6 @@ dependencies:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0.16'
30
- - !ruby/object:Gem::Dependency
31
- name: codecov
32
- requirement: !ruby/object:Gem::Requirement
33
- requirements:
34
- - - "~>"
35
- - !ruby/object:Gem::Version
36
- version: '0'
37
- type: :development
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '0'
44
30
  - !ruby/object:Gem::Dependency
45
31
  name: faker
46
32
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +83,20 @@ dependencies:
97
83
  - - "~>"
98
84
  - !ruby/object:Gem::Version
99
85
  version: '3'
86
+ - !ruby/object:Gem::Dependency
87
+ name: rspec-retry
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: rubocop
102
102
  requirement: !ruby/object:Gem::Requirement
@@ -153,6 +153,20 @@ dependencies:
153
153
  - - "~>"
154
154
  - !ruby/object:Gem::Version
155
155
  version: '2'
156
+ - !ruby/object:Gem::Dependency
157
+ name: simplecov-cobertura
158
+ requirement: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - "~>"
161
+ - !ruby/object:Gem::Version
162
+ version: '2'
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: '2'
156
170
  - !ruby/object:Gem::Dependency
157
171
  name: yard
158
172
  requirement: !ruby/object:Gem::Requirement
@@ -177,6 +191,7 @@ extensions: []
177
191
  extra_rdoc_files: []
178
192
  files:
179
193
  - lib/onlyoffice_api.rb
194
+ - lib/onlyoffice_api/onlyoffice_api_instance.rb
180
195
  - lib/teamlab/config.rb
181
196
  - lib/teamlab/modules/calendar.rb
182
197
  - lib/teamlab/modules/community.rb
@@ -218,6 +233,7 @@ files:
218
233
  - lib/teamlab/modules/mailserver/mailboxes.rb
219
234
  - lib/teamlab/modules/people.rb
220
235
  - lib/teamlab/modules/people/people_reassign.rb
236
+ - lib/teamlab/modules/people/people_remove.rb
221
237
  - lib/teamlab/modules/portals.rb
222
238
  - lib/teamlab/modules/project.rb
223
239
  - lib/teamlab/modules/projects/projects_comments.rb
@@ -236,6 +252,7 @@ files:
236
252
  - lib/teamlab/modules/settings.rb
237
253
  - lib/teamlab/name.rb
238
254
  - lib/teamlab/request.rb
255
+ - lib/teamlab/responce/custom_exceptions.rb
239
256
  - lib/teamlab/response.rb
240
257
  - lib/teamlab/version.rb
241
258
  homepage: https://github.com/ONLYOFFICE/onlyoffice_api_gem
@@ -247,6 +264,7 @@ metadata:
247
264
  documentation_uri: https://www.rubydoc.info/gems/onlyoffice_api
248
265
  homepage_uri: https://github.com/ONLYOFFICE/onlyoffice_api_gem
249
266
  source_code_uri: https://github.com/ONLYOFFICE/onlyoffice_api_gem
267
+ rubygems_mfa_required: 'true'
250
268
  post_install_message:
251
269
  rdoc_options: []
252
270
  require_paths:
@@ -262,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
280
  - !ruby/object:Gem::Version
263
281
  version: '0'
264
282
  requirements: []
265
- rubygems_version: 3.1.6
283
+ rubygems_version: 3.3.7
266
284
  signing_key:
267
285
  specification_version: 4
268
286
  summary: Ruby gem for OnlyOffice. Formerly known as `teamlab`.