groupdocs 1.5.8 → 1.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/CHANGELOG.md +9 -0
  2. data/examples/api-samples/public/docs/sample01.html +34 -15
  3. data/examples/api-samples/public/docs/sample02.html +36 -15
  4. data/examples/api-samples/public/docs/sample03.html +55 -34
  5. data/examples/api-samples/public/docs/sample04.html +33 -14
  6. data/examples/api-samples/public/docs/sample05.html +51 -33
  7. data/examples/api-samples/public/docs/sample06.html +86 -40
  8. data/examples/api-samples/public/docs/sample07.html +32 -13
  9. data/examples/api-samples/public/docs/sample08.html +39 -20
  10. data/examples/api-samples/public/docs/sample09.html +93 -39
  11. data/examples/api-samples/public/docs/sample10.html +39 -21
  12. data/examples/api-samples/public/docs/sample11.html +133 -88
  13. data/examples/api-samples/public/docs/sample12.html +33 -14
  14. data/examples/api-samples/public/docs/sample13.html +14 -7
  15. data/examples/api-samples/public/docs/sample14.html +37 -18
  16. data/examples/api-samples/public/docs/sample15.html +29 -10
  17. data/examples/api-samples/public/docs/sample16.html +58 -25
  18. data/examples/api-samples/public/docs/sample17.html +71 -38
  19. data/examples/api-samples/public/docs/sample18.html +98 -71
  20. data/examples/api-samples/public/docs/sample19.html +74 -42
  21. data/examples/api-samples/public/docs/sample20.html +39 -21
  22. data/examples/api-samples/public/docs/sample21.html +113 -69
  23. data/examples/api-samples/public/docs/sample22.html +89 -43
  24. data/examples/api-samples/public/docs/sample23.html +50 -32
  25. data/examples/api-samples/public/docs/sample24.html +64 -31
  26. data/examples/api-samples/public/docs/sample25.html +107 -60
  27. data/examples/api-samples/public/docs/sample26.html +29 -10
  28. data/examples/api-samples/public/docs/sample27.html +107 -61
  29. data/examples/api-samples/public/docs/sample28.html +158 -9
  30. data/examples/api-samples/public/docs/sample29.html +13 -8
  31. data/examples/api-samples/public/docs/sample30.html +34 -15
  32. data/examples/api-samples/public/docs/sample31.html +107 -76
  33. data/examples/api-samples/public/docs/sample32.html +104 -40
  34. data/examples/api-samples/public/docs/sample33.html +85 -36
  35. data/examples/api-samples/public/docs/sample34.html +30 -11
  36. data/examples/api-samples/public/docs/sample35.html +90 -27
  37. data/examples/api-samples/public/docs/sample36.html +36 -16
  38. data/examples/api-samples/public/docs/sample37.html +144 -265
  39. data/examples/api-samples/public/docs/sample38.html +113 -64
  40. data/examples/api-samples/public/docs/sample39.html +118 -45
  41. data/examples/api-samples/public/docs/sample40.html +81 -46
  42. data/examples/api-samples/public/docs/sample41.html +562 -90
  43. data/examples/api-samples/public/docs/sample42.html +94 -39
  44. data/examples/api-samples/public/docs/sample43.html +669 -0
  45. data/examples/api-samples/samples/sample01.rb +17 -10
  46. data/examples/api-samples/samples/sample02.rb +21 -12
  47. data/examples/api-samples/samples/sample03.rb +35 -29
  48. data/examples/api-samples/samples/sample04.rb +19 -12
  49. data/examples/api-samples/samples/sample05.rb +24 -17
  50. data/examples/api-samples/samples/sample06.rb +38 -32
  51. data/examples/api-samples/samples/sample07.rb +19 -12
  52. data/examples/api-samples/samples/sample08.rb +22 -15
  53. data/examples/api-samples/samples/sample09.rb +31 -29
  54. data/examples/api-samples/samples/sample10.rb +22 -15
  55. data/examples/api-samples/samples/sample11.rb +78 -81
  56. data/examples/api-samples/samples/sample12.rb +19 -21
  57. data/examples/api-samples/samples/sample13.rb +19 -21
  58. data/examples/api-samples/samples/sample14.rb +18 -12
  59. data/examples/api-samples/samples/sample15.rb +17 -10
  60. data/examples/api-samples/samples/sample16.rb +25 -17
  61. data/examples/api-samples/samples/sample17.rb +31 -23
  62. data/examples/api-samples/samples/sample18.rb +60 -55
  63. data/examples/api-samples/samples/sample19.rb +48 -42
  64. data/examples/api-samples/samples/sample20.rb +20 -13
  65. data/examples/api-samples/samples/sample21.rb +62 -54
  66. data/examples/api-samples/samples/sample22.rb +37 -31
  67. data/examples/api-samples/samples/sample23.rb +24 -17
  68. data/examples/api-samples/samples/sample24.rb +29 -22
  69. data/examples/api-samples/samples/sample25.rb +47 -40
  70. data/examples/api-samples/samples/sample26.rb +16 -9
  71. data/examples/api-samples/samples/sample27.rb +46 -39
  72. data/examples/api-samples/samples/sample28.rb +42 -11
  73. data/examples/api-samples/samples/sample29.rb +13 -8
  74. data/examples/api-samples/samples/sample30.rb +19 -12
  75. data/examples/api-samples/samples/sample31.rb +63 -58
  76. data/examples/api-samples/samples/sample32.rb +45 -42
  77. data/examples/api-samples/samples/sample33.rb +36 -25
  78. data/examples/api-samples/samples/sample34.rb +16 -9
  79. data/examples/api-samples/samples/sample35.rb +66 -53
  80. data/examples/api-samples/samples/sample36.rb +19 -15
  81. data/examples/api-samples/samples/sample37.rb +61 -99
  82. data/examples/api-samples/samples/sample38.rb +51 -43
  83. data/examples/api-samples/samples/sample39.rb +78 -62
  84. data/examples/api-samples/samples/sample40.rb +48 -38
  85. data/examples/api-samples/samples/sample41.rb +189 -67
  86. data/examples/api-samples/samples/sample42.rb +37 -29
  87. data/examples/api-samples/samples/sample43.rb +127 -0
  88. data/examples/api-samples/views/_others_samples.haml +4 -2
  89. data/examples/api-samples/views/index.haml +4 -2
  90. data/examples/api-samples/views/sample11.haml +1 -1
  91. data/examples/api-samples/views/sample28.haml +8 -0
  92. data/examples/api-samples/views/sample31.haml +1 -6
  93. data/examples/api-samples/views/sample39.haml +7 -2
  94. data/examples/api-samples/views/sample41.haml +78 -33
  95. data/examples/api-samples/views/sample42.haml +0 -1
  96. data/examples/api-samples/views/sample43.haml +91 -0
  97. data/lib/groupdocs/api/helpers/access_rights_helper.rb +6 -5
  98. data/lib/groupdocs/api/helpers/url_helper.rb +2 -1
  99. data/lib/groupdocs/document.rb +3 -3
  100. data/lib/groupdocs/version.rb +1 -1
  101. metadata +5 -2
@@ -1,9 +1,9 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample32' do
3
3
  haml :sample32
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample32/callback' do
8
8
 
9
9
  source_id = ''
@@ -11,19 +11,19 @@ post '/sample32/callback' do
11
11
  private_key = ''
12
12
  subscriber_email = ''
13
13
 
14
- # Get callback request
14
+ #Get callback request
15
15
  data = JSON.parse(request.body.read)
16
16
  begin
17
17
  raise 'Empty params!' if data.empty?
18
18
 
19
- # Get value of SourceId
19
+ #Get value of SourceId
20
20
  data.each do |key, value|
21
21
  if key == 'SourceId'
22
22
  source_id = value
23
23
  end
24
24
  end
25
25
 
26
- # Get private key and client_id from file user_info.txt
26
+ #Get private key and client_id from file user_info.txt
27
27
  if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
28
28
  contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
29
29
  contents = contents.split(' ')
@@ -32,16 +32,16 @@ post '/sample32/callback' do
32
32
  subscriber_email = contents[2]
33
33
  end
34
34
 
35
- # Create new Form
35
+ #Create new Form
36
36
  form = GroupDocs::Signature::Form.new({:id => source_id})
37
37
 
38
- # Get document by Form id
38
+ #Get document by Form id
39
39
  document = form.documents!({:client_id => client_id, :private_key => private_key})
40
40
 
41
- # An adress recipient
41
+ #An adress recipient
42
42
  to = subscriber_email
43
43
 
44
- # The Body message
44
+ #The Body message
45
45
  body = "
46
46
  <html>
47
47
  <head>
@@ -53,28 +53,22 @@ post '/sample32/callback' do
53
53
  </html>"
54
54
 
55
55
 
56
- # A method send the mail
56
+ #A method send the mail
57
57
  def send_mail(to, body)
58
- #implement your send mail function with your SMTP server
58
+ #Implement your send mail function with your SMTP server
59
59
  return true
60
60
  end
61
61
 
62
- send_mail(to, body) #send notification mail
62
+ send_mail(to, body) #Send notification mail
63
63
 
64
64
  rescue Exception => e
65
65
  err = e.message
66
66
  end
67
67
  end
68
68
 
69
-
70
-
71
-
72
-
73
-
74
-
75
- # POST request
69
+ #POST request
76
70
  post '/sample32' do
77
- # set variables
71
+ #Set variables
78
72
  set :client_id, params[:clientId]
79
73
  set :private_key, params[:privateKey]
80
74
  set :template_guid, params[:templateGuid]
@@ -86,23 +80,30 @@ post '/sample32' do
86
80
 
87
81
  begin
88
82
 
89
- # Check required variables
83
+ #Check required variables
90
84
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
91
85
 
92
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
86
+ #Prepare base path
87
+ if settings.base_path.empty?
88
+ base_path = 'https://api.groupdocs.com'
89
+ elsif settings.base_path.match('/v2.0')
90
+ base_path = settings.base_path.split('/v2.0')[0]
91
+ else
92
+ base_path = settings.base_path
93
+ end
93
94
 
94
- # Configure your access to API server
95
+ #Configure your access to API server
95
96
  GroupDocs.configure do |groupdocs|
96
97
  groupdocs.client_id = settings.client_id
97
98
  groupdocs.private_key = settings.private_key
98
- # Optionally specify API server and version
99
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
99
+ #Optionally specify API server and version
100
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
100
101
  end
101
102
 
102
- # Write client and private key to the file for callback job
103
+ #Write client and private key to the file for callback job
103
104
  if settings.callback
104
105
  out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
105
- # white space is required
106
+ #White space is required
106
107
  out_file.write("#{settings.client_id} ")
107
108
  out_file.write("#{settings.private_key} ")
108
109
  out_file.write("#{settings.email}")
@@ -115,16 +116,16 @@ post '/sample32' do
115
116
  case settings.source
116
117
  when 'form'
117
118
  id = settings.form_guid
118
- # Create new Form with guid
119
+ #Create new Form with guid
119
120
  form = GroupDocs::Signature::Form.new
120
121
  form.name = 'test'
121
122
  form.notifyOwnerOnSign = true
122
123
 
123
- # Create new Form with template
124
+ #Create new Form with template
124
125
  id = form.create!({:formId => guid})
125
126
  form = GroupDocs::Signature::Form.get!(id)
126
127
 
127
- # Publish the Form
128
+ #Publish the Form
128
129
  form.publish!({:callbackUrl => settings.callback})
129
130
  guid = settings.form_guid
130
131
 
@@ -134,34 +135,36 @@ post '/sample32' do
134
135
  form.name = 'test'
135
136
  form.notifyOwnerOnSign = true
136
137
 
137
- # Create new Form with template
138
+ #Create new Form with template
138
139
  guid = form.create!({ :templateId => settings.template_guid})
139
140
 
140
- # Publish the Form
141
+ #Publish the Form
141
142
  form.publish!({:callbackUrl => settings.callback})
142
143
 
143
144
  end
144
145
 
145
- #Get url from request
146
- case settings.base_path
147
-
146
+ #Prepare to sign url
147
+ iframe = "/signature2/forms/signembed/#{guid}"
148
+ # Construct result string
149
+ url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
150
+ #Generate iframe URL
151
+ case base_path
148
152
  when 'https://stage-api-groupdocs.dynabic.com'
149
- url = "http://stage-apps-groupdocs.dynabic.com/signature2/forms/signembed/ #{guid}"
153
+ iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
150
154
  when 'https://dev-api-groupdocs.dynabic.com'
151
- url = "http://dev-apps-groupdocs.dynabic.com/signature2/forms/signembed/ #{guid}"
155
+ iframe = "https://dev-apps.groupdocs.com#{url}"
152
156
  else
153
- url = "https://apps.groupdocs.com/signature2/forms/signembed/ #{guid}"
157
+ iframe = "https://apps.groupdocs.com#{url}"
154
158
  end
155
159
 
156
- # Add the signature to url the request
157
- iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
158
- iframe = "<iframe width='100%' height='600' frameborder='0' src='#{iframe}'></iframe>"
160
+ #Make iframe
161
+ iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
159
162
 
160
163
  rescue Exception => e
161
164
  err = e.message
162
165
  end
163
166
 
164
- # Set variables for template
167
+ #Set variables for template
165
168
  haml :sample32, :locals => {:userId => settings.client_id,
166
169
  :privateKey => settings.private_key,
167
170
  :callback => settings.callback,
@@ -1,11 +1,11 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample33' do
3
3
  haml :sample33
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample33' do
8
- # set variables
8
+ #Set variables
9
9
  set :client_id, params[:clientId]
10
10
  set :private_key, params[:privateKey]
11
11
  set :url_1, params[:url1]
@@ -14,36 +14,44 @@ post '/sample33' do
14
14
  set :base_path, params[:basePath]
15
15
 
16
16
  begin
17
- # Check required variables
17
+ #Check required variables
18
18
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.url_1.empty? or settings.url_2.empty? or settings.url_3.empty?
19
19
 
20
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
20
+ #Prepare base path
21
+ if settings.base_path.empty?
22
+ base_path = 'https://api.groupdocs.com'
23
+ elsif settings.base_path.match('/v2.0')
24
+ base_path = settings.base_path.split('/v2.0')[0]
25
+ else
26
+ base_path = settings.base_path
27
+ end
21
28
 
22
- # Configure your access to API server
29
+ #Configure your access to API server
23
30
  GroupDocs.configure do |groupdocs|
24
31
  groupdocs.client_id = settings.client_id
25
32
  groupdocs.private_key = settings.private_key
26
- # Optionally specify API server and version
27
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
33
+ #Optionally specify API server and version
34
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
35
+
28
36
  end
29
37
 
30
38
 
31
- # Create Array from variables
39
+ #Create Array from variables
32
40
  url = [settings.url_1, settings.url_2, settings.url_3 ]
33
41
 
34
- # Create Hash with the options for job. :status=> -1 means the Draft status of the job
42
+ #Create Hash with the options for job. :status=> -1 means the Draft status of the job
35
43
  options = {:actions => [:convert, :combine], :out_formats => ['pdf'], :status => -1, :name => 'sample'}
36
44
 
37
- # Create Job with provided options with Draft status (Sheduled job)
45
+ #Create Job with provided options with Draft status (Sheduled job)
38
46
  job = GroupDocs::Job.create!(options)
39
47
 
40
- # Upload documents to GroupDocs Storage by url and add the documents to previously created Job
48
+ #Upload documents to GroupDocs Storage by url and add the documents to previously created Job
41
49
  url.each do |url|
42
50
  document = GroupDocs::Storage::File.upload_web!(url).to_document
43
51
  job.add_document!(document, {:check_ownership => false})
44
52
  end
45
53
 
46
- # Update the Job with new status. :status => '0' mean Active status of the job (Start the job)
54
+ #Update the Job with new status. :status => '0' mean Active status of the job (Start the job)
47
55
  id = job.update!({:status => '0'})
48
56
 
49
57
  i = 1
@@ -55,28 +63,31 @@ post '/sample33' do
55
63
  i = i + 1
56
64
  end
57
65
 
58
- # Get the document into Pdf format
66
+ #Get the document into Pdf format
59
67
  file = job.documents!()
60
68
 
61
69
  document = file[:outputs]
62
70
 
63
- # Set iframe with document GUID or raise an error
71
+ #Set iframe with document GUID or raise an error
64
72
  if document
65
73
 
66
- #Get url from request
67
- case settings.base_path
68
-
74
+ #Prepare to sign url
75
+ iframe = "/document-viewer/embed/#{document[0].guid}"
76
+ #Construct result string
77
+ url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
78
+ #Generate iframe URL
79
+ case base_path
69
80
  when 'https://stage-api-groupdocs.dynabic.com'
70
- url = "http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{document[0].guid}"
81
+ iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
71
82
  when 'https://dev-api-groupdocs.dynabic.com'
72
- url = "http://dev-apps-groupdocs.dynabic.com/document-viewer/embed/#{document[0].guid}"
83
+ iframe = "https://dev-apps.groupdocs.com#{url}"
73
84
  else
74
- url = "https://apps.groupdocs.com/document-viewer/embed/#{document[0].guid}"
85
+ iframe = "https://apps.groupdocs.com#{url}"
75
86
  end
76
87
 
77
- # Add the signature in url
78
- iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
79
- iframe = "<iframe width='100%' height='600' frameborder='0' src='#{iframe}'></iframe>"
88
+ #Make iframe
89
+ iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
90
+
80
91
  else
81
92
  raise 'File was not converted'
82
93
  end
@@ -84,6 +95,6 @@ post '/sample33' do
84
95
  err = e.message
85
96
  end
86
97
 
87
- # Set variables for template
98
+ #Set variables for template
88
99
  haml :sample33, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :err => err, :iframe => iframe}
89
100
  end
@@ -1,31 +1,38 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample34' do
3
3
  haml :sample34
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample34' do
8
- # Set variables
8
+ #Set variables
9
9
  set :client_id, params[:clientId]
10
10
  set :private_key, params[:privateKey]
11
11
  set :path, params[:folder]
12
12
  set :base_path, params[:basePath]
13
13
 
14
14
  begin
15
- # Check required variables
15
+ #Check required variables
16
16
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
17
17
 
18
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
18
+ #Prepare base path
19
+ if settings.base_path.empty?
20
+ base_path = 'https://api.groupdocs.com'
21
+ elsif settings.base_path.match('/v2.0')
22
+ base_path = settings.base_path.split('/v2.0')[0]
23
+ else
24
+ base_path = settings.base_path
25
+ end
19
26
 
20
- # Configure your access to API server
27
+ #Configure your access to API server
21
28
  GroupDocs.configure do |groupdocs|
22
29
  groupdocs.client_id = settings.client_id
23
30
  groupdocs.private_key = settings.private_key
24
31
  # Optionally specify API server and version
25
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
32
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
26
33
  end
27
34
 
28
- # Create new Folder
35
+ #Create new Folder
29
36
  folder = GroupDocs::Storage::Folder.create!(settings.path)
30
37
  if folder.id
31
38
  message = "<span style=\"color:green\">Folder was created #{folder.path} </span> "
@@ -35,6 +42,6 @@ post '/sample34' do
35
42
  err = e.message
36
43
  end
37
44
 
38
- # set variables for template
45
+ #Set variables for template
39
46
  haml :sample34, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :message => message, :err => err}
40
47
  end
@@ -1,66 +1,71 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample35' do
3
3
  haml :sample35
4
4
  end
5
5
 
6
6
 
7
- # POST request
7
+ #POST request
8
8
  post '/sample35' do
9
- # Set variables
9
+ #Set variables
10
10
  set :client_id, params[:clientId]
11
11
  set :private_key, params[:privateKey]
12
12
  set :source, params[:source]
13
13
  set :file_id, params[:fileId]
14
14
  set :url, params[:url]
15
- set :path, params[:basePath]
15
+ set :base_path, params[:basePath]
16
16
 
17
17
  begin
18
- # Check required variables
18
+ #Check required variables
19
19
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
20
20
 
21
- if settings.path.empty? then settings.path == 'https://api.groupdocs.com' end
22
- # clean version if it contains
23
- path = settings.path.gsub(/\/v2.0/, '')
21
+ #Prepare base path
22
+ if settings.base_path.empty?
23
+ base_path = 'https://api.groupdocs.com'
24
+ elsif settings.base_path.match('/v2.0')
25
+ base_path = settings.base_path.split('/v2.0')[0]
26
+ else
27
+ base_path = settings.base_path
28
+ end
24
29
 
25
- # Configure your access to API server.
30
+ #Configure your access to API server.
26
31
  GroupDocs.configure do |groupdocs|
27
32
  groupdocs.client_id = settings.client_id
28
33
  groupdocs.private_key = settings.private_key
29
- # optionally specify API server and version
30
- groupdocs.api_server = path # default is 'https://api.groupdocs.com' https://dev-api-groupdocs.dynabic.com/v2.0
34
+ #Optionally specify API server and version
35
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
31
36
 
32
37
  end
33
38
 
34
39
 
35
- # Get document by file GUID
40
+ #Get document by file GUID
36
41
  case settings.source
37
42
  when 'guid'
38
- # Create instance of File
43
+ #Create instance of File
39
44
  file = GroupDocs::Storage::File.new({:guid => settings.file_id})
40
45
  when 'local'
41
- # Construct path
46
+ #Construct path
42
47
  file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
43
- # Open file
48
+ #Open file
44
49
  File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
45
- # Make a request to API using client_id and private_key
50
+ #Make a request to API using client_id and private_key
46
51
  file = GroupDocs::Storage::File.upload!(file_path, {})
47
52
  when 'url'
48
- # Upload file from defined url
53
+ #Upload file from defined url
49
54
  file = GroupDocs::Storage::File.upload_web!(settings.url)
50
55
  else
51
56
  raise 'Wrong GUID source.'
52
57
  end
53
58
 
54
- # Raise exception if something went wrong
59
+ #Raise exception if something went wrong
55
60
  raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
56
61
 
57
62
 
58
- # Make GroupDocs::Storage::Document instance
63
+ #Make GroupDocs::Storage::Document instance
59
64
  document = file.to_document
60
- # Get array of document's fields
65
+ #Get array of document's fields
61
66
  fields = document.fields!
62
67
 
63
- # Create the fields for form
68
+ #Create the fields for form
64
69
  html = ''
65
70
  fields.map do |e|
66
71
 
@@ -90,62 +95,64 @@ post '/sample35' do
90
95
 
91
96
  end
92
97
 
93
-
94
98
  rescue Exception => e
95
99
  err = e.message
96
100
  end
97
101
 
98
- # Set variables for template
99
- haml :sample35, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :base_path => settings.path, :fileId => document.file.guid, :html => html, :err => err}
102
+ #Set variables for template
103
+ haml :sample35, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :fileId => document.file.guid, :base_path => settings.base_path, :html => html, :err => err}
100
104
  end
101
105
 
102
- # GET request
106
+ #GET request
103
107
  get '/sample35/check' do
104
108
  haml :sample35
105
109
  end
106
110
 
107
- # POST request
111
+ #POST request
108
112
  post '/sample35/check' do
109
113
  set :client_id, params[:clientId]
110
114
  set :private_key, params[:privateKey]
111
- set :path, params[:basePath]
115
+ set :base_path, params[:basePath]
112
116
  set :file_id, params[:fileId]
113
117
 
114
118
  begin
115
119
 
116
- if settings.path.empty? then settings.path == 'https://api.groupdocs.com' end
117
-
118
- #clean version if it contains
119
- path = settings.path.gsub(/\/v2.0/, '')
120
+ #Prepare base path
121
+ if settings.base_path.empty?
122
+ base_path = 'https://api.groupdocs.com'
123
+ elsif settings.base_path.match('/v2.0')
124
+ base_path = settings.base_path.split('/v2.0')[0]
125
+ else
126
+ base_path = settings.base_path
127
+ end
120
128
 
121
- # Get document by file GUID
129
+ #Get document by file GUID
122
130
  GroupDocs.configure do |groupdocs|
123
131
  groupdocs.client_id = settings.client_id
124
132
  groupdocs.private_key = settings.private_key
125
- # optionally specify API server and version
126
- groupdocs.api_server = path # default is 'https://api.groupdocs.com'
127
- groupdocs.api_version = '2.0' # default is '2.0'
133
+ #Optionally specify API server and version
134
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
128
135
  end
129
136
 
130
137
 
131
138
  #TODO:
132
139
  #Merge template PDF FIle with the data provided via dynamically created HTML form.
133
140
 
134
- # Create instance of File
141
+ #Create instance of File
135
142
  document = GroupDocs::Storage::File.new({:guid => settings.file_id}).to_document
136
143
 
137
- # Create datasource with fields
144
+ #Create datasource with fields
138
145
  datasource = GroupDocs::DataSource.new
139
146
 
140
- # Get array of document's fields
147
+ #Get array of document's fields
141
148
  fields = document.fields!()
142
149
 
143
- # Get unique fields
150
+ #Get unique fields
144
151
  fields = fields.uniq{ |f| f.name }
145
152
 
146
153
  datasource.fields = []
147
154
 
148
- # Create Field instance and fill the fields
155
+ #Create Field instance and fill the fields
149
156
  fields.each do |field|
150
157
  if field.type == 'Text'
151
158
  datasource.fields << GroupDocs::DataSource::Field.new(name: field.name, type: :text, values: [params[field.name.to_sym]])
@@ -184,14 +191,14 @@ post '/sample35/check' do
184
191
 
185
192
  end
186
193
 
187
- # Adds datasource.
194
+ #Adds datasource.
188
195
  datasource.add!()
189
196
 
190
- # Creates new job to merge datasource into document.
197
+ #Creates new job to merge datasource into document.
191
198
  job = document.datasource!(datasource, {:new_type => 'pdf'})
192
199
 
193
200
  i = 0
194
- # Checks status of Job.
201
+ #Checks status of Job.
195
202
  while i<5 do
196
203
  sleep(5)
197
204
  job_status = GroupDocs::Job.get!(job.id)
@@ -199,22 +206,28 @@ post '/sample35/check' do
199
206
  i += 1
200
207
  end
201
208
 
202
- # Returns an hash of input and output documents associated to job.
209
+ #Returns an hash of input and output documents associated to job.
203
210
  document = job.documents!()
204
211
 
205
- # Set converted document GUID
212
+ #Set converted document GUID
206
213
  guid = document[:inputs][0].outputs[0].guid
207
214
 
208
- case path
209
-
210
- when 'https://stage-api-groupdocs.dynabic.com'
211
- iframe = "<iframe width='100%' height='600' frameborder='0' src='http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{guid}'></iframe>"
212
- when 'https://dev-api-groupdocs.dynabic.com'
213
- iframe = "<iframe width='100%' height='600' frameborder='0' src='http://dev-apps-groupdocs.dynabic.com/document-viewer/embed/#{guid}'></iframe>"
214
- else
215
- iframe = "<iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/document-viewer/embed/#{guid}'></iframe>"
215
+ #Prepare to sign url
216
+ iframe = "/document-viewer/embed/#{guid}"
217
+ # Construct result string
218
+ url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
219
+ #Generate iframe URL
220
+ case base_path
221
+ when 'https://stage-api-groupdocs.dynabic.com'
222
+ iframe = "https://stage-apps-groupdocs.dynabic.com/#{url}"
223
+ when 'https://dev-api-groupdocs.dynabic.com'
224
+ iframe = "https://dev-apps-groupdocs.dynabic.com#{url}"
225
+ else
226
+ iframe = "https://apps.groupdocs.com#{url}"
216
227
  end
217
228
 
229
+ #Make iframe
230
+ iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
218
231
 
219
232
  rescue Exception => e
220
233
  err = e.message