groupdocs 1.2.8 → 1.2.9

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 (69) hide show
  1. data/examples/api-samples/README.md +17 -6
  2. data/examples/api-samples/app.rb +0 -2
  3. data/examples/api-samples/public/GroupDocs_Signature_Demo.pdf +0 -0
  4. data/examples/api-samples/public/docs/docco.css +192 -0
  5. data/examples/api-samples/public/docs/envelope-sample.html +132 -0
  6. data/examples/api-samples/public/docs/sample1.html +26 -0
  7. data/examples/api-samples/public/docs/sample10.html +49 -0
  8. data/examples/api-samples/public/docs/sample11.html +87 -0
  9. data/examples/api-samples/public/docs/sample12.html +40 -0
  10. data/examples/api-samples/public/docs/sample13.html +41 -0
  11. data/examples/api-samples/public/docs/sample14.html +30 -0
  12. data/examples/api-samples/public/docs/sample15.html +27 -0
  13. data/examples/api-samples/public/docs/sample16.html +25 -0
  14. data/examples/api-samples/public/docs/sample17.html +37 -0
  15. data/examples/api-samples/public/docs/sample18.html +62 -0
  16. data/examples/api-samples/public/docs/sample2.html +30 -0
  17. data/examples/api-samples/public/docs/sample3.html +34 -0
  18. data/examples/api-samples/public/docs/sample4.html +41 -0
  19. data/examples/api-samples/public/docs/sample5.html +56 -0
  20. data/examples/api-samples/public/docs/sample6.html +48 -0
  21. data/examples/api-samples/public/docs/sample7.html +43 -0
  22. data/examples/api-samples/public/docs/sample8.html +54 -0
  23. data/examples/api-samples/public/docs/sample9.html +31 -0
  24. data/examples/api-samples/samples/envelope-sample.rb +132 -0
  25. data/examples/api-samples/samples/sample1.rb +10 -2
  26. data/examples/api-samples/samples/sample10.rb +17 -5
  27. data/examples/api-samples/samples/sample11.rb +86 -0
  28. data/examples/api-samples/samples/sample12.rb +39 -0
  29. data/examples/api-samples/samples/sample13.rb +40 -0
  30. data/examples/api-samples/samples/sample14.rb +29 -0
  31. data/examples/api-samples/samples/sample15.rb +26 -0
  32. data/examples/api-samples/samples/sample16.rb +24 -0
  33. data/examples/api-samples/samples/sample17.rb +36 -0
  34. data/examples/api-samples/samples/sample18.rb +61 -0
  35. data/examples/api-samples/samples/sample2.rb +14 -4
  36. data/examples/api-samples/samples/sample3.rb +14 -4
  37. data/examples/api-samples/samples/sample4.rb +12 -3
  38. data/examples/api-samples/samples/sample5.rb +13 -2
  39. data/examples/api-samples/samples/sample6.rb +18 -6
  40. data/examples/api-samples/samples/sample7.rb +9 -0
  41. data/examples/api-samples/samples/sample8.rb +17 -4
  42. data/examples/api-samples/samples/sample9.rb +10 -2
  43. data/examples/api-samples/views/envelope_sample.haml +73 -0
  44. data/examples/api-samples/views/index.haml +18 -0
  45. data/examples/api-samples/views/sample1.haml +21 -0
  46. data/examples/api-samples/views/sample10.haml +21 -0
  47. data/examples/api-samples/views/sample11.haml +141 -0
  48. data/examples/api-samples/views/sample12.haml +94 -0
  49. data/examples/api-samples/views/sample13.haml +90 -0
  50. data/examples/api-samples/views/sample14.haml +86 -0
  51. data/examples/api-samples/views/sample15.haml +75 -0
  52. data/examples/api-samples/views/sample16.haml +68 -0
  53. data/examples/api-samples/views/sample17.haml +80 -0
  54. data/examples/api-samples/views/sample18.haml +87 -0
  55. data/examples/api-samples/views/sample2.haml +21 -0
  56. data/examples/api-samples/views/sample3.haml +23 -2
  57. data/examples/api-samples/views/sample4.haml +21 -0
  58. data/examples/api-samples/views/sample5.haml +21 -0
  59. data/examples/api-samples/views/sample6.haml +22 -1
  60. data/examples/api-samples/views/sample7.haml +21 -0
  61. data/examples/api-samples/views/sample8.haml +22 -1
  62. data/examples/api-samples/views/sample9.haml +21 -0
  63. data/lib/groupdocs/job.rb +5 -3
  64. data/lib/groupdocs/user.rb +33 -0
  65. data/lib/groupdocs/version.rb +1 -1
  66. data/spec/groupdocs/job_spec.rb +5 -0
  67. data/spec/groupdocs/user_spec.rb +22 -0
  68. data/spec/support/json/update_account.json +10 -0
  69. metadata +45 -4
@@ -0,0 +1,132 @@
1
+ # GET request
2
+ get '/envelope-sample' do
3
+ haml :envelope_sample
4
+ end
5
+
6
+ # POST request to handle callback when document was signed
7
+ post '/envelope-sample/sign' do
8
+ # Content Type of callback is application/json
9
+ data = JSON.parse(request.body.read)
10
+ begin
11
+ raise "Empty params!" if data.empty?
12
+ #create empty file and write data as "key: value" to it
13
+ outFile = File.new("signed", "w")
14
+ data.each do |key, value|
15
+ outFile.write("#{key}: #{value} \n")
16
+ end
17
+ outFile.close
18
+ rescue Exception => e
19
+ err = e.message
20
+ end
21
+ end
22
+
23
+
24
+ # POST request to handle callback and download envelop when document was signed
25
+ post '/envelope-sample/sign-and-download' do
26
+ data = JSON.parse(request.body.read)
27
+ begin
28
+ raise "Empty params!" if data.empty?
29
+ GroupDocs.configure do |groupdocs|
30
+ groupdocs.client_id = '' # Your client Client ID here
31
+ groupdocs.private_key = '' # Your API Key here
32
+ groupdocs.api_server = 'https://api.groupdocs.com'
33
+ end
34
+ data.each do |key, value|
35
+ if key == 'SourceId'
36
+ # Create envelop with id and name as SourceId parameter from callback
37
+ envelope = GroupDocs::Signature::Envelope.new id: value,
38
+ name: value
39
+ # download signed documents as archive
40
+ envelope.signed_documents! '.'
41
+ end
42
+ end
43
+ rescue Exception => e
44
+ err = e.message
45
+ end
46
+ end
47
+
48
+ # GET request to check if envelop was signed
49
+ get '/envelope-sample/check' do
50
+ if File.exist?('signed')
51
+ File.readlines('signed').each do |line|
52
+ end
53
+ else
54
+ 'Have not signed yet'
55
+ end
56
+ end
57
+
58
+ # POST request
59
+ post '/envelope-sample' do
60
+ set :client_id, params[:client_id]
61
+ set :private_key, params[:private_key]
62
+
63
+ begin
64
+ raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
65
+
66
+ GroupDocs.configure do |groupdocs|
67
+ groupdocs.client_id = params[:client_id]
68
+ groupdocs.private_key = params[:private_key]
69
+ groupdocs.api_server = 'https://stage-api.groupdocs.com'
70
+ end
71
+
72
+ # upload document
73
+ filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
74
+ File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
75
+ file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
76
+ document = file.to_document
77
+
78
+ # create envelope
79
+ envelope = GroupDocs::Signature::Envelope.new
80
+ envelope.name = "Envelope"
81
+ envelope.email_subject = "Sing this!"
82
+ envelope.create!
83
+
84
+ # add document to envelope
85
+ envelope.add_document! document
86
+
87
+ # update document object after it's created
88
+ document = envelope.documents!.first
89
+
90
+ # add new recipient to envelope
91
+ roles = GroupDocs::Signature::Role.get!
92
+ recipient = GroupDocs::Signature::Recipient.new
93
+ recipient.email = 'john@smith.com'
94
+ recipient.first_name = 'John'
95
+ recipient.last_name = 'Smith'
96
+ recipient.role_id = roles.detect { |role| role.name == "Signer" }.id
97
+ envelope.add_recipient! recipient
98
+
99
+ # update recipient object after it's created
100
+ recipient = envelope.recipients!.first
101
+
102
+ #
103
+ # You can add fields manually.
104
+ #
105
+
106
+ # add city field to envelope
107
+ #field = GroupDocs::Signature::Field.get!.detect { |f| f.type == :single_line }
108
+ #field.name = 'City'
109
+ #field.location = { location_x: 0.3, location_y: 0.2, page: 1 }
110
+ #envelope.add_field! field, document, recipient
111
+
112
+ # add signature field to envelope
113
+ #field = GroupDocs::Signature::Field.get!.detect { |f| f.type == :signature }
114
+ #field.location = { location_x: 0.3, location_y: 0.3, page: 1 }
115
+ #envelope.add_field! field, document, recipient
116
+
117
+ # URL for callback
118
+ webhook = 'http://groupdocs-ruby-samples.herokuapp.com/envelope-sample/sign'
119
+
120
+ # send envelope
121
+ envelope.send! webhook
122
+
123
+ # construct embedded signature url
124
+ url = "https://stage-apps.groupdocs.com/signature/signembed/#{envelope.id}/#{recipient.id}"
125
+ iframe = "<iframe src='#{url}' frameborder='0' width='720' height='600'></iframe>"
126
+
127
+ rescue Exception => e
128
+ err = e.message
129
+ end
130
+
131
+ haml :envelope_sample, :locals => { :client_id => settings.client_id, :private_key => settings.private_key, :err => err, :iframe => iframe}
132
+ end
@@ -1,17 +1,25 @@
1
+ # GET request
1
2
  get '/sample1' do
2
-
3
3
  haml :sample1
4
4
  end
5
5
 
6
+ # POST request
6
7
  post '/sample1' do
8
+ # set variables
7
9
  set :client_id, params[:client_id]
8
10
  set :private_key, params[:private_key]
11
+
9
12
  begin
13
+ # check required variables
10
14
  raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
15
+
16
+ # make a request to API using client_id and private_key
11
17
  user = GroupDocs::User.get!({:client_id => settings.client_id, :private_key => settings.private_key})
18
+
12
19
  rescue Exception => e
13
20
  err = e.message
14
21
  end
15
-
22
+
23
+ # set variables for template
16
24
  haml :sample1, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :user => user, :err => err }
17
25
  end
@@ -1,36 +1,48 @@
1
+ # GET request
1
2
  get '/sample10' do
2
3
  haml :sample10
3
4
  end
4
5
 
6
+ # POST request
5
7
  post '/sample10' do
8
+ # set variables
6
9
  set :client_id, params[:client_id]
7
10
  set :private_key, params[:private_key]
8
11
  set :guid, params[:guid]
9
12
  set :email, params[:email]
13
+
10
14
  begin
15
+ # check required variables
11
16
  raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.guid.empty? or settings.email.empty?
12
17
 
18
+ # make a request to API using client_id and private_key
13
19
  files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
20
+
14
21
  name = nil
15
22
  doc = nil
16
23
  files_list.each do |element|
17
24
  if element.class.name.split('::').last == 'Folder'
18
25
  next
19
26
  end
20
-
27
+
28
+ # get document and document name
21
29
  if element.guid == settings.guid
22
30
  name = element.name
23
31
  doc = element
24
32
  end
25
33
  end
26
34
 
35
+ # Share document. Make a request to API using client_id and private_key
27
36
  shared = doc.to_document.sharers_set!(settings.email.split(" "), { :client_id => settings.client_id, :private_key => settings.private_key});
28
- if shared
29
- shared_emails = settings.email
30
- end
37
+
38
+ # result
39
+ if shared
40
+ shared_emails = settings.email
41
+ end
31
42
  rescue Exception => e
32
43
  err = e.message
33
- end
44
+ end
34
45
 
46
+ # set variables for template
35
47
  haml :sample10, :locals => { :client_id => settings.client_id, :private_key => settings.private_key, :guid => settings.guid, :email=>settings.email, :shared => shared_emails, :err => err }
36
48
  end
@@ -0,0 +1,86 @@
1
+ # GET request
2
+ get '/sample11' do
3
+ haml :sample11
4
+ end
5
+
6
+ # POST request
7
+ post '/sample11' do
8
+ # set variables
9
+ set :client_id, params[:client_id]
10
+ set :private_key, params[:private_key]
11
+ set :file_id, params[:fileId]
12
+ set :annotation_type, params[:annotation_type]
13
+
14
+ begin
15
+ # check required variables
16
+ raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty? or settings.annotation_type.empty?
17
+
18
+ # annotation types
19
+ types = {'text' => 0, 'area' => 1, 'point' => 2}
20
+
21
+ # required parameters
22
+ allParams = allParams = ['annotation_type', 'box_x', 'box_y', 'text']
23
+
24
+ # added required parameters depends on annotation type ['text' or 'area']
25
+ if settings.annotation_type == "text"
26
+ allParams = allParams | ['box_width', 'box_height', 'annotationPosition_x', 'annotationPosition_y']
27
+ elsif settings.annotation_type == "area"
28
+ allParams = allParams | ['box_width', 'box_height']
29
+ end
30
+
31
+ # checking required parameters
32
+ allParams.each do |param|
33
+ raise "Please enter all required parameters" if params[param].empty?
34
+ end
35
+
36
+ # make a request to API using client_id and private_key
37
+ files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
38
+ document = ''
39
+
40
+ # get document by file ID
41
+ files_list.each do |element|
42
+ if element.respond_to?('guid') == true and element.guid == settings.file_id
43
+ document = element
44
+ end
45
+ end
46
+
47
+ unless document.instance_of? String
48
+
49
+ # start create new annotation
50
+ annotation = GroupDocs::Document::Annotation.new(document: document.to_document)
51
+ annotation.type = types[settings.annotation_type]
52
+
53
+ # construct requestBody depends on annotation type
54
+ # text annotation
55
+ if settings.annotation_type == "text"
56
+ annotation.box = {x: params['box_x'], y: params['box_y'], width: params['box_width'], height: params['box_height']}
57
+ annotation.annotationPosition = {x: params['annotationPosition_x'], y: params['annotationPosition_y']}
58
+
59
+ # area annotation
60
+ elsif settings.annotation_type == "area"
61
+ annotation.box = {x: params['box_x'], y: params['box_y'], width: params['box_width'], height: params['box_height']}
62
+ annotation.annotationPosition = {x: 0, y: 0}
63
+
64
+ # point annotation
65
+ elsif settings.annotation_type == "point"
66
+ annotation.box = {x: params['box_x'], y: params['box_y'], width: 0, height: 0}
67
+ annotation.annotationPosition = {x: 0, y: 0}
68
+ end
69
+
70
+ # call create method
71
+ annotation.create!({ :client_id => settings.client_id, :private_key => settings.private_key})
72
+
73
+ # add annotation reply
74
+ reply = GroupDocs::Document::Annotation::Reply.new(annotation: annotation)
75
+ reply.text = params['text']
76
+ reply.create!({ :client_id => settings.client_id, :private_key => settings.private_key})
77
+
78
+ end
79
+
80
+ rescue Exception => e
81
+ err = e.message
82
+ end
83
+
84
+ # set variables for template
85
+ haml :sample11, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.file_id, :annotationType => settings.annotation_type, :annotationId => (defined? annotation.id) ? annotation.id : nil, :annotationText => params['text'], :err => err }
86
+ end
@@ -0,0 +1,39 @@
1
+ # GET request
2
+ get '/sample12' do
3
+ haml :sample12
4
+ end
5
+
6
+ # POST request
7
+ post '/sample12' do
8
+ # set variables
9
+ set :client_id, params[:client_id]
10
+ set :private_key, params[:private_key]
11
+ set :file_id, params[:fileId]
12
+
13
+ begin
14
+ # 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?
16
+
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
+ document = ''
20
+
21
+ # get document by file ID
22
+ files_list.each do |element|
23
+ if element.respond_to?('guid') == true and element.guid == settings.file_id
24
+ document = element
25
+ end
26
+ end
27
+
28
+ unless document.instance_of? String
29
+ # get list of annotations
30
+ annotations = document.to_document.annotations!(:client_id => settings.client_id, :private_key => settings.private_key)
31
+ end
32
+
33
+ rescue Exception => e
34
+ err = e.message
35
+ end
36
+
37
+ # set variables for template
38
+ haml :sample12, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :annotations => annotations, :fileId => settings.file_id, :err => err }
39
+ end
@@ -0,0 +1,40 @@
1
+ # GET request
2
+ get '/sample13' do
3
+ haml :sample13
4
+ end
5
+
6
+ # POST request
7
+ post '/sample13' do
8
+ # set variables
9
+ set :client_id, params[:client_id]
10
+ set :private_key, params[:private_key]
11
+ set :file_id, params[:fileId]
12
+ set :email, params[:email]
13
+
14
+ begin
15
+ # check required variables
16
+ raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty? or settings.email.empty?
17
+
18
+ # make a request to API using client_id and private_key
19
+ files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
20
+ document = ''
21
+
22
+ # get document by file ID
23
+ files_list.each do |element|
24
+ if element.respond_to?('guid') == true and element.guid == settings.file_id
25
+ document = element
26
+ end
27
+ end
28
+
29
+ unless document.instance_of? String
30
+ # add collaborator to doc with annotations
31
+ result = document.to_document.set_collaborators!(settings.email.split(" "), 1, {:client_id => settings.client_id, :private_key => settings.private_key})
32
+ end
33
+
34
+ rescue Exception => e
35
+ err = e.message
36
+ end
37
+
38
+ # set variables for template
39
+ haml :sample13, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.file_id, :email => settings.email, :result => result, :err => err }
40
+ end
@@ -0,0 +1,29 @@
1
+ # GET request
2
+ get '/sample14' do
3
+ haml :sample14
4
+ end
5
+
6
+ # POST request
7
+ post '/sample14' do
8
+ # set variables
9
+ set :client_id, params[:client_id]
10
+ set :private_key, params[:private_key]
11
+ set :folder, params[:folder]
12
+
13
+ begin
14
+ # check required variables
15
+ raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.folder.empty?
16
+
17
+ # make a request to API using client_id and private_key
18
+ files_list = GroupDocs::Storage::Folder.list!(settings.folder, {}, { :client_id => settings.client_id, :private_key => settings.private_key})
19
+
20
+ # get list of shares for a folder
21
+ shares = files_list.first.sharers!({:client_id => settings.client_id, :private_key => settings.private_key})
22
+
23
+ rescue Exception => e
24
+ err = e.message
25
+ end
26
+
27
+ # set variables for template
28
+ haml :sample14, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :folder => settings.folder, :shares => shares, :err => err }
29
+ end
@@ -0,0 +1,26 @@
1
+ # GET request
2
+ get '/sample15' do
3
+ haml :sample15
4
+ end
5
+
6
+ # POST request
7
+ post '/sample15' do
8
+ # set variables
9
+ set :client_id, params[:client_id]
10
+ set :private_key, params[:private_key]
11
+
12
+ begin
13
+ # check required variables
14
+ raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
15
+
16
+ # check the number of document's views. Make a request to API using client_id and private_key
17
+ views = GroupDocs::Document.views!({}, { :client_id => settings.client_id, :private_key => settings.private_key})
18
+ total = views.count()
19
+
20
+ rescue Exception => e
21
+ err = e.message
22
+ end
23
+
24
+ # set variables for template
25
+ haml :sample15, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :total => total, :err => err }
26
+ end
@@ -0,0 +1,24 @@
1
+ # GET request
2
+ get '/sample16' do
3
+ haml :sample16
4
+ end
5
+
6
+ # POST request
7
+ post '/sample16' do
8
+ # set variables
9
+ set :fileId, params[:fileId]
10
+
11
+ begin
12
+ # check required variables
13
+ raise "Please enter all required parameters" if settings.fileId.empty?
14
+
15
+ # construct result iframe
16
+ iframe = "<iframe src='https://apps.groupdocs.com/assembly2/questionnaire-assembly/#{settings.fileId}' frameborder='0' width='100%' height='600'></iframe>"
17
+
18
+ rescue Exception => e
19
+ err = e.message
20
+ end
21
+
22
+ # set variables for template
23
+ haml :sample16, :locals => { :fileId => settings.fileId, :iframe => iframe, :err => err }
24
+ end
@@ -0,0 +1,36 @@
1
+ # GET request
2
+ get '/sample17' do
3
+ haml :sample17
4
+ end
5
+
6
+ # POST request
7
+ post '/sample17' do
8
+ # set variables
9
+ set :client_id, params[:client_id]
10
+ set :private_key, params[:private_key]
11
+ set :file, params[:file]
12
+
13
+ begin
14
+ # check required variables
15
+ raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file.nil?
16
+
17
+ # construct path
18
+ filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
19
+ # open file
20
+ File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
21
+ # upload file
22
+ file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
23
+ # compress file
24
+ file.compress!({client_id: settings.client_id, private_key: settings.private_key})
25
+
26
+ # construct result messages
27
+ massage = "<p>Archive created and saved successfully. Here you can see your <strong>#{params[:file][:filename]}</strong> file in the GroupDocs Embedded Viewer.</p>"
28
+ iframe = "<iframe src='https://apps.groupdocs.com/document-viewer/Embed/#{file.guid}' frameborder='0' width='720' height='600'></iframe>"
29
+
30
+ rescue Exception => e
31
+ err = e.message
32
+ end
33
+
34
+ # set variables for template
35
+ haml :sample17, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :iframe=>iframe, :massage => massage, :err => err }
36
+ end
@@ -0,0 +1,61 @@
1
+ # GET request
2
+ get '/sample18' do
3
+ haml :sample18
4
+ end
5
+
6
+ # POST request
7
+ post '/sample18' do
8
+ # set variables
9
+ set :client_id, params[:client_id]
10
+ set :private_key, params[:private_key]
11
+ set :file_id, params[:fileId]
12
+ set :convert_type, params[:convert_type]
13
+
14
+ begin
15
+ # check required variables
16
+ raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty?
17
+
18
+ # make a request to API using client_id and private_key
19
+ files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
20
+ document = ''
21
+
22
+ # get document by file ID
23
+ files_list.each do |element|
24
+ if element.respond_to?('guid') == true and element.guid == settings.file_id
25
+ document = element
26
+ end
27
+ end
28
+
29
+ message = ""
30
+ unless document.instance_of? String
31
+
32
+ # convert file
33
+ convert = document.to_document.convert!(settings.convert_type, {}, {:client_id => settings.client_id, :private_key => settings.private_key})
34
+ sleep(3)
35
+
36
+ if convert.instance_of? GroupDocs::Job
37
+ # get all jobs
38
+ jobs = GroupDocs::Job::all!({}, {:client_id => settings.client_id, :private_key => settings.private_key})
39
+
40
+ # get job by job ID
41
+ job = ''
42
+ jobs.each do |element|
43
+ if element.id == convert.id
44
+ job = element
45
+ end
46
+ end
47
+
48
+ if job.status == :archived
49
+ message = "<p>Converted file saved successfully."
50
+ end
51
+
52
+ end
53
+ end
54
+
55
+ rescue Exception => e
56
+ err = e.message
57
+ end
58
+
59
+ # set variables for template
60
+ haml :sample18, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.file_id, :message => message, :err => err }
61
+ end
@@ -1,19 +1,29 @@
1
+ # GET request
1
2
  get '/sample2' do
2
3
  haml :sample2
3
4
  end
4
5
 
6
+ # POST request
5
7
  post '/sample2' do
8
+ # set variables
6
9
  set :client_id, params[:client_id]
7
10
  set :private_key, params[:private_key]
8
11
 
9
12
  begin
13
+ # check required variables
10
14
  raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
11
- files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
15
+
16
+ # make a request to API using client_id and private_key
17
+ files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key })
18
+
19
+ # construct list of files
12
20
  filelist = ''
13
- files_list.each {|element| filelist += element.name + '<br />'}
21
+ files_list.each {|element| filelist << "#{element.name}<br />"}
22
+
14
23
  rescue Exception => e
15
24
  err = e.message
16
- end
17
-
25
+ end
26
+
27
+ # set variables for template
18
28
  haml :sample2, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :filelist => filelist, :err => err }
19
29
  end
@@ -1,23 +1,33 @@
1
+ # GET request
1
2
  get '/sample3' do
2
-
3
3
  haml :sample3
4
4
  end
5
5
 
6
+ # POST request
6
7
  post '/sample3' do
8
+ # set variables
7
9
  set :client_id, params[:client_id]
8
10
  set :private_key, params[:private_key]
11
+
9
12
  begin
13
+ # check required variables
10
14
  raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
11
-
15
+
16
+ # construct path
12
17
  filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
18
+ # open file
13
19
  File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
20
+ # make a request to API using client_id and private_key
14
21
  file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
22
+
23
+ # result massages
15
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>"
16
25
  iframe = "<iframe src='https://apps.groupdocs.com/document-viewer/Embed/#{file.guid}' frameborder='0' width='720' height='600'></iframe>"
17
26
 
18
27
  rescue Exception => e
19
28
  err = e.message
20
- end
21
-
29
+ end
30
+
31
+ # set variables for template
22
32
  haml :sample3, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :iframe=>iframe, :massage => massage, :err => err }
23
33
  end
@@ -1,23 +1,31 @@
1
+ # GET request
1
2
  get '/sample4' do
2
3
  haml :sample4
3
4
  end
4
5
 
6
+ # POST request
5
7
  post '/sample4' do
8
+ # set variables
6
9
  set :client_id, params[:client_id]
7
10
  set :private_key, params[:private_key]
8
11
  set :file_id, params[:file_id]
12
+
9
13
  begin
14
+ # check required variables
10
15
  raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty?
11
-
16
+
17
+ # make a request to API using client_id and private_key
12
18
  files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
13
19
  dowload_file = ''
14
20
 
21
+ # get file by file ID
15
22
  files_list.each do |element|
16
23
  if element.id == Integer(settings.file_id)
17
24
  dowload_file = element
18
25
  end
19
26
  end
20
27
 
28
+ # download file
21
29
  dowloaded_file = dowload_file.download!(File.dirname(__FILE__), { :client_id => settings.client_id, :private_key => settings.private_key})
22
30
  unless dowloaded_file.empty?
23
31
  massage = "<font color='green'>File was downloaded to the <font color='blue'>#{dowloaded_file}</font> folder</font> <br />"
@@ -25,7 +33,8 @@ post '/sample4' do
25
33
 
26
34
  rescue Exception => e
27
35
  err = e.message
28
- end
29
-
36
+ end
37
+
38
+ # set variables for template
30
39
  haml :sample4, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :file_id => settings.file_id, :massage => massage, :err => err }
31
40
  end