active_call-zoho_sign 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 216f81e67c69376d2180d986456d6fdd043680d4429bd5f0838446c1e64ec706
4
- data.tar.gz: 2939c3d9638842cfe9d8231f6271b08291c66a674960efd78a1d4304d7a61509
3
+ metadata.gz: 4e6bfddd2811ee821c10b0f03e640a1d5bd61fce4a1f55e710d94284c4428013
4
+ data.tar.gz: 31222714f42fa31b5a8c90c59b1eae1e7f3e10103b3aac99e6ee3899d445c3ed
5
5
  SHA512:
6
- metadata.gz: ca0380d7b312f9e9ce1d4b840eb3d891ebad7300337569a001618a7db9168c1a74a14f92e381e38836062cc4b094fa7a65776befaaf1bd5883454dd84ad0326e
7
- data.tar.gz: 456f26fd3ec6e59966dc633126030800c8196a87d3c2d418b86a9601801781012d2606cb216b76692fc6a5083cf72d911ed78b54f43aeefc2300b7349ff3dc31
6
+ metadata.gz: f0da06b096bad4445ba1985194968119a4c320d961fd9d70dce91efa80206677b0cbd718608e9acfc03f15114de2255509d2d8b7f5863095aecff511566193d5
7
+ data.tar.gz: 46054e1c662f60ce7fe651dfc41bdbe3dc50f4009d94e2871c91230c8ac493e5600e63cae1b038332444759258a064aa3210336d8777485295a9da49acb17a2f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.2] - 2025-03-25
4
+
5
+ - Refactored common REST API methods out into an active_call-api gem.
6
+
3
7
  ## [0.1.1] - 2025-03-22
4
8
 
5
9
  - Add gem install instructions.
data/README.md CHANGED
@@ -4,8 +4,6 @@ Zoho Sign exposes the [Zoho Sign API](https://www.zoho.com/sign/api) endpoints t
4
4
 
5
5
  ## Installation
6
6
 
7
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
-
9
7
  Install the gem and add to the application's Gemfile by executing:
10
8
 
11
9
  ```bash
@@ -1,24 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ZohoSign::BaseService < ActiveCall::Base
4
+ include ActiveCall::Api
5
+
4
6
  self.abstract_class = true
5
7
 
6
8
  CACHE_KEY = { access_token: 'zoho_sign/base_service/access_token' }.freeze
7
9
 
8
- EXCEPTION_MAPPING = {
9
- bad_request: ZohoSign::BadRequestError,
10
- unauthorized: ZohoSign::UnauthorizedError,
11
- forbidden: ZohoSign::ForbiddenError,
12
- not_found: ZohoSign::NotFoundError,
13
- proxy_authentication_required: ZohoSign::ProxyAuthenticationRequiredError,
14
- request_timeout: ZohoSign::RequestTimeoutError,
15
- conflict: ZohoSign::ConflictError,
16
- unprocessable_entity: ZohoSign::UnprocessableEntityError,
17
- too_many_requests: ZohoSign::TooManyRequestsError,
18
- client_error: ZohoSign::ClientError,
19
- server_error: ZohoSign::ServerError
20
- }.freeze
21
-
22
10
  config_accessor :base_url, default: 'https://sign.zoho.com/api/v1', instance_writer: false
23
11
  config_accessor :cache, default: ActiveSupport::Cache::MemoryStore.new, instance_writer: false
24
12
  config_accessor :logger, default: Logger.new($stdout), instance_writer: false
@@ -29,60 +17,34 @@ class ZohoSign::BaseService < ActiveCall::Base
29
17
 
30
18
  attr_reader :facade
31
19
 
32
- validate on: :response do
33
- throw :abort if response.is_a?(Enumerable)
34
-
35
- errors.add(:base, :server_error) and throw :abort if response.status >= 500
36
-
37
- errors.add(:base, :unauthorized) and throw :abort if unauthorized?
38
- errors.add(:base, :forbidden) and throw :abort if forbidden?
39
- errors.add(:base, :not_found) and throw :abort if not_found?
40
- errors.add(:base, :proxy_authentication_required) and throw :abort if proxy_authentication_required?
41
- errors.add(:base, :request_timeout) and throw :abort if request_timeout?
42
- errors.add(:base, :conflict) and throw :abort if conflict?
43
- errors.add(:base, :unprocessable_entity) and throw :abort if unprocessable_entity?
44
- errors.add(:base, :too_many_requests) and throw :abort if too_many_requests?
45
-
46
- # Check for bad_request here since too_many_requests also has a status of 400.
47
- errors.add(:base, :bad_request) and throw :abort if bad_request?
48
-
49
- # We'll use client_error for everything else that we don't have an explicit exception class for.
50
- errors.add(:base, :client_error) and throw :abort if response.status >= 400
51
- end
52
-
53
20
  class << self
54
- def call!(...)
55
- super
56
- rescue ActiveCall::ValidationError => e
57
- raise zoho_sign_validation_error(e)
58
- rescue ActiveCall::RequestError => e
59
- raise zoho_sign_request_error(e)
60
- end
61
-
62
- def zoho_sign_validation_error(exception)
63
- ZohoSign::ValidationError.new(exception.errors, exception.message)
64
- end
65
-
66
- def zoho_sign_request_error(exception)
67
- exception_for(exception.response, exception.errors, exception.message)
68
- end
69
-
70
- def exception_for(response, errors, message = nil)
71
- exception_type = errors.details[:base].first[:error]
72
-
73
- case exception_type
74
- when *EXCEPTION_MAPPING.keys
75
- EXCEPTION_MAPPING[exception_type].new(response, errors, message)
76
- else
77
- ZohoSign::RequestError.new(response, errors, message)
78
- end
21
+ def exception_mapping
22
+ {
23
+ validation_error: ZohoSign::ValidationError,
24
+ request_error: ZohoSign::RequestError,
25
+ client_error: ZohoSign::ClientError,
26
+ server_error: ZohoSign::ServerError,
27
+ bad_request: ZohoSign::BadRequestError,
28
+ unauthorized: ZohoSign::UnauthorizedError,
29
+ forbidden: ZohoSign::ForbiddenError,
30
+ not_found: ZohoSign::NotFoundError,
31
+ not_acceptable: ZohoSign::NotAcceptableError,
32
+ proxy_authentication_required: ZohoSign::ProxyAuthenticationRequiredError,
33
+ request_timeout: ZohoSign::RequestTimeoutError,
34
+ conflict: ZohoSign::ConflictError,
35
+ unprocessable_entity: ZohoSign::UnprocessableEntityError,
36
+ too_many_requests: ZohoSign::TooManyRequestsError,
37
+ internal_server_error: ZohoSign::InternalServerError,
38
+ not_implemented: ZohoSign::NotImplementedError,
39
+ bad_gateway: ZohoSign::BadGatewayError,
40
+ service_unavailable: ZohoSign::ServiceUnavailableError,
41
+ gateway_timeout: ZohoSign::GatewayTimeoutError
42
+ }.freeze
79
43
  end
80
44
  end
81
45
 
82
46
  private
83
47
 
84
- delegate :exception_for, to: :class
85
-
86
48
  def connection
87
49
  @_connection ||= Faraday.new do |conn|
88
50
  conn.url_prefix = base_url
@@ -115,14 +77,6 @@ class ZohoSign::BaseService < ActiveCall::Base
115
77
  cache.fetch(CACHE_KEY[:access_token], expires_in: [service.expires_in - 10, 0].max) { service.facade.access_token }
116
78
  end
117
79
 
118
- def bad_request?
119
- response.status == 400
120
- end
121
-
122
- def unauthorized?
123
- response.status == 401
124
- end
125
-
126
80
  def forbidden?
127
81
  response.status == 403
128
82
  return false unless response.status == 400 && response.body.key?('code')
@@ -144,21 +98,6 @@ class ZohoSign::BaseService < ActiveCall::Base
144
98
  false
145
99
  end
146
100
 
147
- # TODO: Confirm.
148
- def proxy_authentication_required?
149
- response.status == 407
150
- end
151
-
152
- # TODO: Confirm.
153
- def request_timeout?
154
- response.status == 408
155
- end
156
-
157
- # TODO: Confirm.
158
- def conflict?
159
- response.status == 409
160
- end
161
-
162
101
  def unprocessable_entity?
163
102
  return true if response.status == 422
164
103
  return false unless response.status == 400 && response.body.key?('code')
@@ -26,6 +26,9 @@ module ZohoSign
26
26
  # 404
27
27
  class NotFoundError < ClientError; end
28
28
 
29
+ # 406
30
+ class NotAcceptableError < ClientError; end
31
+
29
32
  # 407
30
33
  class ProxyAuthenticationRequiredError < ClientError; end
31
34
 
@@ -43,4 +46,19 @@ module ZohoSign
43
46
 
44
47
  # 500..599
45
48
  class ServerError < RequestError; end
49
+
50
+ # 500
51
+ class InternalServerError < ServerError; end
52
+
53
+ # 501
54
+ class NotImplementedError < ServerError; end
55
+
56
+ # 502
57
+ class BadGatewayError < ServerError; end
58
+
59
+ # 503
60
+ class ServiceUnavailableError < ServerError; end
61
+
62
+ # 504
63
+ class GatewayTimeoutError < ServerError; end
46
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZohoSign
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/zoho_sign.rb CHANGED
@@ -1,11 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_call'
4
- require 'faraday'
5
- require 'faraday/retry'
4
+ require 'active_call/api'
6
5
  require 'faraday/multipart'
7
- require 'faraday/logging/color_formatter'
8
- require 'zeitwerk'
9
6
 
10
7
  loader = Zeitwerk::Loader.for_gem
11
8
  loader.ignore("#{__dir__}/active_call-zoho_sign.rb")
@@ -17,7 +14,3 @@ require_relative 'zoho_sign/error'
17
14
  require_relative 'zoho_sign/version'
18
15
 
19
16
  module ZohoSign; end
20
-
21
- ActiveSupport.on_load(:i18n) do
22
- I18n.load_path << File.expand_path('zoho_sign/locale/en.yml', __dir__)
23
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_call-zoho_sign
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kobus Joubert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-22 00:00:00.000000000 Z
11
+ date: 2025-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_call
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: active_call-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: faraday
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +123,6 @@ files:
109
123
  - lib/zoho_sign/document/list_service.rb
110
124
  - lib/zoho_sign/document/update_service.rb
111
125
  - lib/zoho_sign/error.rb
112
- - lib/zoho_sign/locale/en.yml
113
126
  - lib/zoho_sign/template/document/create_service.rb
114
127
  - lib/zoho_sign/template/document/facade.rb
115
128
  - lib/zoho_sign/template/facade.rb
@@ -125,7 +138,7 @@ metadata:
125
138
  rubygems_mfa_required: 'true'
126
139
  homepage_uri: https://github.com/kobusjoubert/zoho_sign
127
140
  source_code_uri: https://github.com/kobusjoubert/zoho_sign
128
- changelog_uri: https://github.com/kobusjoubert/zoho_sign/CHANGELOG.md
141
+ changelog_uri: https://github.com/kobusjoubert/zoho_sign/blob/main/CHANGELOG.md
129
142
  post_install_message:
130
143
  rdoc_options: []
131
144
  require_paths:
@@ -1,18 +0,0 @@
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'