groupdocs 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/CHANGELOG.md +51 -0
  2. data/examples/api-samples/Gemfile +1 -1
  3. data/examples/api-samples/Gemfile.lock +43 -0
  4. data/examples/api-samples/public/docs/{sample2.html → sample01.html} +39 -19
  5. data/examples/api-samples/public/docs/{sample3.html → sample02.html} +28 -22
  6. data/examples/api-samples/public/docs/sample03.html +285 -0
  7. data/examples/api-samples/public/docs/{sample4.html → sample04.html} +30 -36
  8. data/examples/api-samples/public/docs/{sample5.html → sample05.html} +68 -31
  9. data/examples/api-samples/public/docs/sample06.html +299 -0
  10. data/examples/api-samples/public/docs/{sample7.html → sample07.html} +53 -18
  11. data/examples/api-samples/public/docs/{sample8.html → sample08.html} +64 -41
  12. data/examples/api-samples/public/docs/sample09.html +260 -0
  13. data/examples/api-samples/public/docs/sample10.html +67 -28
  14. data/examples/api-samples/public/docs/sample11.html +171 -55
  15. data/examples/api-samples/public/docs/sample12.html +53 -17
  16. data/examples/api-samples/public/docs/sample13.html +52 -16
  17. data/examples/api-samples/public/docs/sample14.html +51 -8
  18. data/examples/api-samples/public/docs/sample15.html +46 -10
  19. data/examples/api-samples/public/docs/sample16.html +81 -7
  20. data/examples/api-samples/public/docs/sample17.html +103 -15
  21. data/examples/api-samples/public/docs/sample18.html +117 -41
  22. data/examples/api-samples/public/docs/sample19.html +410 -36
  23. data/examples/api-samples/public/docs/sample20.html +46 -10
  24. data/examples/api-samples/public/docs/sample21.html +504 -45
  25. data/examples/api-samples/public/docs/sample22.html +166 -28
  26. data/examples/api-samples/public/docs/sample23.html +61 -25
  27. data/examples/api-samples/public/docs/sample24.html +100 -12
  28. data/examples/api-samples/public/docs/sample25.html +123 -49
  29. data/examples/api-samples/public/docs/sample26.html +41 -8
  30. data/examples/api-samples/public/docs/sample27.html +125 -50
  31. data/examples/api-samples/public/docs/sample28.html +27 -9
  32. data/examples/api-samples/public/docs/sample29.html +10 -10
  33. data/examples/api-samples/public/docs/sample30.html +70 -14
  34. data/examples/api-samples/public/docs/sample31.html +108 -67
  35. data/examples/api-samples/public/docs/sample32.html +71 -99
  36. data/examples/api-samples/public/docs/sample33.html +107 -32
  37. data/examples/api-samples/public/docs/{sample1.html → sample34.html} +58 -18
  38. data/examples/api-samples/public/docs/sample35.html +666 -0
  39. data/examples/api-samples/public/docs/{sample6.html → sample36.html} +56 -37
  40. data/examples/api-samples/public/docs/sample37.html +815 -0
  41. data/examples/api-samples/public/docs/sample38.html +508 -0
  42. data/examples/api-samples/public/docs/sample39.html +921 -0
  43. data/examples/api-samples/public/docs/sample40.html +510 -0
  44. data/examples/api-samples/public/docs/sample41.html +452 -0
  45. data/examples/api-samples/public/docs/sample42.html +311 -0
  46. data/examples/api-samples/public/templates/test_all_fields2.pdf +0 -0
  47. data/examples/api-samples/samples/sample01.rb +37 -0
  48. data/examples/api-samples/samples/sample02.rb +41 -0
  49. data/examples/api-samples/samples/sample03.rb +73 -0
  50. data/examples/api-samples/samples/sample04.rb +47 -0
  51. data/examples/api-samples/samples/{sample5.rb → sample05.rb} +26 -14
  52. data/examples/api-samples/samples/sample06.rb +80 -0
  53. data/examples/api-samples/samples/sample07.rb +52 -0
  54. data/examples/api-samples/samples/sample08.rb +69 -0
  55. data/examples/api-samples/samples/sample09.rb +83 -0
  56. data/examples/api-samples/samples/sample10.rb +29 -15
  57. data/examples/api-samples/samples/sample11.rb +89 -37
  58. data/examples/api-samples/samples/sample12.rb +22 -11
  59. data/examples/api-samples/samples/sample13.rb +22 -10
  60. data/examples/api-samples/samples/sample14.rb +23 -5
  61. data/examples/api-samples/samples/sample15.rb +18 -7
  62. data/examples/api-samples/samples/sample16.rb +28 -4
  63. data/examples/api-samples/samples/sample17.rb +31 -5
  64. data/examples/api-samples/samples/sample18.rb +36 -8
  65. data/examples/api-samples/samples/sample19.rb +138 -18
  66. data/examples/api-samples/samples/sample20.rb +14 -3
  67. data/examples/api-samples/samples/sample21.rb +162 -23
  68. data/examples/api-samples/samples/sample22.rb +73 -22
  69. data/examples/api-samples/samples/sample23.rb +17 -6
  70. data/examples/api-samples/samples/sample24.rb +34 -7
  71. data/examples/api-samples/samples/sample25.rb +37 -12
  72. data/examples/api-samples/samples/sample26.rb +12 -5
  73. data/examples/api-samples/samples/sample27.rb +38 -12
  74. data/examples/api-samples/samples/sample28.rb +25 -6
  75. data/examples/api-samples/samples/sample29.rb +12 -12
  76. data/examples/api-samples/samples/sample30.rb +27 -15
  77. data/examples/api-samples/samples/sample31.rb +44 -33
  78. data/examples/api-samples/samples/sample32.rb +43 -41
  79. data/examples/api-samples/samples/sample33.rb +42 -14
  80. data/examples/api-samples/samples/sample34.rb +40 -0
  81. data/examples/api-samples/samples/sample35.rb +224 -0
  82. data/examples/api-samples/samples/sample36.rb +58 -0
  83. data/examples/api-samples/samples/sample37.rb +229 -0
  84. data/examples/api-samples/samples/sample38.rb +128 -0
  85. data/examples/api-samples/samples/sample39.rb +252 -0
  86. data/examples/api-samples/samples/sample40.rb +164 -0
  87. data/examples/api-samples/samples/sample41.rb +118 -0
  88. data/examples/api-samples/samples/sample42.rb +97 -0
  89. data/examples/api-samples/views/_others_samples.haml +25 -11
  90. data/examples/api-samples/views/index.haml +23 -11
  91. data/examples/api-samples/views/popup.haml +32 -0
  92. data/examples/api-samples/views/{sample1.haml → sample01.haml} +12 -7
  93. data/examples/api-samples/views/{sample2.haml → sample02.haml} +20 -15
  94. data/examples/api-samples/views/sample03.haml +83 -0
  95. data/examples/api-samples/views/sample04.haml +49 -0
  96. data/examples/api-samples/views/{sample5.haml → sample05.haml} +19 -14
  97. data/examples/api-samples/views/sample06.haml +53 -0
  98. data/examples/api-samples/views/sample07.haml +47 -0
  99. data/examples/api-samples/views/{sample8.haml → sample08.haml} +17 -12
  100. data/examples/api-samples/views/{sample9.haml → sample09.haml} +19 -4
  101. data/examples/api-samples/views/sample10.haml +18 -13
  102. data/examples/api-samples/views/sample11.haml +48 -19
  103. data/examples/api-samples/views/sample12.haml +26 -21
  104. data/examples/api-samples/views/sample13.haml +18 -12
  105. data/examples/api-samples/views/sample14.haml +21 -15
  106. data/examples/api-samples/views/sample15.haml +16 -9
  107. data/examples/api-samples/views/sample16.haml +18 -5
  108. data/examples/api-samples/views/sample17.haml +14 -9
  109. data/examples/api-samples/views/sample18.haml +13 -7
  110. data/examples/api-samples/views/sample19.haml +37 -8
  111. data/examples/api-samples/views/sample20.haml +13 -8
  112. data/examples/api-samples/views/sample21.haml +71 -13
  113. data/examples/api-samples/views/sample22.haml +53 -16
  114. data/examples/api-samples/views/sample23.haml +9 -4
  115. data/examples/api-samples/views/sample24.haml +9 -4
  116. data/examples/api-samples/views/sample25.haml +18 -13
  117. data/examples/api-samples/views/sample26.haml +8 -3
  118. data/examples/api-samples/views/sample27.haml +20 -14
  119. data/examples/api-samples/views/sample28.haml +16 -10
  120. data/examples/api-samples/views/sample29.haml +4 -4
  121. data/examples/api-samples/views/sample30.haml +16 -10
  122. data/examples/api-samples/views/sample31.haml +39 -32
  123. data/examples/api-samples/views/sample32.haml +25 -36
  124. data/examples/api-samples/views/sample33.haml +14 -17
  125. data/examples/api-samples/views/sample34.haml +48 -0
  126. data/examples/api-samples/views/sample35.haml +95 -0
  127. data/examples/api-samples/views/sample36.haml +64 -0
  128. data/examples/api-samples/views/sample37.haml +124 -0
  129. data/examples/api-samples/views/sample38.haml +115 -0
  130. data/examples/api-samples/views/sample39.haml +236 -0
  131. data/examples/api-samples/views/sample40.haml +95 -0
  132. data/examples/api-samples/views/{sample4.haml → sample41.haml} +90 -72
  133. data/examples/api-samples/views/sample42.haml +59 -0
  134. data/lib/groupdocs/api/helpers/rest_helper.rb +13 -1
  135. data/lib/groupdocs/datasource.rb +2 -1
  136. data/lib/groupdocs/document.rb +101 -13
  137. data/lib/groupdocs/document/annotation.rb +28 -13
  138. data/lib/groupdocs/document/annotation/marker.rb +18 -0
  139. data/lib/groupdocs/document/annotation/reply.rb +9 -2
  140. data/lib/groupdocs/document/field.rb +5 -1
  141. data/lib/groupdocs/job.rb +12 -2
  142. data/lib/groupdocs/questionnaire.rb +174 -4
  143. data/lib/groupdocs/questionnaire/collector.rb +21 -0
  144. data/lib/groupdocs/questionnaire/question.rb +19 -0
  145. data/lib/groupdocs/questionnaire/question/answer.rb +5 -0
  146. data/lib/groupdocs/questionnaire/question/conditions.rb +20 -0
  147. data/lib/groupdocs/signature.rb +36 -308
  148. data/lib/groupdocs/signature/envelope.rb +146 -4
  149. data/lib/groupdocs/signature/field.rb +20 -1
  150. data/lib/groupdocs/signature/field/location.rb +18 -7
  151. data/lib/groupdocs/signature/form.rb +199 -10
  152. data/lib/groupdocs/signature/shared/document_methods.rb +38 -0
  153. data/lib/groupdocs/signature/shared/entity_methods.rb +0 -1
  154. data/lib/groupdocs/signature/shared/field_methods.rb +13 -38
  155. data/lib/groupdocs/signature/shared/recipient_methods.rb +8 -0
  156. data/lib/groupdocs/signature/template.rb +3 -1
  157. data/lib/groupdocs/storage.rb +4 -1
  158. data/lib/groupdocs/storage/file.rb +18 -1
  159. data/lib/groupdocs/subscription.rb +8 -3
  160. data/lib/groupdocs/user.rb +8 -0
  161. data/lib/groupdocs/version.rb +1 -1
  162. data/spec/groupdocs/document/annotation_spec.rb +1 -14
  163. data/spec/groupdocs/subscription_spec.rb +2 -2
  164. metadata +86 -32
  165. checksums.yaml +0 -15
  166. data/examples/api-samples/public/docs/sample9.html +0 -200
  167. data/examples/api-samples/samples/sample1.rb +0 -25
  168. data/examples/api-samples/samples/sample2.rb +0 -29
  169. data/examples/api-samples/samples/sample3.rb +0 -33
  170. data/examples/api-samples/samples/sample4.rb +0 -51
  171. data/examples/api-samples/samples/sample6.rb +0 -49
  172. data/examples/api-samples/samples/sample7.rb +0 -42
  173. data/examples/api-samples/samples/sample8.rb +0 -61
  174. data/examples/api-samples/samples/sample9.rb +0 -48
  175. data/examples/api-samples/views/sample3.haml +0 -44
  176. data/examples/api-samples/views/sample6.haml +0 -49
  177. data/examples/api-samples/views/sample7.haml +0 -42
@@ -29,14 +29,14 @@ post '/sample32/callback' do
29
29
  contents = contents.split(' ')
30
30
  client_id = contents[0]
31
31
  private_key = contents[1]
32
- subscriber_email = contens[2]
32
+ subscriber_email = contents[2]
33
33
  end
34
34
 
35
35
  # Create new Form
36
36
  form = GroupDocs::Signature::Form.new({:id => source_id})
37
37
 
38
38
  # Get document by Form id
39
- document = form.documents!({}, {:client_id => client_id, :private_key => private_key})
39
+ document = form.documents!({:client_id => client_id, :private_key => private_key})
40
40
 
41
41
  # An adress recipient
42
42
  to = subscriber_email
@@ -67,94 +67,96 @@ post '/sample32/callback' do
67
67
  end
68
68
 
69
69
 
70
- # GET request
71
- get '/sample32/check' do
72
70
 
73
- # Check is there download directory
74
- unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
75
- return 'Directory was not found.'
76
- end
77
71
 
78
- # Get file name from download directory
79
- name = nil
80
- Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
81
- name = file if file != '.' && file != '..'
82
- end
83
-
84
- name
85
- end
86
72
 
87
73
 
88
74
 
89
75
  # POST request
90
76
  post '/sample32' do
91
77
  # set variables
92
- set :client_id, params[:client_id]
93
- set :private_key, params[:private_key]
94
- set :template_guid, params[:template]
95
- set :form_guid, params[:form]
78
+ set :client_id, params[:clientId]
79
+ set :private_key, params[:privateKey]
80
+ set :template_guid, params[:templateGuid]
81
+ set :form_guid, params[:formGuid]
96
82
  set :email, params[:email]
97
- set :callback, params[:callback]
83
+ set :callback, params[:callbackUrl]
98
84
  set :source, params[:source]
99
-
100
- # Set download path
101
- downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
102
-
103
- # Remove all files from download directory or create folder if it not there
104
- if File.directory?(downloads_path)
105
- Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
106
- else
107
- Dir::mkdir(downloads_path)
108
- end
85
+ set :base_path, params[:basePath]
109
86
 
110
87
  begin
111
88
 
112
89
  # Check required variables
113
90
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
114
91
 
115
- # Configure your access to API server.
92
+ if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
93
+
94
+ # Configure your access to API server
116
95
  GroupDocs.configure do |groupdocs|
117
96
  groupdocs.client_id = settings.client_id
118
97
  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'
119
100
  end
120
101
 
121
102
  # Write client and private key to the file for callback job
122
- if settings.callback[0]
103
+ if settings.callback
123
104
  out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
124
105
  # white space is required
125
106
  out_file.write("#{settings.client_id} ")
126
- out_file.write("#{settings.private_key}")
107
+ out_file.write("#{settings.private_key} ")
127
108
  out_file.write("#{settings.email}")
128
109
  out_file.close
129
110
  end
130
111
 
131
- iframe = ''
112
+ guid = nil
113
+ url = nil
132
114
 
133
115
  case settings.source
134
116
  when 'form'
117
+ id = settings.form_guid
135
118
  # Create new Form with guid
136
- form = GroupDocs::Signature::Form.new({:guid => settings.form_guid})
119
+ form = GroupDocs::Signature::Form.new
120
+ form.name = 'test'
121
+ form.notifyOwnerOnSign = true
122
+
123
+ # Create new Form with template
124
+ id = form.create!({:formId => guid})
125
+ form = GroupDocs::Signature::Form.get!(id)
137
126
 
138
127
  # Publish the Form
139
128
  form.publish!({:callbackUrl => settings.callback})
129
+ guid = settings.form_guid
140
130
 
141
- iframe = "https://apps.groupdocs.com/signature2/forms/signembed/ #{settings.form_guid}";
142
131
  when 'template'
143
132
 
144
133
  form = GroupDocs::Signature::Form.new
145
134
  form.name = 'test'
146
135
  form.notifyOwnerOnSign = true
147
136
 
148
-
149
- # Create new Form with template
150
- signature = form.create!({ :templateId => settings.template_guid})
137
+ # Create new Form with template
138
+ guid = form.create!({ :templateId => settings.template_guid})
151
139
 
152
140
  # Publish the Form
153
141
  form.publish!({:callbackUrl => settings.callback})
154
142
 
155
- iframe = "<iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/signature2/forms/signembed/ #{signature}'></iframe>"
156
143
  end
157
144
 
145
+ #Get url from request
146
+ case settings.base_path
147
+
148
+ when 'https://stage-api-groupdocs.dynabic.com'
149
+ url = "http://stage-apps-groupdocs.dynabic.com/signature2/forms/signembed/ #{guid}"
150
+ when 'https://dev-api-groupdocs.dynabic.com'
151
+ url = "http://dev-apps-groupdocs.dynabic.com/signature2/forms/signembed/ #{guid}"
152
+ else
153
+ url = "https://apps.groupdocs.com/signature2/forms/signembed/ #{guid}"
154
+ end
155
+
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>"
159
+
158
160
  rescue Exception => e
159
161
  err = e.message
160
162
  end
@@ -6,31 +6,36 @@ end
6
6
  # POST request
7
7
  post '/sample33' do
8
8
  # set variables
9
- set :client_id, params[:client_id]
10
- set :private_key, params[:private_key]
11
- set :url_1, params[:url_1]
12
- set :url_2, params[:url_2]
13
- set :url_3, params[:url_3]
14
- set :url_4, params[:url_4]
15
- set :url_5, params[:url_5]
9
+ set :client_id, params[:clientId]
10
+ set :private_key, params[:privateKey]
11
+ set :url_1, params[:url1]
12
+ set :url_2, params[:url2]
13
+ set :url_3, params[:url3]
14
+ set :base_path, params[:basePath]
16
15
 
17
16
  begin
18
17
  # Check required variables
19
- 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? or settings.url_4.empty? or settings.url_5.empty?
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?
20
19
 
20
+ if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
21
+
22
+ # Configure your access to API server
21
23
  GroupDocs.configure do |groupdocs|
22
24
  groupdocs.client_id = settings.client_id
23
25
  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'
24
28
  end
25
29
 
30
+
26
31
  # Create Array from variables
27
- url = [settings.url_1, settings.url_2, settings.url_3, settings.url_4, settings.url_5 ]
32
+ url = [settings.url_1, settings.url_2, settings.url_3 ]
28
33
 
29
34
  # Create Hash with the options for job. :status=> -1 means the Draft status of the job
30
35
  options = {:actions => [:convert, :combine], :out_formats => ['pdf'], :status => -1, :name => 'sample'}
31
36
 
32
37
  # Create Job with provided options with Draft status (Sheduled job)
33
- job = GroupDocs::Job.create!(options, {:client_id => client_id, :private_key => private_key})
38
+ job = GroupDocs::Job.create!(options)
34
39
 
35
40
  # Upload documents to GroupDocs Storage by url and add the documents to previously created Job
36
41
  url.each do |url|
@@ -39,16 +44,39 @@ post '/sample33' do
39
44
  end
40
45
 
41
46
  # Update the Job with new status. :status => '0' mean Active status of the job (Start the job)
42
- job.update!({:status => '0'})
43
- sleep(5)
47
+ id = job.update!({:status => '0'})
48
+
49
+ i = 1
50
+
51
+ while i<5 do
52
+ sleep(5)
53
+ job = GroupDocs::Job.get!(id[:job_id])
54
+ break if job.status == :archived
55
+ i = i + 1
56
+ end
57
+
44
58
  # Get the document into Pdf format
45
59
  file = job.documents!()
46
- sleep(7)
60
+
47
61
  document = file[:outputs]
48
62
 
49
63
  # Set iframe with document GUID or raise an error
50
64
  if document
51
- iframe = "<iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/document-viewer/embed/#{document[0].guid}'></iframe>"
65
+
66
+ #Get url from request
67
+ case settings.base_path
68
+
69
+ when 'https://stage-api-groupdocs.dynabic.com'
70
+ url = "http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{document[0].guid}"
71
+ when 'https://dev-api-groupdocs.dynabic.com'
72
+ url = "http://dev-apps-groupdocs.dynabic.com/document-viewer/embed/#{document[0].guid}"
73
+ else
74
+ url = "https://apps.groupdocs.com/document-viewer/embed/#{document[0].guid}"
75
+ end
76
+
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>"
52
80
  else
53
81
  raise 'File was not converted'
54
82
  end
@@ -0,0 +1,40 @@
1
+ # GET request
2
+ get '/sample34' do
3
+ haml :sample34
4
+ end
5
+
6
+ # POST request
7
+ post '/sample34' do
8
+ # Set variables
9
+ set :client_id, params[:clientId]
10
+ set :private_key, params[:privateKey]
11
+ set :path, params[:folder]
12
+ set :base_path, params[:basePath]
13
+
14
+ begin
15
+ # Check required variables
16
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
17
+
18
+ if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
19
+
20
+ # Configure your access to API server
21
+ GroupDocs.configure do |groupdocs|
22
+ groupdocs.client_id = settings.client_id
23
+ 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'
26
+ end
27
+
28
+ # Create new Folder
29
+ folder = GroupDocs::Storage::Folder.create!(settings.path)
30
+ if folder.id
31
+ message = "<span style=\"color:green\">Folder was created #{folder.path} </span> "
32
+ end
33
+
34
+ rescue Exception => e
35
+ err = e.message
36
+ end
37
+
38
+ # set variables for template
39
+ haml :sample34, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :message => message, :err => err}
40
+ end
@@ -0,0 +1,224 @@
1
+ # GET request
2
+ get '/sample35' do
3
+ haml :sample35
4
+ end
5
+
6
+
7
+ # POST request
8
+ post '/sample35' do
9
+ # Set variables
10
+ set :client_id, params[:clientId]
11
+ set :private_key, params[:privateKey]
12
+ set :source, params[:source]
13
+ set :file_id, params[:fileId]
14
+ set :url, params[:url]
15
+ set :path, params[:basePath]
16
+
17
+ begin
18
+ # Check required variables
19
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
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/, '')
24
+
25
+ # Configure your access to API server.
26
+ GroupDocs.configure do |groupdocs|
27
+ groupdocs.client_id = settings.client_id
28
+ 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
31
+
32
+ end
33
+
34
+
35
+ # Get document by file GUID
36
+ case settings.source
37
+ when 'guid'
38
+ # Create instance of File
39
+ file = GroupDocs::Storage::File.new({:guid => settings.file_id})
40
+ when 'local'
41
+ # Construct path
42
+ file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
43
+ # Open file
44
+ File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
45
+ # Make a request to API using client_id and private_key
46
+ file = GroupDocs::Storage::File.upload!(file_path, {})
47
+ when 'url'
48
+ # Upload file from defined url
49
+ file = GroupDocs::Storage::File.upload_web!(settings.url)
50
+ else
51
+ raise 'Wrong GUID source.'
52
+ end
53
+
54
+ # Raise exception if something went wrong
55
+ raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
56
+
57
+
58
+ # Make GroupDocs::Storage::Document instance
59
+ document = file.to_document
60
+ # Get array of document's fields
61
+ fields = document.fields!
62
+
63
+ # Create the fields for form
64
+ html = ''
65
+ fields.map do |e|
66
+
67
+ case e.type
68
+ when 'Text'
69
+ signature = "<br/><label for='#{e.name}'>#{e.name} #{e.mandatory == false ? '<span class="optional">(Optional)</span>' : '<span class="optional">(Required)</span>'}</label><br/><input type='text' name='#{e.name}'></input><br/><br/>"
70
+ html << signature
71
+ when 'RadioButton'
72
+ i = 0
73
+ html.scan(e.name).empty? ? '' : i += 1
74
+ radio = "<br/><label for='#{e.name}'>#{e.name} #{e.mandatory == false ? '<span class="optional">(Optional)</span>' : '<span class="optional">(Required)</span>'}</label><br/><input type='radio' name='#{e.name}' value='#{i}' ></input><br/><br/>"
75
+ html << radio
76
+ when 'Checkbox'
77
+ checkbox = "<br/><label for='#{e.name}'>#{e.name} #{e.mandatory == false ? '<span class="optional">(Optional)</span>' : '<span class="optional">(Required)</span>'}</label><br/><input type='checkbox' name='#{e.name}' ></input><br/><br/>"
78
+ html << checkbox
79
+ when 'Combobox'
80
+ combobox = "<br/><label for='#{e.name}'>#{e.name} #{e.mandatory == false ? '<span class="optional">(Optional)</span>' : '<span class="optional">(Required)</span>'}</label><br/><select name='#{e.name}'>"
81
+ e.acceptableValues.each { |e| combobox << "<option name='#{e}'>#{e}</option>"}
82
+ combobox << "</select><br/><br/>"
83
+ html << combobox
84
+ when 'Listbox'
85
+ listbox = "<br/><label for='#{e.name}'>#{e.name} #{e.mandatory == false ? '<span class="optional">(Optional)</span>' : '<span class="optional">(Required)</span>'}</label><br/><select multiple name='#{e.name}[]'>"
86
+ e.acceptableValues.each { |e| listbox << "<option name='#{e}'>#{e}</option>"}
87
+ listbox << "</select><br/><br/>"
88
+ html << listbox
89
+ end
90
+
91
+ end
92
+
93
+
94
+ rescue Exception => e
95
+ err = e.message
96
+ end
97
+
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}
100
+ end
101
+
102
+ # GET request
103
+ get '/sample35/check' do
104
+ haml :sample35
105
+ end
106
+
107
+ # POST request
108
+ post '/sample35/check' do
109
+ set :client_id, params[:clientId]
110
+ set :private_key, params[:privateKey]
111
+ set :path, params[:basePath]
112
+ set :file_id, params[:fileId]
113
+
114
+ begin
115
+
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
+
121
+ # Get document by file GUID
122
+ GroupDocs.configure do |groupdocs|
123
+ groupdocs.client_id = settings.client_id
124
+ 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'
128
+ end
129
+
130
+
131
+ #TODO:
132
+ #Merge template PDF FIle with the data provided via dynamically created HTML form.
133
+
134
+ # Create instance of File
135
+ document = GroupDocs::Storage::File.new({:guid => settings.file_id}).to_document
136
+
137
+ # Create datasource with fields
138
+ datasource = GroupDocs::DataSource.new
139
+
140
+ # Get array of document's fields
141
+ fields = document.fields!()
142
+
143
+ # Get unique fields
144
+ fields = fields.uniq{ |f| f.name }
145
+
146
+ datasource.fields = []
147
+
148
+ # Create Field instance and fill the fields
149
+ fields.each do |field|
150
+ if field.type == 'Text'
151
+ datasource.fields << GroupDocs::DataSource::Field.new(name: field.name, type: :text, values: [params[field.name.to_sym]])
152
+ end
153
+
154
+ if field.type == "RadioButton" && params[field.name.to_sym]
155
+ datasource.fields << GroupDocs::DataSource::Field.new(name: field.name, type: 'integer', values: [params[field.name.to_sym]])
156
+
157
+ end
158
+
159
+ if field.type == "Checkbox" && params[field.name.to_sym] == 'on'
160
+ datasource.fields << GroupDocs::DataSource::Field.new(name: field.name, type: 'boolean', values: [true])
161
+ end
162
+
163
+ if field.type == "Combobox" && params[field.name.to_sym]
164
+ i = 0
165
+ value = nil
166
+ field.acceptableValues.each do |e|
167
+ e == params[field.name] ? value = i : ''
168
+ i += 1
169
+ end
170
+
171
+ datasource.fields << GroupDocs::DataSource::Field.new(name: field.name, type: 'integer', values: [value])
172
+ end
173
+
174
+ if field.type == "Listbox" && params[field.name.to_sym]
175
+ i = 0
176
+ value = nil
177
+ field.acceptableValues.each do |e|
178
+ e == params[field.name] ? value = i : ''
179
+ i += 1
180
+ end
181
+ datasource.fields << GroupDocs::DataSource::Field.new(name: field.name, type: 'integer', values: [value])
182
+
183
+ end
184
+
185
+ end
186
+
187
+ # Adds datasource.
188
+ datasource.add!()
189
+
190
+ # Creates new job to merge datasource into document.
191
+ job = document.datasource!(datasource, {:new_type => 'pdf'})
192
+
193
+ i = 0
194
+ # Checks status of Job.
195
+ while i<5 do
196
+ sleep(5)
197
+ job_status = GroupDocs::Job.get!(job.id)
198
+ break if job_status.status == :archived
199
+ i += 1
200
+ end
201
+
202
+ # Returns an hash of input and output documents associated to job.
203
+ document = job.documents!()
204
+
205
+ # Set converted document GUID
206
+ guid = document[:inputs][0].outputs[0].guid
207
+
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>"
216
+ end
217
+
218
+
219
+ rescue Exception => e
220
+ err = e.message
221
+ end
222
+
223
+ haml :sample35, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :iframe => iframe, :err => err}
224
+ end