active_call-zoho_sign 0.1.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.
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ZohoSign::Document::UpdateService < ZohoSign::BaseService
4
+ attr_reader :id, :data
5
+
6
+ validates :id, :data, presence: true
7
+
8
+ after_call :set_facade
9
+
10
+ delegate_missing_to :@facade
11
+
12
+ def initialize(id:, data:)
13
+ @id = id
14
+ @data = data
15
+ end
16
+
17
+ # Update a document.
18
+ #
19
+ # ==== Examples
20
+ #
21
+ # service = ZohoSign::Document::UpdateService.call(
22
+ # id: '',
23
+ # data: {
24
+ # requests: {
25
+ # request_name: 'Name Updated',
26
+ # actions: [{
27
+ # action_id: '',
28
+ # action_type: 'SIGN',
29
+ # recipient_email: 'stan.marsh@example.com',
30
+ # recipient_name: 'Stan Marsh'
31
+ # }]
32
+ # }
33
+ # }
34
+ # )
35
+ #
36
+ # service.success? # => true
37
+ # service.errors # => #<ActiveModel::Errors []>
38
+ #
39
+ # service.response # => #<Faraday::Response ...>
40
+ # service.response.status # => 200
41
+ # service.response.body # => {}
42
+ #
43
+ # service.facade # => #<ZohoSign::Document::Facade ...>
44
+ # service.facade.request_name
45
+ # service.request_name
46
+ #
47
+ # PUT /api/v1/requests/:id
48
+ def call
49
+ connection.put("requests/#{id}", **params)
50
+ end
51
+
52
+ private
53
+
54
+ def params
55
+ {
56
+ data: data.to_json
57
+ }
58
+ end
59
+
60
+ def set_facade
61
+ @facade = ZohoSign::Document::Facade.new(response.body['requests'])
62
+ end
63
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoSign
4
+ class Error < StandardError; end
5
+
6
+ class ValidationError < Error
7
+ include ActiveCall::ValidationErrorable
8
+ end
9
+
10
+ class RequestError < Error
11
+ include ActiveCall::RequestErrorable
12
+ end
13
+
14
+ # 400..499
15
+ class ClientError < RequestError; end
16
+
17
+ # 400
18
+ class BadRequestError < ClientError; end
19
+
20
+ # 401
21
+ class UnauthorizedError < ClientError; end
22
+
23
+ # 403
24
+ class ForbiddenError < ClientError; end
25
+
26
+ # 404
27
+ class NotFoundError < ClientError; end
28
+
29
+ # 407
30
+ class ProxyAuthenticationRequiredError < ClientError; end
31
+
32
+ # 408
33
+ class RequestTimeoutError < ClientError; end
34
+
35
+ # 409
36
+ class ConflictError < ClientError; end
37
+
38
+ # 422
39
+ class UnprocessableEntityError < ClientError; end
40
+
41
+ # 429
42
+ class TooManyRequestsError < ClientError; end
43
+
44
+ # 500..599
45
+ class ServerError < RequestError; end
46
+ end
@@ -0,0 +1,18 @@
1
+ en:
2
+ activemodel:
3
+ errors:
4
+ # The values :model, :attribute and :value are always available for interpolation.
5
+ # The value :count is available when applicable. Can be used for pluralization.
6
+ models:
7
+ zoho_sign/base_service:
8
+ bad_request: 'Bad Request'
9
+ client_error: 'Client Error'
10
+ conflict: 'Conflict'
11
+ forbidden: 'Forbidden'
12
+ not_found: 'Not Found'
13
+ proxy_authentication_required: 'Proxy Authentication Required'
14
+ request_timeout: 'Request Timeout'
15
+ server_error: 'Server Error'
16
+ too_many_requests: 'Too Many Requests'
17
+ unauthorized: 'Unauthorized'
18
+ unprocessable_entity: 'Unprocessable Entity'
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ZohoSign::Template::Document::CreateService < ZohoSign::BaseService
4
+ attr_reader :id, :data, :is_quicksend
5
+
6
+ validates :id, :data, presence: true
7
+ validates :is_quicksend, inclusion: { in: [true, false] }
8
+
9
+ after_call :set_facade
10
+
11
+ delegate_missing_to :@facade
12
+
13
+ def initialize(id:, data:, is_quicksend: false)
14
+ @id = id
15
+ @data = data
16
+ @is_quicksend = is_quicksend
17
+ end
18
+
19
+ # Create a document from a template.
20
+ #
21
+ # ==== Examples
22
+ #
23
+ # service = ZohoSign::Template::Document::CreateService.call!(
24
+ # id: '',
25
+ # is_quicksend: true,
26
+ # data: {
27
+ # templates: {
28
+ # request_name: 'Request Document',
29
+ # field_data: {
30
+ # field_text_data: {
31
+ # 'Full name' => 'Eric Cartman',
32
+ # 'Email' => 'eric.cartman@example.com'
33
+ # },
34
+ # field_boolean_data: {
35
+ # 'Agreed to terms' => true
36
+ # },
37
+ # field_date_data: {
38
+ # 'Inception date' => '31/01/2025'
39
+ # }
40
+ # },
41
+ # actions: [{
42
+ # action_type: 'SIGN',
43
+ # recipient_email: 'eric.cartman@example.com',
44
+ # recipient_name: 'Eric Cartman',
45
+ # verify_recipient: false,
46
+ # delivery_mode: 'EMAIL',
47
+ # action_id: '',
48
+ # role: 'Client'
49
+ # }]
50
+ # }
51
+ # }
52
+ # )
53
+ #
54
+ # service.success? # => true
55
+ # service.errors # => #<ActiveModel::Errors []>
56
+ #
57
+ # service.response # => #<Faraday::Response ...>
58
+ # service.response.status # => 200
59
+ # service.response.body # => {}
60
+ #
61
+ # service.facade # => #<ZohoSign::Temlate::Document::Facade ...>
62
+ # service.facade.request_name
63
+ # service.request_name
64
+ #
65
+ # POST /api/v1/templates/:id/createdocument
66
+ def call
67
+ connection.post("templates/#{id}/createdocument", **params)
68
+ end
69
+
70
+ private
71
+
72
+ def params
73
+ {
74
+ data: data.to_json,
75
+ is_quicksend: is_quicksend
76
+ }
77
+ end
78
+
79
+ def set_facade
80
+ @facade = ZohoSign::Template::Document::Facade.new(response.body['requests'])
81
+ end
82
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ZohoSign::Template::Document::Facade
4
+ attr_reader :action_time, :actions, :created_time, :description, :document_fields, :document_ids, :email_reminders,
5
+ :expiration_days, :expire_by, :folder_id, :folder_name, :in_process, :is_deleted, :is_expiring, :is_sequential,
6
+ :modified_time, :notes, :owner_email, :owner_first_name, :owner_id, :owner_last_name, :reminder_period, :request_id,
7
+ :request_name, :request_status, :request_type_id, :request_type_name, :self_sign, :sign_percentage,
8
+ :sign_submitted_time, :template_ids, :templates_used, :validity, :visible_sign_settings, :zsdocumentid
9
+
10
+ def initialize(hash)
11
+ @action_time = hash['action_time']
12
+ @actions = hash['actions']
13
+ @created_time = hash['created_time']
14
+ @description = hash['description']
15
+ @document_fields = hash['document_fields']
16
+ @document_ids = hash['document_ids']
17
+ @email_reminders = hash['email_reminders']
18
+ @expiration_days = hash['expiration_days']
19
+ @expire_by = hash['expire_by']
20
+ @folder_id = hash['folder_id']
21
+ @folder_name = hash['folder_name']
22
+ @in_process = hash['in_process']
23
+ @is_deleted = hash['is_deleted']
24
+ @is_expiring = hash['is_expiring']
25
+ @is_sequential = hash['is_sequential']
26
+ @modified_time = hash['modified_time']
27
+ @notes = hash['notes']
28
+ @owner_email = hash['owner_email']
29
+ @owner_first_name = hash['owner_first_name']
30
+ @owner_id = hash['owner_id']
31
+ @owner_last_name = hash['owner_last_name']
32
+ @reminder_period = hash['reminder_period']
33
+ @request_id = hash['request_id']
34
+ @request_name = hash['request_name']
35
+ @request_status = hash['request_status']
36
+ @request_type_id = hash['request_type_id']
37
+ @request_type_name = hash['request_type_name']
38
+ @self_sign = hash['self_sign']
39
+ @sign_percentage = hash['sign_percentage']
40
+ @sign_submitted_time = hash['sign_submitted_time']
41
+ @template_ids = hash['template_ids']
42
+ @templates_used = hash['templates_used']
43
+ @validity = hash['validity']
44
+ @visible_sign_settings = hash['visible_sign_settings']
45
+ @zsdocumentid = hash['zsdocumentid']
46
+ end
47
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ZohoSign::Template::Facade
4
+ attr_reader :actions, :created_time, :description, :document_ids, :document_fields, :email_reminders,
5
+ :expiration_days, :folder_id, :folder_name, :is_deleted, :is_sequential, :modified_time, :notes, :owner_email,
6
+ :owner_first_name, :owner_id, :owner_last_name, :reminder_period, :request_type_id, :request_type_name,
7
+ :signform_count, :template_id, :template_name, :validity
8
+
9
+ def initialize(hash)
10
+ @actions = hash['actions']
11
+ @created_time = hash['created_time']
12
+ @description = hash['description']
13
+ @document_fields = hash['document_fields']
14
+ @document_ids = hash['document_ids']
15
+ @email_reminders = hash['email_reminders']
16
+ @expiration_days = hash['expiration_days']
17
+ @folder_id = hash['folder_id']
18
+ @folder_name = hash['folder_name']
19
+ @is_deleted = hash['is_deleted']
20
+ @is_sequential = hash['is_sequential']
21
+ @modified_time = hash['modified_time']
22
+ @notes = hash['notes']
23
+ @owner_email = hash['owner_email']
24
+ @owner_first_name = hash['owner_first_name']
25
+ @owner_id = hash['owner_id']
26
+ @owner_last_name = hash['owner_last_name']
27
+ @reminder_period = hash['reminder_period']
28
+ @request_type_id = hash['request_type_id']
29
+ @request_type_name = hash['request_type_name']
30
+ @signform_count = hash['signform_count']
31
+ @template_id = hash['template_id']
32
+ @template_name = hash['template_name']
33
+ @validity = hash['validity']
34
+ end
35
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ZohoSign::Template::GetService < ZohoSign::BaseService
4
+ attr_reader :id
5
+
6
+ after_call :set_facade
7
+
8
+ delegate_missing_to :@facade
9
+
10
+ validates :id, presence: true
11
+
12
+ def initialize(id: nil)
13
+ @id = id
14
+ end
15
+
16
+ # Get a document.
17
+ #
18
+ # ==== Examples
19
+ #
20
+ # service = ZohoSign::Template::GetService.call(id: '')
21
+ #
22
+ # service.success? # => true
23
+ # service.errors # => #<ActiveModel::Errors []>
24
+ #
25
+ # service.response # => #<Faraday::Response ...>
26
+ # service.response.status # => 200
27
+ # service.response.body # => {}
28
+ #
29
+ # service.facade # => #<ZohoSign::Template::Facade ...>
30
+ # service.facade.template_name
31
+ # service.template_name
32
+ #
33
+ # GET /api/v1/templates/:id
34
+ def call
35
+ connection.get("templates/#{id}")
36
+ end
37
+
38
+ private
39
+
40
+ def set_facade
41
+ @facade = ZohoSign::Template::Facade.new(response.body['templates'])
42
+ end
43
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ZohoSign::Template::ListService < ZohoSign::BaseService
4
+ SORT_COLUMNS = %w[template_name owner_first_name modified_time].freeze
5
+ SORT_ORDERS = %w[ASC DESC].freeze
6
+
7
+ include Enumerable
8
+
9
+ attr_reader :limit, :offset, :sort_column, :sort_order, :search_columns
10
+
11
+ validates :limit, presence: true, numericality: { greater_than_or_equal_to: 1 }
12
+ validates :sort_order, inclusion: { in: SORT_ORDERS, message: "Sort order must be one of #{SORT_ORDERS.join(', ')}" }
13
+
14
+ validates :sort_column, inclusion: {
15
+ in: SORT_COLUMNS,
16
+ message: "Sort column must be one of #{SORT_COLUMNS.join(', ')}"
17
+ }
18
+
19
+ validate do
20
+ next if search_columns.empty?
21
+ next if (SORT_COLUMNS | search_columns.keys.map(&:to_s)).size == SORT_COLUMNS.size
22
+
23
+ errors.add(:search_columns, "keys must be one of #{SORT_COLUMNS.join(', ')}")
24
+ throw :abort
25
+ end
26
+
27
+ def initialize(limit: Float::INFINITY, offset: 1, sort_column: 'template_name', sort_order: 'DESC', search_columns: {})
28
+ @limit = limit
29
+ @offset = offset
30
+ @sort_column = sort_column
31
+ @sort_order = sort_order
32
+ @search_columns = search_columns
33
+ end
34
+
35
+ # List documents.
36
+ #
37
+ # ==== Examples
38
+ #
39
+ # service = ZohoSign::Template::ListService.call.first
40
+ # service.request_name
41
+ #
42
+ # ZohoSign::Template::ListService.call(offset: 11, limit: 10).each { _1 }
43
+ # ZohoSign::Template::ListService.call(sort_column: 'template_name', sort_order: 'ASC').each { _1 }
44
+ # ZohoSign::Template::ListService.call(search_columns: { template_name: 'Eric Template' }).each { _1 }
45
+ #
46
+ # GET /api/v1/templates
47
+ def call
48
+ self
49
+ end
50
+
51
+ def each
52
+ return to_enum(:each) unless block_given?
53
+ return if invalid?
54
+
55
+ total = 0
56
+
57
+ catch :list_end do
58
+ loop do
59
+ @response = connection.get('templates', data: params.to_json)
60
+ validate(:response)
61
+
62
+ unless success?
63
+ raise exception_for(response, errors) if bang?
64
+
65
+ throw :list_end
66
+ end
67
+
68
+ response.body['templates'].each do |hash|
69
+ yield ZohoSign::Template::Facade.new(hash)
70
+ total += 1
71
+ throw :list_end if total >= limit
72
+ end
73
+
74
+ break unless response.body.dig('page_context', 'has_more_rows')
75
+
76
+ @_params[:page_context][:start_index] += max_limit_per_request
77
+ end
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def params
84
+ @_params ||= {
85
+ page_context: {
86
+ row_count: max_limit_per_request,
87
+ start_index: offset,
88
+ search_columns: search_columns,
89
+ sort_column: sort_column,
90
+ sort_order: sort_order
91
+ }
92
+ }
93
+ end
94
+
95
+ def max_limit_per_request
96
+ @_max_limit_per_request ||= limit.infinite? ? 100 : [limit, 100].min
97
+ end
98
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoSign
4
+ VERSION = '0.1.0'
5
+ end
data/lib/zoho_sign.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_call'
4
+ require 'faraday'
5
+ require 'faraday/retry'
6
+ require 'faraday/multipart'
7
+ require 'faraday/logging/color_formatter'
8
+ require 'zeitwerk'
9
+
10
+ loader = Zeitwerk::Loader.for_gem
11
+ loader.ignore("#{__dir__}/zoho_sign/error.rb")
12
+ loader.collapse("#{__dir__}/zoho_sign/concerns")
13
+ loader.setup
14
+
15
+ require_relative 'zoho_sign/error'
16
+ require_relative 'zoho_sign/version'
17
+
18
+ module ZohoSign; end
19
+
20
+ ActiveSupport.on_load(:i18n) do
21
+ I18n.load_path << File.expand_path('zoho_sign/locale/en.yml', __dir__)
22
+ end
data/sig/zoho_sign.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module ZohoSign
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_call-zoho_sign
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kobus Joubert
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active_call
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday-retry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday-multipart
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday-logging-color_formatter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
83
+ description: Zoho Sign exposes the Zoho Sign API endpoints through service objects.
84
+ email:
85
+ - kobus@translate3d.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".rspec"
91
+ - ".rubocop.yml"
92
+ - CHANGELOG.md
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/zoho_sign.rb
97
+ - lib/zoho_sign/access_token/facade.rb
98
+ - lib/zoho_sign/access_token/get_service.rb
99
+ - lib/zoho_sign/base_service.rb
100
+ - lib/zoho_sign/current_user/facade.rb
101
+ - lib/zoho_sign/current_user/get_service.rb
102
+ - lib/zoho_sign/document/action/embed_token/facade.rb
103
+ - lib/zoho_sign/document/action/embed_token/get_service.rb
104
+ - lib/zoho_sign/document/create_service.rb
105
+ - lib/zoho_sign/document/delete_service.rb
106
+ - lib/zoho_sign/document/facade.rb
107
+ - lib/zoho_sign/document/get_service.rb
108
+ - lib/zoho_sign/document/list_service.rb
109
+ - lib/zoho_sign/document/update_service.rb
110
+ - lib/zoho_sign/error.rb
111
+ - lib/zoho_sign/locale/en.yml
112
+ - lib/zoho_sign/template/document/create_service.rb
113
+ - lib/zoho_sign/template/document/facade.rb
114
+ - lib/zoho_sign/template/facade.rb
115
+ - lib/zoho_sign/template/get_service.rb
116
+ - lib/zoho_sign/template/list_service.rb
117
+ - lib/zoho_sign/version.rb
118
+ - sig/zoho_sign.rbs
119
+ homepage: https://github.com/kobusjoubert/zoho_sign
120
+ licenses:
121
+ - MIT
122
+ metadata:
123
+ allowed_push_host: https://rubygems.org
124
+ rubygems_mfa_required: 'true'
125
+ homepage_uri: https://github.com/kobusjoubert/zoho_sign
126
+ source_code_uri: https://github.com/kobusjoubert/zoho_sign
127
+ changelog_uri: https://github.com/kobusjoubert/zoho_sign/CHANGELOG.md
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 3.1.0
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubygems_version: 3.3.27
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Zoho Sign
147
+ test_files: []