active_call 0.2.0 → 0.2.1

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: e129c0113e02eef8e739a830213f343eddb585c6798f4237f127256b1a5ac419
4
- data.tar.gz: 550cdfc7e5285f9dc353003eb570fc89ae1d36d54025af035ab2a4751b61658a
3
+ metadata.gz: d67030b5b5cf7b405b842c1295c33912ebaa2b6ad1aeaefa0807e1a0f4fef105
4
+ data.tar.gz: 6b19ccf7e464102efe1e70ab0501ea6bb3aa8a781880f1492cca1bfeee9de576
5
5
  SHA512:
6
- metadata.gz: 91d837ea7bead55372e4eaf777f84f35ac4ad3a9183633e9bc9042d14cdf26ae02c425a30391ff4dc85116d66d38edb62202fa114c5657c9c5bee60fa02bde83
7
- data.tar.gz: 4025432ebc6ef1dbf2cbe5129b4e235808ab91ded26d192c04b7253bca008423e6d054808e3f774421e86bc42465e005ee0e4bfd26241ab19e685fc6ffc219d2
6
+ metadata.gz: 5b0aea3b486558cd5d81ead4cbc1e75c1ae97f1edef31b3d9ed796b04cdb78e24e6aeda57227ade6c927f7a90599dfe16c06dc8065b98dcbb340db8a27f279e4
7
+ data.tar.gz: 46f8fa215650ff0373ada16c79a7bd3f2f5a73ff8aaea30081a6e59ade1a869ac3aff735c132d87bc3774708ef13c2dc7829d802774b238f6acd74a061589063
data/CHANGELOG.md CHANGED
@@ -1,8 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.1] - 2025-03-25
4
+
5
+ - Gemspec `changelog_uri` fixed.
6
+
3
7
  ## [0.2.0] - 2025-03-20
4
8
 
5
- - Added method `.call!` with a bang, which will raise an `ActiveCall::ValidationError` exception when validation fails and an `ActiveCall::RequestError` exception when errors were added to the service object in the `after_call` callback.
9
+ - Added method `.call!` with a bang, which will raise an `ActiveCall::ValidationError` exception when validation fails and an `ActiveCall::RequestError` exception when errors were added to the service object in the `validate on: :response` block.
6
10
  - Use new method `success?` instead of `valid?`.
7
11
  - Method `valid?` will return `true` if the service object passed validation and was able to make the `call` method.
8
12
  - Use `validate, on: :response` to validate the response object.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Active Call
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/active_call.svg?icon=si%3Arubygems)](https://badge.fury.io/rb/active_call)
4
+
3
5
  Active Call provides a standardized way to create service objects.
4
6
 
5
7
  ## Installation
@@ -49,7 +51,7 @@ Define a service object with optional validations and callbacks.
49
51
  ```ruby
50
52
  require 'active_call'
51
53
 
52
- class YourGemName::SomeResource::CreateService < ActiveCall::Base
54
+ class YourGem::SomeResource::CreateService < ActiveCall::Base
53
55
  attr_reader :message
54
56
 
55
57
  validates :message, presence: true
@@ -82,12 +84,12 @@ class YourGemName::SomeResource::CreateService < ActiveCall::Base
82
84
  end
83
85
  ```
84
86
 
85
- ### Using `.call`
87
+ ### Using `call`
86
88
 
87
89
  You will get an **errors** object when validation fails.
88
90
 
89
91
  ```ruby
90
- service = YourGemName::SomeResource::CreateService.call(message: '')
92
+ service = YourGem::SomeResource::CreateService.call(message: '')
91
93
  service.success? # => false
92
94
  service.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=message, type=blank, options={}>]>
93
95
  service.errors.full_messages # => ["Message can't be blank"]
@@ -97,7 +99,7 @@ service.response # => nil
97
99
  A **response** object on a successful `call` invocation.
98
100
 
99
101
  ```ruby
100
- service = YourGemName::SomeResource::CreateService.call(message: ' bar ')
102
+ service = YourGem::SomeResource::CreateService.call(message: ' bar ')
101
103
  service.success? # => true
102
104
  service.response # => {:foo=>"bar"}
103
105
  ```
@@ -105,20 +107,20 @@ service.response # => {:foo=>"bar"}
105
107
  And an **errors** object if you added errors during the `validate, on: :response` validation.
106
108
 
107
109
  ```ruby
108
- service = YourGemName::SomeResource::CreateService.call(message: 'baz')
110
+ service = YourGem::SomeResource::CreateService.call(message: 'baz')
109
111
  service.success? # => false
110
112
  service.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=message, type=invalid, options={:message=>"cannot be baz"}>]>
111
113
  service.errors.full_messages # => ["Message cannot be baz"]
112
114
  service.response # => {:foo=>"baz"}
113
115
  ```
114
116
 
115
- ### Using `.call!`
117
+ ### Using `call!`
116
118
 
117
119
  An `ActiveCall::ValidationError` **exception** gets raised when validation fails.
118
120
 
119
121
  ```ruby
120
122
  begin
121
- service = YourGemName::SomeResource::CreateService.call!(message: '')
123
+ service = YourGem::SomeResource::CreateService.call!(message: '')
122
124
  rescue ActiveCall::ValidationError => exception
123
125
  exception.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=message, type=blank, options={}>]>
124
126
  exception.errors.full_messages # => ["Message can't be blank"]
@@ -128,7 +130,7 @@ end
128
130
  A **response** object on a successful `call` invocation.
129
131
 
130
132
  ```ruby
131
- service = YourGemName::SomeResource::CreateService.call!(message: ' bar ')
133
+ service = YourGem::SomeResource::CreateService.call!(message: ' bar ')
132
134
  service.success? # => true
133
135
  service.response # => {:foo=>"bar"}
134
136
  ```
@@ -137,7 +139,7 @@ And an `ActiveCall::RequestError` **exception** gets raised if you added errors
137
139
 
138
140
  ```ruby
139
141
  begin
140
- service = YourGemName::SomeResource::CreateService.call!(message: 'baz')
142
+ service = YourGem::SomeResource::CreateService.call!(message: 'baz')
141
143
  rescue ActiveCall::RequestError => exception
142
144
  exception.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=message, type=invalid, options={:message=>"cannot be baz"}>]>
143
145
  exception.errors.full_messages # => ["Message cannot be baz"]
@@ -150,17 +152,17 @@ end
150
152
  If you have secrets, use a **configuration** block.
151
153
 
152
154
  ```ruby
153
- class YourGemName::BaseService < ActiveCall::Base
155
+ class YourGem::BaseService < ActiveCall::Base
154
156
  self.abstract_class = true
155
157
 
156
158
  config_accessor :api_key, default: ENV['API_KEY'], instance_writer: false
157
159
  end
158
160
  ```
159
161
 
160
- Then in your application code you can overwite the configuration defaults.
162
+ Then in your application code you can override the configuration defaults.
161
163
 
162
164
  ```ruby
163
- YourGemName::BaseService.configure do |config|
165
+ YourGem::BaseService.configure do |config|
164
166
  config.api_key = Rails.application.credentials.api_key || ENV['API_KEY']
165
167
  end
166
168
  ```
@@ -170,7 +172,7 @@ And implement a service object like so.
170
172
  ```ruby
171
173
  require 'net/http'
172
174
 
173
- class YourGemName::SomeResource::CreateService < YourGemName::BaseService
175
+ class YourGem::SomeResource::CreateService < YourGem::BaseService
174
176
  def call
175
177
  Net::HTTP.get_response(URI("http://example.com/api?#{URI.encode_www_form(api_key: api_key)}"))
176
178
  end
@@ -201,6 +203,7 @@ Now start adding your service objects in the `lib` directory and make sure they
201
203
 
202
204
  ## Gems Using Active Call
203
205
 
206
+ - [nCino KYC DocFox](https://github.com/kobusjoubert/doc_fox)
204
207
  - [Zoho Sign](https://github.com/kobusjoubert/zoho_sign)
205
208
 
206
209
  ## Development
@@ -14,13 +14,13 @@ class ActiveCall::Base
14
14
  # Abstract classes are not meant to be instantiated directly, but rather inherited from.
15
15
  # The `call` method doesn't need to be implemented in abstract classes.
16
16
  #
17
- # Example:
17
+ # ==== Examples
18
18
  #
19
- # class YourGemName::BaseService < ActiveCall::Base
19
+ # class YourGem::BaseService < ActiveCall::Base
20
20
  # self.abstract_class = true
21
21
  # end
22
22
  #
23
- # class YourGemName::SomeResource::CreateService < YourGemName::BaseService
23
+ # class YourGem::SomeResource::CreateService < YourGem::BaseService
24
24
  # def call
25
25
  # # Implementation specific to this service.
26
26
  # end
@@ -33,6 +33,33 @@ class ActiveCall::Base
33
33
  end
34
34
 
35
35
  # TODO: Refactor `call` and `call!`. The only differences are the two lines raising exceptions.
36
+
37
+ # Using `call`
38
+ #
39
+ # ==== Examples
40
+ #
41
+ # You will get an `errors` object when validation fails.
42
+ #
43
+ # service = YourGem::SomeResource::CreateService.call(message: '')
44
+ # service.success? # => false
45
+ # service.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=message, type=blank, options={}>]>
46
+ # service.errors.full_messages # => ["Message can't be blank"]
47
+ # service.response # => nil
48
+ #
49
+ # A `response` object on a successful `call` invocation.
50
+ #
51
+ # service = YourGem::SomeResource::CreateService.call(message: ' bar ')
52
+ # service.success? # => true
53
+ # service.response # => {:foo=>"bar"}
54
+ #
55
+ # And an `errors` object if you added errors during the `validate, on: :response` validation.
56
+ #
57
+ # service = YourGem::SomeResource::CreateService.call(message: 'baz')
58
+ # service.success? # => false
59
+ # service.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=message, type=invalid, options={:message=>"cannot be baz"}>]>
60
+ # service.errors.full_messages # => ["Message cannot be baz"]
61
+ # service.response # => {:foo=>"baz"}
62
+ #
36
63
  def call(...)
37
64
  service_object = new(...)
38
65
  service_object.instance_variable_set(:@bang, false)
@@ -50,6 +77,36 @@ class ActiveCall::Base
50
77
  service_object
51
78
  end
52
79
 
80
+ # Using `call!`
81
+ #
82
+ # ==== Examples
83
+ #
84
+ # An `ActiveCall::ValidationError` exception gets raised when validation fails.
85
+ #
86
+ # begin
87
+ # service = YourGem::SomeResource::CreateService.call!(message: '')
88
+ # rescue ActiveCall::ValidationError => exception
89
+ # exception.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=message, type=blank, options={}>]>
90
+ # exception.errors.full_messages # => ["Message can't be blank"]
91
+ # end
92
+ #
93
+ # A `response` object on a successful `call` invocation.
94
+ #
95
+ # service = YourGem::SomeResource::CreateService.call!(message: ' bar ')
96
+ # service.success? # => true
97
+ # service.response # => {:foo=>"bar"}
98
+ #
99
+ # And an `ActiveCall::RequestError` exception gets raised if you added errors during the `validate, on: :response`
100
+ # validation.
101
+ #
102
+ # begin
103
+ # service = YourGem::SomeResource::CreateService.call!(message: 'baz')
104
+ # rescue ActiveCall::RequestError => exception
105
+ # exception.errors # => #<ActiveModel::Errors [#<ActiveModel::Error attribute=message, type=invalid, options={:message=>"cannot be baz"}>]>
106
+ # exception.errors.full_messages # => ["Message cannot be baz"]
107
+ # exception.response # => {:foo=>"baz"}
108
+ # end
109
+ #
53
110
  def call!(...)
54
111
  service_object = new(...)
55
112
  service_object.instance_variable_set(:@bang, true)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveCall
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_call
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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-20 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: activemodel
@@ -66,7 +66,7 @@ metadata:
66
66
  rubygems_mfa_required: 'true'
67
67
  homepage_uri: https://github.com/kobusjoubert/active_call
68
68
  source_code_uri: https://github.com/kobusjoubert/active_call
69
- changelog_uri: https://github.com/kobusjoubert/active_call/CHANGELOG.md
69
+ changelog_uri: https://github.com/kobusjoubert/active_call/blob/main/CHANGELOG.md
70
70
  post_install_message:
71
71
  rdoc_options: []
72
72
  require_paths: