groupdocs 1.3.0 → 1.4.0

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 (40) hide show
  1. data/.travis.yml +4 -0
  2. data/CHANGELOG.md +32 -0
  3. data/examples/api-samples/public/css/style.css +123 -67
  4. data/examples/api-samples/public/images/help.png +0 -0
  5. data/examples/api-samples/public/images/info.png +0 -0
  6. data/examples/api-samples/public/templates/base-simple_source.html +192 -0
  7. data/examples/api-samples/public/templates/testdocument.html +101 -0
  8. data/examples/api-samples/public/templates/welcome.htm +137 -0
  9. data/examples/api-samples/samples/sample18.rb +134 -31
  10. data/examples/api-samples/views/sample18.haml +127 -9
  11. data/lib/groupdocs/api/request.rb +1 -1
  12. data/lib/groupdocs/document.rb +6 -3
  13. data/lib/groupdocs/signature.rb +6 -0
  14. data/lib/groupdocs/signature/contact.rb +42 -0
  15. data/lib/groupdocs/signature/envelope.rb +71 -0
  16. data/lib/groupdocs/signature/field.rb +21 -2
  17. data/lib/groupdocs/signature/form.rb +162 -9
  18. data/lib/groupdocs/signature/role.rb +5 -31
  19. data/lib/groupdocs/signature/shared/document_methods.rb +2 -1
  20. data/lib/groupdocs/signature/shared/entity_fields.rb +6 -16
  21. data/lib/groupdocs/signature/shared/entity_methods.rb +2 -2
  22. data/lib/groupdocs/signature/shared/field_methods.rb +56 -2
  23. data/lib/groupdocs/storage.rb +1 -0
  24. data/lib/groupdocs/storage/provider.rb +32 -0
  25. data/lib/groupdocs/user.rb +66 -0
  26. data/lib/groupdocs/version.rb +1 -1
  27. data/spec/groupdocs/signature/contact_spec.rb +21 -0
  28. data/spec/groupdocs/signature/envelope_spec.rb +53 -1
  29. data/spec/groupdocs/signature/field_spec.rb +19 -1
  30. data/spec/groupdocs/signature/form_spec.rb +47 -11
  31. data/spec/groupdocs/signature/role_spec.rb +4 -47
  32. data/spec/groupdocs/signature_spec.rb +4 -0
  33. data/spec/groupdocs/storage/provider_spec.rb +22 -0
  34. data/spec/groupdocs/user_spec.rb +54 -0
  35. data/spec/support/json/user_embed_key.json +39 -0
  36. data/spec/support/json/user_providers.json +31 -0
  37. data/spec/support/json/user_roles.json +25 -0
  38. data/spec/support/shared_examples/signature/shared/entity_fields.rb +14 -26
  39. data/spec/support/shared_examples/signature/shared/field_methods.rb +58 -34
  40. metadata +18 -4
@@ -44,37 +44,11 @@ module GroupDocs
44
44
  alias_accessor :can_annotate, :canAnnotate
45
45
  alias_accessor :can_delegate, :canDelegate
46
46
 
47
- #
48
- # Returns true if role can edit.
49
- # @return [Boolean]
50
- #
51
- def can_edit?
52
- can_edit == 1
53
- end
54
-
55
- #
56
- # Returns true if role can sign.
57
- # @return [Boolean]
58
- #
59
- def can_sign?
60
- can_sign == 1
61
- end
62
-
63
- #
64
- # Returns true if role can annotate.
65
- # @return [Boolean]
66
- #
67
- def can_annotate?
68
- can_annotate == 1
69
- end
70
-
71
- #
72
- # Returns true if role can delegate.
73
- # @return [Boolean]
74
- #
75
- def can_delegate?
76
- can_delegate == 1
77
- end
47
+ # Boolean methods for Ruby DSL
48
+ alias_method :can_edit?, :can_edit
49
+ alias_method :can_sign?, :can_sign
50
+ alias_method :can_annotate?, :can_annotate
51
+ alias_method :can_delegate?, :can_delegate
78
52
 
79
53
  end # Signature::Role
80
54
  end # GroupDocs
@@ -24,7 +24,8 @@ module GroupDocs
24
24
  end.execute!
25
25
 
26
26
  json[:documents].map do |document|
27
- file = Storage::File.new(:guid => document[:documentId], :name => document[:name])
27
+ id = document[:documentId] || document[:id]
28
+ file = Storage::File.new(:guid => id, :name => document[:name])
28
29
  Document.new(document.merge(:file => file))
29
30
  end
30
31
  end
@@ -36,6 +36,10 @@ module GroupDocs
36
36
  attr_accessor :documentsPages
37
37
  # @attr [Array<GroupDocs::Signature::Contact>] recipients
38
38
  attr_accessor :recipients
39
+ # @attr [String] watermarkText
40
+ attr_accessor :watermarkText
41
+ # @attr [String] watermarkImage
42
+ attr_accessor :watermarkImage
39
43
 
40
44
  # Human-readable accessors
41
45
  alias_accessor :owner_id, :ownerId
@@ -48,6 +52,8 @@ module GroupDocs
48
52
  alias_accessor :email_body, :emailBody
49
53
  alias_accessor :documents_count, :documentsCount
50
54
  alias_accessor :documents_pages, :documentsPages
55
+ alias_accessor :watermark_text, :watermarkText
56
+ alias_accessor :watermark_image, :watermarkImage
51
57
 
52
58
  #
53
59
  # Converts each recipient to GroupDocs::Signature::Recipient object.
@@ -65,22 +71,6 @@ module GroupDocs
65
71
  end
66
72
  end
67
73
 
68
- #
69
- # Returns true if owner should sign.
70
- # @return [Boolean]
71
- #
72
- def owner_should_sign
73
- @ownerShouldSign == 1 ? true : false
74
- end
75
-
76
- #
77
- # Returns ordered signature type.
78
- # @return [Symbol]
79
- #
80
- def ordered_signature
81
- @orderedSignature == 1 ? :parallel : :ordered
82
- end
83
-
84
74
  end # EntityFields
85
75
  end # Signature
86
76
  end # GroupDocs
@@ -52,8 +52,8 @@ module GroupDocs
52
52
  # envelope.create!
53
53
  #
54
54
  # @param [Hash] options Hash of options
55
- # @option options [Integer] :template_id Template GUID to use
56
- # @option options [Integer] :envelope_id Envelope GUID to use
55
+ # @option options [String] :template_id Template GUID to use
56
+ # @option options [String] :envelope_id Envelope GUID to use
57
57
  # @param [Hash] access Access credentials
58
58
  # @option access [String] :client_id
59
59
  # @option access [String] :private_key
@@ -55,7 +55,7 @@ module GroupDocs
55
55
  #
56
56
  # @example Add field to template
57
57
  # template = GroupDocs::Signature::Template.get!("g94h5g84hj9g4gf23i40j")
58
- # field = GroupDocs::Signature::Field.get!.detect { |f| f.name == "Signature" }
58
+ # field = GroupDocs::Signature::Field.get!.detect { |f| f.type == :signature }
59
59
  # field.location = { location_x: 0.1, location_y: 0.1, page: 1 }
60
60
  # document = template.documents!.first
61
61
  # recipient = template.recipients!.first
@@ -63,7 +63,7 @@ module GroupDocs
63
63
  #
64
64
  # @example Add field to envelope
65
65
  # envelope = GroupDocs::Signature::Envelope.get!("g94h5g84hj9g4gf23i40j")
66
- # field = GroupDocs::Signature::Field.get!.detect { |f| f.name == "Signature" }
66
+ # field = GroupDocs::Signature::Field.get!.detect { |f| f.type == :signature }
67
67
  # field.location = { location_x: 0.1, location_y: 0.1, page: 1 }
68
68
  # document = envelope.documents!.first
69
69
  # recipient = envelope.recipients!.first
@@ -151,6 +151,53 @@ module GroupDocs
151
151
  end.execute!
152
152
  end
153
153
 
154
+ #
155
+ # Assigns document field to new recipient.
156
+ #
157
+ # @example Assign template field
158
+ # template = GroupDocs::Signature::Template.get!("g94h5g84hj9g4gf23i40j")
159
+ # document = template.documents!.first
160
+ # recipient_one = template.recipients![0]
161
+ # recipient_two = template.recipients![1]
162
+ # field = template.fields!(document, recipient).first
163
+ # template.assign_field! field, document, recipient_one, recipient_two
164
+ #
165
+ # @example Assign envelope field
166
+ # envelope = GroupDocs::Signature::Envelope.get!("g94h5g84hj9g4gf23i40j")
167
+ # document = envelope.documents!.first
168
+ # recipient_one = envelope.recipients![0]
169
+ # recipient_two = envelope.recipients![1]
170
+ # field = envelope.fields!(document, recipient).first
171
+ # envelope.assign_field! field, document, recipient_one, recipient_two
172
+ #
173
+ # @param [GroupDocs::Signature::Field] field
174
+ # @param [GroupDocs::Document] document
175
+ # @param [GroupDocs::Signature::Recipient] assign_from
176
+ # @param [GroupDocs::Signature::Recipient] assign_to
177
+ # @param [Hash] access Access credentials
178
+ # @option access [String] :client_id
179
+ # @option access [String] :private_key
180
+ # @raise [ArgumentError] if field is not GroupDocs::Signature::Field
181
+ # @raise [ArgumentError] if document is not GroupDocs::Document
182
+ #
183
+ def assign_field!(field, document, assign_from, assign_to, access = {})
184
+ field.is_a?(GroupDocs::Signature::Field) or raise ArgumentError,
185
+ "Field should be GroupDocs::Signature::Field object, received: #{field.inspect}"
186
+ document.is_a?(GroupDocs::Document) or raise ArgumentError,
187
+ "Document should be GroupDocs::Document object, received: #{document.inspect}"
188
+ assign_from.is_a?(GroupDocs::Signature::Recipient) or raise ArgumentError,
189
+ "Assign from should be GroupDocs::Signature::Recipient object, received: #{assign_from.inspect}"
190
+ assign_to.is_a?(GroupDocs::Signature::Recipient) or raise ArgumentError,
191
+ "Assign to should be GroupDocs::Signature::Recipient object, received: #{assign_to.inspect}"
192
+
193
+ Api::Request.new do |request|
194
+ request[:access] = access
195
+ request[:method] = :POST
196
+ request[:path] = "/signature/{{client_id}}/#{class_name.pluralize}/#{id}/documents/#{document.file.guid}/field/#{field.id}",
197
+ request[:request_body] = { :currentRecipientId => assign_from.id, :newRecipientId => assign_to.id }
198
+ end.execute!
199
+ end
200
+
154
201
  #
155
202
  # Deletes field.
156
203
  #
@@ -259,6 +306,13 @@ module GroupDocs
259
306
  # location = field.locations.first
260
307
  # envelope.delete_field_location! location, field
261
308
  #
309
+ # @example Delete field location in form
310
+ # form = GroupDocs::Signature::Form.get!("g94h5g84hj9g4gf23i40j")
311
+ # document = form.documents!.first
312
+ # field = form.fields!(document).first
313
+ # location = field.locations.first
314
+ # form.delete_field_location! location, field
315
+ #
262
316
  # @param [GroupDocs::Signature::Field::Location] location
263
317
  # @param [GroupDocs::Signature::Field] field
264
318
  # @param [Hash] access Access credentials
@@ -1,6 +1,7 @@
1
1
  require 'groupdocs/storage/folder'
2
2
  require 'groupdocs/storage/file'
3
3
  require 'groupdocs/storage/package'
4
+ require 'groupdocs/storage/provider'
4
5
 
5
6
 
6
7
  module GroupDocs
@@ -0,0 +1,32 @@
1
+ module GroupDocs
2
+ module Storage
3
+ class Provider < Api::Entity
4
+
5
+ # @attr [Integer] id
6
+ attr_accessor :id
7
+ # @attr [String] provider
8
+ attr_accessor :provider
9
+ # @attr [String] type
10
+ attr_accessor :type
11
+ # @attr [String] token
12
+ attr_accessor :token
13
+ # @attr [String] publicKey
14
+ attr_accessor :publicKey
15
+ # @attr [String] privateKey
16
+ attr_accessor :privateKey
17
+ # @attr [String] rootFolder
18
+ attr_accessor :rootFolder
19
+ # @attr [Boolean] isPrimary
20
+ attr_accessor :isPrimary
21
+ # @attr [String] serviceHost
22
+ attr_accessor :serviceHost
23
+
24
+ alias_accessor :public_key, :publicKey
25
+ alias_accessor :private_key, :privateKey
26
+ alias_accessor :root_folder, :rootFolder
27
+ alias_accessor :is_primary, :isPrimary
28
+ alias_accessor :service_host, :serviceHost
29
+
30
+ end # Provider
31
+ end # Storage
32
+ end # GroupDocs
@@ -59,6 +59,54 @@ module GroupDocs
59
59
  GroupDocs::User.new data.merge(json)
60
60
  end
61
61
 
62
+ #
63
+ # Generates new active user embed key.
64
+ #
65
+ # @example
66
+ # GroupDocs::User.embed_key!('test-area')
67
+ # #=> "60a06ef8f23a49cf807977f1444fbdd8"
68
+ #
69
+ # @param [String] area
70
+ # @param [Hash] access Access credentials
71
+ # @option access [String] :client_id
72
+ # @option access [String] :private_key
73
+ # @return [String]
74
+ #
75
+ def self.embed_key!(area, access = {})
76
+ json = Api::Request.new do |request|
77
+ request[:access] = access
78
+ request[:method] = :GET
79
+ request[:path] = "/mgmt/{{client_id}}/embedkey/new/#{area}"
80
+ end.execute!
81
+
82
+ json[:key][:guid]
83
+ end
84
+
85
+ #
86
+ # Returns an array of storage providers.
87
+ #
88
+ # @example
89
+ # providers = GroupDocs::User.providers!
90
+ # providers.first.provider
91
+ # #=> "Dropbox"
92
+ #
93
+ # @param [Hash] access Access credentials
94
+ # @option access [String] :client_id
95
+ # @option access [String] :private_key
96
+ # @return [Array<GroupDocs::Storage::Provider>]
97
+ #
98
+ def self.providers!(access = {})
99
+ json = Api::Request.new do |request|
100
+ request[:access] = access
101
+ request[:method] = :GET
102
+ request[:path] = '/mgmt/{{client_id}}/storages'
103
+ end.execute!
104
+
105
+ json[:providers].map do |provider|
106
+ Storage::Provider.new(provider)
107
+ end
108
+ end
109
+
62
110
  # @attr [Integer] id
63
111
  attr_accessor :id
64
112
  # @attr [String] guid
@@ -174,5 +222,23 @@ module GroupDocs
174
222
  end
175
223
  end
176
224
 
225
+ #
226
+ # Returns an array of roles.
227
+ #
228
+ # @param [Hash] access Access credentials
229
+ # @option access [String] :client_id
230
+ # @option access [String] :private_key
231
+ # @return [Array]
232
+ #
233
+ def roles!(access = {})
234
+ json = Api::Request.new do |request|
235
+ request[:access] = access
236
+ request[:method] = :GET
237
+ request[:path] = '/mgmt/{{client_id}}/roles'
238
+ end.execute!
239
+
240
+ json[:roles]
241
+ end
242
+
177
243
  end # User
178
244
  end # GroupDocs
@@ -1,3 +1,3 @@
1
1
  module GroupDocs
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.0'
3
3
  end # GroupDocs
@@ -57,6 +57,27 @@ describe GroupDocs::Signature::Contact do
57
57
  end
58
58
  end
59
59
 
60
+ describe '.add_integration!' do
61
+ before(:each) do
62
+ mock_api_server('{ "status": "Ok", "result": { "contact": null }}')
63
+ end
64
+
65
+ let(:integration) do
66
+ {
67
+ :provider => :google,
68
+ :refresh_token => 'token',
69
+ :access_token => 'token',
70
+ :access_token_expiration => '2014-12-12'
71
+ }
72
+ end
73
+
74
+ it 'accepts access credentials hash' do
75
+ lambda do
76
+ described_class.add_integration!(integration, :client_id => 'client_id', :private_key => 'private_key')
77
+ end.should_not raise_error(ArgumentError)
78
+ end
79
+ end
80
+
60
81
  it { should have_accessor(:id) }
61
82
  it { should have_accessor(:firstName) }
62
83
  it { should have_accessor(:lastName) }
@@ -62,11 +62,13 @@ describe GroupDocs::Signature::Envelope do
62
62
  it { should have_accessor(:status) }
63
63
  it { should have_accessor(:statusDateTime) }
64
64
  it { should have_accessor(:envelopeExpireTime) }
65
+ it { should have_accessor(:isDemo) }
65
66
  it { should have_accessor(:status) }
66
67
 
67
68
  it { should alias_accessor(:creation_date_time, :creationDateTime) }
68
69
  it { should alias_accessor(:status_date_time, :statusDateTime) }
69
70
  it { should alias_accessor(:envelope_expire_time, :envelopeExpireTime) }
71
+ it { should alias_accessor(:is_demo, :isDemo) }
70
72
 
71
73
  describe '#status' do
72
74
  it 'converts status to human-readable format' do
@@ -115,6 +117,29 @@ describe GroupDocs::Signature::Envelope do
115
117
  end
116
118
  end
117
119
 
120
+ describe '#delegate_recipient!' do
121
+ let(:old) { GroupDocs::Signature::Recipient.new }
122
+ let(:new) { GroupDocs::Signature::Recipient.new }
123
+
124
+ before(:each) do
125
+ mock_api_server('{ "status": "Ok", "result": {}}')
126
+ end
127
+
128
+ it 'accepts access credentials hash' do
129
+ lambda do
130
+ subject.delegate_recipient!(old, new, :client_id => 'client_id', :private_key => 'private_key')
131
+ end.should_not raise_error(ArgumentError)
132
+ end
133
+
134
+ it 'raises error if old recipient is not GroupDocs::Signature::Recipient object' do
135
+ lambda { subject.delegate_recipient!('Recipient', new) }.should raise_error(ArgumentError)
136
+ end
137
+
138
+ it 'raises error if new recipient is not GroupDocs::Signature::Recipient object' do
139
+ lambda { subject.delegate_recipient!(old, 'Recipient') }.should raise_error(ArgumentError)
140
+ end
141
+ end
142
+
118
143
  describe '#fill_field!' do
119
144
  let(:field) { GroupDocs::Signature::Field.new(:location => { :location_x => 0.1, :page => 1 }) }
120
145
  let(:document) { GroupDocs::Document.new(:file => GroupDocs::Storage::File.new) }
@@ -242,7 +267,7 @@ describe GroupDocs::Signature::Envelope do
242
267
  mock_api_server(File.read('spec/support/files/resume.pdf'))
243
268
  end
244
269
 
245
- it 'downloads ZIP file' do
270
+ it 'downloads PDF file' do
246
271
  file = stub('file')
247
272
  subject.stub(:documents! => [1])
248
273
  Object::File.should_receive(:open).with("#{path}/#{subject.name}.pdf", 'wb').and_yield(file)
@@ -266,6 +291,33 @@ describe GroupDocs::Signature::Envelope do
266
291
  end
267
292
  end
268
293
 
294
+ describe '#signed_document!' do
295
+ before(:each) do
296
+ mock_api_server(File.read('spec/support/files/resume.pdf'))
297
+ subject.name = 'envelope'
298
+ end
299
+
300
+ let(:path) { Dir.tmpdir }
301
+ let(:document) { GroupDocs::Document.new(:file => GroupDocs::Storage::File.new) }
302
+
303
+ it 'accepts access credentials hash' do
304
+ lambda do
305
+ subject.signed_document!(document, path, :client_id => 'client_id', :private_key => 'private_key')
306
+ end.should_not raise_error(ArgumentError)
307
+ end
308
+
309
+ it 'returns saved file path' do
310
+ subject.signed_document!(document, path).should == "#{path}/#{subject.name}.pdf"
311
+ end
312
+
313
+ it 'downloads PDF file' do
314
+ file = stub('file')
315
+ Object::File.should_receive(:open).with("#{path}/#{subject.name}.pdf", 'wb').and_yield(file)
316
+ file.should_receive(:write).with(File.read('spec/support/files/resume.pdf'))
317
+ subject.signed_document!(document, path)
318
+ end
319
+ end
320
+
269
321
  describe '#logs!' do
270
322
  before(:each) do
271
323
  mock_api_server(load_json('envelope_logs'))
@@ -72,7 +72,6 @@ describe GroupDocs::Signature::Field do
72
72
  it { should alias_accessor(:font_italic, :fontItalic) }
73
73
  it { should alias_accessor(:font_underline, :fontUnderline) }
74
74
  it { should alias_accessor(:is_system, :isSystem) }
75
- it { should alias_accessor(:acceptable_values, :acceptableValues) }
76
75
  it { should alias_accessor(:default_value, :defaultValue) }
77
76
  it { should alias_accessor(:text_rows, :textRows) }
78
77
  it { should alias_accessor(:text_columns, :textColumns) }
@@ -163,6 +162,25 @@ describe GroupDocs::Signature::Field do
163
162
  end
164
163
  end
165
164
 
165
+ describe '#acceptable_values=' do
166
+ it 'converts values in machine-readable format if array is passed' do
167
+ subject.acceptable_values = %w(on off)
168
+ subject.instance_variable_get(:@acceptableValues).should == 'on;off'
169
+ end
170
+
171
+ it 'saves values as is if not an array is passed' do
172
+ subject.acceptable_values = 'on;off'
173
+ subject.instance_variable_get(:@acceptableValues).should == 'on;off'
174
+ end
175
+ end
176
+
177
+ describe '#acceptable_values' do
178
+ it 'returns values in human-readable format' do
179
+ subject.acceptable_values = %w(on off)
180
+ subject.acceptable_values.should == %w(on off)
181
+ end
182
+ end
183
+
166
184
  describe '#create!' do
167
185
  before(:each) do
168
186
  mock_api_server(load_json('signature_field_add'))