groupdocs 1.5.8 → 1.5.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 (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,14 +1,14 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample19' do
3
3
  haml :sample19
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample19/compere_callback' do
8
- # Set download path
8
+ #Set download path
9
9
  downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
10
10
 
11
- # Get callback request
11
+ #Get callback request
12
12
  data = JSON.parse(request.body.read)
13
13
  begin
14
14
  raise 'Empty params!' if data.empty?
@@ -16,14 +16,14 @@ post '/sample19/compere_callback' do
16
16
  client_id = nil
17
17
  private_key = nil
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(' ')
@@ -31,13 +31,13 @@ post '/sample19/compere_callback' do
31
31
  private_key = contents.last
32
32
  end
33
33
 
34
- # Create Job instance
34
+ #Create Job instance
35
35
  job = GroupDocs::Job.new({:id => source_id})
36
36
 
37
- # Get document by job id
37
+ #Get document by job id
38
38
  documents = job.documents!({:client_id => client_id, :private_key => private_key})
39
39
 
40
- # Download converted file
40
+ #Download converted file
41
41
  documents[:inputs].first.outputs.first.download!(downloads_path, {:client_id => client_id, :private_key => private_key})
42
42
 
43
43
  rescue Exception => e
@@ -45,15 +45,15 @@ post '/sample19/compere_callback' do
45
45
  end
46
46
  end
47
47
 
48
- # GET request
48
+ #GET request
49
49
  get '/sample19/check' do
50
50
 
51
- # Check is there download directory
51
+ #Check is there download directory
52
52
  unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
53
53
  return 'Directory was not found.'
54
54
  end
55
55
 
56
- # Get file name from download directory
56
+ #Get file name from download directory
57
57
  name = nil
58
58
  Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
59
59
  name = file if file != '.' && file != '..'
@@ -62,15 +62,15 @@ get '/sample19/check' do
62
62
  name
63
63
  end
64
64
 
65
- # GET request
65
+ #GET request
66
66
  get '/sample19/downloads/:filename' do |filename|
67
- # Send file with header to download it
67
+ #Send file with header to download it
68
68
  send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
69
69
  end
70
70
 
71
- # POST request
71
+ #POST request
72
72
  post '/sample19' do
73
- # Set variables
73
+ #Set variables
74
74
  set :client_id, params[:clientId]
75
75
  set :private_key, params[:privateKey]
76
76
  set :sourceFileId, params[:sourceFileId]
@@ -78,10 +78,10 @@ post '/sample19' do
78
78
  set :callback, params[:callback]
79
79
  set :base_path, params[:basePath]
80
80
 
81
- # Set download path
81
+ #Set download path
82
82
  downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
83
83
 
84
- # Remove all files from download directory or create folder if it not there
84
+ #Remove all files from download directory or create folder if it not there
85
85
  if File.directory?(downloads_path)
86
86
  Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
87
87
  else
@@ -90,35 +90,42 @@ post '/sample19' do
90
90
 
91
91
  begin
92
92
 
93
- # Check required variables
93
+ #Check required variables
94
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
95
 
96
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
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
97
104
 
98
- # Configure your access to API server
105
+ #Configure your access to API server
99
106
  GroupDocs.configure do |groupdocs|
100
107
  groupdocs.client_id = settings.client_id
101
108
  groupdocs.private_key = settings.private_key
102
- # Optionally specify API server and version
103
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
109
+ #Optionally specify API server and version
110
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
104
111
  end
105
112
 
106
- # Write client and private key to the file for callback job
113
+ #Write client and private key to the file for callback job
107
114
  if settings.callback
108
115
  out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
109
- # white space is required
116
+ #White space is required
110
117
  out_file.write("#{settings.client_id} ")
111
118
  out_file.write("#{settings.private_key}")
112
119
  out_file.close
113
120
  end
114
121
 
115
- # Make a request to API using client_id and private_key
122
+ #Make a request to API using client_id and private_key
116
123
  files_list = GroupDocs::Storage::Folder.list!('/', {})
117
124
 
118
125
  source_document = ''
119
126
  target_document = ''
120
127
 
121
- # Get source and target documents by file ID
128
+ #Get source and target documents by file ID
122
129
  files_list.each do |element|
123
130
  if element.respond_to?('guid') == true and element.guid == settings.sourceFileId
124
131
  source_document = element
@@ -142,37 +149,36 @@ post '/sample19' do
142
149
  i += 1
143
150
  end
144
151
 
145
-
146
- # Get job by ID
152
+ #Get job by ID
147
153
  job = GroupDocs::Job.new(id: info.id)
148
154
 
149
- # Get all job documents
155
+ #Get all job documents
150
156
  documents = job.documents!()
151
- # Get compared file giud
157
+ #Get compared file giud
152
158
  guid = documents[:outputs].first.file.guid
153
159
 
154
- #Get url from request
160
+ #Prepare to sign url
161
+ iframe = "/document-viewer/embed/#{guid}"
162
+ # Construct result string
163
+ url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
164
+ #Generate iframe URL
155
165
  case settings.base_path
156
-
157
166
  when 'https://stage-api-groupdocs.dynabic.com'
158
- url = "http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{guid}"
167
+ iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
159
168
  when 'https://dev-api-groupdocs.dynabic.com'
160
- url = "http://dev-apps-groupdocs.dynabic.com/document-viewer/embed/#{guid}"
169
+ iframe = "https://dev-apps.groupdocs.com#{url}"
161
170
  else
162
- url = "https://apps.groupdocs.com/document-viewer/embed/#{guid}"
171
+ iframe = "https://apps.groupdocs.com#{url}"
163
172
  end
164
173
 
165
- # Add the signature to url request
166
- iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
167
- # Construct result iframe
168
- iframe = "<iframe src='#{iframe}' frameborder='0' width='100%' height='600'></iframe>"
169
-
174
+ #Construct result iframe
175
+ iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
170
176
  end
171
177
 
172
178
  rescue Exception => e
173
179
  err = e.message
174
180
  end
175
181
 
176
- # Set variables for template
182
+ #Set variables for template
177
183
  haml :sample19, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :sourceFileId => settings.sourceFileId, :targetFileId => settings.targetFileId, :callback => settings.callback, :iframe => iframe, :err => err}
178
184
  end
@@ -1,11 +1,11 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample20' do
3
3
  haml :sample20
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample20' do
8
- # set variables
8
+ #Set variables
9
9
  set :client_id, params[:clientId]
10
10
  set :private_key, params[:privateKey]
11
11
  set :resultFileId, params[:resultFileId]
@@ -13,26 +13,33 @@ post '/sample20' do
13
13
 
14
14
  begin
15
15
 
16
- # check required variables
16
+ #Check required variables
17
17
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.resultFileId.empty?
18
18
 
19
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
19
+ #Prepare base path
20
+ if settings.base_path.empty?
21
+ base_path = 'https://api.groupdocs.com'
22
+ elsif settings.base_path.match('/v2.0')
23
+ base_path = settings.base_path.split('/v2.0')[0]
24
+ else
25
+ base_path = settings.base_path
26
+ end
20
27
 
21
- # Configure your access to API server
28
+ #Configure your access to API server
22
29
  GroupDocs.configure do |groupdocs|
23
30
  groupdocs.client_id = settings.client_id
24
31
  groupdocs.private_key = settings.private_key
25
- # Optionally specify API server and version
26
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
32
+ #Optionally specify API server and version
33
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
27
34
  end
28
35
 
29
- # construct new storage file
36
+ #Construct new storage file
30
37
  file = GroupDocs::Storage::File.new(guid: settings.resultFileId)
31
- # construct new document
38
+ #Construct new document
32
39
  document = GroupDocs::Document.new(file: file)
33
- # get compare changes
34
- changes = document.changes!()
35
40
 
41
+ #Get compare changes
42
+ changes = document.changes!()
36
43
  result = ''
37
44
  result += "<table class='border'>"
38
45
  result += "<tr><td><font color='green'>Change Name</font></td><td><font color='green'>Change</font></td></tr>"
@@ -56,6 +63,6 @@ post '/sample20' do
56
63
  err = e.message
57
64
  end
58
65
 
59
- # set variables for template
66
+ #Set variables for template
60
67
  haml :sample20, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :resultFileId => settings.resultFileId, :result => result, :err => err}
61
68
  end
@@ -1,14 +1,14 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample21' do
3
3
  haml :sample21
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample21/signature_callback' do
8
- # Set download path
8
+ #Set download path
9
9
  downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
10
10
 
11
- # Get callback request
11
+ #Get callback request
12
12
  data = JSON.parse(request.body.read)
13
13
  begin
14
14
  raise 'Empty params!' if data.empty?
@@ -16,14 +16,14 @@ post '/sample21/signature_callback' do
16
16
  client_id = nil
17
17
  private_key = nil
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(' ')
@@ -31,13 +31,13 @@ post '/sample21/signature_callback' do
31
31
  private_key = contents.last
32
32
  end
33
33
 
34
- # Create Job instance
34
+ #Create Job instance
35
35
  job = GroupDocs::Signature::Envelope.new({:id => source_id})
36
36
 
37
- # Get document by job id
37
+ #Get document by job id
38
38
  documents = job.documents!({}, {:client_id => client_id, :private_key => private_key})
39
39
 
40
- # Download converted file
40
+ #Download converted file
41
41
  documents[0].file.download!(downloads_path, {:client_id => client_id, :private_key => private_key})
42
42
 
43
43
  rescue Exception => e
@@ -46,15 +46,15 @@ post '/sample21/signature_callback' do
46
46
  end
47
47
 
48
48
 
49
- # GET request
49
+ #GET request
50
50
  get '/sample21/check' do
51
51
 
52
- # Check is there download directory
52
+ #Check is there download directory
53
53
  unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
54
54
  return 'Directory was not found.'
55
55
  end
56
56
 
57
- # Get file name from download directory
57
+ #Get file name from download directory
58
58
  name = nil
59
59
  Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
60
60
  name = file if file != '.' && file != '..'
@@ -63,15 +63,15 @@ get '/sample21/check' do
63
63
  name
64
64
  end
65
65
 
66
- # GET request
66
+ #GET request
67
67
  get '/sample21/downloads/:filename' do |filename|
68
- # Send file with header to download it
68
+ #Send file with header to download it
69
69
  send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
70
70
  end
71
71
 
72
- # POST request
72
+ #POST request
73
73
  post '/sample21' do
74
- # set variables
74
+ #Set variables
75
75
  set :client_id, params[:clientId]
76
76
  set :private_key, params[:privateKey]
77
77
  set :email, params[:email]
@@ -83,10 +83,10 @@ post '/sample21' do
83
83
  set :url, params[:url]
84
84
  set :source, params[:source]
85
85
 
86
- # Set download path
86
+ #Set download path
87
87
  downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
88
88
 
89
- # Remove all files from download directory or create folder if it not there
89
+ #Remove all files from download directory or create folder if it not there
90
90
  if File.directory?(downloads_path)
91
91
  Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
92
92
  else
@@ -94,111 +94,119 @@ post '/sample21' do
94
94
  end
95
95
 
96
96
  begin
97
- # Check required variables
97
+ #Check required variables
98
98
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.email.empty? or settings.name.empty? or settings.lastName.empty?
99
99
 
100
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
100
+ #Prepare base path
101
+ if settings.base_path.empty?
102
+ base_path = 'https://api.groupdocs.com'
103
+ elsif settings.base_path.match('/v2.0')
104
+ base_path = settings.base_path.split('/v2.0')[0]
105
+ else
106
+ base_path = settings.base_path
107
+ end
101
108
 
102
- # Configure your access to API server
109
+ #Configure your access to API server
103
110
  GroupDocs.configure do |groupdocs|
104
111
  groupdocs.client_id = settings.client_id
105
112
  groupdocs.private_key = settings.private_key
106
- # Optionally specify API server and version
107
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
113
+ #Optionally specify API server and version
114
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
108
115
  end
109
116
 
110
- # Write client and private key to the file for callback job
117
+ #Write client and private key to the file for callback job
111
118
  if settings.callback
112
119
  out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
113
- # white space is required
120
+ #White space is required
114
121
  out_file.write("#{settings.client_id} ")
115
122
  out_file.write("#{settings.private_key}")
116
123
  out_file.close
117
124
  end
118
125
 
119
126
  file = nil
120
- # get document by file GUID
127
+ #Get document by file GUID
121
128
  case settings.source
122
129
  when 'guid'
123
- # Create instance of File
130
+ #Create instance of File
124
131
  file = GroupDocs::Storage::File.new({:guid => settings.fileId}).to_document.metadata!()
125
132
  file = file.last_view.document.file.to_document
126
133
  when 'local'
127
- # construct path
134
+ #Construct path
128
135
  file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
129
- # open file
136
+
137
+ #Open file
130
138
  File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
131
- # make a request to API using client_id and private_key
139
+ #Make a request to API using client_id and private_key
132
140
  file = GroupDocs::Storage::File.upload!(file_path, {}).to_document
133
141
  when 'url'
134
- # Upload file from defined url
142
+ #Upload file from defined url
135
143
  file = GroupDocs::Storage::File.upload_web!(settings.url).to_document
136
144
  else
137
145
  raise 'Wrong GUID source.'
138
146
  end
139
147
 
140
148
  name = file.name
141
- # create envelope using user id and entered by user name
149
+ #Create envelope using user id and entered by user name
142
150
  envelope = GroupDocs::Signature::Envelope.new
143
151
  envelope.name = file.name
144
152
  envelope.email_subject = 'Sing this!'
145
153
  envelope.create!({})
146
154
 
147
- # Add uploaded document to envelope
155
+ #Add uploaded document to envelope
148
156
  envelope.add_document!(file, {})
149
157
 
150
- # Get role list for current user
158
+ #Get role list for current user
151
159
  roles = GroupDocs::Signature::Role.get!({})
152
160
 
153
- # Create new recipient
161
+ #Create new recipient
154
162
  recipient = GroupDocs::Signature::Recipient.new
155
163
  recipient.email = settings.email
156
164
  recipient.first_name = settings.name
157
165
  recipient.last_name = settings.lastName
158
166
  recipient.role_id = roles.detect { |role| role.name == 'Signer' }.id
159
167
 
160
- # Add recipient to envelope
161
- add = envelope.add_recipient!(recipient)
168
+ #Add recipient to envelope
169
+ recipient = envelope.add_recipient!(recipient)
162
170
 
163
- # Get recipient id
164
- recipient.id = add[:recipient][:id]
165
171
 
166
- # Get document id
172
+ #Get document id
167
173
  document = envelope.documents!({})
168
174
 
169
175
 
170
- # Get field and add the location to field
176
+ #Get field and add the location to field
171
177
  field = GroupDocs::Signature::Field.get!({}).detect { |f| f.type == :signature }
172
178
  field.location = {:location_x => 0.15, :location_y => 0.73, :location_w => 150, :location_h => 50, :page => 1}
173
179
  field.name = 'EMPLOYEE SIGNATURE'
174
180
 
175
- # Add field to envelope
181
+ #Add field to envelope
176
182
  envelope.add_field!(field, document[0], recipient, {})
177
183
 
178
184
 
179
- # Send envelop
185
+ #Send envelop
180
186
  envelope.send!({:callbackUrl => settings.callback})
181
187
 
182
- #Get url from request
183
- case settings.base_path
184
-
188
+ #Prepare to sign url
189
+ iframe = "/signature2/signembed/#{envelope.id}/#{recipient.id}"
190
+ #Construct result string
191
+ url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
192
+ #Generate iframe URL
193
+ case base_path
185
194
  when 'https://stage-api-groupdocs.dynabic.com'
186
- url = "http://stage-apps-groupdocs.dynabic.com/signature/signembed/#{envelope.id}/#{recipient.id}"
195
+ iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
187
196
  when 'https://dev-api-groupdocs.dynabic.com'
188
- url = "http://dev-apps-groupdocs.dynabic.com/signature/signembed/#{envelope.id}/#{recipient.id}"
197
+ iframe = "https://dev-apps.groupdocs.com#{url}"
189
198
  else
190
- url = "https://apps.groupdocs.com/signature/signembed/#{envelope.id}/#{recipient.id}"
199
+ iframe = "https://apps.groupdocs.com#{url}"
191
200
  end
192
201
 
193
-
194
- iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
195
- # Make iframe
196
- iframe = "<iframe src='#{iframe}' frameborder='0' width='720' height='600'></iframe>"
202
+ #Make iframe
203
+ iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
204
+ #Create message
197
205
  message = "<p>File was uploaded to GroupDocs. Here you can see your <strong>#{name}</strong> file in the GroupDocs Embedded Viewer.</p>"
198
206
  rescue Exception => e
199
207
  err = e.message
200
208
  end
201
209
 
202
- # Set variables for template
210
+ #Set variables for template
203
211
  haml :sample21, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :email => settings.email, :name => settings.name, :lastName => settings.lastName, :iframe => iframe, :massage => message, :err => err, :callback => settings.callback,}
204
212
  end