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,32 +1,39 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample26' do
3
3
  haml :sample26
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample26' do
8
8
  set :email, params[:login]
9
9
  set :password, params[:password]
10
10
  set :base_path, params[:basePath]
11
11
 
12
12
  begin
13
- # Check required variables
13
+ #Check required variables
14
14
  raise 'Please enter all required parameters' if settings.email.empty? or settings.password.empty?
15
15
 
16
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
16
+ #Prepare base path
17
+ if settings.base_path.empty?
18
+ base_path = 'https://api.groupdocs.com'
19
+ elsif settings.base_path.match('/v2.0')
20
+ base_path = settings.base_path.split('/v2.0')[0]
21
+ else
22
+ base_path = settings.base_path
23
+ end
17
24
 
18
- # Configure your access to API server
25
+ #Configure your access to API server
19
26
  GroupDocs.configure do |groupdocs|
20
- # Optionally specify API server and version
21
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
27
+ #Optionally specify API server and version
28
+ groupdocs.api_server = base_path #Default is 'https://api.groupdocs.com'
22
29
  end
23
- # Make a request to API using email and password
30
+ #Make a request to API using email and password
24
31
  user = GroupDocs::User.login!(settings.email, settings.password)
25
32
 
26
33
  rescue Exception => e
27
34
  err = e.message
28
35
  end
29
36
 
30
- # Set variables for template
37
+ #Set variables for template
31
38
  haml :sample26, :locals => {:user => user, :err => err}
32
39
  end
@@ -1,11 +1,11 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample27' do
3
3
  haml :sample27
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample27' do
8
- # Set variables
8
+ #Set variables
9
9
  set :client_id, params[:clientId]
10
10
  set :private_key, params[:privateKey]
11
11
  set :file_id, params[:fileId]
@@ -17,10 +17,10 @@ post '/sample27' do
17
17
  set :type, params[:type]
18
18
  set :base_path, params[:basePath]
19
19
 
20
- # Set download path
20
+ #Set download path
21
21
  downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
22
22
 
23
- # Remove all files from download directory or create folder if it not there
23
+ #Remove all files from download directory or create folder if it not there
24
24
  if File.directory?(downloads_path)
25
25
  Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
26
26
  else
@@ -28,28 +28,35 @@ post '/sample27' do
28
28
  end
29
29
 
30
30
  begin
31
- # Check required variables
31
+ #Check required variables
32
32
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
33
33
 
34
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
34
+ #Prepare base path
35
+ if settings.base_path.empty?
36
+ base_path = 'https://api.groupdocs.com'
37
+ elsif settings.base_path.match('/v2.0')
38
+ base_path = settings.base_path.split('/v2.0')[0]
39
+ else
40
+ base_path = settings.base_path
41
+ end
35
42
 
36
- # Configure your access to API server
43
+ #Configure your access to API server
37
44
  GroupDocs.configure do |groupdocs|
38
45
  groupdocs.client_id = settings.client_id
39
46
  groupdocs.private_key = settings.private_key
40
- # Optionally specify API server and version
41
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
47
+ #Optionally specify API server and version
48
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
42
49
  end
43
50
 
44
- # Get document by file GUID
51
+ #Get document by file GUID
45
52
  case settings.source
46
53
  when 'guid'
47
- # Create instance of File
54
+ #Create instance of File
48
55
  file = GroupDocs::Storage::File.new({:guid => settings.file_id})
49
56
  when 'local'
50
- # Construct path
57
+ #Construct path
51
58
  file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
52
- # Open file
59
+ #Open file
53
60
  File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
54
61
  # Make a request to API using client_id and private_key
55
62
  file = GroupDocs::Storage::File.upload!(file_path, {})
@@ -60,59 +67,59 @@ post '/sample27' do
60
67
  raise 'Wrong GUID source.'
61
68
  end
62
69
 
63
- # Raise exception if something went wrong
70
+ #Raise exception if something went wrong
64
71
  raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
65
72
 
66
- # Make GroupDocs::Storage::Document instance
73
+ #Make GroupDocs::Storage::Document instance
67
74
  document = file.to_document
68
75
 
69
- # Create datasource with fields
76
+ #Create datasource with fields
70
77
  datasource = GroupDocs::DataSource.new
71
78
 
72
- # Get arry of document's fields
79
+ #Get arry of document's fields
73
80
  enteredData = {"sex" => settings.sex, "name" => settings.name, "age"=> settings.age, "sunrise" => settings.sunrise}
74
81
 
75
- # Create Field instance and fill the fields
82
+ #Create Field instance and fill the fields
76
83
  datasource.fields = enteredData.map { |key, value| GroupDocs::DataSource::Field.new(name: key, type: :text, values: Array.new() << value) }
77
84
 
78
85
 
79
- # Adds datasource.
86
+ #Adds datasource.
80
87
  datasource.add!()
81
88
 
82
- # Creates new job to merge datasource into document.
89
+ #Creates new job to merge datasource into document.
83
90
  job = document.datasource!(datasource, {:new_type => settings.type})
84
- sleep 10 # wait for merge and convert
91
+ sleep 10 #Wait for merge and convert
85
92
 
86
- # Returns an hash of input and output documents associated to job.
93
+ #Returns an hash of input and output documents associated to job.
87
94
  document = job.documents!()
88
95
 
89
- # Download file
96
+ #Download file
90
97
  document[:inputs][0].outputs[0].download!(downloads_path)
91
98
 
92
- # Set converted document GUID
99
+ #Set converted document GUID
93
100
  guid = document[:inputs][0].outputs[0].guid
94
101
 
95
- # Set converted document Name
102
+ #Set converted document Name
96
103
  file_name = document[:inputs][0].outputs[0].name
97
104
 
98
- #Get url from request
99
- case settings.base_path
100
-
105
+ #Prepare to sign url
106
+ iframe = "/document-viewer/embed/#{guid}"
107
+ # Construct result string
108
+ url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
109
+ #Generate iframe URL
110
+ case base_path
101
111
  when 'https://stage-api-groupdocs.dynabic.com'
102
- url = "http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{guid}"
112
+ iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
103
113
  when 'https://dev-api-groupdocs.dynabic.com'
104
- url = "http://dev-apps-groupdocs.dynabic.com/document-viewer/embed/#{guid}"
114
+ iframe = "https://dev-apps.groupdocs.com#{url}"
105
115
  else
106
- url = "https://apps.groupdocs.com/document-viewer/embed/#{guid}"
116
+ iframe = "https://apps.groupdocs.com#{url}"
107
117
  end
108
118
 
109
- # Add the signature to url the request
110
-
111
- iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
112
-
113
- # Set iframe with document GUID or raise an error
119
+ #Set iframe with document GUID or raise an error
114
120
  if guid
115
- iframe = "<iframe width='100%' height='600' frameborder='0' src='#{iframe}'></iframe>"
121
+ #Make iframe
122
+ iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
116
123
  else
117
124
  raise 'File was not converted'
118
125
  end
@@ -121,6 +128,6 @@ post '/sample27' do
121
128
  err = e.message
122
129
  end
123
130
 
124
- # Set variables for template
131
+ #Set variables for template
125
132
  haml :sample27, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :sex => settings.sex, :age => settings.age, :sunrise => settings.sunrise, :name => settings.name, :type => settings.type, :iframe => iframe, :file_name => file_name, :err => err}
126
133
  end
@@ -1,52 +1,61 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample28' do
3
3
  haml :sample28
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample28' do
8
- # set variables
8
+ #Set variables
9
9
  set :client_id, params[:clientId]
10
10
  set :private_key, params[:privateKey]
11
11
  set :file_id, params[:fileId]
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? or settings.file_id.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
- # make a request to API using client_id and private_key
35
+ #Make a request to API using client_id and private_key
29
36
  files_list = GroupDocs::Storage::Folder.list!('/', {})
30
37
  document = ''
31
38
 
32
- # get document by file ID
39
+ #Get document by file ID
33
40
  files_list.each do |element|
34
41
  if element.respond_to?('guid') == true and element.guid == settings.file_id
35
42
  document = element
36
43
  end
37
44
  end
38
45
 
46
+ document = GroupDocs::Storage::File.new(guid: settings.file_id)
39
47
 
40
48
  unless document.instance_of? String
41
- # get list of annotations
49
+ #Get list of annotations
42
50
  annotations = document.to_document.annotations!()
43
51
 
44
- # delete all annotations from document
52
+ #Delete all annotations from document
45
53
  annotations.each do |annotation|
46
54
  annotation.remove!()
47
55
  end
48
56
  case settings.base_path
49
57
 
58
+ <<<<<<< HEAD
50
59
  when 'https://stage-api-groupdocs.dynabic.com'
51
60
  iframe = "<iframe width='100%' height='600' frameborder='0' src='http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{settings.file_id}'></iframe>"
52
61
  when 'https://dev-api-groupdocs.dynabic.com'
@@ -54,6 +63,24 @@ post '/sample28' do
54
63
  else
55
64
  iframe = "<iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/document-viewer/embed/#{settings.file_id}'></iframe>"
56
65
  end
66
+ =======
67
+ #Prepare to sign url
68
+ iframe = "/document-viewer/embed/#{settings.file_id}"
69
+ # Construct result string
70
+ url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
71
+ #Generate iframe URL
72
+ case base_path
73
+ when 'https://stage-api-groupdocs.dynabic.com'
74
+ iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
75
+ when 'https://dev-api-groupdocs.dynabic.com'
76
+ iframe = "https://dev-apps.groupdocs.com#{url}"
77
+ else
78
+ iframe = "https://apps.groupdocs.com#{url}"
79
+ end
80
+ #Make iframe
81
+ iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
82
+
83
+ >>>>>>> samples-dev
57
84
  message = 'Annotations was deleted from document'
58
85
  end
59
86
 
@@ -61,6 +88,10 @@ post '/sample28' do
61
88
  err = e.message
62
89
  end
63
90
 
91
+ <<<<<<< HEAD
64
92
  # set variables for template
93
+ =======
94
+ #Set variables for template
95
+ >>>>>>> samples-dev
65
96
  haml :sample28, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :messages => message, :iframe => iframe, :fileId => settings.file_id, :err => err}
66
97
  end
@@ -1,11 +1,12 @@
1
+ #GET request
1
2
  get '/sample29' do
2
3
  haml :sample29
3
4
  end
4
5
 
5
- # POST request
6
+ #POST request
6
7
  post '/sample29' do
7
8
 
8
- # set variables
9
+ #Set variables
9
10
  set :client_id, params[:clientId]
10
11
  set :base_path, params[:serverType]
11
12
  set :url, params[:url]
@@ -16,24 +17,28 @@ post '/sample29' do
16
17
 
17
18
  begin
18
19
 
19
- #If base base is empty seting base path to prod server
20
- base_path = 'https://api.groupdocs.com/v2.0' unless !base_path.empty?
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
+ end
21
26
 
22
27
  #Generate iframe url for chosen server
23
28
  if (!url.empty?)
24
29
 
25
30
  if (base_path == "https://api.groupdocs.com/v2.0")
26
- iframe = "https://apps.groupdocs.com/document-viewer/embed?url=#{url} &user_id=#{client_id}"
31
+ iframe = "https://apps.groupdocs.com/document-viewer/embed?url=#{url}&user_id=#{client_id}"
27
32
  elsif (base_path == "https://dev-api.groupdocs.com/v2.0")
28
33
 
29
34
  #iframe to dev server
30
- iframe = "https://dev-apps.groupdocs.com/document-viewer/embed?url=#{url} &user_id=#{client_id}"
35
+ iframe = "https://dev-apps.groupdocs.com/document-viewer/embed?url=#{url}&user_id=#{client_id}"
31
36
  elsif (base_path == "https://stage-api.groupdocs.com/v2.0")
32
37
 
33
38
  #iframe to test server
34
- iframe = "https://stage-apps.groupdocs.com/document-viewer/embed?url=#{url} &user_id=#{client_id}"
39
+ iframe = "https://stage-apps.groupdocs.com/document-viewer/embed?url=#{url}&user_id=#{client_id}"
35
40
  elsif (base_path == "http://realtime-api.groupdocs.com")
36
- iframe = "http://realtime-apps.groupdocs.com/document-viewer/embed?url=#{url} &user_id=#{client_id}"
41
+ iframe = "http://realtime-apps.groupdocs.com/document-viewer/embed?url=#{url}&user_id=#{client_id}"
37
42
  end
38
43
 
39
44
 
@@ -1,35 +1,42 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample30' do
3
3
  haml :sample30
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample30' do
8
- # Set variables
8
+ #Set variables
9
9
  set :client_id, params[:clientId]
10
10
  set :private_key, params[:privateKey]
11
11
  set :name, params[:fileName]
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? or settings.name.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
- # Optionally specify API server and version
25
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
31
+ #Optionally specify API server and version
32
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
26
33
  end
27
34
 
28
- # Make a request to API using client_id and private_key
35
+ #Make a request to API using client_id and private_key
29
36
  files_list = GroupDocs::Storage::Folder.list!('/', {})
30
37
  document = ''
31
38
 
32
- # Get document by file ID
39
+ #Get document by file ID
33
40
  files_list.each do |element|
34
41
  if element.respond_to?('name') == true and element.name == settings.name
35
42
  document = element
@@ -37,7 +44,7 @@ post '/sample30' do
37
44
  end
38
45
 
39
46
 
40
- # Delete file from GroupDocs Storage
47
+ #Delete file from GroupDocs Storage
41
48
  document.delete!()
42
49
 
43
50
  message = 'Done, file deleted from your GroupDocs Storage'
@@ -46,6 +53,6 @@ post '/sample30' do
46
53
  err = e.message
47
54
  end
48
55
 
49
- # Set variables for template
56
+ #Set variables for template
50
57
  haml :sample30, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :message => message, :name => settings.name, :err => err}
51
58
  end
@@ -1,14 +1,14 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample31' do
3
3
  haml :sample31
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample31/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 '/sample31/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 '/sample31/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
@@ -46,15 +46,15 @@ post '/sample31/callback' do
46
46
  end
47
47
 
48
48
 
49
- # GET request
49
+ #GET request
50
50
  get '/sample31/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,16 +63,16 @@ get '/sample31/check' do
63
63
  name
64
64
  end
65
65
 
66
- # GET request
66
+ #GET request
67
67
  get '/sample31/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
72
 
73
- # POST request
73
+ #POST request
74
74
  post '/sample31' do
75
- # set variables
75
+ #Set variables
76
76
  set :client_id, params[:clientId]
77
77
  set :private_key, params[:privateKey]
78
78
  set :template_guid, params[:templateGuid]
@@ -96,112 +96,116 @@ post '/sample31' do
96
96
  end
97
97
 
98
98
  begin
99
- # check required variables
99
+ #Check required variables
100
100
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
101
101
 
102
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
102
+ #Prepare base path
103
+ if settings.base_path.empty?
104
+ base_path = 'https://api.groupdocs.com'
105
+ elsif settings.base_path.match('/v2.0')
106
+ base_path = settings.base_path.split('/v2.0')[0]
107
+ else
108
+ base_path = settings.base_path
109
+ end
103
110
 
104
- # Configure your access to API server
111
+ #Configure your access to API server
105
112
  GroupDocs.configure do |groupdocs|
106
113
  groupdocs.client_id = settings.client_id
107
114
  groupdocs.private_key = settings.private_key
108
- # Optionally specify API server and version
109
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
115
+ #Optionally specify API server and version
116
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
110
117
  end
111
118
 
112
- # Write client and private key to the file for callback job
119
+ #Write client and private key to the file for callback job
113
120
  if settings.callback[0]
114
121
  out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
115
- # white space is required
122
+ #White space is required
116
123
  out_file.write("#{settings.client_id} ")
117
124
  out_file.write("#{settings.private_key}")
118
125
  out_file.close
119
126
  end
120
- if settings.last_name.empty?
121
- settings.last_name = 'test'
122
- end
127
+
123
128
  file = nil
124
- # Create instance of File
129
+ #Create instance of File
125
130
  file = GroupDocs::Storage::File.new({:guid => settings.template_guid})
126
- # Raise exception if something went wrong
131
+ #Raise exception if something went wrong
127
132
  raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
128
133
 
129
- # Make GroupDocs::Storage::Document instance
134
+ #Make GroupDocs::Storage::Document instance
130
135
  document = file.to_document
131
136
 
132
- # Create datasource with fields
137
+ #Create datasource with fields
133
138
  datasource = GroupDocs::DataSource.new
134
139
 
135
- # Get arry of document's fields
136
- enteredData = {"email" => settings.email, "name" => settings.name, "last_name" => settings.last_name, "country"=> settings.country, "city" => settings.city, "street" => settings.street}
140
+ #Get arry of document's fields
141
+ enteredData = {"email" => settings.email, "name" => settings.name, "country"=> settings.country, "city" => settings.city, "street" => settings.street}
137
142
 
138
143
 
139
- # Create Field instance and fill the fields
144
+ #Create Field instance and fill the fields
140
145
  datasource.fields = enteredData.map { |key, value| GroupDocs::DataSource::Field.new(name: key, type: :text, values: Array.new() << value) }
141
146
 
142
- # Adds datasource.
147
+ #Adds datasource.
143
148
  datasource.add!()
144
149
 
145
150
 
146
- # Creates new job to merge datasource into document.
151
+ #Creates new job to merge datasource into document.
147
152
  job = document.datasource!(datasource, {:new_type => "pdf"})
148
153
  sleep 10 # wait for merge and convert
149
154
 
150
- # Returns an hash of input and output documents associated to job.
155
+ #Returns an hash of input and output documents associated to job.
151
156
  jobInfo = job.documents!()
152
157
 
153
- # Creates new document to envelope
158
+ #Creates new document to envelope
154
159
  document = jobInfo[:inputs][0].outputs[0].to_document
155
160
 
156
- # Creates envelope using user id and entered by user name
161
+ #Creates envelope using user id and entered by user name
157
162
  envelope = GroupDocs::Signature::Envelope.new
158
163
  envelope.name = jobInfo[:inputs][0].outputs[0].name
159
164
  envelope.create!({})
160
165
 
161
- # Adds uploaded document to envelope
162
- envelope.add_document!(document, {})
166
+ #Adds uploaded document to envelope
167
+ envelope.add_document!(document, {parseFields: true})
163
168
 
164
- # Get role list for current user
169
+ #Get role list for current user
165
170
  roles = GroupDocs::Signature::Role.get!({})
166
171
 
167
- # Creates new recipient
172
+ #Creates new recipient
168
173
  recipient = GroupDocs::Signature::Recipient.new
169
174
  recipient.email = settings.email
170
175
  recipient.first_name = settings.name
171
- recipient.last_name = settings.last_name
176
+ recipient.last_name = "lastName"
172
177
  recipient.role_id = roles.detect { |role| role.name == 'Signer' }.id
173
178
 
174
- # Adds recipient to envelope
179
+ #Adds recipient to envelope
175
180
  envelope.add_recipient!(recipient)
176
181
  #Get recipients
177
182
  recipientGet = envelope.recipients!({}).first
178
183
 
179
- # Send envelope
184
+ #Send envelope
180
185
  envelope.send!({:callbackUrl => settings.callback})
181
186
 
182
- #Get url from request
183
- case settings.base_path
184
-
187
+ #Prepare to sign url
188
+ iframe = "/signature2/signembed/#{envelope.id}/#{recipientGet.id}"
189
+ # Construct result string
190
+ url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
191
+ #Generate iframe URL
192
+ case base_path
185
193
  when 'https://stage-api-groupdocs.dynabic.com'
186
- url = "http://stage-apps-groupdocs.dynabic.com/signature2/signembed/#{envelope.id}/#{recipientGet.id}"
194
+ iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
187
195
  when 'https://dev-api-groupdocs.dynabic.com'
188
- url = "http://dev-apps-groupdocs.dynabic.com/signature2/signembed/#{envelope.id}/#{recipientGet.id}"
196
+ iframe = "https://dev-apps.groupdocs.com#{url}"
189
197
  else
190
- url = "https://apps.groupdocs.com/signature2/signembed/#{envelope.id}/#{recipientGet.id}"
198
+ iframe = "https://apps.groupdocs.com#{url}"
191
199
  end
192
200
 
193
- # Add the signature in url
194
- iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
195
-
196
- # Make iframe
197
- iframe = "<iframe src='#{iframe}' frameborder='0' width='720' height='600'></iframe>"
198
-
201
+ #Make iframe
202
+ iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
199
203
 
200
204
  rescue Exception => e
201
205
  err = e.message
202
206
  end
203
207
 
204
- # set variables for template
208
+ #Set variables for template
205
209
  haml :sample31, :locals => {:userId => settings.client_id,
206
210
  :privateKey => settings.private_key,
207
211
  :callback => settings.callback,
@@ -211,5 +215,6 @@ post '/sample31' do
211
215
  :city => settings.city,
212
216
  :street => settings.street,
213
217
  :iframe => iframe,
218
+ :templateGuid => settings.template_guid,
214
219
  :err => err}
215
220
  end