smartsheet 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39e7fb7367eec5afc35fd45a2b6d22c9e0bdb8dc
4
- data.tar.gz: cb77015b925dd36ef95109ce6e6130deb366b2ec
3
+ metadata.gz: d40986baa13b5cbda5dbf6bab61056dfc3e64b34
4
+ data.tar.gz: e8fea36ef79dd09ce22a632f5134d5561db01673
5
5
  SHA512:
6
- metadata.gz: 2c076e95bbc9b1e31152df02c10c69b7ffc4c1e2dac4290d6ec235144f19720fbf98c403e9d30548ca3abded03c03f58176b09dea1207f3c1b35d346680be7de
7
- data.tar.gz: 79946c8168b1a0d39654ac6a0b27e305cd7f6252fdef0c3a7fa5da5dade00c3cf9f7da65033846501403bfe5082297fce58426904c8e4dfb0dead95195e61e85
6
+ metadata.gz: bc87fcc08699c74aa731c9f0c1fd04b2790abbd473ae14ccf92ee3b39a522b9f8369e3b5a5c15b1963923263b7b84d4a2b366de8241198ab6e73ddb3904c6f56
7
+ data.tar.gz: 54e1bc705a081fcf7809a14b11cbc43f571f61ce59cd225772d66a613397cd0318d5a574eb0b973c8622860a3496ad6f0a6560386fb3a1f03e519e4f8d881d19
data/CHANGELOG.md CHANGED
@@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- N/A
9
+ ## [1.2.0] - 2018-06-29
10
+ ### Added
11
+ - Added support for 'import sheet from XLSX, CSV file' endpoints
10
12
 
11
13
  ## [1.1.0] - 2018-03-16
12
14
  ### Added
@@ -95,7 +97,8 @@ N/A
95
97
  - Support for logging
96
98
  - Test suite with unit tests and two-column-accounting endpoint tests
97
99
 
98
- [Unreleased]: https://github.com/smartsheet-platform/smartsheet-ruby-sdk/compare/v1.1.0...HEAD
100
+ [Unreleased]: https://github.com/smartsheet-platform/smartsheet-ruby-sdk/compare/v1.2.0...HEAD
101
+ [1.2.0]: https://github.com/smartsheet-platform/smartsheet-ruby-sdk/compare/v1.1.0...v1.2.0
99
102
  [1.1.0]: https://github.com/smartsheet-platform/smartsheet-ruby-sdk/compare/v1.0.0...v1.1.0
100
103
  [1.0.0]: https://github.com/smartsheet-platform/smartsheet-ruby-sdk/compare/v1.0.0.beta.2...v1.0.0
101
104
  [1.0.0.beta.2]: https://github.com/smartsheet-platform/smartsheet-ruby-sdk/compare/v1.0.0.beta.1...v1.0.0.beta.2
@@ -27,5 +27,29 @@ module Smartsheet
27
27
  @content_type = content_type
28
28
  end
29
29
  end
30
+
31
+ # Specification for file sheet import by path and MIME content type
32
+ class ImportPathFileSpec
33
+ attr_reader :upload_io, :filename, :content_type, :file_length
34
+
35
+ def initialize(path, content_type)
36
+ @file_length = File.size(path)
37
+ @filename = nil
38
+ @upload_io = Faraday::UploadIO.new(path, content_type)
39
+ @content_type = content_type
40
+ end
41
+ end
42
+
43
+ # Specification for file sheet import by {::File}, file length, and MIME content type
44
+ class ImportObjectFileSpec
45
+ attr_reader :upload_io, :filename, :content_type, :file_length
46
+
47
+ def initialize(file, file_length, content_type)
48
+ @file_length = file_length
49
+ @filename = nil
50
+ @upload_io = Faraday::UploadIO.new(file, content_type)
51
+ @content_type = content_type
52
+ end
53
+ end
30
54
  end
31
55
  end
@@ -69,7 +69,12 @@ module Smartsheet
69
69
 
70
70
  def content_disposition
71
71
  if endpoint_spec.sending_file?
72
- {'Content-Disposition': "attachment; filename=\"#{CGI::escape(request_spec.filename)}\""}
72
+ filename_suffix =
73
+ if request_spec.filename.nil?
74
+ then ''
75
+ else "; filename=\"#{CGI::escape(request_spec.filename)}\""
76
+ end
77
+ {'Content-Disposition': "attachment#{filename_suffix}"}
73
78
  else
74
79
  {}
75
80
  end
@@ -88,4 +93,4 @@ module Smartsheet
88
93
  end
89
94
  end
90
95
  end
91
- end
96
+ end
@@ -1,6 +1,6 @@
1
1
  module Smartsheet
2
2
  module Constants
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.2.0'.freeze
4
4
 
5
5
  USER_AGENT = 'smartsheet-ruby-sdk'.freeze
6
6
  API_URL = 'https://api.smartsheet.com/2.0'.freeze
@@ -9,6 +9,8 @@ module Smartsheet
9
9
  EXCEL_TYPE = 'application/vnd.ms-excel'.freeze
10
10
  PDF_TYPE = 'application/pdf'.freeze
11
11
  CSV_TYPE = 'text/csv'.freeze
12
+ OPENXML_SPREADSHEET_TYPE =
13
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.freeze
12
14
 
13
15
  DEFAULT_MAX_RETRY_TIME = 15
14
16
  DEFAULT_BACKOFF_METHOD = proc { |iteration, _result| 2**iteration + rand }
@@ -1,45 +1,45 @@
1
1
  module Smartsheet
2
- # Cross-sheet References Endpoints
3
- # @see http://smartsheet-platform.github.io/api-docs/?ruby#cross-sheet-references API
4
- # Cross-sheet References Docs
5
- class CrossSheetReferences
6
- attr_reader :client
7
- private :client
8
-
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def create(sheet_id:, body:, params: {}, header_overrides: {})
14
- endpoint_spec = Smartsheet::API::EndpointSpec.new(:post, ['sheets', :sheet_id, 'crosssheetreferences'], body_type: :json)
15
- request_spec = Smartsheet::API::RequestSpec.new(
16
- header_overrides: header_overrides,
17
- params: params,
18
- body: body,
19
- sheet_id: sheet_id
20
- )
21
- client.make_request(endpoint_spec, request_spec)
22
- end
23
-
24
- def list(sheet_id:, params: {}, header_overrides: {})
25
- endpoint_spec = Smartsheet::API::EndpointSpec.new(:get, ['sheets', :sheet_id, 'crosssheetreferences'])
26
- request_spec = Smartsheet::API::RequestSpec.new(
27
- params: params,
28
- header_overrides: header_overrides,
29
- sheet_id: sheet_id
30
- )
31
- client.make_request(endpoint_spec, request_spec)
32
- end
33
-
34
- def get(sheet_id:, cross_sheet_reference_id:, params: {}, header_overrides: {})
35
- endpoint_spec = Smartsheet::API::EndpointSpec.new(:get, ['sheets', :sheet_id, 'crosssheetreferences', :cross_sheet_reference_id])
36
- request_spec = Smartsheet::API::RequestSpec.new(
37
- params: params,
38
- header_overrides: header_overrides,
39
- sheet_id: sheet_id,
40
- cross_sheet_reference_id: cross_sheet_reference_id
41
- )
42
- client.make_request(endpoint_spec, request_spec)
43
- end
2
+ # Cross-sheet References Endpoints
3
+ # @see http://smartsheet-platform.github.io/api-docs/?ruby#cross-sheet-references API
4
+ # Cross-sheet References Docs
5
+ class CrossSheetReferences
6
+ attr_reader :client
7
+ private :client
8
+
9
+ def initialize(client)
10
+ @client = client
44
11
  end
45
- end
12
+
13
+ def create(sheet_id:, body:, params: {}, header_overrides: {})
14
+ endpoint_spec = Smartsheet::API::EndpointSpec.new(:post, ['sheets', :sheet_id, 'crosssheetreferences'], body_type: :json)
15
+ request_spec = Smartsheet::API::RequestSpec.new(
16
+ header_overrides: header_overrides,
17
+ params: params,
18
+ body: body,
19
+ sheet_id: sheet_id
20
+ )
21
+ client.make_request(endpoint_spec, request_spec)
22
+ end
23
+
24
+ def list(sheet_id:, params: {}, header_overrides: {})
25
+ endpoint_spec = Smartsheet::API::EndpointSpec.new(:get, ['sheets', :sheet_id, 'crosssheetreferences'])
26
+ request_spec = Smartsheet::API::RequestSpec.new(
27
+ params: params,
28
+ header_overrides: header_overrides,
29
+ sheet_id: sheet_id
30
+ )
31
+ client.make_request(endpoint_spec, request_spec)
32
+ end
33
+
34
+ def get(sheet_id:, cross_sheet_reference_id:, params: {}, header_overrides: {})
35
+ endpoint_spec = Smartsheet::API::EndpointSpec.new(:get, ['sheets', :sheet_id, 'crosssheetreferences', :cross_sheet_reference_id])
36
+ request_spec = Smartsheet::API::RequestSpec.new(
37
+ params: params,
38
+ header_overrides: header_overrides,
39
+ sheet_id: sheet_id,
40
+ cross_sheet_reference_id: cross_sheet_reference_id
41
+ )
42
+ client.make_request(endpoint_spec, request_spec)
43
+ end
44
+ end
45
+ end
@@ -1,6 +1,7 @@
1
1
  require 'smartsheet/api/endpoint_spec'
2
2
  require 'smartsheet/api/request_spec'
3
3
  require 'smartsheet/constants'
4
+ require 'smartsheet/error'
4
5
 
5
6
  require 'smartsheet/endpoints/sheets/automation_rules'
6
7
  require 'smartsheet/endpoints/sheets/cells'
@@ -214,6 +215,172 @@ module Smartsheet
214
215
  client.make_request(endpoint_spec, request_spec)
215
216
  end
216
217
 
218
+ def import_from_file(file:, file_type:, file_length:, params: {}, header_overrides: {})
219
+ endpoint_spec = Smartsheet::API::EndpointSpec.new(
220
+ :post,
221
+ ['sheets', 'import'],
222
+ body_type: :file
223
+ )
224
+ content_type = file_type_to_content_type(file_type)
225
+ request_spec = Smartsheet::API::RequestSpec.new(
226
+ params: params,
227
+ header_overrides: header_overrides,
228
+ file_spec: Smartsheet::API::ImportObjectFileSpec.new(file, file_length, content_type)
229
+ )
230
+ client.make_request(endpoint_spec, request_spec)
231
+ end
232
+
233
+ def import_from_file_path(path:, file_type:, params: {}, header_overrides: {})
234
+ endpoint_spec = Smartsheet::API::EndpointSpec.new(
235
+ :post,
236
+ ['sheets', 'import'],
237
+ body_type: :file
238
+ )
239
+ content_type = file_type_to_content_type(file_type)
240
+ request_spec = Smartsheet::API::RequestSpec.new(
241
+ params: params,
242
+ header_overrides: header_overrides,
243
+ file_spec: Smartsheet::API::ImportPathFileSpec.new(path, content_type)
244
+ )
245
+ client.make_request(endpoint_spec, request_spec)
246
+ end
247
+
248
+ def import_from_file_into_folder(
249
+ folder_id:,
250
+ file:,
251
+ file_type:,
252
+ file_length:,
253
+ params: {},
254
+ header_overrides: {}
255
+ )
256
+ endpoint_spec = Smartsheet::API::EndpointSpec.new(
257
+ :post,
258
+ ['folders', :folder_id, 'sheets', 'import'],
259
+ body_type: :file
260
+ )
261
+ content_type = file_type_to_content_type(file_type)
262
+ request_spec = Smartsheet::API::RequestSpec.new(
263
+ params: params,
264
+ header_overrides: header_overrides,
265
+ file_spec: Smartsheet::API::ImportObjectFileSpec.new(file, file_length, content_type),
266
+ folder_id: folder_id
267
+ )
268
+ client.make_request(endpoint_spec, request_spec)
269
+ end
270
+
271
+ def import_from_file_path_into_folder(
272
+ folder_id:,
273
+ path:,
274
+ file_type:,
275
+ params: {},
276
+ header_overrides: {}
277
+ )
278
+ endpoint_spec = Smartsheet::API::EndpointSpec.new(
279
+ :post,
280
+ ['folders', :folder_id, 'sheets', 'import'],
281
+ body_type: :file
282
+ )
283
+ content_type = file_type_to_content_type(file_type)
284
+ request_spec = Smartsheet::API::RequestSpec.new(
285
+ params: params,
286
+ header_overrides: header_overrides,
287
+ file_spec: Smartsheet::API::ImportPathFileSpec.new(path, content_type),
288
+ folder_id: folder_id
289
+ )
290
+ client.make_request(endpoint_spec, request_spec)
291
+ end
292
+
293
+ def import_from_file_into_workspace(
294
+ workspace_id:,
295
+ file:,
296
+ file_type:,
297
+ file_length:,
298
+ params: {},
299
+ header_overrides: {}
300
+ )
301
+ endpoint_spec = Smartsheet::API::EndpointSpec.new(
302
+ :post,
303
+ ['workspaces', :workspace_id, 'sheets', 'import'],
304
+ body_type: :file
305
+ )
306
+ content_type = file_type_to_content_type(file_type)
307
+ request_spec = Smartsheet::API::RequestSpec.new(
308
+ params: params,
309
+ header_overrides: header_overrides,
310
+ file_spec: Smartsheet::API::ImportObjectFileSpec.new(file, file_length, content_type),
311
+ workspace_id: workspace_id
312
+ )
313
+ client.make_request(endpoint_spec, request_spec)
314
+ end
315
+
316
+ def import_from_file_path_into_workspace(
317
+ workspace_id:,
318
+ path:,
319
+ file_type:,
320
+ params: {},
321
+ header_overrides: {}
322
+ )
323
+ endpoint_spec = Smartsheet::API::EndpointSpec.new(
324
+ :post,
325
+ ['workspaces', :workspace_id, 'sheets', 'import'],
326
+ body_type: :file
327
+ )
328
+ content_type = file_type_to_content_type(file_type)
329
+ request_spec = Smartsheet::API::RequestSpec.new(
330
+ params: params,
331
+ header_overrides: header_overrides,
332
+ file_spec: Smartsheet::API::ImportPathFileSpec.new(path, content_type),
333
+ workspace_id: workspace_id
334
+ )
335
+ client.make_request(endpoint_spec, request_spec)
336
+ end
337
+
338
+ ### These endpoints are not yet implemented; these endpoints can be re-included once they are
339
+ ### active
340
+
341
+ # def import_and_replace_sheet_from_file(
342
+ # sheet_id:,
343
+ # file:,
344
+ # file_type:,
345
+ # file_length:,
346
+ # params: {},
347
+ # header_overrides: {}
348
+ # )
349
+ # endpoint_spec = Smartsheet::API::EndpointSpec.new(
350
+ # :post,
351
+ # ['sheets', :sheet_id, 'import'],
352
+ # body_type: :file
353
+ # )
354
+ # content_type = file_type_to_content_type(file_type)
355
+ # request_spec = Smartsheet::API::RequestSpec.new(
356
+ # params: params,
357
+ # header_overrides: header_overrides,
358
+ # file_spec: Smartsheet::API::ImportObjectFileSpec.new(file, file_length, content_type)
359
+ # )
360
+ # client.make_request(endpoint_spec, request_spec)
361
+ # end
362
+
363
+ # def import_and_replace_sheet_from_file_path(
364
+ # sheet_id:,
365
+ # path:,
366
+ # file_type:,
367
+ # params: {},
368
+ # header_overrides: {}
369
+ # )
370
+ # endpoint_spec = Smartsheet::API::EndpointSpec.new(
371
+ # :post,
372
+ # ['sheets', :sheet_id, 'import'],
373
+ # body_type: :file
374
+ # )
375
+ # content_type = file_type_to_content_type(file_type)
376
+ # request_spec = Smartsheet::API::RequestSpec.new(
377
+ # params: params,
378
+ # header_overrides: header_overrides,
379
+ # file_spec: Smartsheet::API::ImportPathFileSpec.new(path, content_type)
380
+ # )
381
+ # client.make_request(endpoint_spec, request_spec)
382
+ # end
383
+
217
384
  def copy(sheet_id:, body:, params: {}, header_overrides: {})
218
385
  endpoint_spec = Smartsheet::API::EndpointSpec.new(
219
386
  :post,
@@ -322,5 +489,22 @@ module Smartsheet
322
489
  )
323
490
  client.make_request(endpoint_spec, request_spec)
324
491
  end
492
+
493
+ private
494
+
495
+ def file_type_to_content_type(file_type)
496
+ mapping = {
497
+ csv: Constants::CSV_TYPE,
498
+ xlsx: Constants::OPENXML_SPREADSHEET_TYPE
499
+ }
500
+
501
+ mapping.fetch(file_type) do |_|
502
+ available_types = mapping.keys.join(', ')
503
+
504
+ raise Smartsheet::Error.new(
505
+ "Unsupported file type: #{file_type}\nValid types: #{available_types}"
506
+ )
507
+ end
508
+ end
325
509
  end
326
510
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartsheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Smartsheet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-16 00:00:00.000000000 Z
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday