ovh-http2sms 0.1.0 → 0.1.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: 7cab24237194aeab0d46e5b7d5bde5679ddca4018ec7f61c47e4bb01e58c7971
4
- data.tar.gz: 15ee708e4911827648e2f3f221029b510c2eedf694fd7e4bac34dcd9add7b8ba
3
+ metadata.gz: 379778cdfb0ec7db8c02be8d631383b38dbb2ed134146ad519161b71e53f7fe5
4
+ data.tar.gz: d98a196b6193e12001b82a3ca671ab675baabaff8557e8f9d0cd5f6e03930a93
5
5
  SHA512:
6
- metadata.gz: 232378bd0d9f850989b6c608b1c90b0c1399870f920fb2faf5aaad288b92025b1e099d4bf0a73c903f7245c647c465be6b933dbcf12e7b07a054356db01cce75
7
- data.tar.gz: ad6bc71528908dd2ebf9985efa2d6f7d3d720811f1d52624ab9f50311b23df43f2296d949e1110115be1f7e52cf4b0dc972a8ceb81adeca6598d150a2f786f17
6
+ metadata.gz: 72e97574d9d71b27ca7757811cf448977064edd4f5aa92e9d994e39f951f098e1e7ab0dd0158841e8cc0af4f435c8d77f870ef71dc9624bc31650c44df14eb82
7
+ data.tar.gz: 70181b9b726da29c98914681f75e037328b9bb7d2094b76b7698d11eaf97f498a0d2aef84037ce67eaac41432e078aa6b117b0f5e97879af518372a158dcd985
data/CHANGELOG.md CHANGED
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.1] - 2025-01-29
11
+
12
+ ### Added
13
+
14
+ - Request lifecycle callbacks for monitoring and metrics:
15
+ - `before_request`: called before each API request with filtered params
16
+ - `after_request`: called after each request with response
17
+ - `on_success`: called on successful SMS delivery
18
+ - `on_failure`: called on failed delivery
19
+ - Dependabot configuration for automated dependency updates
20
+ - Community contribution files:
21
+ - `CONTRIBUTING.md` with development guidelines
22
+ - Pull request template
23
+ - Issue templates for bugs and feature requests
24
+ - `SenderNotFoundError` exception for status 241
25
+ - `ResponseParseError` exception for malformed responses
26
+
27
+ ### Changed
28
+
29
+ - Improved error handling with more specific exception types
30
+
10
31
  ## [0.1.0] - 2025-01-28
11
32
 
12
33
  ### Added
@@ -46,5 +67,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
46
67
  - Faraday >= 1.0, < 3.0
47
68
  - gsm_encoder ~> 0.1.7
48
69
 
49
- [Unreleased]: https://github.com/fkiene/ovh-http2sms/compare/v0.1.0...HEAD
70
+ [Unreleased]: https://github.com/fkiene/ovh-http2sms/compare/v0.1.1...HEAD
71
+ [0.1.1]: https://github.com/fkiene/ovh-http2sms/compare/v0.1.0...v0.1.1
50
72
  [0.1.0]: https://github.com/fkiene/ovh-http2sms/releases/tag/v0.1.0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,90 @@
1
+ # Contributing to OVH HTTP2SMS
2
+
3
+ Thank you for your interest in contributing! This document provides guidelines for contributing to the project.
4
+
5
+ ## Getting Started
6
+
7
+ 1. Fork the repository
8
+ 2. Clone your fork locally
9
+ 3. Set up the development environment:
10
+
11
+ ```bash
12
+ # With Docker (recommended)
13
+ docker compose run --rm dev
14
+
15
+ # Without Docker
16
+ bin/setup
17
+ ```
18
+
19
+ ## Development Workflow
20
+
21
+ ### Running Tests
22
+
23
+ ```bash
24
+ # With Docker
25
+ docker compose run --rm test
26
+
27
+ # Without Docker
28
+ bundle exec rspec
29
+ ```
30
+
31
+ ### Running Linter
32
+
33
+ ```bash
34
+ # With Docker
35
+ docker compose run --rm lint
36
+
37
+ # Without Docker
38
+ bundle exec rubocop
39
+ ```
40
+
41
+ ### Code Coverage
42
+
43
+ Tests must maintain 95% minimum code coverage. Coverage reports are generated in the `coverage/` directory.
44
+
45
+ ## Pull Request Process
46
+
47
+ 1. Create a feature branch from `main`:
48
+ ```bash
49
+ git checkout -b feature/my-feature
50
+ ```
51
+
52
+ 2. Make your changes following the code style guidelines
53
+
54
+ 3. Write tests for new functionality
55
+
56
+ 4. Ensure all tests pass and linting is clean:
57
+ ```bash
58
+ docker compose run --rm test
59
+ docker compose run --rm lint
60
+ ```
61
+
62
+ 5. Commit using [Conventional Commits](https://www.conventionalcommits.org/):
63
+ - `feat:` for new features
64
+ - `fix:` for bug fixes
65
+ - `docs:` for documentation
66
+ - `test:` for tests
67
+ - `chore:` for maintenance
68
+
69
+ 6. Push and create a Pull Request
70
+
71
+ ## Code Style
72
+
73
+ - Follow the existing code patterns
74
+ - Use `frozen_string_literal: true` in all Ruby files
75
+ - Add YARD documentation for public methods
76
+ - Keep methods small and focused
77
+
78
+ ## Reporting Issues
79
+
80
+ When reporting issues, please include:
81
+
82
+ - Ruby version
83
+ - Gem version
84
+ - Steps to reproduce
85
+ - Expected vs actual behavior
86
+ - Error messages and stack traces
87
+
88
+ ## Questions?
89
+
90
+ Open an issue for questions or discussions about the project.
data/README.md CHANGED
@@ -125,6 +125,36 @@ Ovh::Http2sms.configure do |config|
125
125
  end
126
126
  ```
127
127
 
128
+ ### Callbacks
129
+
130
+ Register callbacks for monitoring, logging, or metrics collection:
131
+
132
+ ```ruby
133
+ Ovh::Http2sms.configure do |config|
134
+ # Called before each request (params have password filtered)
135
+ config.before_request do |params|
136
+ Rails.logger.info("Sending SMS to #{params[:to]}")
137
+ end
138
+
139
+ # Called after each request
140
+ config.after_request do |response|
141
+ StatsD.histogram("sms.duration", response_time)
142
+ end
143
+
144
+ # Called on successful delivery
145
+ config.on_success do |response|
146
+ StatsD.increment("sms.success")
147
+ StatsD.gauge("sms.credits", response.credits_remaining)
148
+ end
149
+
150
+ # Called on failed delivery
151
+ config.on_failure do |response|
152
+ StatsD.increment("sms.failure", tags: ["error:#{response.error_type}"])
153
+ Sentry.capture_message("SMS delivery failed: #{response.error_message}")
154
+ end
155
+ end
156
+ ```
157
+
128
158
  ## Usage Examples
129
159
 
130
160
  ### Basic Send
@@ -185,12 +185,20 @@ module Ovh
185
185
 
186
186
  def execute_request(query_params, content_type)
187
187
  log_request(query_params)
188
+ run_before_request_callbacks(query_params)
188
189
 
189
190
  response = make_http_request(query_params)
190
191
  parsed_response = parse_response(response, content_type)
191
192
 
192
193
  log_response(parsed_response)
193
- handle_error_response(parsed_response) if parsed_response.failure?
194
+ run_after_request_callbacks(parsed_response)
195
+
196
+ if parsed_response.failure?
197
+ run_on_failure_callbacks(parsed_response)
198
+ handle_error_response(parsed_response)
199
+ else
200
+ run_on_success_callbacks(parsed_response)
201
+ end
194
202
 
195
203
  parsed_response
196
204
  rescue Faraday::Error => e
@@ -248,6 +256,24 @@ module Ovh
248
256
  "[OVH HTTP2SMS] Response: status=#{response.status} success=#{response.success?}"
249
257
  )
250
258
  end
259
+
260
+ def run_before_request_callbacks(params)
261
+ safe_params = params.dup
262
+ safe_params[:password] = "[FILTERED]"
263
+ @config.before_request_callbacks.each { |callback| callback.call(safe_params) }
264
+ end
265
+
266
+ def run_after_request_callbacks(response)
267
+ @config.after_request_callbacks.each { |callback| callback.call(response) }
268
+ end
269
+
270
+ def run_on_success_callbacks(response)
271
+ @config.on_success_callbacks.each { |callback| callback.call(response) }
272
+ end
273
+
274
+ def run_on_failure_callbacks(response)
275
+ @config.on_failure_callbacks.each { |callback| callback.call(response) }
276
+ end
251
277
  end
252
278
  end
253
279
  end
@@ -46,6 +46,18 @@ module Ovh
46
46
  # @return [String] API endpoint URL
47
47
  attr_accessor :api_endpoint
48
48
 
49
+ # @return [Array<Proc>] Callbacks executed before each request
50
+ attr_reader :before_request_callbacks
51
+
52
+ # @return [Array<Proc>] Callbacks executed after each request
53
+ attr_reader :after_request_callbacks
54
+
55
+ # @return [Array<Proc>] Callbacks executed on successful delivery
56
+ attr_reader :on_success_callbacks
57
+
58
+ # @return [Array<Proc>] Callbacks executed on failed delivery
59
+ attr_reader :on_failure_callbacks
60
+
49
61
  # Environment variable prefix
50
62
  ENV_PREFIX = "OVH_SMS_"
51
63
 
@@ -62,6 +74,15 @@ module Ovh
62
74
  reset!
63
75
  end
64
76
 
77
+ # Ensure callbacks are properly duplicated
78
+ def initialize_dup(other)
79
+ super
80
+ @before_request_callbacks = other.before_request_callbacks.dup
81
+ @after_request_callbacks = other.after_request_callbacks.dup
82
+ @on_success_callbacks = other.on_success_callbacks.dup
83
+ @on_failure_callbacks = other.on_failure_callbacks.dup
84
+ end
85
+
65
86
  # Reset configuration to defaults and environment variables
66
87
  #
67
88
  # @return [void]
@@ -78,10 +99,69 @@ module Ovh
78
99
  self.default_sender = nil
79
100
  self.logger = nil
80
101
 
102
+ # Reset callbacks
103
+ @before_request_callbacks = []
104
+ @after_request_callbacks = []
105
+ @on_success_callbacks = []
106
+ @on_failure_callbacks = []
107
+
81
108
  # Load from environment variables
82
109
  load_from_env
83
110
  end
84
111
 
112
+ # Register a callback to be executed before each request
113
+ #
114
+ # @yield [Hash] The request parameters (with password filtered)
115
+ # @return [void]
116
+ #
117
+ # @example Log all requests
118
+ # config.before_request do |params|
119
+ # Rails.logger.info("Sending SMS to #{params[:to]}")
120
+ # end
121
+ def before_request(&block)
122
+ @before_request_callbacks << block if block_given?
123
+ end
124
+
125
+ # Register a callback to be executed after each request
126
+ #
127
+ # @yield [Response] The parsed response object
128
+ # @return [void]
129
+ #
130
+ # @example Track metrics
131
+ # config.after_request do |response|
132
+ # StatsD.increment("sms.sent", tags: ["status:#{response.status}"])
133
+ # end
134
+ def after_request(&block)
135
+ @after_request_callbacks << block if block_given?
136
+ end
137
+
138
+ # Register a callback to be executed on successful delivery
139
+ #
140
+ # @yield [Response] The successful response object
141
+ # @return [void]
142
+ #
143
+ # @example Track success
144
+ # config.on_success do |response|
145
+ # StatsD.increment("sms.success")
146
+ # StatsD.gauge("sms.credits", response.credits_remaining)
147
+ # end
148
+ def on_success(&block)
149
+ @on_success_callbacks << block if block_given?
150
+ end
151
+
152
+ # Register a callback to be executed on failed delivery
153
+ #
154
+ # @yield [Response] The failed response object
155
+ # @return [void]
156
+ #
157
+ # @example Track failures
158
+ # config.on_failure do |response|
159
+ # StatsD.increment("sms.failure", tags: ["error:#{response.error_type}"])
160
+ # end
161
+ def on_failure(&block)
162
+ @on_failure_callbacks << block if block_given?
163
+ end
164
+
85
165
  # Check if the configuration is valid for making API requests
86
166
  #
87
167
  # @return [Boolean] true if required fields are present
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ovh
4
4
  module Http2sms
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ovh-http2sms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - François Kiene
@@ -153,6 +153,7 @@ files:
153
153
  - ".dockerignore"
154
154
  - ".env.example"
155
155
  - CHANGELOG.md
156
+ - CONTRIBUTING.md
156
157
  - Dockerfile
157
158
  - Gemfile
158
159
  - LICENSE.txt