groupdocs 0.3.11 → 1.0.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 (122) hide show
  1. data/CHANGELOG.md +150 -0
  2. data/README.md +6 -58
  3. data/Rakefile +1 -1
  4. data/examples/README.md +13 -0
  5. data/examples/annotations/Gemfile +5 -0
  6. data/examples/annotations/app.rb +67 -0
  7. data/groupdocs.gemspec +3 -3
  8. data/lib/groupdocs.rb +11 -2
  9. data/lib/groupdocs/api/entity.rb +17 -1
  10. data/lib/groupdocs/api/helpers/path_helper.rb +10 -10
  11. data/lib/groupdocs/api/helpers/rest_helper.rb +7 -2
  12. data/lib/groupdocs/api/helpers/url_helper.rb +2 -4
  13. data/lib/groupdocs/api/request.rb +2 -4
  14. data/lib/groupdocs/datasource.rb +2 -2
  15. data/lib/groupdocs/datasource/field.rb +1 -1
  16. data/lib/groupdocs/document.rb +6 -18
  17. data/lib/groupdocs/document/annotation.rb +25 -2
  18. data/lib/groupdocs/document/annotation/reply.rb +6 -10
  19. data/lib/groupdocs/document/change.rb +1 -1
  20. data/lib/groupdocs/document/field.rb +1 -1
  21. data/lib/groupdocs/document/metadata.rb +1 -1
  22. data/lib/groupdocs/document/rectangle.rb +1 -1
  23. data/lib/groupdocs/document/view.rb +1 -1
  24. data/lib/groupdocs/job.rb +51 -8
  25. data/lib/groupdocs/questionnaire.rb +2 -2
  26. data/lib/groupdocs/questionnaire/execution.rb +1 -1
  27. data/lib/groupdocs/questionnaire/page.rb +1 -1
  28. data/lib/groupdocs/questionnaire/question.rb +1 -1
  29. data/lib/groupdocs/questionnaire/question/answer.rb +1 -1
  30. data/lib/groupdocs/signature.rb +134 -0
  31. data/lib/groupdocs/signature/contact.rb +141 -0
  32. data/lib/groupdocs/signature/envelope.rb +376 -0
  33. data/lib/groupdocs/signature/envelope/log.rb +22 -0
  34. data/lib/groupdocs/signature/field.rb +253 -0
  35. data/lib/groupdocs/signature/field/location.rb +72 -0
  36. data/lib/groupdocs/signature/form.rb +202 -0
  37. data/lib/groupdocs/signature/list.rb +93 -0
  38. data/lib/groupdocs/signature/recipient.rb +47 -0
  39. data/lib/groupdocs/signature/role.rb +84 -0
  40. data/lib/groupdocs/signature/shared.rb +6 -0
  41. data/lib/groupdocs/signature/shared/document_methods.rb +98 -0
  42. data/lib/groupdocs/signature/shared/entity_fields.rb +94 -0
  43. data/lib/groupdocs/signature/shared/entity_methods.rb +145 -0
  44. data/lib/groupdocs/signature/shared/field_methods.rb +282 -0
  45. data/lib/groupdocs/signature/shared/recipient_methods.rb +63 -0
  46. data/lib/groupdocs/signature/shared/resource_methods.rb +65 -0
  47. data/lib/groupdocs/signature/template.rb +104 -0
  48. data/lib/groupdocs/storage/file.rb +69 -62
  49. data/lib/groupdocs/storage/folder.rb +54 -88
  50. data/lib/groupdocs/storage/package.rb +1 -1
  51. data/lib/groupdocs/subscription.rb +113 -0
  52. data/lib/groupdocs/subscription/limit.rb +24 -0
  53. data/lib/groupdocs/user.rb +22 -2
  54. data/lib/groupdocs/version.rb +1 -1
  55. data/spec/groupdocs/api/entity_spec.rb +14 -0
  56. data/spec/groupdocs/api/helpers/path_helper_spec.rb +6 -19
  57. data/spec/groupdocs/api/helpers/rest_helper_spec.rb +9 -0
  58. data/spec/groupdocs/api/request_spec.rb +2 -7
  59. data/spec/groupdocs/datasource_spec.rb +3 -7
  60. data/spec/groupdocs/document/annotation/reply_spec.rb +11 -20
  61. data/spec/groupdocs/document/annotation_spec.rb +35 -31
  62. data/spec/groupdocs/document/field_spec.rb +1 -4
  63. data/spec/groupdocs/document/rectangle_spec.rb +10 -22
  64. data/spec/groupdocs/document_spec.rb +7 -27
  65. data/spec/groupdocs/job_spec.rb +43 -0
  66. data/spec/groupdocs/questionnaire/question_spec.rb +2 -6
  67. data/spec/groupdocs/questionnaire_spec.rb +3 -7
  68. data/spec/groupdocs/signature/contact_spec.rb +129 -0
  69. data/spec/groupdocs/signature/envelope/log_spec.rb +23 -0
  70. data/spec/groupdocs/signature/envelope_spec.rb +296 -0
  71. data/spec/groupdocs/signature/field/location_spec.rb +73 -0
  72. data/spec/groupdocs/signature/field_spec.rb +264 -0
  73. data/spec/groupdocs/signature/form_spec.rb +174 -0
  74. data/spec/groupdocs/signature/list_spec.rb +92 -0
  75. data/spec/groupdocs/signature/recipient_spec.rb +37 -0
  76. data/spec/groupdocs/signature/role_spec.rb +100 -0
  77. data/spec/groupdocs/signature/template_spec.rb +82 -0
  78. data/spec/groupdocs/signature_spec.rb +117 -0
  79. data/spec/groupdocs/storage/file_spec.rb +76 -61
  80. data/spec/groupdocs/storage/folder_spec.rb +43 -90
  81. data/spec/groupdocs/storage/package_spec.rb +1 -2
  82. data/spec/groupdocs/subscription/limit_spec.rb +24 -0
  83. data/spec/groupdocs/subscription_spec.rb +85 -0
  84. data/spec/groupdocs/user_spec.rb +27 -18
  85. data/spec/groupdocs_spec.rb +11 -0
  86. data/spec/spec_helper.rb +10 -1
  87. data/spec/support/files/envelope.zip +0 -0
  88. data/spec/support/json/annotation_access_set.json +11 -0
  89. data/spec/support/json/contact_add.json +12 -0
  90. data/spec/support/json/contacts_get.json +19 -0
  91. data/spec/support/json/contacts_import.json +8 -0
  92. data/spec/support/json/envelope_get.json +46 -0
  93. data/spec/support/json/envelope_logs.json +16 -0
  94. data/spec/support/json/envelopes_all.json +48 -0
  95. data/spec/support/json/envelopes_resources.json +31 -0
  96. data/spec/support/json/form_get.json +21 -0
  97. data/spec/support/json/forms_all.json +23 -0
  98. data/spec/support/json/job_get.json +30 -0
  99. data/spec/support/json/list_add.json +12 -0
  100. data/spec/support/json/lists_get.json +19 -0
  101. data/spec/support/json/signature_create.json +12 -0
  102. data/spec/support/json/signature_field_add.json +25 -0
  103. data/spec/support/json/signature_fields_get.json +27 -0
  104. data/spec/support/json/signature_roles_get.json +17 -0
  105. data/spec/support/json/signatures_get.json +19 -0
  106. data/spec/support/json/subscription_plan_get.json +9 -0
  107. data/spec/support/json/subscription_plans_get.json +17 -0
  108. data/spec/support/json/template_get.json +35 -0
  109. data/spec/support/json/template_get_documents.json +15 -0
  110. data/spec/support/json/template_get_recipients.json +20 -0
  111. data/spec/support/json/templates_all.json +37 -0
  112. data/spec/support/json/user_users_get.json +27 -0
  113. data/spec/support/shared_examples/signature/shared/document_methods.rb +68 -0
  114. data/spec/support/shared_examples/signature/shared/entity_fields.rb +89 -0
  115. data/spec/support/shared_examples/signature/shared/entity_methods.rb +116 -0
  116. data/spec/support/shared_examples/signature/shared/field_methods.rb +188 -0
  117. data/spec/support/shared_examples/signature/shared/recipient_methods.rb +42 -0
  118. data/spec/support/shared_examples/signature/shared/resource_methods.rb +46 -0
  119. metadata +139 -29
  120. data/lib/groupdocs/extensions.rb +0 -1
  121. data/lib/groupdocs/extensions/lookup.rb +0 -52
  122. data/spec/support/shared_examples/extensions/lookup.rb +0 -57
@@ -1,5 +1,5 @@
1
1
  module GroupDocs
2
- class Questionnaire::Question < GroupDocs::Api::Entity
2
+ class Questionnaire::Question < Api::Entity
3
3
 
4
4
  require 'groupdocs/questionnaire/question/answer'
5
5
 
@@ -1,5 +1,5 @@
1
1
  module GroupDocs
2
- class Questionnaire::Question::Answer < GroupDocs::Api::Entity
2
+ class Questionnaire::Question::Answer < Api::Entity
3
3
 
4
4
  # @attr [String] text
5
5
  attr_accessor :text
@@ -0,0 +1,134 @@
1
+ module GroupDocs
2
+ class Signature < Api::Entity
3
+
4
+ require 'groupdocs/signature/shared'
5
+ require 'groupdocs/signature/contact'
6
+ require 'groupdocs/signature/envelope'
7
+ require 'groupdocs/signature/field'
8
+ require 'groupdocs/signature/form'
9
+ require 'groupdocs/signature/list'
10
+ require 'groupdocs/signature/recipient'
11
+ require 'groupdocs/signature/role'
12
+ require 'groupdocs/signature/template'
13
+
14
+ #
15
+ # Returns a list of all user signatures.
16
+ #
17
+ # @param [Hash] access Access credentials
18
+ # @option access [String] :client_id
19
+ # @option access [String] :private_key
20
+ # @return [Array<GroupDocs::Signature>]
21
+ #
22
+ def self.get!(access = {})
23
+ json = Api::Request.new do |request|
24
+ request[:access] = access
25
+ request[:method] = :GET
26
+ request[:path] = '/signature/{{client_id}}/signatures'
27
+ end.execute!
28
+
29
+ json[:signatures].map do |signature|
30
+ new(signature)
31
+ end
32
+ end
33
+
34
+ # @attr [String] id
35
+ attr_accessor :id
36
+ # @attr [String] userGuid
37
+ attr_accessor :userGuid
38
+ # @attr [String] recipientId
39
+ attr_accessor :recipientId
40
+ # @attr [String] name
41
+ attr_accessor :name
42
+ # @attr [String] companyName
43
+ attr_accessor :companyName
44
+ # @attr [String] position
45
+ attr_accessor :position
46
+ # @attr [String] firstName
47
+ attr_accessor :firstName
48
+ # @attr [String] lastName
49
+ attr_accessor :lastName
50
+ # @attr [String] fullName
51
+ attr_accessor :fullName
52
+ # @attr [String] textInitials
53
+ attr_accessor :textInitials
54
+ # @attr [String] signatureImageFileId
55
+ attr_accessor :signatureImageFileId
56
+ # @attr [String] initialsImageFileId
57
+ attr_accessor :initialsImageFileId
58
+ # @attr [String] signatureImageUrl
59
+ attr_accessor :signatureImageUrl
60
+ # @attr [String] initialsImageUrl
61
+ attr_accessor :initialsImageUrl
62
+ # @attr [String] createdTimeStamp
63
+ attr_accessor :createdTimeStamp
64
+
65
+ # Human-readable accessors
66
+ alias_method :user_guid, :userGuid
67
+ alias_method :user_guid=, :userGuid=
68
+ alias_method :recipient_id, :recipientId
69
+ alias_method :recipient_id=, :recipientId=
70
+ alias_method :company_name, :companyName
71
+ alias_method :company_name=, :companyName=
72
+ alias_method :first_name, :firstName
73
+ alias_method :first_name=, :firstName=
74
+ alias_method :last_name, :lastName
75
+ alias_method :last_name=, :lastName=
76
+ alias_method :full_name, :fullName
77
+ alias_method :full_name=, :fullName=
78
+ alias_method :text_initials, :textInitials
79
+ alias_method :text_initials=, :textInitials=
80
+ alias_method :signature_image_file_id, :signatureImageFileId
81
+ alias_method :signature_image_file_id=, :signatureImageFileId=
82
+ alias_method :initials_image_file_id, :initialsImageFileId
83
+ alias_method :initials_image_file_id=, :initialsImageFileId=
84
+ alias_method :signature_image_url, :signatureImageUrl
85
+ alias_method :signature_image_url=, :signatureImageUrl=
86
+ alias_method :initials_image_url, :initialsImageUrl
87
+ alias_method :initials_image_url=, :initialsImageUrl=
88
+ alias_method :created_time_stamp, :createdTimeStamp
89
+ alias_method :created_time_stamp=, :createdTimeStamp=
90
+
91
+ #
92
+ # Creates signature.
93
+ #
94
+ # @example
95
+ # signature = GroupDocs::Signature.new
96
+ # signature.first_name = 'John'
97
+ # signature.last_name = 'Smith'
98
+ # signature.create! "John Smith's Signature"
99
+ #
100
+ # @param [String] title Signature title
101
+ # @param [Hash] access Access credentials
102
+ # @option access [String] :client_id
103
+ # @option access [String] :private_key
104
+ #
105
+ def create!(title, access = {})
106
+ api = Api::Request.new do |request|
107
+ request[:access] = access
108
+ request[:method] = :POST
109
+ request[:path] = '/signature/{{client_id}}/signature'
110
+ request[:request_body] = to_hash
111
+ end
112
+ api.add_params(name: title)
113
+ json = api.execute!
114
+
115
+ self.id = json[:signature][:id]
116
+ end
117
+
118
+ #
119
+ # Deletes signature.
120
+ #
121
+ # @param [Hash] access Access credentials
122
+ # @option access [String] :client_id
123
+ # @option access [String] :private_key
124
+ #
125
+ def delete!(access = {})
126
+ Api::Request.new do |request|
127
+ request[:access] = access
128
+ request[:method] = :DELETE
129
+ request[:path] = "/signature/{{client_id}}/signatures/#{id}"
130
+ end.execute!
131
+ end
132
+
133
+ end # Signature
134
+ end # GroupDocs
@@ -0,0 +1,141 @@
1
+ module GroupDocs
2
+ class Signature::Contact < Api::Entity
3
+
4
+ #
5
+ # Returns a list of all contacts.
6
+ #
7
+ # @param [Hash] options Hash of options
8
+ # @option options [Integer] :page Page to start with
9
+ # @option options [Integer] :records How many items to list
10
+ # @option options [String] :firstName Filter by first name
11
+ # @option options [String] :lastName Filter by last name
12
+ # @option options [String] :email Filter by last name
13
+ # @param [Hash] access Access credentials
14
+ # @option access [String] :client_id
15
+ # @option access [String] :private_key
16
+ # @return [Array<GroupDocs::Signature::Contact>]
17
+ #
18
+ def self.get!(options = {}, access = {})
19
+ api = Api::Request.new do |request|
20
+ request[:access] = access
21
+ request[:method] = :GET
22
+ request[:path] = '/signature/{{client_id}}/contacts'
23
+ end
24
+ api.add_params(options)
25
+ json = api.execute!
26
+
27
+ json[:contacts].map do |contact|
28
+ new(contact)
29
+ end
30
+ end
31
+
32
+ #
33
+ # Imports array of contacts.
34
+ #
35
+ # @example
36
+ # contact_one = GroupDocs::Signature::Contact.new
37
+ # contact_one.first_name = 'John'
38
+ # contact_one.last_name = 'Smith'
39
+ # contact_one.email = 'john@smith.com'
40
+ # contact_two = GroupDocs::Signature::Contact.new
41
+ # contact_two.first_name = 'Carla'
42
+ # contact_two.last_name = 'Smith'
43
+ # contact_two.email = 'carla@smith.com'
44
+ # GroupDocs::Signature::Contact.import!([contact_one, contact_two])
45
+ #
46
+ # @param [Array<GroupDocs::Signature::Contact>] contacts
47
+ # @param [Hash] access Access credentials
48
+ # @option access [String] :client_id
49
+ # @option access [String] :private_key
50
+ #
51
+ def self.import!(contacts, access = {})
52
+ contacts.is_a?(Array) or raise ArgumentError, "Contacts should be array, received: #{contacts.inspect}"
53
+ contacts.each do |contact|
54
+ contact.is_a?(GroupDocs::Signature::Contact) or raise ArgumentError, "Contact should be GroupDocs::Signature::Contact, received: #{contact.inspect}"
55
+ end
56
+
57
+ Api::Request.new do |request|
58
+ request[:access] = access
59
+ request[:method] = :POST
60
+ request[:path] = '/signature/{{client_id}}/contacts'
61
+ request[:request_body] = contacts.map { |contact| contact.to_hash }
62
+ end.execute!
63
+ end
64
+
65
+ # @attr [String] id
66
+ attr_accessor :id
67
+ # @attr [String] firstName
68
+ attr_accessor :firstName
69
+ # @attr [String] lastName
70
+ attr_accessor :lastName
71
+ # @attr [String] nickname
72
+ attr_accessor :nickname
73
+ # @attr [String] email
74
+ attr_accessor :email
75
+ # @attr [String] provider
76
+ attr_accessor :provider
77
+
78
+ # Human-readable accessors
79
+ alias_method :first_name, :firstName
80
+ alias_method :first_name=, :firstName=
81
+ alias_method :last_name, :lastName
82
+ alias_method :last_name=, :lastName=
83
+
84
+ #
85
+ # Adds contact.
86
+ #
87
+ # @example
88
+ # contact = GroupDocs::Signature::Contact.new
89
+ # contact.first_name = 'John'
90
+ # contact.last_name = 'Smith'
91
+ # contact.email = 'john@smith.com'
92
+ # contact.add!
93
+ #
94
+ # @param [Hash] access Access credentials
95
+ # @option access [String] :client_id
96
+ # @option access [String] :private_key
97
+ #
98
+ def add!(access = {})
99
+ json = Api::Request.new do |request|
100
+ request[:access] = access
101
+ request[:method] = :POST
102
+ request[:path] = '/signature/{{client_id}}/contact'
103
+ request[:request_body] = to_hash
104
+ end.execute!
105
+
106
+ self.id = json[:contact][:id]
107
+ end
108
+
109
+ #
110
+ # Updates contact.
111
+ #
112
+ # @param [Hash] access Access credentials
113
+ # @option access [String] :client_id
114
+ # @option access [String] :private_key
115
+ #
116
+ def update!(access = {})
117
+ Api::Request.new do |request|
118
+ request[:access] = access
119
+ request[:method] = :POST
120
+ request[:path] = "/signature/{{client_id}}/contacts/#{id}"
121
+ request[:request_body] = to_hash
122
+ end.execute!
123
+ end
124
+
125
+ #
126
+ # Deletes contact.
127
+ #
128
+ # @param [Hash] access Access credentials
129
+ # @option access [String] :client_id
130
+ # @option access [String] :private_key
131
+ #
132
+ def delete!(access = {})
133
+ Api::Request.new do |request|
134
+ request[:access] = access
135
+ request[:method] = :DELETE
136
+ request[:path] = "/signature/{{client_id}}/contacts/#{id}"
137
+ end.execute!
138
+ end
139
+
140
+ end # Signature::Contact
141
+ end # GroupDocs
@@ -0,0 +1,376 @@
1
+ module GroupDocs
2
+ class Signature::Envelope < Api::Entity
3
+
4
+ require 'groupdocs/signature/envelope/log'
5
+
6
+ STATUSES = {
7
+ draft: -1,
8
+ annotation: 0,
9
+ in_progress: 1,
10
+ expired: 2,
11
+ canceled: 3,
12
+ failed: 4,
13
+ completed: 5,
14
+ archived: 6,
15
+ }
16
+
17
+ include Signature::DocumentMethods
18
+ include Signature::EntityFields
19
+ include Signature::EntityMethods
20
+ include Signature::FieldMethods
21
+ include Signature::RecipientMethods
22
+ extend Signature::ResourceMethods
23
+
24
+ #
25
+ # Returns a list of all envelopes.
26
+ #
27
+ # @param [Hash] options Hash of options
28
+ # @option options [Integer] :page Page to start with
29
+ # @option options [Integer] :records How many items to list
30
+ # @option options [Integer] :status_id Filter by status identifier
31
+ # @option options [String] :document Filter by document GUID
32
+ # @option options [String] :recipient Filter by recipient email
33
+ # @option options [String] :date Filter by date
34
+ # @option options [String] :name Filter by name
35
+ # @param [Hash] access Access credentials
36
+ # @option access [String] :client_id
37
+ # @option access [String] :private_key
38
+ # @return [Array<GroupDocs::Signature::Envelope>]
39
+ #
40
+ def self.all!(options = {}, access = {})
41
+ status_id = options.delete(:status_id)
42
+ options[:statusId] = status_id if status_id
43
+
44
+ api = Api::Request.new do |request|
45
+ request[:access] = access
46
+ request[:method] = :GET
47
+ request[:path] = '/signature/{{client_id}}/envelopes'
48
+ end
49
+ api.add_params(options)
50
+ json = api.execute!
51
+
52
+ json[:envelopes].map do |envelope|
53
+ new(envelope)
54
+ end
55
+ end
56
+
57
+ #
58
+ # Returns a list of all envelopes where user is recipient.
59
+ #
60
+ # @param [Hash] options Hash of options
61
+ # @option options [Integer] :page Page to start with
62
+ # @option options [Integer] :records How many items to list
63
+ # @option options [Integer] :statusId Filter by status identifier
64
+ # @param [Hash] access Access credentials
65
+ # @option access [String] :client_id
66
+ # @option access [String] :private_key
67
+ # @return [Array<GroupDocs::Signature::Envelope>]
68
+ #
69
+ def self.for_me!(options = {}, access = {})
70
+ api = Api::Request.new do |request|
71
+ request[:access] = access
72
+ request[:method] = :GET
73
+ request[:path] = '/signature/{{client_id}}/envelopes/recipient'
74
+ end
75
+ api.add_params(options)
76
+ json = api.execute!
77
+
78
+ json[:envelopes].map do |envelope|
79
+ new(envelope)
80
+ end
81
+ end
82
+
83
+ # @attr [String] creationDateTime
84
+ attr_accessor :creationDateTime
85
+ # @attr [Symbol] status
86
+ attr_accessor :status
87
+ # @attr [String] statusDateTime
88
+ attr_accessor :statusDateTime
89
+ # @attr [Integer] envelopeExpireTime
90
+ attr_accessor :envelopeExpireTime
91
+ # @attr [Symbol] status
92
+ attr_accessor :status
93
+
94
+ # Human-readable accessors
95
+ alias_method :creation_date_time, :creationDateTime
96
+ alias_method :creation_date_time=, :creationDateTime=
97
+ alias_method :status_date_time, :statusDateTime
98
+ alias_method :status_date_time=, :statusDateTime=
99
+ alias_method :envelope_expire_time, :envelopeExpireTime
100
+ alias_method :envelope_expire_time=, :envelopeExpireTime=
101
+
102
+ #
103
+ # Converts status to human-readable format.
104
+ # @return [Symbol]
105
+ #
106
+ def status
107
+ STATUSES.invert[@status]
108
+ end
109
+
110
+ #
111
+ # Adds recipient to envelope.
112
+ #
113
+ # @example
114
+ # roles = GroupDocs::Signature::Role.get!
115
+ # envelope = GroupDocs::Signature::Envelope.get!("g94h5g84hj9g4gf23i40j")
116
+ # recipient = GroupDocs::Signature::Recipient.new
117
+ # recipient.email = 'john@smith.com'
118
+ # recipient.first_name = 'John'
119
+ # recipient.last_name = 'Smith'
120
+ # recipient.role_id = roles.detect { |role| role.name == "Signer" }.id
121
+ # envelope.add_recipient! recipient
122
+ #
123
+ # @param [GroupDocs::Signature::Recipient] recipient
124
+ # @param [Hash] access Access credentials
125
+ # @option access [String] :client_id
126
+ # @option access [String] :private_key
127
+ # @raise [ArgumentError] if recipient is not GroupDocs::Signature::Recipient
128
+ #
129
+ def add_recipient!(recipient, access = {})
130
+ recipient.is_a?(GroupDocs::Signature::Recipient) or raise ArgumentError,
131
+ "Recipient should be GroupDocs::Signature::Recipient object, received: #{recipient.inspect}"
132
+
133
+ api = Api::Request.new do |request|
134
+ request[:access] = access
135
+ request[:method] = :POST
136
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/recipient"
137
+ end
138
+ api.add_params(email: recipient.email,
139
+ firstname: recipient.first_name,
140
+ lastname: recipient.last_name,
141
+ role: recipient.role_id,
142
+ order: recipient.order)
143
+ api.execute!
144
+ end
145
+
146
+ #
147
+ # Modify recipient of envelope.
148
+ #
149
+ # @example
150
+ # envelope = GroupDocs::Signature::Envelope.get!("g94h5g84hj9g4gf23i40j")
151
+ # recipient = envelope.recipients!.first
152
+ # recipient.first_name = 'Johnny'
153
+ # envelope.modify_recipient! recipient
154
+ #
155
+ # @param [GroupDocs::Signature::Recipient] recipient
156
+ # @param [Hash] access Access credentials
157
+ # @option access [String] :client_id
158
+ # @option access [String] :private_key
159
+ # @raise [ArgumentError] if recipient is not GroupDocs::Signature::Recipient
160
+ #
161
+ def modify_recipient!(recipient, access = {})
162
+ recipient.is_a?(GroupDocs::Signature::Recipient) or raise ArgumentError,
163
+ "Recipient should be GroupDocs::Signature::Recipient object, received: #{recipient.inspect}"
164
+
165
+ api = Api::Request.new do |request|
166
+ request[:access] = access
167
+ request[:method] = :PUT
168
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/recipient/#{recipient.id}"
169
+ end
170
+ api.add_params(email: recipient.email,
171
+ firstname: recipient.first_name,
172
+ lastname: recipient.last_name,
173
+ role: recipient.role_id,
174
+ order: recipient.order)
175
+ api.execute!
176
+ end
177
+
178
+ #
179
+ # Fills field with value.
180
+ #
181
+ # Value differs depending on field type. See examples below.
182
+ #
183
+ # @example Fill single line field
184
+ # envelope = GroupDocs::Signature::Envelope.get!("g94h5g84hj9g4gf23i40j")
185
+ # document = envelope.documents!.first
186
+ # recipient = envelope.recipients!.first
187
+ # field = envelope.fields!(document, recipient).first
188
+ # envelope.fill_field! "my_data", field, document, recipient
189
+ #
190
+ # @example Fill signature field
191
+ # envelope = GroupDocs::Signature::Envelope.get!("g94h5g84hj9g4gf23i40j")
192
+ # document = envelope.documents!.first
193
+ # recipient = envelope.recipients!.first
194
+ # field = envelope.fields!(document, recipient).first
195
+ # signature = GroupDocs::Signature.get!.first
196
+ # envelope.fill_field! signature, field, document, recipient
197
+ #
198
+ # @example Fill checkbox field
199
+ # envelope = GroupDocs::Signature::Envelope.get!("g94h5g84hj9g4gf23i40j")
200
+ # document = envelope.documents!.first
201
+ # recipient = envelope.recipients!.first
202
+ # field = envelope.fields!(document, recipient).first
203
+ # envelope.fill_field! false, field, document, recipient
204
+ #
205
+ # @param [String, Boolean, GroupDocs::Signature] value
206
+ # @param [GroupDocs::Signature::Field] field
207
+ # @param [GroupDocs::Document] document
208
+ # @param [GroupDocs::Signature::Recipient] recipient
209
+ # @param [Hash] access Access credentials
210
+ # @option access [String] :client_id
211
+ # @option access [String] :private_key
212
+ # @return [GroupDocs::Signature::Field] filled field
213
+ # @raise [ArgumentError] if field is not GroupDocs::Signature::Field
214
+ # @raise [ArgumentError] if document is not GroupDocs::Document
215
+ # @raise [ArgumentError] if recipient is not GroupDocs::Signature::Recipient
216
+ #
217
+ def fill_field!(value, field, document, recipient, access = {})
218
+ field.is_a?(GroupDocs::Signature::Field) or raise ArgumentError,
219
+ "Field should be GroupDocs::Signature::Field object, received: #{field.inspect}"
220
+ document.is_a?(GroupDocs::Document) or raise ArgumentError,
221
+ "Document should be GroupDocs::Document object, received: #{document.inspect}"
222
+ recipient.is_a?(GroupDocs::Signature::Recipient) or raise ArgumentError,
223
+ "Recipient should be GroupDocs::Signature::Recipient object, received: #{recipient.inspect}"
224
+
225
+ api = Api::Request.new do |request|
226
+ request[:access] = access
227
+ request[:method] = :PUT
228
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/documents/#{document.file.guid}/recipient/#{recipient.id}/field/#{field.id}"
229
+ end
230
+
231
+ type = field.field_type
232
+ if type == :signature && value.is_a?(GroupDocs::Signature)
233
+ api.add_params(signatureId: value.id)
234
+ else
235
+ if type == :checkbox
236
+ value = (value ? 'on' : 'off')
237
+ end
238
+ api.options[:request_body] = value
239
+ api.options[:plain] = true
240
+ end
241
+
242
+ json = api.execute!
243
+ Signature::Field.new(json[:field])
244
+ end
245
+
246
+ #
247
+ # Signs envelope.
248
+ #
249
+ # @param [GroupDocs::Signature::Recipient] recipient
250
+ # @param [Hash] access Access credentials
251
+ # @option access [String] :client_id
252
+ # @option access [String] :private_key
253
+ # @raise [ArgumentError] if recipient is not GroupDocs::Signature::Recipient
254
+ #
255
+ def sign!(recipient, access = {})
256
+ recipient.is_a?(GroupDocs::Signature::Recipient) or raise ArgumentError,
257
+ "Recipient should be GroupDocs::Signature::Recipient object, received: #{recipient.inspect}"
258
+
259
+ Api::Request.new do |request|
260
+ request[:access] = access
261
+ request[:method] = :PUT
262
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/recipient/#{recipient.id}/sign"
263
+ end.execute!
264
+ end
265
+
266
+ #
267
+ # Declines envelope.
268
+ #
269
+ # @param [GroupDocs::Signature::Recipient] recipient
270
+ # @param [Hash] access Access credentials
271
+ # @option access [String] :client_id
272
+ # @option access [String] :private_key
273
+ # @raise [ArgumentError] if recipient is not GroupDocs::Signature::Recipient
274
+ #
275
+ def decline!(recipient, access = {})
276
+ recipient.is_a?(GroupDocs::Signature::Recipient) or raise ArgumentError,
277
+ "Recipient should be GroupDocs::Signature::Recipient object, received: #{recipient.inspect}"
278
+
279
+ Api::Request.new do |request|
280
+ request[:access] = access
281
+ request[:method] = :PUT
282
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/recipient/#{recipient.id}/decline"
283
+ end.execute!
284
+ end
285
+
286
+ #
287
+ # Downloads all signed documents as ZIP file to given pat.
288
+ #
289
+ # @param [String] path Directory to download file to
290
+ # @param [Hash] access Access credentials
291
+ # @option access [String] :client_id
292
+ # @option access [String] :private_key
293
+ # @return [String] path to file
294
+ #
295
+ def signed_documents!(path, access = {})
296
+ response = Api::Request.new do |request|
297
+ request[:access] = access
298
+ request[:method] = :DOWNLOAD
299
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/documents/get"
300
+ end.execute!
301
+
302
+ filepath = "#{path}/#{name}.zip"
303
+ Object::File.open(filepath, 'w') do |file|
304
+ file.write(response)
305
+ end
306
+
307
+ filepath
308
+ end
309
+
310
+ #
311
+ # Returns a list of audit logs.
312
+ #
313
+ # @param [Hash] access Access credentials
314
+ # @option access [String] :client_id
315
+ # @option access [String] :private_key
316
+ # @return [Array<GroupDocs::Signature::Envelope::Log>]
317
+ #
318
+ def logs!(access = {})
319
+ json = Api::Request.new do |request|
320
+ request[:access] = access
321
+ request[:method] = :GET
322
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/logs"
323
+ end.execute!
324
+
325
+ json[:logs].map do |log|
326
+ Log.new(log)
327
+ end
328
+ end
329
+
330
+ #
331
+ # Sends envelope.
332
+ #
333
+ # @param [Hash] access Access credentials
334
+ # @option access [String] :client_id
335
+ # @option access [String] :private_key
336
+ #
337
+ def send!(access = {})
338
+ Api::Request.new do |request|
339
+ request[:access] = access
340
+ request[:method] = :PUT
341
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/send"
342
+ end.execute!
343
+ end
344
+
345
+ #
346
+ # Archives completed envelope.
347
+ #
348
+ # @param [Hash] access Access credentials
349
+ # @option access [String] :client_id
350
+ # @option access [String] :private_key
351
+ #
352
+ def archive!(access = {})
353
+ Api::Request.new do |request|
354
+ request[:access] = access
355
+ request[:method] = :PUT
356
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/archive"
357
+ end.execute!
358
+ end
359
+
360
+ #
361
+ # Restarts expired envelope.
362
+ #
363
+ # @param [Hash] access Access credentials
364
+ # @option access [String] :client_id
365
+ # @option access [String] :private_key
366
+ #
367
+ def restart!(access = {})
368
+ Api::Request.new do |request|
369
+ request[:access] = access
370
+ request[:method] = :PUT
371
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/restart"
372
+ end.execute!
373
+ end
374
+
375
+ end # Signature::Envelope
376
+ end # GroupDocs