rails_api_guard 0.2.1 → 0.2.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: 93890693de684b76c7ac78ed99e9d1ca804272c7cbf14b1c8087d5070ab2fcea
4
- data.tar.gz: f4056a7057f5d56e26143ebf7d810d2d742090a2e920c4cf29a9b289bea96924
3
+ metadata.gz: 113eca3b940fb42eb59e46207a1389447a14b1c8e664397bcf2e48060bc87c49
4
+ data.tar.gz: 7ed64fb43fcf0f8225dc0e0a237c35f6b5720e1b0686126d27381766ada440f2
5
5
  SHA512:
6
- metadata.gz: a4b8acff3abc11669ad3d6ca6a1d35886e06f420f51f27822d6292e942b920b10faccfe4a365c15e337b410330283868876249b5909e5da9bcb8efd815efa95b
7
- data.tar.gz: e6cab1599d4edcf9b013a89139e7bd398764ca5491d3d0d076742472de1414cbe0ee77514b4439077d4209d9ce6c078ad3c935005ffe3753b0156b6362adea41
6
+ metadata.gz: c5736712e78258a58be184b20bf67628c943c3005649f0a0bc3917c8f416e29b4c4b57cddf5266895bd5073aff91375d2fbbfad25159b58b5fe8cce3f854c97d
7
+ data.tar.gz: 40e092d2d0ca2471179055399df4fea4e38fddb751ffccb6bd51c0063e77e19b2f065deec319e2e2d45c54f5695465726a6d56de09e4952df0d37c489c100224
data/README.md CHANGED
@@ -34,6 +34,20 @@ config.middleware.use RailsApiGuard::Middleware::RateLimiter
34
34
  ## Configuration
35
35
  Edit `config/initializers/rails_api_guard.rb` to set request limits, expiry time, Slack alerts, and excluded endpoint patterns.
36
36
 
37
+ ## Slack Notifications
38
+
39
+ RailsApiGuard can optionally send Slack alerts whenever a request exceeds the defined rate limit threshold.
40
+
41
+ ### Configuration
42
+
43
+ To enable Slack alerts, set your Slack webhook URL in the initializer:
44
+
45
+ ```ruby
46
+ # config/initializers/rails_api_guard.rb
47
+ RailsApiGuard.configure do |config|
48
+ config.slack_webhook_url = ENV["SLACK_WEBHOOK_URL"]
49
+ end
50
+
37
51
  ## Contributing
38
52
  Contribution directions are yet to add.
39
53
 
@@ -5,11 +5,22 @@ module RailsApiGuard
5
5
  class SlackNotifier
6
6
  def self.notify(message)
7
7
  webhook_url = RailsApiGuard.config.slack_webhook_url
8
- return unless webhook_url.present?
9
-
10
- payload = { text: message }
11
-
12
- HTTParty.post(webhook_url, body: payload.to_json, headers: { 'Content-Type' => 'application/json' })
8
+
9
+ if webhook_url.nil?
10
+ Rails.logger.warn 'no Slack webhook URl configured'
11
+ Rails.logger.warn "Message : #{message}"
12
+ return
13
+ end
14
+
15
+ response = HTTParty.post(
16
+ webhook_url,
17
+ body: { text: message }.to_json,
18
+ headers: { 'Content-Type' => 'application/json' }
19
+ )
20
+
21
+ unless rails.success?
22
+ Rails.logger.error "Failed to send Slack alert: #{response.code} - #{response.body}"
23
+ end
13
24
  end
14
25
  end
15
26
  end
@@ -1,3 +1,3 @@
1
1
  module RailsApiGuard
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_api_guard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sugat dhole
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-30 00:00:00.000000000 Z
11
+ date: 2025-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails