groupdocs 2.2.0 → 2.3.0
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.
- checksums.yaml +7 -0
- data/.travis.yml +9 -9
- data/CHANGELOG.md +482 -477
- data/Gemfile +3 -3
- data/LICENSE.txt +21 -21
- data/README.md +94 -94
- data/Rakefile +9 -9
- data/examples/README.md +12 -12
- data/examples/api-samples/Gemfile +5 -5
- data/examples/api-samples/Gemfile.lock +49 -49
- data/examples/api-samples/README.md +23 -23
- data/examples/api-samples/public/css/style.css +229 -229
- data/examples/api-samples/public/docs/annotation-sample.html +167 -167
- data/examples/api-samples/public/docs/docco.css +500 -500
- data/examples/api-samples/public/docs/envelope-sample.html +374 -374
- data/examples/api-samples/public/docs/sample01.html +181 -181
- data/examples/api-samples/public/docs/sample02.html +199 -199
- data/examples/api-samples/public/docs/sample03.html +318 -318
- data/examples/api-samples/public/docs/sample04.html +217 -217
- data/examples/api-samples/public/docs/sample05.html +296 -296
- data/examples/api-samples/public/docs/sample06.html +347 -347
- data/examples/api-samples/public/docs/sample07.html +209 -209
- data/examples/api-samples/public/docs/sample08.html +277 -277
- data/examples/api-samples/public/docs/sample09.html +314 -314
- data/examples/api-samples/public/docs/sample10.html +270 -270
- data/examples/api-samples/public/docs/sample11.html +462 -462
- data/examples/api-samples/public/docs/sample12.html +199 -199
- data/examples/api-samples/public/docs/sample13.html +201 -201
- data/examples/api-samples/public/docs/sample14.html +204 -204
- data/examples/api-samples/public/docs/sample15.html +182 -182
- data/examples/api-samples/public/docs/sample16.html +234 -234
- data/examples/api-samples/public/docs/sample17.html +309 -309
- data/examples/api-samples/public/docs/sample18.html +721 -721
- data/examples/api-samples/public/docs/sample19.html +631 -631
- data/examples/api-samples/public/docs/sample20.html +230 -230
- data/examples/api-samples/public/docs/sample21.html +790 -790
- data/examples/api-samples/public/docs/sample22.html +408 -408
- data/examples/api-samples/public/docs/sample25.html +550 -550
- data/examples/api-samples/public/templates/base-simple_source.html +191 -191
- data/examples/api-samples/public/templates/testdocument.html +100 -100
- data/examples/api-samples/public/templates/welcome.htm +137 -137
- data/examples/api-samples/samples/annotation-sample.rb +56 -56
- data/examples/api-samples/samples/envelope-sample.rb +133 -133
- data/examples/api-samples/samples/sample01.rb +44 -44
- data/examples/api-samples/samples/sample02.rb +50 -50
- data/examples/api-samples/samples/sample03.rb +79 -79
- data/examples/api-samples/samples/sample04.rb +54 -54
- data/examples/api-samples/samples/sample05.rb +83 -83
- data/examples/api-samples/samples/sample06.rb +86 -86
- data/examples/api-samples/samples/sample07.rb +59 -59
- data/examples/api-samples/samples/sample08.rb +76 -76
- data/examples/api-samples/samples/sample09.rb +85 -85
- data/examples/api-samples/samples/sample10.rb +70 -70
- data/examples/api-samples/samples/sample11.rb +132 -132
- data/examples/api-samples/samples/sample12.rb +48 -48
- data/examples/api-samples/samples/sample13.rb +49 -49
- data/examples/api-samples/samples/sample14.rb +54 -54
- data/examples/api-samples/samples/sample15.rb +43 -43
- data/examples/api-samples/samples/sample16.rb +57 -57
- data/examples/api-samples/samples/sample17.rb +70 -70
- data/examples/api-samples/samples/sample18.rb +190 -190
- data/examples/api-samples/samples/sample19.rb +188 -188
- data/examples/api-samples/samples/sample20.rb +68 -68
- data/examples/api-samples/samples/sample21.rb +212 -212
- data/examples/api-samples/samples/sample22.rb +109 -109
- data/examples/api-samples/samples/sample25.rb +127 -127
- data/examples/api-samples/views/_others_samples.haml +233 -233
- data/examples/api-samples/views/annotation_sample.haml +63 -63
- data/examples/api-samples/views/envelope_sample.haml +72 -72
- data/examples/api-samples/views/index.haml +235 -235
- data/examples/api-samples/views/layout.haml +3 -3
- data/examples/api-samples/views/sample01.haml +63 -63
- data/examples/api-samples/views/sample02.haml +52 -52
- data/examples/api-samples/views/sample03.haml +87 -87
- data/examples/api-samples/views/sample04.haml +55 -55
- data/examples/api-samples/views/sample05.haml +86 -86
- data/examples/api-samples/views/sample06.haml +58 -58
- data/examples/api-samples/views/sample07.haml +52 -52
- data/examples/api-samples/views/sample08.haml +100 -100
- data/examples/api-samples/views/sample09.haml +95 -95
- data/examples/api-samples/views/sample10.haml +93 -93
- data/examples/api-samples/views/sample11.haml +140 -140
- data/examples/api-samples/views/sample12.haml +68 -68
- data/examples/api-samples/views/sample13.haml +64 -64
- data/examples/api-samples/views/sample14.haml +60 -60
- data/examples/api-samples/views/sample15.haml +51 -51
- data/examples/api-samples/views/sample16.haml +50 -50
- data/examples/api-samples/views/sample17.haml +54 -54
- data/examples/api-samples/views/sample18.haml +143 -143
- data/examples/api-samples/views/sample19.haml +92 -92
- data/examples/api-samples/views/sample20.haml +54 -54
- data/examples/api-samples/views/sample21.haml +123 -123
- data/examples/api-samples/views/sample22.haml +106 -106
- data/examples/api-samples/views/sample25.haml +101 -101
- data/examples/api-samples/views/sample31.haml +2 -2
- data/examples/api-samples/web.rb +20 -20
- data/examples/viewer/Gemfile +5 -5
- data/examples/viewer/app.rb +52 -52
- data/groupdocs.gemspec +31 -31
- data/lib/groupdocs.rb +62 -62
- data/lib/groupdocs/api.rb +6 -6
- data/lib/groupdocs/api/entity.rb +112 -112
- data/lib/groupdocs/api/helpers.rb +11 -11
- data/lib/groupdocs/api/helpers/access_mode_helper.rb +27 -27
- data/lib/groupdocs/api/helpers/access_rights_helper.rb +55 -55
- data/lib/groupdocs/api/helpers/accessor_helper.rb +30 -30
- data/lib/groupdocs/api/helpers/byte_flag_helper.rb +49 -49
- data/lib/groupdocs/api/helpers/credentials_helper.rb +35 -35
- data/lib/groupdocs/api/helpers/mime_helper.rb +21 -21
- data/lib/groupdocs/api/helpers/path_helper.rb +28 -28
- data/lib/groupdocs/api/helpers/rest_helper.rb +99 -99
- data/lib/groupdocs/api/helpers/signature_public_helper.rb +22 -22
- data/lib/groupdocs/api/helpers/status_helper.rb +27 -27
- data/lib/groupdocs/api/helpers/url_helper.rb +101 -101
- data/lib/groupdocs/api/request.rb +91 -91
- data/lib/groupdocs/datasource.rb +249 -249
- data/lib/groupdocs/datasource/field.rb +39 -39
- data/lib/groupdocs/document.rb +1550 -1550
- data/lib/groupdocs/document/annotation.rb +421 -421
- data/lib/groupdocs/document/annotation/reply.rb +173 -173
- data/lib/groupdocs/document/annotation/reviewer.rb +66 -66
- data/lib/groupdocs/document/change.rb +56 -56
- data/lib/groupdocs/document/field.rb +53 -53
- data/lib/groupdocs/document/metadata.rb +32 -32
- data/lib/groupdocs/document/rectangle.rb +18 -18
- data/lib/groupdocs/document/view.rb +36 -36
- data/lib/groupdocs/errors.rb +8 -8
- data/lib/groupdocs/job.rb +468 -468
- data/lib/groupdocs/questionnaire.rb +530 -530
- data/lib/groupdocs/questionnaire/collector.rb +335 -335
- data/lib/groupdocs/questionnaire/execution.rb +181 -181
- data/lib/groupdocs/questionnaire/page.rb +43 -43
- data/lib/groupdocs/questionnaire/question.rb +108 -108
- data/lib/groupdocs/questionnaire/question/answer.rb +15 -15
- data/lib/groupdocs/signature.rb +380 -380
- data/lib/groupdocs/signature/contact.rb +181 -181
- data/lib/groupdocs/signature/envelope.rb +747 -747
- data/lib/groupdocs/signature/envelope/log.rb +20 -20
- data/lib/groupdocs/signature/field.rb +286 -286
- data/lib/groupdocs/signature/field/location.rb +71 -71
- data/lib/groupdocs/signature/form.rb +804 -804
- data/lib/groupdocs/signature/list.rb +92 -92
- data/lib/groupdocs/signature/recipient.rb +79 -79
- data/lib/groupdocs/signature/role.rb +54 -54
- data/lib/groupdocs/signature/shared.rb +6 -6
- data/lib/groupdocs/signature/shared/document_methods.rb +158 -158
- data/lib/groupdocs/signature/shared/entity_fields.rb +76 -76
- data/lib/groupdocs/signature/shared/entity_methods.rb +144 -144
- data/lib/groupdocs/signature/shared/field_methods.rb +354 -354
- data/lib/groupdocs/signature/shared/recipient_methods.rb +75 -75
- data/lib/groupdocs/signature/shared/resource_methods.rb +65 -65
- data/lib/groupdocs/signature/template.rb +124 -124
- data/lib/groupdocs/storage.rb +44 -44
- data/lib/groupdocs/storage/file.rb +432 -432
- data/lib/groupdocs/storage/folder.rb +288 -288
- data/lib/groupdocs/storage/package.rb +48 -48
- data/lib/groupdocs/storage/provider.rb +32 -32
- data/lib/groupdocs/subscription.rb +323 -323
- data/lib/groupdocs/subscription/limit.rb +20 -20
- data/lib/groupdocs/user.rb +955 -930
- data/lib/groupdocs/version.rb +3 -3
- data/spec/groupdocs/api/entity_spec.rb +55 -55
- data/spec/groupdocs/api/helpers/access_mode_helper_spec.rb +21 -21
- data/spec/groupdocs/api/helpers/access_rights_helper_spec.rb +43 -43
- data/spec/groupdocs/api/helpers/accessor_helper_spec.rb +16 -16
- data/spec/groupdocs/api/helpers/byte_flag_helper_spec.rb +23 -23
- data/spec/groupdocs/api/helpers/credentials_helpers_spec.rb +48 -48
- data/spec/groupdocs/api/helpers/mime_helper_spec.rb +16 -16
- data/spec/groupdocs/api/helpers/path_helper_spec.rb +15 -15
- data/spec/groupdocs/api/helpers/rest_helper_spec.rb +161 -161
- data/spec/groupdocs/api/helpers/signature_public_helper_spec.rb +21 -21
- data/spec/groupdocs/api/helpers/status_helper_spec.rb +22 -22
- data/spec/groupdocs/api/helpers/url_helper_spec.rb +112 -112
- data/spec/groupdocs/api/request_spec.rb +112 -112
- data/spec/groupdocs/datasource/field_spec.rb +29 -29
- data/spec/groupdocs/datasource_spec.rb +145 -145
- data/spec/groupdocs/document/annotation/reply_spec.rb +154 -154
- data/spec/groupdocs/document/annotation/reviewer_spec.rb +51 -51
- data/spec/groupdocs/document/annotation_spec.rb +234 -234
- data/spec/groupdocs/document/change_spec.rb +39 -39
- data/spec/groupdocs/document/field_spec.rb +28 -28
- data/spec/groupdocs/document/metadata_spec.rb +21 -21
- data/spec/groupdocs/document/rectangle_spec.rb +14 -14
- data/spec/groupdocs/document/view_spec.rb +33 -33
- data/spec/groupdocs/document_spec.rb +859 -859
- data/spec/groupdocs/errors_spec.rb +7 -7
- data/spec/groupdocs/job_spec.rb +323 -323
- data/spec/groupdocs/questionnaire/collector_spec.rb +197 -197
- data/spec/groupdocs/questionnaire/execution_spec.rb +162 -162
- data/spec/groupdocs/questionnaire/page_spec.rb +47 -47
- data/spec/groupdocs/questionnaire/question/answer_spec.rb +9 -9
- data/spec/groupdocs/questionnaire/question_spec.rb +75 -75
- data/spec/groupdocs/questionnaire_spec.rb +295 -295
- data/spec/groupdocs/signature/contact_spec.rb +142 -142
- data/spec/groupdocs/signature/envelope/log_spec.rb +15 -15
- data/spec/groupdocs/signature/envelope_spec.rb +384 -384
- data/spec/groupdocs/signature/field/location_spec.rb +40 -40
- data/spec/groupdocs/signature/field_spec.rb +235 -235
- data/spec/groupdocs/signature/form_spec.rb +205 -205
- data/spec/groupdocs/signature/list_spec.rb +87 -87
- data/spec/groupdocs/signature/recipient_spec.rb +26 -26
- data/spec/groupdocs/signature/role_spec.rb +47 -47
- data/spec/groupdocs/signature/template_spec.rb +80 -80
- data/spec/groupdocs/signature_spec.rb +194 -194
- data/spec/groupdocs/storage/file_spec.rb +303 -303
- data/spec/groupdocs/storage/folder_spec.rb +270 -270
- data/spec/groupdocs/storage/package_spec.rb +38 -38
- data/spec/groupdocs/storage/provider_spec.rb +21 -21
- data/spec/groupdocs/storage_spec.rb +27 -27
- data/spec/groupdocs/subscription/limit_spec.rb +16 -16
- data/spec/groupdocs/subscription_spec.rb +74 -74
- data/spec/groupdocs/user_spec.rb +257 -257
- data/spec/groupdocs_spec.rb +63 -63
- data/spec/spec_helper.rb +73 -73
- data/spec/support/json/annotation_access_set.json +11 -11
- data/spec/support/json/annotation_collaborators_get.json +16 -16
- data/spec/support/json/annotation_collaborators_set.json +16 -16
- data/spec/support/json/annotation_create.json +12 -12
- data/spec/support/json/annotation_list.json +32 -32
- data/spec/support/json/annotation_marker_move.json +10 -10
- data/spec/support/json/annotation_move.json +8 -8
- data/spec/support/json/annotation_remove.json +9 -9
- data/spec/support/json/annotation_replies_create.json +9 -9
- data/spec/support/json/annotation_replies_get.json +25 -25
- data/spec/support/json/annotation_reviewers_get.json +18 -18
- data/spec/support/json/comparison_changes.json +46 -46
- data/spec/support/json/comparison_compare.json +8 -8
- data/spec/support/json/comparison_document.json +10 -10
- data/spec/support/json/contact_add.json +12 -12
- data/spec/support/json/contacts_get.json +19 -19
- data/spec/support/json/contacts_import.json +8 -8
- data/spec/support/json/datasource_add.json +8 -8
- data/spec/support/json/datasource_get.json +22 -22
- data/spec/support/json/datasource_remove.json +8 -8
- data/spec/support/json/datasource_update.json +8 -8
- data/spec/support/json/delete_account.json +9 -9
- data/spec/support/json/document_access_info_get.json +14 -14
- data/spec/support/json/document_convert.json +8 -8
- data/spec/support/json/document_datasource.json +10 -10
- data/spec/support/json/document_fields.json +34 -34
- data/spec/support/json/document_formats.json +8 -8
- data/spec/support/json/document_metadata.json +15 -15
- data/spec/support/json/document_page_images_get.json +20 -20
- data/spec/support/json/document_questionnaire_create.json +9 -9
- data/spec/support/json/document_questionnaires.json +23 -23
- data/spec/support/json/document_sharers_remove.json +8 -8
- data/spec/support/json/document_sharers_set.json +16 -16
- data/spec/support/json/document_thumbnails.json +24 -24
- data/spec/support/json/document_views.json +32 -32
- data/spec/support/json/envelope_get.json +46 -46
- data/spec/support/json/envelope_logs.json +16 -16
- data/spec/support/json/envelope_recipient_add.json +26 -26
- data/spec/support/json/envelopes_all.json +48 -48
- data/spec/support/json/envelopes_resources.json +31 -31
- data/spec/support/json/file_compress.json +8 -8
- data/spec/support/json/file_copy.json +14 -14
- data/spec/support/json/file_delete.json +5 -5
- data/spec/support/json/file_move.json +14 -14
- data/spec/support/json/file_upload.json +8 -8
- data/spec/support/json/folder_create.json +8 -8
- data/spec/support/json/folder_delete.json +5 -5
- data/spec/support/json/folder_list.json +22 -22
- data/spec/support/json/folder_move.json +8 -8
- data/spec/support/json/folder_sharers_get.json +16 -16
- data/spec/support/json/folder_sharers_remove.json +8 -8
- data/spec/support/json/folder_sharers_set.json +16 -16
- data/spec/support/json/form_get.json +21 -21
- data/spec/support/json/forms_all.json +23 -23
- data/spec/support/json/job_add_url.json +8 -8
- data/spec/support/json/job_create.json +8 -8
- data/spec/support/json/job_documents.json +40 -40
- data/spec/support/json/job_file_add.json +8 -8
- data/spec/support/json/job_get.json +30 -30
- data/spec/support/json/job_update.json +7 -7
- data/spec/support/json/jobs_get.json +58 -58
- data/spec/support/json/list_add.json +12 -12
- data/spec/support/json/lists_get.json +19 -19
- data/spec/support/json/package_create.json +7 -7
- data/spec/support/json/questionnaire_collector.json +17 -17
- data/spec/support/json/questionnaire_collectors.json +38 -38
- data/spec/support/json/questionnaire_collectors_add.json +10 -10
- data/spec/support/json/questionnaire_create.json +10 -10
- data/spec/support/json/questionnaire_datasources.json +26 -26
- data/spec/support/json/questionnaire_execution_add.json +9 -9
- data/spec/support/json/questionnaire_execution_status_set.json +8 -8
- data/spec/support/json/questionnaire_execution_update.json +8 -8
- data/spec/support/json/questionnaire_executions.json +28 -28
- data/spec/support/json/questionnaire_get.json +17 -17
- data/spec/support/json/questionnaire_remove.json +8 -8
- data/spec/support/json/questionnaire_update.json +8 -8
- data/spec/support/json/questionnaires_get.json +40 -40
- data/spec/support/json/sign_documents.json +16 -16
- data/spec/support/json/signature_create.json +12 -12
- data/spec/support/json/signature_field_add.json +25 -25
- data/spec/support/json/signature_fields_get.json +27 -27
- data/spec/support/json/signature_roles_get.json +17 -17
- data/spec/support/json/signatures_get.json +19 -19
- data/spec/support/json/storage_info.json +10 -10
- data/spec/support/json/subscription_plan_get.json +9 -9
- data/spec/support/json/subscription_plans_get.json +17 -17
- data/spec/support/json/template_get.json +35 -35
- data/spec/support/json/template_get_documents.json +15 -15
- data/spec/support/json/template_get_recipients.json +20 -20
- data/spec/support/json/templates_all.json +37 -37
- data/spec/support/json/templates_get.json +21 -21
- data/spec/support/json/update_account.json +10 -10
- data/spec/support/json/user_area.json +67 -67
- data/spec/support/json/user_embed_key.json +38 -38
- data/spec/support/json/user_get_embed_key.json +67 -67
- data/spec/support/json/user_login.json +67 -67
- data/spec/support/json/user_profile_get.json +24 -24
- data/spec/support/json/user_providers.json +31 -31
- data/spec/support/json/user_roles.json +25 -25
- data/spec/support/json/user_users_get.json +27 -27
- data/spec/support/shared_examples/api/entity.rb +39 -39
- data/spec/support/shared_examples/api/helpers/access_mode_helper.rb +11 -11
- data/spec/support/shared_examples/api/helpers/status_helper.rb +11 -11
- data/spec/support/shared_examples/signature/shared/document_methods.rb +68 -68
- data/spec/support/shared_examples/signature/shared/entity_fields.rb +56 -56
- data/spec/support/shared_examples/signature/shared/entity_methods.rb +116 -116
- data/spec/support/shared_examples/signature/shared/field_methods.rb +220 -220
- data/spec/support/shared_examples/signature/shared/recipient_methods.rb +46 -46
- data/spec/support/shared_examples/signature/shared/resource_methods.rb +46 -46
- metadata +35 -55
@@ -1,190 +1,190 @@
|
|
1
|
-
#GET request
|
2
|
-
get '/sample-18-how-to-convert-doc-to-docx-docx-to-doc-docx-to-pdf-and-ppt-to-pdf' do
|
3
|
-
haml :sample18
|
4
|
-
end
|
5
|
-
|
6
|
-
#POST request
|
7
|
-
post '/sample18/convert_callback' do
|
8
|
-
#Set download path
|
9
|
-
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
10
|
-
|
11
|
-
#Get callback request
|
12
|
-
data = JSON.parse(request.body.read)
|
13
|
-
begin
|
14
|
-
raise 'Empty params!' if data.empty?
|
15
|
-
source_id = nil
|
16
|
-
client_id = nil
|
17
|
-
private_key = nil
|
18
|
-
|
19
|
-
#Get value of SourceId
|
20
|
-
data.each do |key, value|
|
21
|
-
if key == 'SourceId'
|
22
|
-
source_id = value
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
#Get private key and client_id from file user_info.txt
|
27
|
-
if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
28
|
-
contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
29
|
-
contents = contents.split(' ')
|
30
|
-
client_id = contents.first
|
31
|
-
private_key = contents.last
|
32
|
-
end
|
33
|
-
|
34
|
-
#Create Job instance
|
35
|
-
job = GroupDocs::Job.new({:id => source_id})
|
36
|
-
|
37
|
-
#Get document by job id
|
38
|
-
documents = job.documents!({:client_id => client_id, :private_key => private_key})
|
39
|
-
|
40
|
-
#Download converted file
|
41
|
-
documents[:inputs].first.outputs.first.download!(downloads_path, {:client_id => client_id, :private_key => private_key})
|
42
|
-
|
43
|
-
rescue Exception => e
|
44
|
-
err = e.message
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
#GET request
|
50
|
-
get '/sample18/check' do
|
51
|
-
|
52
|
-
#Check is there download directory
|
53
|
-
unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
|
54
|
-
return 'Directory was not found.'
|
55
|
-
end
|
56
|
-
|
57
|
-
#Get file name from download directory
|
58
|
-
name = nil
|
59
|
-
Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
|
60
|
-
name = file if file != '.' && file != '..'
|
61
|
-
end
|
62
|
-
|
63
|
-
name
|
64
|
-
end
|
65
|
-
|
66
|
-
#GET request
|
67
|
-
get '/sample18/downloads/:filename' do |filename|
|
68
|
-
# Send file with header to download it
|
69
|
-
send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
#POST request
|
74
|
-
post '/sample-18-how-to-convert-doc-to-docx-docx-to-doc-docx-to-pdf-and-ppt-to-pdf' do
|
75
|
-
#Set variables
|
76
|
-
set :client_id, params[:clientId]
|
77
|
-
set :private_key, params[:privateKey]
|
78
|
-
set :source, params[:source]
|
79
|
-
set :file_id, params[:fileId]
|
80
|
-
set :url, params[:url]
|
81
|
-
set :convert_type, params[:convertType]
|
82
|
-
set :callback, params[:callback]
|
83
|
-
set :base_path, params[:basePath]
|
84
|
-
|
85
|
-
#Set download path
|
86
|
-
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
87
|
-
|
88
|
-
#Remove all files from download directory or create folder if it not there
|
89
|
-
if File.directory?(downloads_path)
|
90
|
-
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
91
|
-
else
|
92
|
-
Dir::mkdir(downloads_path)
|
93
|
-
end
|
94
|
-
|
95
|
-
begin
|
96
|
-
#Check required variables
|
97
|
-
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
98
|
-
|
99
|
-
#Prepare base path
|
100
|
-
if settings.base_path.empty?
|
101
|
-
base_path = 'https://api.groupdocs.com'
|
102
|
-
elsif settings.base_path.match('/v2.0')
|
103
|
-
base_path = settings.base_path.split('/v2.0')[0]
|
104
|
-
else
|
105
|
-
base_path = settings.base_path
|
106
|
-
end
|
107
|
-
|
108
|
-
#Configure your access to API server
|
109
|
-
GroupDocs.configure do |groupdocs|
|
110
|
-
groupdocs.client_id = settings.client_id
|
111
|
-
groupdocs.private_key = settings.private_key
|
112
|
-
#Optionally specify API server and version
|
113
|
-
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
114
|
-
end
|
115
|
-
|
116
|
-
#Write client and private key to the file for callback job
|
117
|
-
if settings.callback[0]
|
118
|
-
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
119
|
-
#White space is required
|
120
|
-
out_file.write("#{settings.client_id} ")
|
121
|
-
out_file.write("#{settings.private_key}")
|
122
|
-
out_file.close
|
123
|
-
end
|
124
|
-
|
125
|
-
file = nil
|
126
|
-
|
127
|
-
#Get document by file GUID
|
128
|
-
case settings.source
|
129
|
-
when 'guid'
|
130
|
-
#Create instance of File
|
131
|
-
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
132
|
-
when 'local'
|
133
|
-
#Construct path
|
134
|
-
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
135
|
-
#Open file
|
136
|
-
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
137
|
-
#Make a request to API using client_id and private_key
|
138
|
-
file = GroupDocs::Storage::File.upload!(file_path, {})
|
139
|
-
when 'url'
|
140
|
-
#Upload file from defined url
|
141
|
-
file = GroupDocs::Storage::File.upload_web!(settings.url)
|
142
|
-
else
|
143
|
-
raise 'Wrong GUID source.'
|
144
|
-
end
|
145
|
-
|
146
|
-
#Raise exception if something went wrong
|
147
|
-
raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
|
148
|
-
|
149
|
-
#Make document from file
|
150
|
-
document = file.to_document
|
151
|
-
#Convert document
|
152
|
-
convert = document.convert!(settings.convert_type, {:callback => settings.callback})
|
153
|
-
#Waite 15 seconds for while file converting
|
154
|
-
for i in 1..5
|
155
|
-
i+=1
|
156
|
-
sleep(2)
|
157
|
-
if GroupDocs::Job.get!(convert.id).status.to_s == 'archived' then break end
|
158
|
-
end
|
159
|
-
|
160
|
-
|
161
|
-
#Get array of changes in document from job
|
162
|
-
original_document = convert.documents!()
|
163
|
-
|
164
|
-
#Get converted document GUID
|
165
|
-
guid = original_document[:inputs].first.outputs.first.guid
|
166
|
-
|
167
|
-
#Prepare to sign url
|
168
|
-
iframe = "/document-viewer/embed/#{guid}"
|
169
|
-
# Construct result string
|
170
|
-
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
171
|
-
#Generate iframe URL
|
172
|
-
case base_path
|
173
|
-
when 'https://stage-api-groupdocs.dynabic.com'
|
174
|
-
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
175
|
-
when 'https://dev-api-groupdocs.dynabic.com'
|
176
|
-
iframe = "https://dev-apps.groupdocs.com#{url}"
|
177
|
-
else
|
178
|
-
iframe = "https://apps.groupdocs.com#{url}"
|
179
|
-
end
|
180
|
-
|
181
|
-
#Make iframe
|
182
|
-
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
183
|
-
|
184
|
-
rescue Exception => e
|
185
|
-
err = e.message
|
186
|
-
end
|
187
|
-
|
188
|
-
#Set variables for template
|
189
|
-
haml :sample18, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :callback => settings.callback, :fileId => file, :converted => guid, :iframe => iframe, :err => err}
|
190
|
-
end
|
1
|
+
#GET request
|
2
|
+
get '/sample-18-how-to-convert-doc-to-docx-docx-to-doc-docx-to-pdf-and-ppt-to-pdf' do
|
3
|
+
haml :sample18
|
4
|
+
end
|
5
|
+
|
6
|
+
#POST request
|
7
|
+
post '/sample18/convert_callback' do
|
8
|
+
#Set download path
|
9
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
10
|
+
|
11
|
+
#Get callback request
|
12
|
+
data = JSON.parse(request.body.read)
|
13
|
+
begin
|
14
|
+
raise 'Empty params!' if data.empty?
|
15
|
+
source_id = nil
|
16
|
+
client_id = nil
|
17
|
+
private_key = nil
|
18
|
+
|
19
|
+
#Get value of SourceId
|
20
|
+
data.each do |key, value|
|
21
|
+
if key == 'SourceId'
|
22
|
+
source_id = value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
#Get private key and client_id from file user_info.txt
|
27
|
+
if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
28
|
+
contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
29
|
+
contents = contents.split(' ')
|
30
|
+
client_id = contents.first
|
31
|
+
private_key = contents.last
|
32
|
+
end
|
33
|
+
|
34
|
+
#Create Job instance
|
35
|
+
job = GroupDocs::Job.new({:id => source_id})
|
36
|
+
|
37
|
+
#Get document by job id
|
38
|
+
documents = job.documents!({:client_id => client_id, :private_key => private_key})
|
39
|
+
|
40
|
+
#Download converted file
|
41
|
+
documents[:inputs].first.outputs.first.download!(downloads_path, {:client_id => client_id, :private_key => private_key})
|
42
|
+
|
43
|
+
rescue Exception => e
|
44
|
+
err = e.message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
#GET request
|
50
|
+
get '/sample18/check' do
|
51
|
+
|
52
|
+
#Check is there download directory
|
53
|
+
unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
|
54
|
+
return 'Directory was not found.'
|
55
|
+
end
|
56
|
+
|
57
|
+
#Get file name from download directory
|
58
|
+
name = nil
|
59
|
+
Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
|
60
|
+
name = file if file != '.' && file != '..'
|
61
|
+
end
|
62
|
+
|
63
|
+
name
|
64
|
+
end
|
65
|
+
|
66
|
+
#GET request
|
67
|
+
get '/sample18/downloads/:filename' do |filename|
|
68
|
+
# Send file with header to download it
|
69
|
+
send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
#POST request
|
74
|
+
post '/sample-18-how-to-convert-doc-to-docx-docx-to-doc-docx-to-pdf-and-ppt-to-pdf' do
|
75
|
+
#Set variables
|
76
|
+
set :client_id, params[:clientId]
|
77
|
+
set :private_key, params[:privateKey]
|
78
|
+
set :source, params[:source]
|
79
|
+
set :file_id, params[:fileId]
|
80
|
+
set :url, params[:url]
|
81
|
+
set :convert_type, params[:convertType]
|
82
|
+
set :callback, params[:callback]
|
83
|
+
set :base_path, params[:basePath]
|
84
|
+
|
85
|
+
#Set download path
|
86
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
87
|
+
|
88
|
+
#Remove all files from download directory or create folder if it not there
|
89
|
+
if File.directory?(downloads_path)
|
90
|
+
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
91
|
+
else
|
92
|
+
Dir::mkdir(downloads_path)
|
93
|
+
end
|
94
|
+
|
95
|
+
begin
|
96
|
+
#Check required variables
|
97
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
98
|
+
|
99
|
+
#Prepare base path
|
100
|
+
if settings.base_path.empty?
|
101
|
+
base_path = 'https://api.groupdocs.com'
|
102
|
+
elsif settings.base_path.match('/v2.0')
|
103
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
104
|
+
else
|
105
|
+
base_path = settings.base_path
|
106
|
+
end
|
107
|
+
|
108
|
+
#Configure your access to API server
|
109
|
+
GroupDocs.configure do |groupdocs|
|
110
|
+
groupdocs.client_id = settings.client_id
|
111
|
+
groupdocs.private_key = settings.private_key
|
112
|
+
#Optionally specify API server and version
|
113
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
114
|
+
end
|
115
|
+
|
116
|
+
#Write client and private key to the file for callback job
|
117
|
+
if settings.callback[0]
|
118
|
+
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
119
|
+
#White space is required
|
120
|
+
out_file.write("#{settings.client_id} ")
|
121
|
+
out_file.write("#{settings.private_key}")
|
122
|
+
out_file.close
|
123
|
+
end
|
124
|
+
|
125
|
+
file = nil
|
126
|
+
|
127
|
+
#Get document by file GUID
|
128
|
+
case settings.source
|
129
|
+
when 'guid'
|
130
|
+
#Create instance of File
|
131
|
+
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
132
|
+
when 'local'
|
133
|
+
#Construct path
|
134
|
+
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
135
|
+
#Open file
|
136
|
+
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
137
|
+
#Make a request to API using client_id and private_key
|
138
|
+
file = GroupDocs::Storage::File.upload!(file_path, {})
|
139
|
+
when 'url'
|
140
|
+
#Upload file from defined url
|
141
|
+
file = GroupDocs::Storage::File.upload_web!(settings.url)
|
142
|
+
else
|
143
|
+
raise 'Wrong GUID source.'
|
144
|
+
end
|
145
|
+
|
146
|
+
#Raise exception if something went wrong
|
147
|
+
raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
|
148
|
+
|
149
|
+
#Make document from file
|
150
|
+
document = file.to_document
|
151
|
+
#Convert document
|
152
|
+
convert = document.convert!(settings.convert_type, {:callback => settings.callback})
|
153
|
+
#Waite 15 seconds for while file converting
|
154
|
+
for i in 1..5
|
155
|
+
i+=1
|
156
|
+
sleep(2)
|
157
|
+
if GroupDocs::Job.get!(convert.id).status.to_s == 'archived' then break end
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
#Get array of changes in document from job
|
162
|
+
original_document = convert.documents!()
|
163
|
+
|
164
|
+
#Get converted document GUID
|
165
|
+
guid = original_document[:inputs].first.outputs.first.guid
|
166
|
+
|
167
|
+
#Prepare to sign url
|
168
|
+
iframe = "/document-viewer/embed/#{guid}"
|
169
|
+
# Construct result string
|
170
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
171
|
+
#Generate iframe URL
|
172
|
+
case base_path
|
173
|
+
when 'https://stage-api-groupdocs.dynabic.com'
|
174
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
175
|
+
when 'https://dev-api-groupdocs.dynabic.com'
|
176
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
177
|
+
else
|
178
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
179
|
+
end
|
180
|
+
|
181
|
+
#Make iframe
|
182
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
183
|
+
|
184
|
+
rescue Exception => e
|
185
|
+
err = e.message
|
186
|
+
end
|
187
|
+
|
188
|
+
#Set variables for template
|
189
|
+
haml :sample18, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :callback => settings.callback, :fileId => file, :converted => guid, :iframe => iframe, :err => err}
|
190
|
+
end
|
@@ -1,188 +1,188 @@
|
|
1
|
-
#GET request
|
2
|
-
get '/sample-19-how-to-compare-documents' do
|
3
|
-
haml :sample19
|
4
|
-
end
|
5
|
-
|
6
|
-
#POST request
|
7
|
-
post '/sample19/compere_callback' do
|
8
|
-
#Set download path
|
9
|
-
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
10
|
-
|
11
|
-
#Get callback request
|
12
|
-
data = JSON.parse(request.body.read)
|
13
|
-
begin
|
14
|
-
raise 'Empty params!' if data.empty?
|
15
|
-
source_id = nil
|
16
|
-
client_id = nil
|
17
|
-
private_key = nil
|
18
|
-
|
19
|
-
#Get value of SourceId
|
20
|
-
data.each do |key, value|
|
21
|
-
if key == 'SourceId'
|
22
|
-
source_id = value
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
#Get private key and client_id from file user_info.txt
|
27
|
-
if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
28
|
-
contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
29
|
-
contents = contents.split(' ')
|
30
|
-
client_id = contents.first
|
31
|
-
private_key = contents.last
|
32
|
-
end
|
33
|
-
|
34
|
-
#Create Job instance
|
35
|
-
job = GroupDocs::Job.new({:id => source_id})
|
36
|
-
|
37
|
-
#Get document by job id
|
38
|
-
documents = job.documents!({:client_id => client_id, :private_key => private_key})
|
39
|
-
|
40
|
-
#Download converted file
|
41
|
-
documents[:inputs].first.outputs.first.download!(downloads_path, {:client_id => client_id, :private_key => private_key})
|
42
|
-
|
43
|
-
rescue Exception => e
|
44
|
-
err = e.message
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
#GET request
|
49
|
-
get '/sample19/check' do
|
50
|
-
|
51
|
-
#Check is there download directory
|
52
|
-
unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
|
53
|
-
return 'Directory was not found.'
|
54
|
-
end
|
55
|
-
|
56
|
-
#Get file name from download directory
|
57
|
-
name = nil
|
58
|
-
Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
|
59
|
-
name = file if file != '.' && file != '..'
|
60
|
-
end
|
61
|
-
|
62
|
-
name
|
63
|
-
end
|
64
|
-
|
65
|
-
#GET request
|
66
|
-
get '/sample19/downloads/:filename' do |filename|
|
67
|
-
#Send file with header to download it
|
68
|
-
send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
|
69
|
-
end
|
70
|
-
|
71
|
-
#POST request
|
72
|
-
post '/sample-19-how-to-compare-documents' do
|
73
|
-
#Set variables
|
74
|
-
set :client_id, params[:clientId]
|
75
|
-
set :private_key, params[:privateKey]
|
76
|
-
set :sourceFileId, params[:sourceFileId]
|
77
|
-
set :targetFileId, params[:targetFileId]
|
78
|
-
set :callback, params[:callback]
|
79
|
-
set :base_path, params[:basePath]
|
80
|
-
|
81
|
-
#Set download path
|
82
|
-
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
83
|
-
|
84
|
-
#Remove all files from download directory or create folder if it not there
|
85
|
-
if File.directory?(downloads_path)
|
86
|
-
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
87
|
-
else
|
88
|
-
Dir::mkdir(downloads_path)
|
89
|
-
end
|
90
|
-
|
91
|
-
begin
|
92
|
-
|
93
|
-
#Check required variables
|
94
|
-
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.sourceFileId.empty? or settings.targetFileId.empty?
|
95
|
-
|
96
|
-
#Prepare base path
|
97
|
-
if settings.base_path.empty?
|
98
|
-
base_path = 'https://api.groupdocs.com'
|
99
|
-
elsif settings.base_path.match('/v2.0')
|
100
|
-
base_path = settings.base_path.split('/v2.0')[0]
|
101
|
-
else
|
102
|
-
base_path = settings.base_path
|
103
|
-
end
|
104
|
-
|
105
|
-
#Configure your access to API server
|
106
|
-
GroupDocs.configure do |groupdocs|
|
107
|
-
groupdocs.client_id = settings.client_id
|
108
|
-
groupdocs.private_key = settings.private_key
|
109
|
-
#Optionally specify API server and version
|
110
|
-
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
111
|
-
end
|
112
|
-
|
113
|
-
#Write client and private key to the file for callback job
|
114
|
-
if settings.callback
|
115
|
-
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
116
|
-
#White space is required
|
117
|
-
out_file.write("#{settings.client_id} ")
|
118
|
-
out_file.write("#{settings.private_key}")
|
119
|
-
out_file.close
|
120
|
-
end
|
121
|
-
|
122
|
-
#Make a request to API using client_id and private_key
|
123
|
-
files_list = GroupDocs::Storage::Folder.list!('/', {})
|
124
|
-
|
125
|
-
source_document = ''
|
126
|
-
target_document = ''
|
127
|
-
|
128
|
-
#Get source and target documents by file ID
|
129
|
-
files_list.each do |element|
|
130
|
-
if element.respond_to?('guid') == true and element.guid == settings.sourceFileId
|
131
|
-
source_document = element
|
132
|
-
else
|
133
|
-
source_document = GroupDocs::Storage::File.new(guid: settings.sourceFileId)
|
134
|
-
end
|
135
|
-
if element.respond_to?('guid') == true and element.guid == settings.targetFileId
|
136
|
-
target_document = element
|
137
|
-
else
|
138
|
-
target_document = GroupDocs::Storage::File.new(guid: settings.targetFileId)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
unless source_document.instance_of? String and target_document.instance_of? String
|
143
|
-
|
144
|
-
info = source_document.to_document.compare!(target_document.to_document, settings.callback)
|
145
|
-
|
146
|
-
i = 0
|
147
|
-
|
148
|
-
while i<5 do
|
149
|
-
sleep(5)
|
150
|
-
job = GroupDocs::Job.get!(info.id)
|
151
|
-
break if job.status == :archived
|
152
|
-
i += 1
|
153
|
-
end
|
154
|
-
|
155
|
-
#Get job by ID
|
156
|
-
job = GroupDocs::Job.new(id: info.id)
|
157
|
-
|
158
|
-
#Get all job documents
|
159
|
-
documents = job.documents!()
|
160
|
-
#Get compared file giud
|
161
|
-
guid = documents[:outputs].first.file.guid
|
162
|
-
embedkey = GroupDocs::User.get_embed_key!('comparison')
|
163
|
-
|
164
|
-
#Prepare to sign url
|
165
|
-
iframe = "/document-comparison2/embed/#{embedkey}/#{guid}"
|
166
|
-
# Construct result string
|
167
|
-
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
168
|
-
#Generate iframe URL
|
169
|
-
case settings.base_path
|
170
|
-
when 'https://stage-api-groupdocs.dynabic.com'
|
171
|
-
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
172
|
-
when 'https://dev-api-groupdocs.dynabic.com'
|
173
|
-
iframe = "https://dev-apps.groupdocs.com#{url}"
|
174
|
-
else
|
175
|
-
iframe = "https://apps.groupdocs.com#{url}"
|
176
|
-
end
|
177
|
-
|
178
|
-
#Construct result iframe
|
179
|
-
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
180
|
-
end
|
181
|
-
|
182
|
-
rescue Exception => e
|
183
|
-
err = e.message
|
184
|
-
end
|
185
|
-
|
186
|
-
#Set variables for template
|
187
|
-
haml :sample19, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :sourceFileId => settings.sourceFileId, :targetFileId => settings.targetFileId, :callback => settings.callback, :iframe => iframe, :err => err}
|
188
|
-
end
|
1
|
+
#GET request
|
2
|
+
get '/sample-19-how-to-compare-documents' do
|
3
|
+
haml :sample19
|
4
|
+
end
|
5
|
+
|
6
|
+
#POST request
|
7
|
+
post '/sample19/compere_callback' do
|
8
|
+
#Set download path
|
9
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
10
|
+
|
11
|
+
#Get callback request
|
12
|
+
data = JSON.parse(request.body.read)
|
13
|
+
begin
|
14
|
+
raise 'Empty params!' if data.empty?
|
15
|
+
source_id = nil
|
16
|
+
client_id = nil
|
17
|
+
private_key = nil
|
18
|
+
|
19
|
+
#Get value of SourceId
|
20
|
+
data.each do |key, value|
|
21
|
+
if key == 'SourceId'
|
22
|
+
source_id = value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
#Get private key and client_id from file user_info.txt
|
27
|
+
if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
28
|
+
contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
29
|
+
contents = contents.split(' ')
|
30
|
+
client_id = contents.first
|
31
|
+
private_key = contents.last
|
32
|
+
end
|
33
|
+
|
34
|
+
#Create Job instance
|
35
|
+
job = GroupDocs::Job.new({:id => source_id})
|
36
|
+
|
37
|
+
#Get document by job id
|
38
|
+
documents = job.documents!({:client_id => client_id, :private_key => private_key})
|
39
|
+
|
40
|
+
#Download converted file
|
41
|
+
documents[:inputs].first.outputs.first.download!(downloads_path, {:client_id => client_id, :private_key => private_key})
|
42
|
+
|
43
|
+
rescue Exception => e
|
44
|
+
err = e.message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
#GET request
|
49
|
+
get '/sample19/check' do
|
50
|
+
|
51
|
+
#Check is there download directory
|
52
|
+
unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
|
53
|
+
return 'Directory was not found.'
|
54
|
+
end
|
55
|
+
|
56
|
+
#Get file name from download directory
|
57
|
+
name = nil
|
58
|
+
Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
|
59
|
+
name = file if file != '.' && file != '..'
|
60
|
+
end
|
61
|
+
|
62
|
+
name
|
63
|
+
end
|
64
|
+
|
65
|
+
#GET request
|
66
|
+
get '/sample19/downloads/:filename' do |filename|
|
67
|
+
#Send file with header to download it
|
68
|
+
send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
|
69
|
+
end
|
70
|
+
|
71
|
+
#POST request
|
72
|
+
post '/sample-19-how-to-compare-documents' do
|
73
|
+
#Set variables
|
74
|
+
set :client_id, params[:clientId]
|
75
|
+
set :private_key, params[:privateKey]
|
76
|
+
set :sourceFileId, params[:sourceFileId]
|
77
|
+
set :targetFileId, params[:targetFileId]
|
78
|
+
set :callback, params[:callback]
|
79
|
+
set :base_path, params[:basePath]
|
80
|
+
|
81
|
+
#Set download path
|
82
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
83
|
+
|
84
|
+
#Remove all files from download directory or create folder if it not there
|
85
|
+
if File.directory?(downloads_path)
|
86
|
+
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
87
|
+
else
|
88
|
+
Dir::mkdir(downloads_path)
|
89
|
+
end
|
90
|
+
|
91
|
+
begin
|
92
|
+
|
93
|
+
#Check required variables
|
94
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.sourceFileId.empty? or settings.targetFileId.empty?
|
95
|
+
|
96
|
+
#Prepare base path
|
97
|
+
if settings.base_path.empty?
|
98
|
+
base_path = 'https://api.groupdocs.com'
|
99
|
+
elsif settings.base_path.match('/v2.0')
|
100
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
101
|
+
else
|
102
|
+
base_path = settings.base_path
|
103
|
+
end
|
104
|
+
|
105
|
+
#Configure your access to API server
|
106
|
+
GroupDocs.configure do |groupdocs|
|
107
|
+
groupdocs.client_id = settings.client_id
|
108
|
+
groupdocs.private_key = settings.private_key
|
109
|
+
#Optionally specify API server and version
|
110
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
111
|
+
end
|
112
|
+
|
113
|
+
#Write client and private key to the file for callback job
|
114
|
+
if settings.callback
|
115
|
+
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
116
|
+
#White space is required
|
117
|
+
out_file.write("#{settings.client_id} ")
|
118
|
+
out_file.write("#{settings.private_key}")
|
119
|
+
out_file.close
|
120
|
+
end
|
121
|
+
|
122
|
+
#Make a request to API using client_id and private_key
|
123
|
+
files_list = GroupDocs::Storage::Folder.list!('/', {})
|
124
|
+
|
125
|
+
source_document = ''
|
126
|
+
target_document = ''
|
127
|
+
|
128
|
+
#Get source and target documents by file ID
|
129
|
+
files_list.each do |element|
|
130
|
+
if element.respond_to?('guid') == true and element.guid == settings.sourceFileId
|
131
|
+
source_document = element
|
132
|
+
else
|
133
|
+
source_document = GroupDocs::Storage::File.new(guid: settings.sourceFileId)
|
134
|
+
end
|
135
|
+
if element.respond_to?('guid') == true and element.guid == settings.targetFileId
|
136
|
+
target_document = element
|
137
|
+
else
|
138
|
+
target_document = GroupDocs::Storage::File.new(guid: settings.targetFileId)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
unless source_document.instance_of? String and target_document.instance_of? String
|
143
|
+
|
144
|
+
info = source_document.to_document.compare!(target_document.to_document, settings.callback)
|
145
|
+
|
146
|
+
i = 0
|
147
|
+
|
148
|
+
while i<5 do
|
149
|
+
sleep(5)
|
150
|
+
job = GroupDocs::Job.get!(info.id)
|
151
|
+
break if job.status == :archived
|
152
|
+
i += 1
|
153
|
+
end
|
154
|
+
|
155
|
+
#Get job by ID
|
156
|
+
job = GroupDocs::Job.new(id: info.id)
|
157
|
+
|
158
|
+
#Get all job documents
|
159
|
+
documents = job.documents!()
|
160
|
+
#Get compared file giud
|
161
|
+
guid = documents[:outputs].first.file.guid
|
162
|
+
embedkey = GroupDocs::User.get_embed_key!('comparison')
|
163
|
+
|
164
|
+
#Prepare to sign url
|
165
|
+
iframe = "/document-comparison2/embed/#{embedkey}/#{guid}"
|
166
|
+
# Construct result string
|
167
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
168
|
+
#Generate iframe URL
|
169
|
+
case settings.base_path
|
170
|
+
when 'https://stage-api-groupdocs.dynabic.com'
|
171
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
172
|
+
when 'https://dev-api-groupdocs.dynabic.com'
|
173
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
174
|
+
else
|
175
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
176
|
+
end
|
177
|
+
|
178
|
+
#Construct result iframe
|
179
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
180
|
+
end
|
181
|
+
|
182
|
+
rescue Exception => e
|
183
|
+
err = e.message
|
184
|
+
end
|
185
|
+
|
186
|
+
#Set variables for template
|
187
|
+
haml :sample19, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :sourceFileId => settings.sourceFileId, :targetFileId => settings.targetFileId, :callback => settings.callback, :iframe => iframe, :err => err}
|
188
|
+
end
|