smsru_ruby 1.0.0 → 1.0.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 +4 -4
- data/README.md +15 -3
- data/lib/sms_ru/version.rb +1 -1
- data/lib/sms_ru/webhook.rb +12 -4
- data/smsru_ruby.gemspec +11 -0
- metadata +10 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 83b4caabc11d6eb0b3795b891079da1125ab846268aeddb7eb88b75db0237078
|
|
4
|
+
data.tar.gz: 663be0182ac17cf6d607d9e56ce30f0d4703a5c9c2b84d9dc77c01bc57c006e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f323d6639adc27b88586dde1ea065122895fc0aba8056afb14c9f617d8b5cf68e54d65742e6b2077bdab2a13f07aa5b192c0e787f5d1c0f6353e6fe130d9d64d
|
|
7
|
+
data.tar.gz: 25f64521bddde691a57dd54617c95ff6732796377647d6df1861e6b79d70ba911c51a9ba6094f2c5ed1ab88acf7add67e7a6905ca3f8f456999902af5c6dd1e0
|
data/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# smsru_ruby
|
|
2
2
|
|
|
3
|
+
> [!WARNING]
|
|
4
|
+
> **This gem has been renamed to [`smsru-ruby`](https://rubygems.org/gems/smsru-ruby) and is no longer maintained.**
|
|
5
|
+
> Switch your `Gemfile` to `gem "smsru-ruby"` and your code to `require "smsru-ruby"`.
|
|
6
|
+
> The Ruby API is unchanged — the top-level class is still `SmsRu`. See <https://github.com/svyatov/smsru-ruby>.
|
|
7
|
+
|
|
3
8
|
[](https://rubygems.org/gems/smsru_ruby)
|
|
4
9
|
[](https://github.com/svyatov/smsru_ruby/actions/workflows/main.yml)
|
|
5
10
|
[](https://codecov.io/gh/svyatov/smsru_ruby)
|
|
@@ -286,16 +291,23 @@ In your webhook handler, verify the signature, parse the payload, and
|
|
|
286
291
|
acknowledge it by replying with the string `"100"`:
|
|
287
292
|
|
|
288
293
|
```ruby
|
|
294
|
+
# In Rails, params[:data] is ActionController::Parameters, not a Hash — convert
|
|
295
|
+
# it with .to_unsafe_h first, or the numeric-key ordering the signature depends
|
|
296
|
+
# on is skipped and the check below rejects the payload. The payload is
|
|
297
|
+
# signature-verified, so to_unsafe_h is safe here (.to_h would drop keys).
|
|
298
|
+
# In bare Rack params["data"] is already a Hash; pass it as-is.
|
|
299
|
+
data = params[:data].to_unsafe_h
|
|
300
|
+
|
|
289
301
|
# Reject forged callbacks: SMS.ru signs every payload with your api_id.
|
|
290
302
|
# The check is constant-time (timing-attack safe).
|
|
291
|
-
unless SmsRu::Webhook.valid?(
|
|
303
|
+
unless SmsRu::Webhook.valid?(data, params[:hash], "YOUR_API_ID")
|
|
292
304
|
return head(:forbidden)
|
|
293
305
|
end
|
|
294
306
|
|
|
295
307
|
# SMS.ru sends up to 100 records as POST fields data[0]..data[N]
|
|
296
|
-
# (a Hash in Rack
|
|
308
|
+
# (a Hash in Rack, an Array in PHP). #parse handles either shape and
|
|
297
309
|
# returns a typed event per record.
|
|
298
|
-
SmsRu::Webhook.parse(
|
|
310
|
+
SmsRu::Webhook.parse(data).each do |event|
|
|
299
311
|
case event
|
|
300
312
|
when SmsRu::Events::SmsStatus # delivery report
|
|
301
313
|
# event.id, event.status_code, event.created_at; event.delivered? => 103
|
data/lib/sms_ru/version.rb
CHANGED
data/lib/sms_ru/webhook.rb
CHANGED
|
@@ -3,15 +3,23 @@
|
|
|
3
3
|
class SmsRu
|
|
4
4
|
# Parses the inbound webhook payload SMS.ru POSTs to your callback URL and
|
|
5
5
|
# verifies its signature. SMS.ru sends the records as POST fields
|
|
6
|
-
# `data[0]..data[N]`
|
|
7
|
-
#
|
|
6
|
+
# `data[0]..data[N]` plus a `hash` field; acknowledge the webhook by replying
|
|
7
|
+
# with "100".
|
|
8
|
+
#
|
|
9
|
+
# The `data` param arrives as a Hash in bare Rack and an Array in PHP-style
|
|
10
|
+
# clients. In Rails it is an `ActionController::Parameters`, which is **not** a
|
|
11
|
+
# Hash — convert it with `.to_unsafe_h` first, or the numeric-key ordering the
|
|
12
|
+
# signature depends on is skipped and {valid?} rejects the payload. The
|
|
13
|
+
# payload is signature-verified, so `to_unsafe_h` is safe here (`.to_h` would
|
|
14
|
+
# drop unpermitted keys).
|
|
8
15
|
#
|
|
9
16
|
# {parse} returns one typed event per record — a {SmsRu::Events::SmsStatus},
|
|
10
17
|
# {SmsRu::Events::CallcheckStatus}, {SmsRu::Events::Test}, or
|
|
11
18
|
# {SmsRu::Events::Unknown} — best handled with a case match:
|
|
12
19
|
#
|
|
13
|
-
#
|
|
14
|
-
# SmsRu::Webhook.
|
|
20
|
+
# data = params[:data].to_unsafe_h # Rails; pass params["data"] as-is in bare Rack
|
|
21
|
+
# return head(:forbidden) unless SmsRu::Webhook.valid?(data, params[:hash], api_id)
|
|
22
|
+
# SmsRu::Webhook.parse(data).each do |event|
|
|
15
23
|
# case event
|
|
16
24
|
# when SmsRu::Events::SmsStatus then update_delivery(event.id, event.status_code)
|
|
17
25
|
# when SmsRu::Events::CallcheckStatus then confirm(event.id) if event.confirmed?
|
data/smsru_ruby.gemspec
CHANGED
|
@@ -15,6 +15,17 @@ Gem::Specification.new do |spec|
|
|
|
15
15
|
spec.homepage = "https://github.com/svyatov/smsru_ruby"
|
|
16
16
|
spec.license = "MIT"
|
|
17
17
|
|
|
18
|
+
spec.post_install_message = <<~MSG
|
|
19
|
+
NOTE: `smsru_ruby` has been renamed to `smsru-ruby` and is no longer maintained.
|
|
20
|
+
|
|
21
|
+
Please switch:
|
|
22
|
+
* Gemfile: gem "smsru-ruby"
|
|
23
|
+
* require: require "smsru-ruby"
|
|
24
|
+
|
|
25
|
+
The Ruby API is unchanged (the top-level class is still `SmsRu`).
|
|
26
|
+
https://github.com/svyatov/smsru-ruby
|
|
27
|
+
MSG
|
|
28
|
+
|
|
18
29
|
spec.required_ruby_version = ">= 3.2.0"
|
|
19
30
|
|
|
20
31
|
spec.require_paths = ["lib"]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smsru_ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Leonid Svyatov
|
|
@@ -61,6 +61,15 @@ metadata:
|
|
|
61
61
|
source_code_uri: https://github.com/svyatov/smsru_ruby
|
|
62
62
|
changelog_uri: https://github.com/svyatov/smsru_ruby/blob/main/CHANGELOG.md
|
|
63
63
|
bug_tracker_uri: https://github.com/svyatov/smsru_ruby/issues
|
|
64
|
+
post_install_message: |
|
|
65
|
+
NOTE: `smsru_ruby` has been renamed to `smsru-ruby` and is no longer maintained.
|
|
66
|
+
|
|
67
|
+
Please switch:
|
|
68
|
+
* Gemfile: gem "smsru-ruby"
|
|
69
|
+
* require: require "smsru-ruby"
|
|
70
|
+
|
|
71
|
+
The Ruby API is unchanged (the top-level class is still `SmsRu`).
|
|
72
|
+
https://github.com/svyatov/smsru-ruby
|
|
64
73
|
rdoc_options: []
|
|
65
74
|
require_paths:
|
|
66
75
|
- lib
|