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,33 +1,40 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample07' do
3
3
  haml :sample07
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample07' do
8
- # Set variables
8
+ #Set variables
9
9
  set :client_id, params[:clientId]
10
10
  set :private_key, params[:privateKey]
11
11
  set :base_path, params[:basePath]
12
12
 
13
13
  begin
14
- # Check required variables
14
+ #Check required variables
15
15
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
16
16
 
17
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
17
+ #Prepare base path
18
+ if settings.base_path.empty?
19
+ base_path = 'https://api.groupdocs.com'
20
+ elsif settings.base_path.match('/v2.0')
21
+ base_path = settings.base_path.split('/v2.0')[0]
22
+ else
23
+ base_path = settings.base_path
24
+ end
18
25
 
19
- # Configure your access to API server
26
+ #Configure your access to API server
20
27
  GroupDocs.configure do |groupdocs|
21
28
  groupdocs.client_id = settings.client_id
22
29
  groupdocs.private_key = settings.private_key
23
- # Optionally specify API server and version
24
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
30
+ #Optionally specify API server and version
31
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
25
32
  end
26
33
 
27
- # Make a request to API using client_id and private_key
34
+ #Make a request to API using client_id and private_key
28
35
  files_list = GroupDocs::Storage::Folder.list!('/', {:extended => true}, {:client_id => settings.client_id, :private_key => settings.private_key})
29
36
 
30
- # Construct result string
37
+ #Construct result string
31
38
  thumbnails = ''
32
39
  files_list.each do |element|
33
40
  if element.class.name.split('::').last == 'Folder'
@@ -35,7 +42,7 @@ post '/sample07' do
35
42
  end
36
43
  if element.thumbnail
37
44
  name = element.name
38
- thumbnails += "<p><img src='data:image/png;base64,#{element.thumbnail}', width='40px', height='40px'> #{name}</p>"
45
+ thumbnails += "<img src='data:image/png;base64,#{element.thumbnail}', width='40px', height='40px'> #{name}"
39
46
  end
40
47
  end
41
48
 
@@ -47,6 +54,6 @@ post '/sample07' do
47
54
  err = e.message
48
55
  end
49
56
 
50
- # Set variables for template
57
+ #Set variables for template
51
58
  haml :sample07, :locals => {:clientId => settings.client_id, :privateKey => settings.private_key, :thumbnailList => thumbnails, :err => err}
52
59
  end
@@ -1,11 +1,11 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample08' do
3
3
  haml :sample08
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample08' do
8
- # Set variables
8
+ #Set variables
9
9
  set :client_id, params[:clientId]
10
10
  set :private_key, params[:privateKey]
11
11
  set :guid, params[:guid]
@@ -15,33 +15,40 @@ post '/sample08' do
15
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.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
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
22
29
 
23
- # Configure your access to API server
30
+ #Configure your access to API server
24
31
  GroupDocs.configure do |groupdocs|
25
32
  groupdocs.client_id = settings.client_id
26
33
  groupdocs.private_key = settings.private_key
27
- # Optionally specify API server and version
28
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
34
+ #Optionally specify API server and version
35
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
29
36
  end
30
37
 
31
38
  file = nil
32
39
  doc = nil
33
40
  metadata = nil
34
41
 
35
- # Get document by file GUID
42
+ #Get document by file GUID
36
43
  case settings.source
37
44
  when 'guid'
38
45
  file = GroupDocs::Storage::File.new({:guid => settings.file_id})
39
46
  when 'local'
40
- # Construct path
47
+ #Construct path
41
48
  filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
42
- # Open file
49
+ #Open file
43
50
  File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
44
- # Make a request to API using client_id and private_key
51
+ #Make a request to API using client_id and private_key
45
52
  file = GroupDocs::Storage::File.upload!(filepath, {})
46
53
  when 'url'
47
54
  file = GroupDocs::Storage::File.upload_web!(settings.url)
@@ -52,10 +59,10 @@ post '/sample08' do
52
59
  doc = file.to_document
53
60
  metadata = doc.metadata!()
54
61
 
55
- # Get document page images
62
+ #Get document page images
56
63
  images = doc.page_images!(800, 400, {:first_page => 0, :page_count => metadata.views_count})
57
64
 
58
- # Result
65
+ #Result
59
66
  unless images.empty?
60
67
  image = images[Integer(settings.page_number)]
61
68
  end
@@ -64,6 +71,6 @@ post '/sample08' do
64
71
  err = e.message
65
72
  end
66
73
 
67
- # Set variables for template
74
+ #Set variables for template
68
75
  haml :sample08, :locals => {:clientId => settings.client_id, :privateKey => settings.private_key, :guid => settings.guid, :pageNumber => settings.page_number, :image => image, :err => err}
69
76
  end
@@ -1,9 +1,9 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample09' do
3
3
  haml :sample09
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample09' do
8
8
  # Set variables
9
9
  set :file_id, params[:fileId]
@@ -17,30 +17,37 @@ post '/sample09' do
17
17
  set :base_path, params[:basePath]
18
18
 
19
19
  begin
20
- # Check required variables
20
+ #Check required variables
21
21
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.width.empty? or settings.height.empty?
22
22
 
23
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
23
+ #Prepare base path
24
+ if settings.base_path.empty?
25
+ base_path = 'https://api.groupdocs.com'
26
+ elsif settings.base_path.match('/v2.0')
27
+ base_path = settings.base_path.split('/v2.0')[0]
28
+ else
29
+ base_path = settings.base_path
30
+ end
24
31
 
25
- # Configure your access to API server
32
+ #Configure your access to API server
26
33
  GroupDocs.configure do |groupdocs|
27
34
  groupdocs.client_id = settings.client_id
28
35
  groupdocs.private_key = settings.private_key
29
- # Optionally specify API server and version
30
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
36
+ #Optionally specify API server and version
37
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
31
38
  end
32
39
 
33
- # Get document by file GUID
40
+ #Get document by file GUID
34
41
  file = nil
35
42
  case settings.source
36
43
  when 'guid'
37
44
  file = GroupDocs::Storage::File.new({:guid => settings.file_id})
38
45
  when 'local'
39
- # Construct path
46
+ #Construct path
40
47
  filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
41
- # Open file
48
+ #Open file
42
49
  File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
43
- # Make a request to API using client_id and private_key
50
+ #Make a request to API using client_id and private_key
44
51
  file = GroupDocs::Storage::File.upload!(filepath, {})
45
52
  when 'url'
46
53
  file = GroupDocs::Storage::File.upload_web!(settings.url)
@@ -51,33 +58,28 @@ post '/sample09' do
51
58
 
52
59
  case settings.check
53
60
  when 'viewer'
54
- case settings.base_path
55
- when 'https://stage-api-groupdocs.dynabic.com'
56
- url = "http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{file.guid}?frameborder='0' width='#{settings.width}' height='#{settings.height}'"
57
- when 'https://dev-api-groupdocs.dynabic.com'
58
- url = "http://dev-apps-groupdocs.dynabic.com/document-viewer/embed/#{file.guid}?frameborder='0' width='#{settings.width}' height='#{settings.height}'"
59
- else
60
- url = "https://apps.groupdocs.com/document-viewer/embed/#{file.guid}?frameborder='0' width='#{settings.width}' height='#{settings.height}'"
61
- end
62
-
61
+ #Prepare to sign url
62
+ iframe = "/document-viewer/embed/#{file.guid}?frameborder='0' width='#{settings.width}' height='#{settings.height}'"
63
63
  when 'annotation'
64
- case settings.base_path
64
+ #Prepare to sign url
65
+ iframe = "/document-annotation2/embed/#{file.guid}?frameborder='0' width='#{settings.width}' height='#{settings.height}'"
66
+ end
67
+ #Sign url
68
+ url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
69
+ #Generate iframe URL
70
+ case settings.base_path
65
71
  when 'https://stage-api-groupdocs.dynabic.com'
66
- url = "http://stage-apps-groupdocs.dynabic.com/document-annotation2/embed/#{file.guid}?frameborder='0' width='#{settings.width}' height='#{settings.height}'"
72
+ iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
67
73
  when 'https://dev-api-groupdocs.dynabic.com'
68
- url = "http://dev-apps-groupdocs.dynabic.com/document-annotation2/embed/#{file.guid}?frameborder='0' width='#{settings.width}' height='#{settings.height}'"
74
+ iframe = "https://dev-apps.groupdocs.com#{url}"
69
75
  else
70
- url = "https://apps.groupdocs.com/document-annotation2/embed/#{file.guid}?frameborder='0' width='#{settings.width}' height='#{settings.height}'"
71
- end
76
+ iframe = "https://apps.groupdocs.com#{url}"
72
77
  end
73
78
 
74
- # Construct result string
75
- url = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
76
-
77
79
  rescue Exception => e
78
80
  err = e.message
79
81
  end
80
82
 
81
83
  # Set variables for template
82
- haml :sample09, :locals => {:guid => file.guid, :width => settings.width, :height => settings.height, :v_url => url, :err => err}
84
+ haml :sample09, :locals => {:guid => file.guid, :width => settings.width, :height => settings.height, :v_url => iframe, :err => err}
83
85
  end
@@ -1,11 +1,11 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample10' do
3
3
  haml :sample10
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample10' do
8
- # Set variables
8
+ #Set variables
9
9
  set :client_id, params[:clientId]
10
10
  set :private_key, params[:privateKey]
11
11
  set :guid, params[:fileId]
@@ -14,32 +14,39 @@ post '/sample10' 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.guid.empty? or settings.email.empty?
19
19
 
20
20
 
21
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
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
22
29
 
23
- # Configure your access to API server
30
+ #Configure your access to API server
24
31
  GroupDocs.configure do |groupdocs|
25
32
  groupdocs.client_id = settings.client_id
26
33
  groupdocs.private_key = settings.private_key
27
- # Optionally specify API server and version
28
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
34
+ #Optionally specify API server and version
35
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
29
36
  end
30
37
 
31
- # Get document by file GUID
38
+ #Get document by file GUID
32
39
  file = nil
33
40
  case settings.source
34
41
  when 'guid'
35
42
  file = GroupDocs::Storage::File.new({:guid => settings.guid}).to_document.metadata!()
36
43
  file = file.last_view.document.file
37
44
  when 'local'
38
- # Construct path
45
+ #Construct path
39
46
  filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
40
- # Open file
47
+ #Open file
41
48
  File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
42
- # Make a request to API using client_id and private_key
49
+ #Make a request to API using client_id and private_key
43
50
  file = GroupDocs::Storage::File.upload!(filepath, {})
44
51
  when 'url'
45
52
  file = GroupDocs::Storage::File.upload_web!(settings.url)
@@ -47,10 +54,10 @@ post '/sample10' do
47
54
  raise 'Wrong GUID source.'
48
55
  end
49
56
 
50
- # Share document. Make a request to API using client_id and private_key
57
+ #Share document. Make a request to API using client_id and private_key
51
58
  shared = file.to_document.sharers_set!(settings.email.split(' '))
52
59
 
53
- # Result
60
+ #Result
54
61
  if shared
55
62
  shared_emails = settings.email
56
63
  end
@@ -58,6 +65,6 @@ post '/sample10' do
58
65
  err = e.message
59
66
  end
60
67
 
61
- # Set variables for template
68
+ #Set variables for template
62
69
  haml :sample10, :locals => {:clientId => settings.client_id, :privateKey => settings.private_key, :guid => settings.guid, :email => settings.email, :shared => shared_emails, :err => err}
63
70
  end
@@ -1,11 +1,11 @@
1
- # GET request
1
+ #GET request
2
2
  get '/sample11' do
3
3
  haml :sample11
4
4
  end
5
5
 
6
- # POST request
6
+ #POST request
7
7
  post '/sample11' 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]
@@ -15,17 +15,24 @@ post '/sample11' do
15
15
 
16
16
  begin
17
17
 
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? or settings.file_id.empty? or settings.annotation_type.empty?
20
20
 
21
- if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
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
22
29
 
23
- # Configure your access to API server
30
+ #Configure your access to API server
24
31
  GroupDocs.configure do |groupdocs|
25
32
  groupdocs.client_id = settings.client_id
26
33
  groupdocs.private_key = settings.private_key
27
- # Optionally specify API server and version
28
- groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
34
+ #Optionally specify API server and version
35
+ groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
29
36
  end
30
37
 
31
38
  if settings.annotation_id != ''
@@ -33,92 +40,82 @@ post '/sample11' do
33
40
  file = GroupDocs::Storage::File.new({:guid => settings.file_id}).to_document
34
41
  annotation = file.annotations!()
35
42
 
36
- # Remove annotation from document
43
+ #Remove annotation from document
37
44
  remove = annotation.last.remove!()
38
45
  message = "You delete the annotation id = #{remove[:guid]} "
39
46
  else
40
- # Annotation types
41
- types = {:text => "0", :area => "1", :point => "2"}
42
-
43
-
44
- # Required parameters
45
- all_params = all_params = ['annotationType', 'boxX', 'boxY', 'text']
46
-
47
- # Added required parameters depends on annotation type ['text' or 'area']
48
- if settings.annotation_type == 'text'
49
- all_params = all_params | ['boxWidth', 'boxHeight', 'annotationPositionX', 'annotationPositionY', 'rangePosition', 'rangeLength']
50
- elsif settings.annotation_type == 'area'
51
- all_params = all_params | ['boxWidth', 'boxHeight']
52
- end
53
-
54
- # Checking required parameters
55
- all_params.each do |param|
56
- raise 'Please enter all required parameters' if params[param].empty?
57
- end
58
-
59
- # Make a request to API using client_id and private_key
60
- files_list = GroupDocs::Storage::Folder.list!('/', {})
61
-
62
- document = ''
47
+ #Annotation types
48
+ types = {:text => "0", :area => "1", :point => "2"}
63
49
 
64
- # Get document by file ID
65
- files_list.each do |element|
66
- if element.respond_to?('guid') == true and element.guid == settings.file_id
67
- document = element
68
- end
69
- end
70
-
71
- unless document.instance_of? String
72
50
 
73
- # Start create new annotation
74
- annotation = GroupDocs::Document::Annotation.new(document: document.to_document)
51
+ #Required parameters
52
+ all_params = all_params = ['annotationType', 'boxX', 'boxY', 'text']
75
53
 
76
-
77
- info = nil
78
- # Construct requestBody depends on annotation type
79
- # Text annotation
54
+ #Added required parameters depends on annotation type ['text' or 'area']
80
55
  if settings.annotation_type == 'text'
81
- annotation.box = GroupDocs::Document::Rectangle.new ({x: params['boxX'], y: params['boxY'], width: params['boxWidth'], height: params['boxHeight']})
82
- annotation.annotationPosition = {x: params['annotationPositionX'], y: params['annotationPositionY']}
83
- range = {position: params['rangePosition'], length: params['rangeLength']}
84
- info = {:box => annotation_box, :annotationPosition => annotation_annotationPosition, :range => range, :type => types[settings.annotation_type.to_sym], :replies => [{:text => params['text']}]}
85
- # Area annotation
56
+ all_params = all_params | ['boxWidth', 'boxHeight', 'annotationPositionX', 'annotationPositionY', 'rangePosition', 'rangeLength']
86
57
  elsif settings.annotation_type == 'area'
87
- annotation_box = {x: params['boxX'], y: params['boxY'], width: params['boxWidth'], height: params['boxHeight']}
88
- annotation_annotationPosition = {x: 0, y: 0}
89
- info = {:box => annotation_box, :annotationPosition => annotation_annotationPosition, :type => types[settings.annotation_type.to_sym], :replies => [{:text => params['text']}]}
90
- # Point annotation
91
- elsif settings.annotation_type == 'point'
92
- annotation_box = {x: params['boxX'], y: params['boxY'], width: 0, height: 0}
93
- annotation_annotationPosition = {x: 0, y: 0}
94
-
95
- info = {:box => annotation_box, :annotationPosition => annotation_annotationPosition, :type => types[settings.annotation_type.to_sym], :replies => [{:text => params['text']}] }
58
+ all_params = all_params | ['boxWidth', 'boxHeight']
96
59
  end
97
60
 
98
-
99
- # Call create method
100
- annotation.create!(info)
101
- id = annotation.document.file.id
102
- # Get document guid
103
- guid = annotation.document.file.guid
104
-
105
- case settings.base_path
106
-
107
- when 'https://stage-api-groupdocs.dynabic.com'
108
- url = "http://stage-apps-groupdocs.dynabic.com/document-annotation2/embed/#{guid}"
109
- when 'https://dev-api-groupdocs.dynabic.com'
110
- url = "http://dev-apps-groupdocs.dynabic.com/document-annotation2/embed/#{guid}"
111
- else
112
- url = "http://apps.groupdocs.com/document-annotation2/embed/#{guid}"
61
+ #Checking required parameters
62
+ all_params.each do |param|
63
+ raise 'Please enter all required parameters' if params[param].empty?
113
64
  end
114
65
 
115
- #Add the signature in url
116
- url = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
117
- # Set iframe with document GUID
118
- iframe = "<iframe src='#{url}' frameborder='0' width='720' height='600'></iframe>"
119
-
120
- end
66
+ #Create document object
67
+ document = GroupDocs::Storage::File.new(guid: settings.file_id).to_document
68
+
69
+ unless document.instance_of? String
70
+
71
+ #Start create new annotation
72
+ annotation = GroupDocs::Document::Annotation.new(document: document)
73
+
74
+ info = nil
75
+ #Construct requestBody depends on annotation type
76
+ #Text annotation
77
+ if settings.annotation_type == 'text'
78
+ annotation.box = GroupDocs::Document::Rectangle.new ({x: params['boxX'], y: params['boxY'], width: params['boxWidth'], height: params['boxHeight']})
79
+ annotation.annotationPosition = {x: params['annotationPositionX'], y: params['annotationPositionY']}
80
+ range = {position: params['rangePosition'], length: params['rangeLength']}
81
+ info = {:box => annotation_box, :annotationPosition => annotation_annotationPosition, :range => range, :type => types[settings.annotation_type.to_sym], :replies => [{:text => params['text']}]}
82
+ #Area annotation
83
+ elsif settings.annotation_type == 'area'
84
+ annotation_box = {x: params['boxX'], y: params['boxY'], width: params['boxWidth'], height: params['boxHeight']}
85
+ annotation_annotationPosition = {x: 0, y: 0}
86
+ info = {:box => annotation_box, :annotationPosition => annotation_annotationPosition, :type => types[settings.annotation_type.to_sym], :replies => [{:text => params['text']}]}
87
+ #Point annotation
88
+ elsif settings.annotation_type == 'point'
89
+ annotation_box = {x: params['boxX'], y: params['boxY'], width: 0, height: 0}
90
+ annotation_annotationPosition = {x: 0, y: 0}
91
+
92
+ info = {:box => annotation_box, :annotationPosition => annotation_annotationPosition, :type => types[settings.annotation_type.to_sym], :replies => [{:text => params['text']}] }
93
+ end
94
+
95
+ #Call create method
96
+ annotation.create!(info)
97
+ id = annotation.document.file.id
98
+ #Get document guid
99
+ guid = annotation.document.file.guid
100
+
101
+ #Prepare to sign url
102
+ iframe = "/document-annotation2/embed/#{guid}"
103
+ #Construct result string
104
+ url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
105
+ #Generate iframe URL
106
+ case base_path
107
+ when 'https://stage-api-groupdocs.dynabic.com'
108
+ iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
109
+ when 'https://dev-api-groupdocs.dynabic.com'
110
+ iframe = "https://dev-apps.groupdocs.com#{url}"
111
+ else
112
+ iframe = "https://apps.groupdocs.com#{url}"
113
+ end
114
+
115
+ #Make iframe
116
+ iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
121
117
 
118
+ end
122
119
  end
123
120
 
124
121
  rescue Exception => e