groupdocs 1.5.0 → 1.5.1

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 (90) hide show
  1. data/CHANGELOG.md +6 -0
  2. data/examples/api-samples/README.md +1 -1
  3. data/examples/api-samples/public/css/style.css +2 -2
  4. data/examples/api-samples/public/docs/annotation-sample.html +57 -0
  5. data/examples/api-samples/public/docs/envelope-sample.html +32 -32
  6. data/examples/api-samples/public/docs/sample1.html +3 -3
  7. data/examples/api-samples/public/docs/sample10.html +25 -24
  8. data/examples/api-samples/public/docs/sample11.html +17 -17
  9. data/examples/api-samples/public/docs/sample12.html +4 -4
  10. data/examples/api-samples/public/docs/sample13.html +5 -5
  11. data/examples/api-samples/public/docs/sample14.html +5 -5
  12. data/examples/api-samples/public/docs/sample15.html +4 -4
  13. data/examples/api-samples/public/docs/sample16.html +3 -3
  14. data/examples/api-samples/public/docs/sample17.html +3 -3
  15. data/examples/api-samples/public/docs/sample18.html +129 -34
  16. data/examples/api-samples/public/docs/sample19.html +59 -0
  17. data/examples/api-samples/public/docs/sample2.html +5 -5
  18. data/examples/api-samples/public/docs/sample20.html +51 -0
  19. data/examples/api-samples/public/docs/sample21.html +66 -0
  20. data/examples/api-samples/public/docs/sample22.html +53 -0
  21. data/examples/api-samples/public/docs/sample3.html +4 -4
  22. data/examples/api-samples/public/docs/sample4.html +27 -16
  23. data/examples/api-samples/public/docs/sample5.html +29 -22
  24. data/examples/api-samples/public/docs/sample6.html +6 -6
  25. data/examples/api-samples/public/docs/sample7.html +8 -8
  26. data/examples/api-samples/public/docs/sample8.html +31 -23
  27. data/examples/api-samples/public/docs/sample9.html +26 -8
  28. data/examples/api-samples/public/templates/merge_feid_doc.docx +0 -0
  29. data/examples/api-samples/samples/annotation-sample.rb +22 -16
  30. data/examples/api-samples/samples/envelope-sample.rb +26 -25
  31. data/examples/api-samples/samples/sample1.rb +2 -2
  32. data/examples/api-samples/samples/sample10.rb +21 -20
  33. data/examples/api-samples/samples/sample11.rb +18 -18
  34. data/examples/api-samples/samples/sample12.rb +3 -3
  35. data/examples/api-samples/samples/sample13.rb +4 -4
  36. data/examples/api-samples/samples/sample14.rb +4 -4
  37. data/examples/api-samples/samples/sample15.rb +3 -3
  38. data/examples/api-samples/samples/sample16.rb +2 -2
  39. data/examples/api-samples/samples/sample17.rb +2 -2
  40. data/examples/api-samples/samples/sample18.rb +90 -106
  41. data/examples/api-samples/samples/sample19.rb +5 -5
  42. data/examples/api-samples/samples/sample2.rb +4 -4
  43. data/examples/api-samples/samples/sample20.rb +4 -4
  44. data/examples/api-samples/samples/sample21.rb +4 -4
  45. data/examples/api-samples/samples/sample22.rb +2 -2
  46. data/examples/api-samples/samples/sample23.rb +0 -0
  47. data/examples/api-samples/samples/sample24.rb +0 -0
  48. data/examples/api-samples/samples/sample25.rb +96 -0
  49. data/examples/api-samples/samples/sample3.rb +3 -3
  50. data/examples/api-samples/samples/sample4.rb +23 -12
  51. data/examples/api-samples/samples/sample5.rb +23 -16
  52. data/examples/api-samples/samples/sample6.rb +8 -8
  53. data/examples/api-samples/samples/sample7.rb +7 -7
  54. data/examples/api-samples/samples/sample8.rb +29 -21
  55. data/examples/api-samples/samples/sample9.rb +23 -5
  56. data/examples/api-samples/views/_others_samples.haml +57 -0
  57. data/examples/api-samples/views/annotation_sample.haml +30 -30
  58. data/examples/api-samples/views/envelope_sample.haml +31 -31
  59. data/examples/api-samples/views/index.haml +33 -25
  60. data/examples/api-samples/views/sample1.haml +22 -69
  61. data/examples/api-samples/views/sample10.haml +57 -73
  62. data/examples/api-samples/views/sample11.haml +31 -79
  63. data/examples/api-samples/views/sample12.haml +18 -66
  64. data/examples/api-samples/views/sample13.haml +21 -70
  65. data/examples/api-samples/views/sample14.haml +18 -67
  66. data/examples/api-samples/views/sample15.haml +15 -63
  67. data/examples/api-samples/views/sample16.haml +13 -61
  68. data/examples/api-samples/views/sample17.haml +19 -67
  69. data/examples/api-samples/views/sample18.haml +74 -159
  70. data/examples/api-samples/views/sample19.haml +25 -74
  71. data/examples/api-samples/views/sample2.haml +19 -66
  72. data/examples/api-samples/views/sample20.haml +19 -68
  73. data/examples/api-samples/views/sample21.haml +28 -76
  74. data/examples/api-samples/views/sample22.haml +29 -77
  75. data/examples/api-samples/views/sample23.haml +0 -0
  76. data/examples/api-samples/views/sample24.haml +0 -0
  77. data/examples/api-samples/views/sample25.haml +91 -0
  78. data/examples/api-samples/views/sample3.haml +20 -68
  79. data/examples/api-samples/views/sample4.haml +53 -68
  80. data/examples/api-samples/views/sample5.haml +54 -70
  81. data/examples/api-samples/views/sample6.haml +21 -69
  82. data/examples/api-samples/views/sample7.haml +19 -66
  83. data/examples/api-samples/views/sample8.haml +60 -75
  84. data/examples/api-samples/views/sample9.haml +54 -70
  85. data/examples/api-samples/web.rb +20 -0
  86. data/lib/groupdocs/api/request.rb +4 -2
  87. data/lib/groupdocs/version.rb +1 -1
  88. data/spec/groupdocs/api/request_spec.rb +10 -2
  89. metadata +18 -5
  90. data/examples/api-samples/app.rb +0 -15
@@ -16,7 +16,7 @@ post '/sample22' do
16
16
  begin
17
17
 
18
18
  # check required variables
19
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.fileId.empty? or settings.email.empty? or settings.first_name.empty? or settings.last_name.empty?
19
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.fileId.empty? or settings.email.empty? or settings.first_name.empty? or settings.last_name.empty?
20
20
 
21
21
  # create new user
22
22
  user = GroupDocs::User.new
@@ -48,5 +48,5 @@ post '/sample22' do
48
48
  end
49
49
 
50
50
  # set variables for template
51
- haml :sample22, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.fileId, :email => settings.email, :first_name => settings.first_name, :last_name => settings.last_name }
51
+ haml :sample22, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.fileId, :email => settings.email, :first_name => settings.first_name, :last_name => settings.last_name, :err => err}
52
52
  end
@@ -0,0 +1,96 @@
1
+ # GET request
2
+ get '/sample25' do
3
+ haml :sample25
4
+ end
5
+
6
+ # POST request
7
+ post '/sample25' do
8
+ # set variables
9
+ set :client_id, params[:client_id]
10
+ set :private_key, params[:private_key]
11
+ set :source, params[:source]
12
+ set :file_id, params[:fileId]
13
+ set :url, params[:url]
14
+
15
+ # Set download path
16
+ downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
17
+
18
+ # Remove all files from download directory or create folder if it not there
19
+ if File.directory?(downloads_path)
20
+ Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
21
+ else
22
+ Dir::mkdir(downloads_path)
23
+ end
24
+
25
+ begin
26
+ # Check required variables
27
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
28
+
29
+
30
+ # get document by file GUID
31
+ case settings.source
32
+ when 'guid'
33
+ # Create instance of File
34
+ file = GroupDocs::Storage::File.new({:guid => settings.file_id})
35
+ when 'local'
36
+ # Construct path
37
+ file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
38
+ # Open file
39
+ File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
40
+ # Make a request to API using client_id and private_key
41
+ file = GroupDocs::Storage::File.upload!(file_path, {}, {:client_id => settings.client_id, :private_key => settings.private_key})
42
+ when 'url'
43
+ # Upload file from defined url
44
+ file = GroupDocs::Storage::File.upload_web!(settings.url, {:client_id => settings.client_id, :private_key => settings.private_key})
45
+ else
46
+ raise 'Wrong GUID source.'
47
+ end
48
+
49
+ # Raise exception if something went wrong
50
+ raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
51
+
52
+ # Make GroupDocs::Storage::Document instance
53
+ document = file.to_document
54
+
55
+ # Create datasource with fields
56
+ datasource = GroupDocs::DataSource.new
57
+
58
+ # Get arry of document's fields
59
+ fields = document.fields!({:client_id => settings.client_id, :private_key => settings.private_key})
60
+
61
+ # Create Field instance and fill the fields
62
+ datasource.fields = fields.map { |field| GroupDocs::DataSource::Field.new(name: field.name, type: :text, values: %w(value1 value2)) }
63
+
64
+ # Adds datasource.
65
+ datasource.add!({:client_id => settings.client_id, :private_key => settings.private_key})
66
+
67
+
68
+ # Creates new job to merge datasource into document.
69
+ job = document.datasource!(datasource, {:new_type => 'pdf'}, {:client_id => settings.client_id, :private_key => settings.private_key})
70
+ sleep 10 # wait for merge and convert
71
+
72
+ # Returns an hash of input and output documents associated to job.
73
+ document = job.documents!({:client_id => settings.client_id, :private_key => settings.private_key})
74
+
75
+ # Download file
76
+ document[:inputs][0].outputs[0].download!("#{File.dirname(__FILE__)}/../public/downloads", {:client_id => settings.client_id, :private_key => settings.private_key})
77
+
78
+ # Set converted document GUID
79
+ guid = document[:inputs][0].outputs[0].guid
80
+ # Set converted document Name
81
+ file_name = document[:inputs][0].outputs[0].name
82
+
83
+ # Set iframe with document GUID or raise an error
84
+ if guid
85
+ iframe = "<iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/document-viewer/embed/#{guid}'></iframe>"
86
+ else
87
+ raise 'File was not converted'
88
+ end
89
+
90
+ rescue Exception => e
91
+ err = e.message
92
+ end
93
+
94
+ # set variables for template
95
+ haml :sample25, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :iframe => iframe, :file_name => file_name, :err => err}
96
+ end
@@ -11,7 +11,7 @@ post '/sample3' do
11
11
 
12
12
  begin
13
13
  # check required variables
14
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
14
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
15
15
 
16
16
  # construct path
17
17
  filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
@@ -23,11 +23,11 @@ post '/sample3' do
23
23
  # result massages
24
24
  massage = "<p>File was uploaded to GroupDocs. Here you can see your <strong>#{params[:file][:filename]}</strong> file in the GroupDocs Embedded Viewer.</p>"
25
25
  iframe = "<iframe src='https://apps.groupdocs.com/document-viewer/Embed/#{file.guid}' frameborder='0' width='720' height='600'></iframe>"
26
-
26
+
27
27
  rescue Exception => e
28
28
  err = e.message
29
29
  end
30
30
 
31
31
  # set variables for template
32
- haml :sample3, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :iframe=>iframe, :massage => massage, :err => err }
32
+ haml :sample3, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :iframe => iframe, :massage => massage, :err => err}
33
33
  end
@@ -9,24 +9,35 @@ post '/sample4' do
9
9
  set :client_id, params[:client_id]
10
10
  set :private_key, params[:private_key]
11
11
  set :file_id, params[:file_id]
12
+ set :source, params[:source]
13
+ set :url, params[:url]
12
14
 
13
15
  begin
14
16
  # check required variables
15
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty?
17
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
16
18
 
17
- # make a request to API using client_id and private_key
18
- files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
19
- dowload_file = ''
20
-
21
- # get file by file ID
22
- files_list.each do |element|
23
- if element.id == Integer(settings.file_id)
24
- dowload_file = element
25
- end
19
+ # get file GUID
20
+ file = nil
21
+ case settings.source
22
+ when 'guid'
23
+ file = GroupDocs::Storage::File.new({:guid => settings.file_id})
24
+ when 'local'
25
+ # construct path
26
+ filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
27
+ # open file
28
+ File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
29
+ # make a request to API using client_id and private_key
30
+ file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
31
+ when 'url'
32
+ file = GroupDocs::Storage::File.upload_web!(settings.url, client_id: settings.client_id, private_key: settings.private_key)
33
+ else
34
+ raise 'Wrong GUID source.'
26
35
  end
27
36
 
37
+ pp file
38
+ pp file.name
28
39
  # download file
29
- dowloaded_file = dowload_file.download!(File.dirname(__FILE__), { :client_id => settings.client_id, :private_key => settings.private_key})
40
+ dowloaded_file = file.download!("#{File.dirname(__FILE__)}/../public/downloads", {:client_id => settings.client_id, :private_key => settings.private_key})
30
41
  unless dowloaded_file.empty?
31
42
  massage = "<font color='green'>File was downloaded to the <font color='blue'>#{dowloaded_file}</font> folder</font> <br />"
32
43
  end
@@ -36,5 +47,5 @@ post '/sample4' do
36
47
  end
37
48
 
38
49
  # set variables for template
39
- haml :sample4, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :file_id => settings.file_id, :massage => massage, :err => err }
50
+ haml :sample4, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :file_id => settings.file_id, :massage => massage, :err => err}
40
51
  end
@@ -9,35 +9,42 @@ post '/sample5' do
9
9
  set :client_id, params[:client_id]
10
10
  set :private_key, params[:private_key]
11
11
  set :file_id, params[:file_id]
12
+ set :url, params[:url]
12
13
  set :copy, params[:copy]
13
14
  set :move, params[:move]
14
15
  set :dest_path, params[:dest_path]
15
-
16
+
16
17
  begin
17
18
  # check required variables
18
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty?
19
-
20
- # make a request to API using client_id and private_key
21
- files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
19
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty?
22
20
 
23
- # get file by file ID
24
- manipulate_file = nil
25
- files_list.each do |element|
26
- if element.id == Integer(settings.file_id)
27
- manipulate_file = element
28
- end
21
+ file = nil
22
+ # get document by file GUID
23
+ case settings.source
24
+ when 'guid'
25
+ file = GroupDocs::Storage::File.new({:guid => settings.file_id})
26
+ when 'local'
27
+ # construct path
28
+ filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
29
+ # open file
30
+ File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
31
+ # make a request to API using client_id and private_key
32
+ file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
33
+ when 'url'
34
+ file = GroupDocs::Storage::File.upload_web!(settings.url, client_id: settings.client_id, private_key: settings.private_key)
35
+ else
36
+ raise 'Wrong GUID source.'
29
37
  end
30
- raise "No file with such FileID" if manipulate_file.nil?
31
38
 
32
39
  # copy file using request to API
33
40
  unless settings.copy.nil?
34
- file = manipulate_file.copy!(settings.dest_path, {}, { :client_id => settings.client_id, :private_key => settings.private_key})
41
+ file = file.copy!(settings.dest_path, {}, {:client_id => settings.client_id, :private_key => settings.private_key})
35
42
  button = settings.copy
36
43
  end
37
44
 
38
45
  # move file using request to API
39
46
  unless settings.move.nil?
40
- file = manipulate_file.move!(settings.dest_path, {}, { :client_id => settings.client_id, :private_key => settings.private_key})
47
+ file = file.move!(settings.dest_path, {}, {:client_id => settings.client_id, :private_key => settings.private_key})
41
48
  button = settings.move
42
49
  end
43
50
 
@@ -45,11 +52,11 @@ post '/sample5' do
45
52
  if file
46
53
  massage = "File was #{button}'ed to the #{settings.dest_path} folder"
47
54
  end
48
-
55
+
49
56
  rescue Exception => e
50
57
  err = e.message
51
58
  end
52
59
 
53
60
  # set variables for template
54
- haml :sample5, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :file_id => settings.file_id, :dest_path => settings.dest_path, :massage => massage, :err => err }
61
+ haml :sample5, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :file_id => settings.file_id, :dest_path => settings.dest_path, :massage => massage, :err => err}
55
62
  end
@@ -8,29 +8,29 @@ post '/sample6' do
8
8
  # set variables
9
9
  set :client_id, params[:client_id]
10
10
  set :private_key, params[:private_key]
11
-
11
+
12
12
  begin
13
13
  # check required variables
14
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
14
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
15
15
 
16
16
  # construct file path and open file
17
- file_one_path = "#{Dir.tmpdir}/#{params[:document][:filename]}"
17
+ file_one_path = "#{Dir.tmpdir}/#{params[:document][:filename]}"
18
18
  File.open(file_one_path, 'wb') { |f| f.write(params[:document][:tempfile].read) }
19
19
 
20
20
  # create new file
21
- file_one = GroupDocs::Storage::File.new(name: params[:document][:filename], local_path: file_one_path)
21
+ file_one = GroupDocs::Storage::File.new(name: params[:document][:filename], local_path: file_one_path)
22
22
  document_one = file_one.to_document
23
23
 
24
24
  # construct signature path and open file
25
- signature_one_path = "#{Dir.tmpdir}/#{params[:signature][:filename]}"
25
+ signature_one_path = "#{Dir.tmpdir}/#{params[:signature][:filename]}"
26
26
  File.open(signature_one_path, 'wb') { |f| f.write(params[:signature][:tempfile].read) }
27
27
 
28
28
  # add signature to file using API
29
29
  signature_one = GroupDocs::Signature.new(name: 'Test', image_path: signature_one_path)
30
- signature_one.position = { top: 0.1, left: 0.07, width: 50, height: 50}
30
+ signature_one.position = {top: 0.1, left: 0.07, width: 50, height: 50}
31
31
 
32
32
  # make a request to API using client_id and private_key
33
- signed_documents = GroupDocs::Document.sign_documents!([document_one], [signature_one], {}, { :client_id => settings.client_id, :private_key => settings.private_key })
33
+ signed_documents = GroupDocs::Document.sign_documents!([document_one], [signature_one], {}, {:client_id => settings.client_id, :private_key => settings.private_key})
34
34
  guid = signed_documents.first.file.guid
35
35
 
36
36
  # generate result
@@ -43,5 +43,5 @@ post '/sample6' do
43
43
  end
44
44
 
45
45
  # set variables for template
46
- haml :sample6, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :iframe => iframe, :err => err }
46
+ haml :sample6, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :iframe => iframe, :err => err}
47
47
  end
@@ -8,13 +8,13 @@ post '/sample7' do
8
8
  # set variables
9
9
  set :client_id, params[:client_id]
10
10
  set :private_key, params[:private_key]
11
-
11
+
12
12
  begin
13
13
  # check required variables
14
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
14
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
15
15
 
16
16
  # make a request to API using client_id and private_key
17
- files_list = GroupDocs::Storage::Folder.list!('/', {:extended => true}, { :client_id => settings.client_id, :private_key => settings.private_key})
17
+ files_list = GroupDocs::Storage::Folder.list!('/', {:extended => true}, {:client_id => settings.client_id, :private_key => settings.private_key})
18
18
 
19
19
  # construct result string
20
20
  thumbnails = ''
@@ -22,13 +22,13 @@ post '/sample7' do
22
22
  if element.class.name.split('::').last == 'Folder'
23
23
  next
24
24
  end
25
-
25
+
26
26
  if element.thumbnail
27
- name = element.name
27
+ name = element.name
28
28
  thumbnails += "<p><img src='data:image/png;base64,#{element.thumbnail}', width='40px', height='40px'> #{name}</p>"
29
29
  end
30
30
  end
31
-
31
+
32
32
  unless thumbnails.empty?
33
33
  set :thumbnails, thumbnails
34
34
  end
@@ -38,5 +38,5 @@ post '/sample7' do
38
38
  end
39
39
 
40
40
  # set variables for template
41
- haml :sample7, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :thumbnailList => thumbnails, :err => err }
41
+ haml :sample7, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :thumbnailList => thumbnails, :err => err}
42
42
  end
@@ -10,34 +10,42 @@ post '/sample8' do
10
10
  set :private_key, params[:private_key]
11
11
  set :guid, params[:guid]
12
12
  set :page_number, params[:page_number]
13
-
14
- # file = GroupDocs::Storage::Folder.list!.last
15
- # document = file.to_document
16
- # document.page_images! 1024, 768, first_page: 0, page_count: 1
17
-
13
+
14
+ # file = GroupDocs::Storage::Folder.list!.last
15
+ # document = file.to_document
16
+ # document.page_images! 1024, 768, first_page: 0, page_count: 1
17
+
18
18
  begin
19
19
  # check required variables
20
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
21
-
22
- # make a request to API using client_id and private_key
23
- files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
20
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
24
21
 
22
+ file = nil
25
23
  doc = nil
26
24
  metadata = nil
27
- files_list.each do |element|
28
- if element.class.name.split('::').last == 'Folder'
29
- next
30
- end
31
-
32
- # find document and get metadata
33
- if element.guid == settings.guid
34
- metadata = element.to_document.metadata!({ :client_id => settings.client_id, :private_key => settings.private_key})
35
- doc = element.to_document
36
- end
25
+
26
+ # get document by file GUID
27
+ case settings.source
28
+ when 'guid'
29
+ file = GroupDocs::Storage::File.new({:guid => settings.file_id})
30
+ when 'local'
31
+ # construct path
32
+ filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
33
+ # open file
34
+ File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
35
+ # make a request to API using client_id and private_key
36
+ file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
37
+ when 'url'
38
+ file = GroupDocs::Storage::File.upload_web!(settings.url, client_id: settings.client_id, private_key: settings.private_key)
39
+ else
40
+ raise 'Wrong GUID source.'
37
41
  end
38
42
 
43
+ doc = file.to_document
44
+ metadata = doc.metadata!({:client_id => settings.client_id, :private_key => settings.private_key})
45
+
46
+
39
47
  # get document page images
40
- images = doc.page_images!(800, 400, {:first_page => 0, :page_count => metadata.page_count}, { :client_id => settings.client_id, :private_key => settings.private_key})
48
+ images = doc.page_images!(800, 400, {:first_page => 0, :page_count => metadata.page_count}, {:client_id => settings.client_id, :private_key => settings.private_key})
41
49
 
42
50
  # result
43
51
  unless images.empty?
@@ -49,5 +57,5 @@ post '/sample8' do
49
57
  end
50
58
 
51
59
  # set variables for template
52
- haml :sample8, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :guid =>settings.guid , :page_number=>settings.page_number, :image=>image, :err => err }
60
+ haml :sample8, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :guid => settings.guid, :page_number => settings.page_number, :image => image, :err => err}
53
61
  end
@@ -6,17 +6,35 @@ end
6
6
  # POST request
7
7
  post '/sample9' do
8
8
  # set variables
9
- set :guid, params[:guid]
9
+ set :file_id, params[:fileId]
10
10
  set :width, params[:width]
11
11
  set :height, params[:height]
12
12
 
13
13
  begin
14
14
  # check required variables
15
- raise "Please enter all required parameters" if settings.guid.empty? or settings.width.empty? or settings.height.empty?
15
+ raise 'Please enter all required parameters' if settings.guid.empty? or settings.width.empty? or settings.height.empty?
16
+
17
+ # get document by file GUID
18
+ file = nil
19
+ case settings.source
20
+ when 'guid'
21
+ file = GroupDocs::Storage::File.new({:guid => settings.file_id})
22
+ when 'local'
23
+ # construct path
24
+ filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
25
+ # open file
26
+ File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
27
+ # make a request to API using client_id and private_key
28
+ file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
29
+ when 'url'
30
+ file = GroupDocs::Storage::File.upload_web!(settings.url, client_id: settings.client_id, private_key: settings.private_key)
31
+ else
32
+ raise 'Wrong GUID source.'
33
+ end
16
34
 
17
35
  # construct result string
18
- v_url = "https://apps.groupdocs.com/document-viewer/embed/#{settings.guid}?frameborder='0' width='#{settings.width}' height='#{settings.height}'"
19
-
36
+ v_url = "https://apps.groupdocs.com/document-viewer/embed/#{file.guid}?frameborder='0' width='#{settings.width}' height='#{settings.height}'"
37
+
20
38
  if v_url
21
39
  v_url = v_url
22
40
  end
@@ -26,5 +44,5 @@ post '/sample9' do
26
44
  end
27
45
 
28
46
  # set variables for template
29
- haml :sample9, :locals => { :guid => settings.guid, :width => settings.width, :height => settings.height, :v_url=>v_url, :err => err }
47
+ haml :sample9, :locals => {:guid => settings.guid, :width => settings.width, :height => settings.height, :v_url => v_url, :err => err}
30
48
  end