files.com 1.0.33 → 1.0.34

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTORS +1 -0
  3. data/Gemfile +3 -1
  4. data/_VERSION +1 -1
  5. data/lib/files.com.rb +1 -0
  6. data/lib/files.com/api_client.rb +5 -1
  7. data/lib/files.com/list.rb +95 -0
  8. data/lib/files.com/models/api_key.rb +0 -1
  9. data/lib/files.com/models/automation.rb +0 -1
  10. data/lib/files.com/models/behavior.rb +1 -3
  11. data/lib/files.com/models/bundle.rb +0 -1
  12. data/lib/files.com/models/dns_record.rb +0 -1
  13. data/lib/files.com/models/file.rb +9 -8
  14. data/lib/files.com/models/file_action.rb +3 -3
  15. data/lib/files.com/models/file_comment.rb +1 -2
  16. data/lib/files.com/models/folder.rb +4 -3
  17. data/lib/files.com/models/group.rb +0 -1
  18. data/lib/files.com/models/group_user.rb +0 -1
  19. data/lib/files.com/models/history.rb +0 -5
  20. data/lib/files.com/models/history_export.rb +0 -1
  21. data/lib/files.com/models/invoice.rb +0 -1
  22. data/lib/files.com/models/ip_address.rb +0 -1
  23. data/lib/files.com/models/lock.rb +3 -4
  24. data/lib/files.com/models/message.rb +0 -1
  25. data/lib/files.com/models/message_comment.rb +0 -1
  26. data/lib/files.com/models/message_comment_reaction.rb +0 -1
  27. data/lib/files.com/models/message_reaction.rb +0 -1
  28. data/lib/files.com/models/notification.rb +0 -1
  29. data/lib/files.com/models/payment.rb +0 -1
  30. data/lib/files.com/models/permission.rb +0 -1
  31. data/lib/files.com/models/project.rb +0 -1
  32. data/lib/files.com/models/public_key.rb +0 -1
  33. data/lib/files.com/models/remote_server.rb +0 -1
  34. data/lib/files.com/models/request.rb +1 -3
  35. data/lib/files.com/models/sso_strategy.rb +0 -1
  36. data/lib/files.com/models/style.rb +3 -3
  37. data/lib/files.com/models/usage_daily_snapshot.rb +0 -1
  38. data/lib/files.com/models/usage_snapshot.rb +0 -1
  39. data/lib/files.com/models/user.rb +0 -1
  40. data/lib/files.com/models/user_cipher_use.rb +0 -1
  41. data/spec/list_spec.rb +192 -0
  42. data/spec/models/file_spec.rb +36 -0
  43. data/spec/models/folder_spec.rb +40 -0
  44. data/spec/spec_helper.rb +36 -0
  45. data/test.sh +8 -0
  46. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 826a7f03949844aebecf585f0a51b79d77faaddeb353ce8f993f8d45e3d202b3
4
- data.tar.gz: 9c4b4f2ecee43ec3e0606fbd80cb708918c8d0f6a4a3f8bdb096ee33098540ce
3
+ metadata.gz: 95f6118254b939d113400ea9575b5f352f957de2760b911d4cbddca2daaf2e7b
4
+ data.tar.gz: ff0ebe62222940de1aac19014c8f88c23f3bf27a279f01982c0afb237a695849
5
5
  SHA512:
6
- metadata.gz: c5c94fcd236187d9ad215a2157b7cf2db9a57860ba77ea4c49e8b6abe1abda29e22d163f9aa4a599aa1257d3e0220bd495d24658950e364fceb76e1810d9e854
7
- data.tar.gz: 24c4306f9ad6ad772da4355eba69e66d64da3054c83748a58ce46b5cf723d81fa6a4423129e9a8a47cbc7a2812ac50548bb9e8625af098818ff73c8160e5dfad
6
+ metadata.gz: 1360c574244c44858bdeb03d2b83e3d5c0f05a2f4bc313fe3d78317188dc1fd0982e69848e41b5e408c0b90766786417753185b0af1d44e7c870be8f9ab843a1
7
+ data.tar.gz: 1225e3cc3ac3c3a10448eea2b01ba048f0b54a6f93f6faec6114fda68cd9625365515853844d1416393012a75d0defc691b5950c69507a243e787b3d63451a85
data/CONTRIBUTORS CHANGED
@@ -1,2 +1,3 @@
1
1
  Kevin Bombino <kevin.bombino@files.com>
2
2
  Martyn Garcia <martyn.garcia@files.com>
3
+ Dustin Zeisler <dustin.zeisler@files.com>
data/Gemfile CHANGED
@@ -6,5 +6,7 @@ group :development, :test do
6
6
  gem 'pry'
7
7
  gem 'pry-byebug'
8
8
  gem 'rake', '~> 12.0.0'
9
- gem 'rspec'
9
+ gem 'rspec', '~> 3.9.0'
10
+ gem 'rubocop'
11
+ gem 'memory_profiler'
10
12
  end
data/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.33
1
+ 1.0.34
data/lib/files.com.rb CHANGED
@@ -22,6 +22,7 @@ require "files.com/errors"
22
22
  require "files.com/response"
23
23
  require "files.com/system_profiler"
24
24
  require "files.com/util"
25
+ require "files.com/list"
25
26
 
26
27
  require "files.com/models/account_line_item"
27
28
  require "files.com/models/action"
@@ -132,6 +132,10 @@ module Files
132
132
  end
133
133
  end
134
134
 
135
+ def cursor
136
+ @last_response.http_headers["x-files-cursor"]
137
+ end
138
+
135
139
  private def api_url(url = "", base_url = nil)
136
140
  (base_url || Files.base_url) + "/api/rest/v1" + url
137
141
  end
@@ -232,7 +236,7 @@ module Files
232
236
  http_headers: resp.http_headers,
233
237
  http_status: resp.http_status,
234
238
  json_body: resp.data,
235
- code: error_data[:code],
239
+ code: error_data[:code] || resp.http_status,
236
240
  }
237
241
 
238
242
  case resp.http_status
@@ -0,0 +1,95 @@
1
+ module Files
2
+ class List
3
+ include Enumerable
4
+
5
+ def initialize(resource_wrapper, params, current_response = nil, current_options = nil, &request_page)
6
+ @resource_wrapper = resource_wrapper
7
+ @params = params
8
+ @current_response = current_response
9
+ @current_options = current_options
10
+ @request_page = request_page
11
+ end
12
+
13
+ # Iterates through each resource in all pages, making additional fetches to
14
+ # the API as necessary.
15
+ #
16
+ # Note that this method will make as many API calls as necessary to fetch
17
+ # all resources. For more granular control, please see +each+ and
18
+ # +next_page+.
19
+ def auto_paging_each
20
+ return enum_for(:auto_paging_each).lazy unless block_given?
21
+
22
+ loop do
23
+ page = next_page
24
+ break unless page.valid_response?
25
+
26
+ page.set_cursor
27
+
28
+ page.wrap_data do |data|
29
+ yield data
30
+ end
31
+ break if page.on_last_page?
32
+ end
33
+ end
34
+
35
+ # Iterates through each resource in the current page.
36
+ #
37
+ # Note that this method makes no effort to fetch a new page when it gets to
38
+ # the end of the current page's resources. See also +auto_paging_each+.
39
+ def each(&block)
40
+ page = current_page
41
+ return [] unless page.valid_response?
42
+
43
+ page.set_cursor
44
+ page.wrap_data { |data| block.call data }
45
+ end
46
+
47
+ # Fetches the next page of resources (if there is one).
48
+ #
49
+ # This method will try to respect the per_page set. If none
50
+ # was given, the default per_page will be used.
51
+ def next_page
52
+ self.class.new(resource_wrapper, params, *request_page.call, &request_page)
53
+ end
54
+
55
+ protected
56
+
57
+ attr_reader :resource_wrapper,
58
+ :params,
59
+ :request_page
60
+
61
+ def current_page
62
+ @current_page ||= if @current_response and @current_options
63
+ self
64
+ else
65
+ next_page
66
+ end
67
+ end
68
+
69
+ def data
70
+ @current_response.data
71
+ end
72
+
73
+ def wrap_data
74
+ data.map do |object|
75
+ yield resource_wrapper.new(object, @current_options)
76
+ end
77
+ end
78
+
79
+ def set_cursor
80
+ params[:cursor] ||= @current_options[:client].cursor
81
+ end
82
+
83
+ def cursor
84
+ params[:cursor]
85
+ end
86
+
87
+ def valid_response?
88
+ @current_response.http_status == 200
89
+ end
90
+
91
+ def on_last_page?
92
+ !cursor or (data.count < params[:per_page])
93
+ end
94
+ end
95
+ end
@@ -147,7 +147,6 @@ module Files
147
147
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
148
148
 
149
149
  response, options = Api.send_request("/api_keys", :get, params, options)
150
- response.data.map { |object| ApiKey.new(object, options) }
151
150
  end
152
151
 
153
152
  def self.all(params = {}, options = {})
@@ -191,7 +191,6 @@ module Files
191
191
  raise InvalidParameterError.new("Bad parameter: automation must be an String") if params.dig(:automation) and !params.dig(:automation).is_a?(String)
192
192
 
193
193
  response, options = Api.send_request("/automations", :get, params, options)
194
- response.data.map { |object| Automation.new(object, options) }
195
194
  end
196
195
 
197
196
  def self.all(params = {}, options = {})
@@ -112,7 +112,6 @@ module Files
112
112
  raise InvalidParameterError.new("Bad parameter: behavior must be an String") if params.dig(:behavior) and !params.dig(:behavior).is_a?(String)
113
113
 
114
114
  response, options = Api.send_request("/behaviors", :get, params, options)
115
- response.data.map { |object| Behavior.new(object, options) }
116
115
  end
117
116
 
118
117
  def self.all(params = {}, options = {})
@@ -137,8 +136,7 @@ module Files
137
136
  raise InvalidParameterError.new("Bad parameter: behavior must be an String") if params.dig(:behavior) and !params.dig(:behavior).is_a?(String)
138
137
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
139
138
 
140
- response, options = Api.send_request("/behaviors/folders/#{Addressable::URI.encode_component(params[:path])}", :get, params, options)
141
- response.data.map { |object| Behavior.new(object, options) }
139
+ response, options = Api.send_request("/behaviors/folders/#{URI.encode_www_form_component(params[:path])}", :get, params, options)
142
140
  end
143
141
 
144
142
  # Parameters:
@@ -166,7 +166,6 @@ module Files
166
166
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
167
167
 
168
168
  response, options = Api.send_request("/bundles", :get, params, options)
169
- response.data.map { |object| Bundle.new(object, options) }
170
169
  end
171
170
 
172
171
  def self.all(params = {}, options = {})
@@ -39,7 +39,6 @@ module Files
39
39
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
40
40
 
41
41
  response, options = Api.send_request("/dns_records", :get, params, options)
42
- response.data.map { |object| DnsRecord.new(object, options) }
43
42
  end
44
43
 
45
44
  def self.all(params = {}, options = {})
@@ -45,7 +45,7 @@ module Files
45
45
  def self.exist?(path, options = {})
46
46
  find(path, {}, options)
47
47
  true
48
- rescue ApiError => e
48
+ rescue Error => e
49
49
  if e.code == 404
50
50
  false
51
51
  else
@@ -90,8 +90,8 @@ module Files
90
90
  new(path).mtime
91
91
  end
92
92
 
93
- def self.open(path, mode = "r", &block)
94
- file = new(path, mode)
93
+ def self.open(path, mode = "r", options={}, &block)
94
+ file = new(path, mode, options)
95
95
  if block
96
96
  yield file
97
97
  file.close
@@ -187,7 +187,8 @@ module Files
187
187
 
188
188
  def initialize(*args)
189
189
  @attributes = (args[0].is_a?(Hash) && args[0]) || {}
190
- @options = (args[1].is_a?(Hash) && args[1]) || {}
190
+ @options = (args[1].is_a?(Hash) && args[1])
191
+ @options ||= (args[2].is_a?(Hash) && args[2]) || {}
191
192
  @attributes[:path] = args[0] if args[0].is_a?(String)
192
193
  @mode = args[1] || 'r' if args[1].is_a?(String)
193
194
  @write_io = StringIO.new
@@ -925,7 +926,7 @@ module Files
925
926
  raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer)
926
927
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
927
928
 
928
- response, options = Api.send_request("/files/#{Addressable::URI.encode_component(params[:path])}", :get, params, options)
929
+ response, options = Api.send_request("/files/#{URI.encode_www_form_component(params[:path])}", :get, params, options)
929
930
  File.new(response.data, options)
930
931
  end
931
932
 
@@ -960,7 +961,7 @@ module Files
960
961
  raise InvalidParameterError.new("Bad parameter: structure must be an String") if params.dig(:structure) and !params.dig(:structure).is_a?(String)
961
962
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
962
963
 
963
- response, options = Api.send_request("/files/#{Addressable::URI.encode_component(params[:path])}", :post, params, options)
964
+ response, options = Api.send_request("/files/#{URI.encode_www_form_component(params[:path])}", :post, params, options)
964
965
  File.new(response.data, options)
965
966
  end
966
967
 
@@ -975,7 +976,7 @@ module Files
975
976
  raise InvalidParameterError.new("Bad parameter: priority_color must be an String") if params.dig(:priority_color) and !params.dig(:priority_color).is_a?(String)
976
977
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
977
978
 
978
- response, options = Api.send_request("/files/#{Addressable::URI.encode_component(params[:path])}", :patch, params, options)
979
+ response, options = Api.send_request("/files/#{URI.encode_www_form_component(params[:path])}", :patch, params, options)
979
980
  File.new(response.data, options)
980
981
  end
981
982
 
@@ -987,7 +988,7 @@ module Files
987
988
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
988
989
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
989
990
 
990
- response, _options = Api.send_request("/files/#{Addressable::URI.encode_component(params[:path])}", :delete, params, options)
991
+ response, _options = Api.send_request("/files/#{URI.encode_www_form_component(params[:path])}", :delete, params, options)
991
992
  response.data
992
993
  end
993
994
 
@@ -76,7 +76,7 @@ module Files
76
76
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
77
77
  raise MissingParameterError.new("Parameter missing: destination") unless params.dig(:destination)
78
78
 
79
- response, _options = Api.send_request("/file_actions/copy/#{Addressable::URI.encode_component(params[:path])}", :post, params, options)
79
+ response, _options = Api.send_request("/file_actions/copy/#{URI.encode_www_form_component(params[:path])}", :post, params, options)
80
80
  response.data
81
81
  end
82
82
 
@@ -92,7 +92,7 @@ module Files
92
92
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
93
93
  raise MissingParameterError.new("Parameter missing: destination") unless params.dig(:destination)
94
94
 
95
- response, _options = Api.send_request("/file_actions/move/#{Addressable::URI.encode_component(params[:path])}", :post, params, options)
95
+ response, _options = Api.send_request("/file_actions/move/#{URI.encode_www_form_component(params[:path])}", :post, params, options)
96
96
  response.data
97
97
  end
98
98
 
@@ -115,7 +115,7 @@ module Files
115
115
  raise InvalidParameterError.new("Bad parameter: restart must be an Integer") if params.dig(:restart) and !params.dig(:restart).is_a?(Integer)
116
116
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
117
117
 
118
- response, options = Api.send_request("/file_actions/begin_upload/#{Addressable::URI.encode_component(params[:path])}", :post, params, options)
118
+ response, options = Api.send_request("/file_actions/begin_upload/#{URI.encode_www_form_component(params[:path])}", :post, params, options)
119
119
  FilePartUpload.new(response.data, options)
120
120
  end
121
121
  end
@@ -96,8 +96,7 @@ module Files
96
96
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
97
97
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
98
98
 
99
- response, options = Api.send_request("/file_comments/files/#{Addressable::URI.encode_component(params[:path])}", :get, params, options)
100
- response.data.map { |object| FileComment.new(object, options) }
99
+ response, options = Api.send_request("/file_comments/files/#{URI.encode_www_form_component(params[:path])}", :get, params, options)
101
100
  end
102
101
 
103
102
  # Parameters:
@@ -353,8 +353,9 @@ module Files
353
353
  raise InvalidParameterError.new("Bad parameter: search must be an String") if params.dig(:search) and !params.dig(:search).is_a?(String)
354
354
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
355
355
 
356
- response, options = Api.send_request("/folders/#{Addressable::URI.encode_component(params[:path])}", :get, params, options)
357
- response.data.map { |object| File.new(object, options) }
356
+ List.new(File, params) do
357
+ Api.send_request("/folders/#{Addressable::URI.encode_component(params[:path])}", :get, params, options)
358
+ end
358
359
  end
359
360
 
360
361
  # Create folder
@@ -364,7 +365,7 @@ module Files
364
365
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
365
366
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
366
367
 
367
- response, options = Api.send_request("/folders/#{Addressable::URI.encode_component(params[:path])}", :post, params, options)
368
+ response, options = Api.send_request("/folders/#{URI.encode_www_form_component(params[:path])}", :post, params, options)
368
369
  File.new(response.data, options)
369
370
  end
370
371
  end
@@ -117,7 +117,6 @@ module Files
117
117
  raise InvalidParameterError.new("Bad parameter: ids must be an String") if params.dig(:ids) and !params.dig(:ids).is_a?(String)
118
118
 
119
119
  response, options = Api.send_request("/groups", :get, params, options)
120
- response.data.map { |object| Group.new(object, options) }
121
120
  end
122
121
 
123
122
  def self.all(params = {}, options = {})
@@ -113,7 +113,6 @@ module Files
113
113
  raise InvalidParameterError.new("Bad parameter: group_id must be an Integer") if params.dig(:group_id) and !params.dig(:group_id).is_a?(Integer)
114
114
 
115
115
  response, options = Api.send_request("/group_users", :get, params, options)
116
- response.data.map { |object| GroupUser.new(object, options) }
117
116
  end
118
117
 
119
118
  def self.all(params = {}, options = {})
@@ -95,7 +95,6 @@ module Files
95
95
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
96
96
 
97
97
  response, options = Api.send_request("/history/files(/*path)", :get, params, options)
98
- response.data.map { |object| Action.new(object, options) }
99
98
  end
100
99
 
101
100
  # Parameters:
@@ -119,7 +118,6 @@ module Files
119
118
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
120
119
 
121
120
  response, options = Api.send_request("/history/folders(/*path)", :get, params, options)
122
- response.data.map { |object| Action.new(object, options) }
123
121
  end
124
122
 
125
123
  # Parameters:
@@ -143,7 +141,6 @@ module Files
143
141
  raise MissingParameterError.new("Parameter missing: user_id") unless params.dig(:user_id)
144
142
 
145
143
  response, options = Api.send_request("/history/users/#{params[:user_id]}", :get, params, options)
146
- response.data.map { |object| Action.new(object, options) }
147
144
  end
148
145
 
149
146
  # Parameters:
@@ -162,7 +159,6 @@ module Files
162
159
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
163
160
 
164
161
  response, options = Api.send_request("/history/login", :get, params, options)
165
- response.data.map { |object| Action.new(object, options) }
166
162
  end
167
163
 
168
164
  # Parameters:
@@ -181,7 +177,6 @@ module Files
181
177
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
182
178
 
183
179
  response, options = Api.send_request("/history", :get, params, options)
184
- response.data.map { |object| Action.new(object, options) }
185
180
  end
186
181
 
187
182
  def self.all(params = {}, options = {})
@@ -260,7 +260,6 @@ module Files
260
260
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
261
261
 
262
262
  response, options = Api.send_request("/history_exports", :get, params, options)
263
- response.data.map { |object| HistoryExport.new(object, options) }
264
263
  end
265
264
 
266
265
  def self.all(params = {}, options = {})
@@ -89,7 +89,6 @@ module Files
89
89
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
90
90
 
91
91
  response, options = Api.send_request("/invoices", :get, params, options)
92
- response.data.map { |object| AccountLineItem.new(object, options) }
93
92
  end
94
93
 
95
94
  def self.all(params = {}, options = {})
@@ -39,7 +39,6 @@ module Files
39
39
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
40
40
 
41
41
  response, options = Api.send_request("/ip_addresses", :get, params, options)
42
- response.data.map { |object| IpAddress.new(object, options) }
43
42
  end
44
43
 
45
44
  def self.all(params = {}, options = {})
@@ -147,8 +147,7 @@ module Files
147
147
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
148
148
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
149
149
 
150
- response, options = Api.send_request("/locks/#{Addressable::URI.encode_component(params[:path])}", :get, params, options)
151
- response.data.map { |object| Lock.new(object, options) }
150
+ response, options = Api.send_request("/locks/#{URI.encode_www_form_component(params[:path])}", :get, params, options)
152
151
  end
153
152
 
154
153
  # Create Lock
@@ -162,7 +161,7 @@ module Files
162
161
  raise InvalidParameterError.new("Bad parameter: timeout must be an Integer") if params.dig(:timeout) and !params.dig(:timeout).is_a?(Integer)
163
162
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
164
163
 
165
- response, options = Api.send_request("/locks/#{Addressable::URI.encode_component(params[:path])}", :post, params, options)
164
+ response, options = Api.send_request("/locks/#{URI.encode_www_form_component(params[:path])}", :post, params, options)
166
165
  Lock.new(response.data, options)
167
166
  end
168
167
 
@@ -176,7 +175,7 @@ module Files
176
175
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
177
176
  raise MissingParameterError.new("Parameter missing: token") unless params.dig(:token)
178
177
 
179
- response, _options = Api.send_request("/locks/#{Addressable::URI.encode_component(params[:path])}", :delete, params, options)
178
+ response, _options = Api.send_request("/locks/#{URI.encode_www_form_component(params[:path])}", :delete, params, options)
180
179
  response.data
181
180
  end
182
181
 
@@ -121,7 +121,6 @@ module Files
121
121
  raise MissingParameterError.new("Parameter missing: project_id") unless params.dig(:project_id)
122
122
 
123
123
  response, options = Api.send_request("/messages", :get, params, options)
124
- response.data.map { |object| Message.new(object, options) }
125
124
  end
126
125
 
127
126
  def self.all(params = {}, options = {})
@@ -97,7 +97,6 @@ module Files
97
97
  raise MissingParameterError.new("Parameter missing: message_id") unless params.dig(:message_id)
98
98
 
99
99
  response, options = Api.send_request("/message_comments", :get, params, options)
100
- response.data.map { |object| MessageComment.new(object, options) }
101
100
  end
102
101
 
103
102
  def self.all(params = {}, options = {})
@@ -74,7 +74,6 @@ module Files
74
74
  raise MissingParameterError.new("Parameter missing: message_comment_id") unless params.dig(:message_comment_id)
75
75
 
76
76
  response, options = Api.send_request("/message_comment_reactions", :get, params, options)
77
- response.data.map { |object| MessageCommentReaction.new(object, options) }
78
77
  end
79
78
 
80
79
  def self.all(params = {}, options = {})
@@ -74,7 +74,6 @@ module Files
74
74
  raise MissingParameterError.new("Parameter missing: message_id") unless params.dig(:message_id)
75
75
 
76
76
  response, options = Api.send_request("/message_reactions", :get, params, options)
77
- response.data.map { |object| MessageReaction.new(object, options) }
78
77
  end
79
78
 
80
79
  def self.all(params = {}, options = {})
@@ -169,7 +169,6 @@ module Files
169
169
  raise InvalidParameterError.new("Bad parameter: group_id must be an Integer") if params.dig(:group_id) and !params.dig(:group_id).is_a?(Integer)
170
170
 
171
171
  response, options = Api.send_request("/notifications", :get, params, options)
172
- response.data.map { |object| Notification.new(object, options) }
173
172
  end
174
173
 
175
174
  def self.all(params = {}, options = {})
@@ -89,7 +89,6 @@ module Files
89
89
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
90
90
 
91
91
  response, options = Api.send_request("/payments", :get, params, options)
92
- response.data.map { |object| AccountLineItem.new(object, options) }
93
92
  end
94
93
 
95
94
  def self.all(params = {}, options = {})
@@ -130,7 +130,6 @@ module Files
130
130
  raise InvalidParameterError.new("Bad parameter: user_id must be an String") if params.dig(:user_id) and !params.dig(:user_id).is_a?(String)
131
131
 
132
132
  response, options = Api.send_request("/permissions", :get, params, options)
133
- response.data.map { |object| Permission.new(object, options) }
134
133
  end
135
134
 
136
135
  def self.all(path, params = {}, options = {})
@@ -74,7 +74,6 @@ module Files
74
74
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
75
75
 
76
76
  response, options = Api.send_request("/projects", :get, params, options)
77
- response.data.map { |object| Project.new(object, options) }
78
77
  end
79
78
 
80
79
  def self.all(params = {}, options = {})
@@ -108,7 +108,6 @@ module Files
108
108
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
109
109
 
110
110
  response, options = Api.send_request("/public_keys", :get, params, options)
111
- response.data.map { |object| PublicKey.new(object, options) }
112
111
  end
113
112
 
114
113
  def self.all(params = {}, options = {})
@@ -258,7 +258,6 @@ module Files
258
258
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
259
259
 
260
260
  response, options = Api.send_request("/remote_servers", :get, params, options)
261
- response.data.map { |object| RemoteServer.new(object, options) }
262
261
  end
263
262
 
264
263
  def self.all(params = {}, options = {})
@@ -121,7 +121,6 @@ module Files
121
121
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
122
122
 
123
123
  response, options = Api.send_request("/requests", :get, params, options)
124
- response.data.map { |object| Request.new(object, options) }
125
124
  end
126
125
 
127
126
  def self.all(params = {}, options = {})
@@ -143,8 +142,7 @@ module Files
143
142
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
144
143
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
145
144
 
146
- response, options = Api.send_request("/requests/folders/#{Addressable::URI.encode_component(params[:path])}", :get, params, options)
147
- response.data.map { |object| Request.new(object, options) }
145
+ response, options = Api.send_request("/requests/folders/#{URI.encode_www_form_component(params[:path])}", :get, params, options)
148
146
  end
149
147
 
150
148
  # Create Request
@@ -129,7 +129,6 @@ module Files
129
129
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
130
130
 
131
131
  response, options = Api.send_request("/sso_strategies", :get, params, options)
132
- response.data.map { |object| SsoStrategy.new(object, options) }
133
132
  end
134
133
 
135
134
  def self.all(params = {}, options = {})
@@ -93,7 +93,7 @@ module Files
93
93
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
94
94
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
95
95
 
96
- response, options = Api.send_request("/styles/#{Addressable::URI.encode_component(params[:path])}", :get, params, options)
96
+ response, options = Api.send_request("/styles/#{URI.encode_www_form_component(params[:path])}", :get, params, options)
97
97
  Style.new(response.data, options)
98
98
  end
99
99
 
@@ -110,7 +110,7 @@ module Files
110
110
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
111
111
  raise MissingParameterError.new("Parameter missing: file") unless params.dig(:file)
112
112
 
113
- response, options = Api.send_request("/styles/#{Addressable::URI.encode_component(params[:path])}", :patch, params, options)
113
+ response, options = Api.send_request("/styles/#{URI.encode_www_form_component(params[:path])}", :patch, params, options)
114
114
  Style.new(response.data, options)
115
115
  end
116
116
 
@@ -120,7 +120,7 @@ module Files
120
120
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
121
121
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
122
122
 
123
- response, _options = Api.send_request("/styles/#{Addressable::URI.encode_component(params[:path])}", :delete, params, options)
123
+ response, _options = Api.send_request("/styles/#{URI.encode_www_form_component(params[:path])}", :delete, params, options)
124
124
  response.data
125
125
  end
126
126
 
@@ -39,7 +39,6 @@ module Files
39
39
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
40
40
 
41
41
  response, options = Api.send_request("/usage_daily_snapshots", :get, params, options)
42
- response.data.map { |object| UsageDailySnapshot.new(object, options) }
43
42
  end
44
43
 
45
44
  def self.all(params = {}, options = {})
@@ -84,7 +84,6 @@ module Files
84
84
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
85
85
 
86
86
  response, options = Api.send_request("/usage_snapshots", :get, params, options)
87
- response.data.map { |object| UsageSnapshot.new(object, options) }
88
87
  end
89
88
 
90
89
  def self.all(params = {}, options = {})
@@ -609,7 +609,6 @@ module Files
609
609
  raise InvalidParameterError.new("Bad parameter: search must be an String") if params.dig(:search) and !params.dig(:search).is_a?(String)
610
610
 
611
611
  response, options = Api.send_request("/users", :get, params, options)
612
- response.data.map { |object| User.new(object, options) }
613
612
  end
614
613
 
615
614
  def self.all(params = {}, options = {})
@@ -51,7 +51,6 @@ module Files
51
51
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
52
52
 
53
53
  response, options = Api.send_request("/user_cipher_uses", :get, params, options)
54
- response.data.map { |object| UserCipherUse.new(object, options) }
55
54
  end
56
55
 
57
56
  def self.all(params = {}, options = {})
data/spec/list_spec.rb ADDED
@@ -0,0 +1,192 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Files::List do
4
+ ResourceWrapper = Struct.new(:object, :options)
5
+ let(:options) { { client: client } }
6
+ let(:client) { instance_double(Files::ApiClient, cursor: nil) }
7
+ let(:params) { {} }
8
+
9
+ describe "#auto_paging_each" do
10
+ context "when per_page is set" do
11
+ let(:params) { { per_page: per_page } }
12
+ let(:per_page) { 3 }
13
+
14
+ context "when response includes a cursor" do
15
+ let(:client) { instance_double(Files::ApiClient, cursor: "XXX-XXX") }
16
+
17
+ it "does not call the API until out of responses" do
18
+ server_results = ('a'..'h').to_a
19
+ times_block_yielded = 0
20
+ list = described_class.new(ResourceWrapper, params) {
21
+ times_block_yielded += 1
22
+ [
23
+ instance_double(Files::Response, data: server_results.shift(per_page), http_status: 200),
24
+ options
25
+ ]
26
+ }
27
+ results = list.auto_paging_each
28
+ expect(results.class).to eq(Enumerator::Lazy)
29
+ expect(times_block_yielded).to eq(0)
30
+ expect(results.next.object).to eq('a')
31
+ expect(times_block_yielded).to eq(1)
32
+ expect(results.next.object).to eq('b')
33
+ expect(results.next.object).to eq('c')
34
+ expect(results.next.object).to eq('d')
35
+ expect(times_block_yielded).to eq(2)
36
+ expect(results.next.object).to eq('e')
37
+ expect(results.next.object).to eq('f')
38
+ expect(results.next.object).to eq('g')
39
+ expect(results.next.object).to eq('h')
40
+ expect(times_block_yielded).to eq(3)
41
+ end
42
+
43
+ it "stops calling the API once there is an error" do
44
+ server_results = ('a'..'h').to_a
45
+ times_block_yielded = 0
46
+ list = described_class.new(ResourceWrapper, params) {
47
+ times_block_yielded += 1
48
+ [
49
+ instance_double(Files::Response, data: server_results.shift(per_page), http_status: 400),
50
+ options
51
+ ]
52
+ }
53
+ results = list.auto_paging_each
54
+ expect(results.count).to eq(0)
55
+ expect(times_block_yielded).to eq(1)
56
+ end
57
+ end
58
+
59
+ context "when response does not include a cursor" do
60
+ let(:client) { instance_double(Files::ApiClient, cursor: nil) }
61
+
62
+ it "stops requesting any more results after the first try" do
63
+ server_results = ('a'..'h').to_a
64
+ times_block_yielded = 0
65
+ list = described_class.new(ResourceWrapper, params) {
66
+ times_block_yielded += 1
67
+ [
68
+ instance_double(Files::Response, data: server_results.shift(per_page), http_status: 200),
69
+ options
70
+ ]
71
+ }
72
+ results = list.auto_paging_each
73
+ expect(results.count).to eq(3)
74
+ expect(times_block_yielded).to eq(1)
75
+ end
76
+ end
77
+ end
78
+
79
+ it "returns all results at once" do
80
+ server_results = ('a'..'h').to_a
81
+ times_block_yielded = 0
82
+ list = described_class.new(ResourceWrapper, params) {
83
+ times_block_yielded += 1
84
+ [
85
+ instance_double(Files::Response, data: server_results, http_status: 200),
86
+ options
87
+ ]
88
+ }
89
+ results = list.auto_paging_each
90
+ expect(results.count).to eq(8)
91
+ expect(times_block_yielded).to eq(1)
92
+ end
93
+ end
94
+
95
+ describe "#each" do
96
+ it "returns all results at once" do
97
+ server_results = ('a'..'h').to_a
98
+ times_block_yielded = 0
99
+ results = described_class.new(ResourceWrapper, params) {
100
+ times_block_yielded += 1
101
+ [
102
+ instance_double(Files::Response, data: server_results, http_status: 200),
103
+ options
104
+ ]
105
+ }
106
+ expect(results.count).to eq(8)
107
+ expect(times_block_yielded).to eq(1)
108
+ end
109
+
110
+ context "when per_page is set" do
111
+ let(:params) { { per_page: per_page } }
112
+ let(:per_page) { 3 }
113
+
114
+ context "when response includes a cursor" do
115
+ let(:client) { instance_double(Files::ApiClient, cursor: "XXX-XXX") }
116
+
117
+ it "does not call the API until out of responses" do
118
+ server_results = ('a'..'h').to_a
119
+ times_block_yielded = 0
120
+ list = described_class.new(ResourceWrapper, params) {
121
+ times_block_yielded += 1
122
+ [
123
+ instance_double(Files::Response, data: server_results.shift(per_page), http_status: 200),
124
+ options
125
+ ]
126
+ }
127
+ results = list.enum_for(:each)
128
+ expect(times_block_yielded).to eq(0)
129
+ expect(results.next.object).to eq('a')
130
+ expect(times_block_yielded).to eq(1)
131
+ expect(results.next.object).to eq('b')
132
+ expect(results.next.object).to eq('c')
133
+ next_results = list.next_page.enum_for(:each)
134
+ expect(times_block_yielded).to eq(2)
135
+ expect(next_results.next.object).to eq('d')
136
+ expect(next_results.next.object).to eq('e')
137
+ expect(next_results.next.object).to eq('f')
138
+ next_results = list.next_page.enum_for(:each)
139
+ expect(times_block_yielded).to eq(3)
140
+ expect(next_results.next.object).to eq('g')
141
+ expect(next_results.next.object).to eq('h')
142
+ next_results = list.next_page.enum_for(:each)
143
+ expect(next_results.count).to eq(0)
144
+ end
145
+
146
+ it "return the same data when call more than once" do
147
+ server_results = ('a'..'h').to_a
148
+ list = described_class.new(ResourceWrapper, params) {
149
+ [
150
+ instance_double(Files::Response, data: server_results.shift(per_page), http_status: 200),
151
+ options
152
+ ]
153
+ }
154
+ expect(list.to_a).to eq(list.to_a)
155
+ end
156
+
157
+ it "stops calling the API once there is an error" do
158
+ server_results = ('a'..'h').to_a
159
+ times_block_yielded = 0
160
+ results = described_class.new(ResourceWrapper, params) {
161
+ times_block_yielded += 1
162
+ [
163
+ instance_double(Files::Response, data: server_results, http_status: 400),
164
+ options
165
+ ]
166
+ }
167
+ expect(results.count).to eq(0)
168
+ expect(times_block_yielded).to eq(1)
169
+ end
170
+ end
171
+
172
+ context "when response does not include a cursor" do
173
+ let(:client) { instance_double(Files::ApiClient, cursor: nil) }
174
+
175
+ it "stops requesting any more results after the first try" do
176
+ server_results = ('a'..'h').to_a
177
+ times_block_yielded = 0
178
+ list = described_class.new(ResourceWrapper, params) {
179
+ times_block_yielded += 1
180
+ [
181
+ instance_double(Files::Response, data: server_results, http_status: 200),
182
+ options
183
+ ]
184
+ }
185
+ results = list.enum_for(:each)
186
+ expect(results.count).to eq(8)
187
+ expect(times_block_yielded).to eq(1)
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Files::File, :with_test_folder do
4
+ describe "#read" do
5
+ before do
6
+ Files::File.open(test_folder.join("read.txt").to_s, 'w', options) do |f|
7
+ f.write("contents")
8
+ end
9
+ end
10
+
11
+ it "returns the body of the file" do
12
+ file = Files::File.find(test_folder.join("read.txt").to_s, {}, options)
13
+ expect(file.read).to eq("contents")
14
+ end
15
+ end
16
+
17
+ describe "#write" do
18
+ it "can take string" do
19
+ Files::File.open(test_folder.join("write-as-string.txt").to_s, 'w', options) do |f|
20
+ f.write("I am a string")
21
+ end
22
+
23
+ file = Files::File.find(test_folder.join("write-as-string.txt").to_s, {}, options)
24
+ expect(file.read).to eq("I am a string")
25
+ end
26
+
27
+ it "can take IO object" do
28
+ Files::File.open(test_folder.join("write-as-io.txt").to_s, 'w', options) do |f|
29
+ f.write(StringIO.new("I am a string via IO"))
30
+ end
31
+
32
+ file = Files::File.find(test_folder.join("write-as-io.txt").to_s, {}, options)
33
+ expect(file.read).to eq("I am a string via IO")
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Files::Folder, :with_test_folder do
4
+ describe "#list_for" do
5
+ before do
6
+ Files::File.open(test_folder.join("example.txt").to_s, 'w', options) do |f|
7
+ f.write("my text")
8
+ end
9
+
10
+ Files::Folder.mkdir(test_folder.join("other").to_s, {}, options)
11
+
12
+ Files::File.open(test_folder.join("other/example2.txt").to_s, 'w', options) do |f|
13
+ f.write("my text 2")
14
+ end
15
+ end
16
+
17
+ it "lists from the root" do
18
+ results = described_class.list_for(test_folder.to_s, {}, options)
19
+
20
+ expect(results.map(&:path).to_a).to match_array([ test_folder.join("example.txt").to_s, test_folder.join("other").to_s ])
21
+ expect(results.map(&:type).to_a).to match_array(%w[file directory])
22
+ end
23
+ end
24
+
25
+ describe "#delete" do
26
+ it "deletes a folder" do
27
+ Files::Folder.mkdir(test_folder.join("my-new-folder").to_s, {}, options)
28
+ Files::Folder.delete(test_folder.join("my-new-folder").to_s, {}, options)
29
+
30
+ expect(Files::Folder.exist?(test_folder.join("my-new-folder").to_s, options)).to eq(false)
31
+ end
32
+ end
33
+
34
+ describe "mkdir" do
35
+ it "makes a new folder" do
36
+ Files::Folder.mkdir(test_folder.join("my-new-folder").to_s, {}, options)
37
+ expect(Files::Folder.exist?(test_folder.join("my-new-folder").to_s, options)).to eq(true)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,36 @@
1
+ require "files.com"
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |expectations|
5
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_partial_doubles = true
10
+ end
11
+
12
+ RSpec.shared_context "API Helpers" do
13
+ let(:test_folder) { @test_folder }
14
+ let(:api_key) { @api_key }
15
+ let(:options) { { api_key: api_key } }
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ config.include_context "API Helpers", :with_test_folder
20
+ end
21
+
22
+ config.around(:example, :with_test_folder) do |all|
23
+ @api_key = ENV["TEST_API_KEY"] || File.read("../../config/test_api_key.txt")
24
+ @test_folder = Pathname.new("files_regional_worker/#{SecureRandom.uuid}")
25
+ Files::Folder.exist?("files_regional_worker", api_key: @api_key)
26
+ Files::Folder.mkdir("files_regional_worker", {}, api_key: @api_key) unless Files::Folder.exist?("files_regional_worker", api_key: @api_key)
27
+ Files::Folder.mkdir(@test_folder.to_s, {}, api_key: @api_key)
28
+ all.run
29
+ Files::Folder.delete(@test_folder.to_s, { recursive: true }, api_key: @api_key)
30
+ end
31
+
32
+ config.shared_context_metadata_behavior = :apply_to_host_groups
33
+ config.disable_monkey_patching!
34
+ config.order = :random
35
+ Kernel.srand config.seed
36
+ end
data/test.sh ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler"
3
+ Bundler.with_clean_env do
4
+ Dir.chdir("generated/ruby") do
5
+ system "bundle install" if ARGV[0] == "true"
6
+ system "bundle exec rspec"
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: files.com
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.33
4
+ version: 1.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - files.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-06 00:00:00.000000000 Z
11
+ date: 2020-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -152,6 +152,7 @@ files:
152
152
  - lib/files.com/api.rb
153
153
  - lib/files.com/api_client.rb
154
154
  - lib/files.com/errors.rb
155
+ - lib/files.com/list.rb
155
156
  - lib/files.com/models/account.rb
156
157
  - lib/files.com/models/account_line_item.rb
157
158
  - lib/files.com/models/action.rb
@@ -233,6 +234,11 @@ files:
233
234
  - lib/files.com/system_profiler.rb
234
235
  - lib/files.com/util.rb
235
236
  - lib/files.com/version.rb
237
+ - spec/list_spec.rb
238
+ - spec/models/file_spec.rb
239
+ - spec/models/folder_spec.rb
240
+ - spec/spec_helper.rb
241
+ - test.sh
236
242
  - test/test.rb
237
243
  homepage: https://www.files.com
238
244
  licenses: