noticed 2.4.3 → 2.5.0
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 +29 -7
- data/app/models/concerns/noticed/notification_methods.rb +1 -1
- data/app/models/noticed/ephemeral.rb +5 -1
- data/lib/noticed/bulk_delivery_method.rb +8 -3
- data/lib/noticed/bulk_delivery_methods/bluesky.rb +49 -0
- data/lib/noticed/bulk_delivery_methods/test.rb +2 -2
- data/lib/noticed/delivery_methods/ios.rb +4 -0
- data/lib/noticed/version.rb +1 -1
- data/lib/noticed.rb +1 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d93cc608d5422344ca6aff8b4941508dc76b3192e9052c853677f2bc222a98e
|
4
|
+
data.tar.gz: 7932559c8b60c97b0798815872f8146588bfb7bb3b82cb5a3a60e53fbe49bf14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 223e40cacfffb9da94953284319f5fb865161996daf39d0c7b3c5697cd41e1923fc394e3d3ee782d1eba8513adcb91006ef6bc962fb1908672181eb024de880c
|
7
|
+
data.tar.gz: aac70f09103d1737c5cef2cbfdf87275cc5f595dc84ffd38500561585c4f89574e427448fc8011cbc0bb16b9b06f191cecbadc9831ed8c60a857b0cf9e2d330b
|
data/README.md
CHANGED
@@ -41,6 +41,7 @@ Delivery methods we officially support:
|
|
41
41
|
|
42
42
|
Bulk delivery methods we support:
|
43
43
|
|
44
|
+
* [Bluesky](docs/bulk_delivery_methods/bluesky.md)
|
44
45
|
* [Discord](docs/bulk_delivery_methods/discord.md)
|
45
46
|
* [Slack](docs/bulk_delivery_methods/slack.md)
|
46
47
|
* [Webhook](docs/bulk_delivery_methods/webhook.md)
|
@@ -107,7 +108,7 @@ class NewCommentNotifier < Noticed::Event
|
|
107
108
|
|
108
109
|
deliver_by :email do |config|
|
109
110
|
config.mailer = "CommentMailer"
|
110
|
-
config.if = ->
|
111
|
+
config.if = -> { !!recipient.preferences[:email] }
|
111
112
|
end
|
112
113
|
|
113
114
|
bulk_deliver_by :discord do |config|
|
@@ -374,9 +375,29 @@ Each of these options are available for every delivery method (individual or bul
|
|
374
375
|
|
375
376
|
* `config.if` — Intended for a lambda or method; runs after the `wait` if configured; cancels the delivery method if returns falsey
|
376
377
|
* `config.unless` — Intended for a lambda or method; runs after the `wait` if configured; cancels the delivery method if returns truthy
|
378
|
+
|
379
|
+
The following are evaluated in the context of the Notification so it can be customize to the recipient:
|
380
|
+
|
377
381
|
* `config.wait` — (Should yield an `ActiveSupport::Duration`) Delays the job that runs this delivery method for the given duration of time
|
378
382
|
* `config.wait_until` — (Should yield a specific time object) Delays the job that runs this delivery method until the specific time specified
|
379
|
-
* `config.queue` — Sets the ActiveJob queue name to be used for the job that runs this delivery method
|
383
|
+
* `config.queue` — Sets the ActiveJob queue name to be used for the job that runs this delivery method.
|
384
|
+
|
385
|
+
When using a symbol, the matching method must be defined inside the `notification_methods` block:
|
386
|
+
|
387
|
+
```ruby
|
388
|
+
# app/notifiers/message_notifier.rb
|
389
|
+
class MessageNotifier < Noticed::Event
|
390
|
+
deliver_by :delivery_method do |config|
|
391
|
+
config.queue = :queue
|
392
|
+
end
|
393
|
+
|
394
|
+
notification_methods do
|
395
|
+
def queue
|
396
|
+
"high_priority"
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
400
|
+
```
|
380
401
|
|
381
402
|
### 📨 Sending Notifications
|
382
403
|
|
@@ -407,8 +428,8 @@ Recipients can also be computed inside a notifier:
|
|
407
428
|
class NewCommentNotifier < ApplicationNotifier
|
408
429
|
recipients ->{ params[:record].thread.all_authors }
|
409
430
|
|
410
|
-
# or
|
411
|
-
recipients do
|
431
|
+
# or
|
432
|
+
recipients do
|
412
433
|
params[:record].thread.all_authors
|
413
434
|
end
|
414
435
|
|
@@ -465,8 +486,8 @@ module MyApp
|
|
465
486
|
# ...
|
466
487
|
|
467
488
|
config.to_prepare do
|
468
|
-
Noticed::Event.include
|
469
|
-
Noticed::Notification.include
|
489
|
+
Noticed::Event.include EventExtensions
|
490
|
+
Noticed::Notification.include NotificationExtensions
|
470
491
|
end
|
471
492
|
end
|
472
493
|
end
|
@@ -506,6 +527,7 @@ Individual delivery methods:
|
|
506
527
|
|
507
528
|
Bulk delivery methods:
|
508
529
|
|
530
|
+
* [Bluesky](docs/bulk_delivery_methods/bluesky.md)
|
509
531
|
* [Discord](docs/bulk_delivery_methods/discord.md)
|
510
532
|
* [Slack](docs/bulk_delivery_methods/slack.md)
|
511
533
|
* [Webhook](docs/bulk_delivery_methods/webhook.md)
|
@@ -580,7 +602,7 @@ end
|
|
580
602
|
|
581
603
|
A common custom delivery method in the Rails world might be to Delivery to the web via turbo stream.
|
582
604
|
|
583
|
-
Note: This example
|
605
|
+
Note: This example uses custom methods that extend the `Noticed::Notification` class.
|
584
606
|
|
585
607
|
See the [Custom Noticed Model Methods](#custom-noticed-model-methods) section for more information.
|
586
608
|
|
@@ -6,7 +6,7 @@ module Noticed
|
|
6
6
|
# Generate a Notification class each time a Notifier is defined
|
7
7
|
def inherited(notifier)
|
8
8
|
super
|
9
|
-
notifier.const_set :Notification, Class.new(Noticed::Notification)
|
9
|
+
notifier.const_set :Notification, Class.new(const_defined?(:Notification) ? const_get(:Notification) : Noticed::Notification)
|
10
10
|
end
|
11
11
|
|
12
12
|
def notification_methods(&block)
|
@@ -37,8 +37,10 @@ module Noticed
|
|
37
37
|
const_get(:Notification).class_eval(&block)
|
38
38
|
end
|
39
39
|
|
40
|
-
def deliver(recipients)
|
40
|
+
def deliver(recipients = nil)
|
41
|
+
recipients ||= evaluate_recipients
|
41
42
|
recipients = Array.wrap(recipients)
|
43
|
+
|
42
44
|
bulk_delivery_methods.each do |_, deliver_by|
|
43
45
|
deliver_by.ephemeral_perform_later(self.class.name, recipients, params)
|
44
46
|
end
|
@@ -48,6 +50,8 @@ module Noticed
|
|
48
50
|
deliver_by.ephemeral_perform_later(self.class.name, recipient, params)
|
49
51
|
end
|
50
52
|
end
|
53
|
+
|
54
|
+
self
|
51
55
|
end
|
52
56
|
|
53
57
|
def record
|
@@ -3,14 +3,17 @@ module Noticed
|
|
3
3
|
include ApiClient
|
4
4
|
include RequiredOptions
|
5
5
|
|
6
|
+
extend ActiveModel::Callbacks
|
7
|
+
define_model_callbacks :deliver
|
8
|
+
|
6
9
|
class_attribute :logger, default: Rails.logger
|
7
10
|
|
8
11
|
attr_reader :config, :event
|
9
12
|
|
10
|
-
def perform(delivery_method_name, event,
|
13
|
+
def perform(delivery_method_name, event, recipient: nil, params: {}, overrides: {})
|
11
14
|
# Ephemeral notifications
|
12
15
|
if event.is_a? String
|
13
|
-
@event =
|
16
|
+
@event = event.constantize.new_with_params(recipient, params)
|
14
17
|
@config = overrides
|
15
18
|
else
|
16
19
|
@event = event
|
@@ -20,7 +23,9 @@ module Noticed
|
|
20
23
|
return false if config.has_key?(:if) && !evaluate_option(:if)
|
21
24
|
return false if config.has_key?(:unless) && evaluate_option(:unless)
|
22
25
|
|
23
|
-
deliver
|
26
|
+
run_callbacks :deliver do
|
27
|
+
deliver
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
def deliver
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Noticed
|
2
|
+
module BulkDeliveryMethods
|
3
|
+
class Bluesky < BulkDeliveryMethod
|
4
|
+
required_options :identifier, :password, :json
|
5
|
+
|
6
|
+
# bulk_deliver_by :bluesky do |config|
|
7
|
+
# config.identifier = ENV["BLUESKY_ID"]
|
8
|
+
# config.password = ENV["BLUESKY_PASSWORD"]
|
9
|
+
# config.json = {text: "...", createdAt: "..."}
|
10
|
+
# end
|
11
|
+
|
12
|
+
def deliver
|
13
|
+
Rails.logger.debug(evaluate_option(:json))
|
14
|
+
post_request(
|
15
|
+
"https://#{host}/xrpc/com.atproto.repo.createRecord",
|
16
|
+
headers: {"Authorization" => "Bearer #{token}"},
|
17
|
+
json: {
|
18
|
+
repo: identifier,
|
19
|
+
collection: "app.bsky.feed.post",
|
20
|
+
record: evaluate_option(:json)
|
21
|
+
}
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def token
|
26
|
+
start_session.dig("accessJwt")
|
27
|
+
end
|
28
|
+
|
29
|
+
def start_session
|
30
|
+
response = post_request(
|
31
|
+
"https://#{host}/xrpc/com.atproto.server.createSession",
|
32
|
+
json: {
|
33
|
+
identifier: identifier,
|
34
|
+
password: evaluate_option(:password)
|
35
|
+
}
|
36
|
+
)
|
37
|
+
JSON.parse(response.body)
|
38
|
+
end
|
39
|
+
|
40
|
+
def host
|
41
|
+
@host ||= evaluate_option(:host) || "bsky.social"
|
42
|
+
end
|
43
|
+
|
44
|
+
def identifier
|
45
|
+
@identifier ||= evaluate_option(:identifier)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -16,6 +16,7 @@ module Noticed
|
|
16
16
|
connection_pool.with do |connection|
|
17
17
|
response = connection.push(apn)
|
18
18
|
raise "Timeout sending iOS push notification" unless response
|
19
|
+
connection.close
|
19
20
|
|
20
21
|
if bad_token?(response) && config[:invalid_token]
|
21
22
|
# Allow notification to cleanup invalid iOS device tokens
|
@@ -62,6 +63,9 @@ module Noticed
|
|
62
63
|
handler = proc do |connection|
|
63
64
|
connection.on(:error) do |exception|
|
64
65
|
Rails.logger.info "Apnotic exception raised: #{exception}"
|
66
|
+
if config[:error_handler].respond_to?(:call)
|
67
|
+
notification.instance_exec(exception, &config[:error_handler])
|
68
|
+
end
|
65
69
|
end
|
66
70
|
end
|
67
71
|
|
data/lib/noticed/version.rb
CHANGED
data/lib/noticed.rb
CHANGED
@@ -20,6 +20,7 @@ module Noticed
|
|
20
20
|
autoload :Translation, "noticed/translation"
|
21
21
|
|
22
22
|
module BulkDeliveryMethods
|
23
|
+
autoload :Bluesky, "noticed/bulk_delivery_methods/bluesky"
|
23
24
|
autoload :Discord, "noticed/bulk_delivery_methods/discord"
|
24
25
|
autoload :Slack, "noticed/bulk_delivery_methods/slack"
|
25
26
|
autoload :Test, "noticed/bulk_delivery_methods/test"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noticed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/noticed.rb
|
59
59
|
- lib/noticed/api_client.rb
|
60
60
|
- lib/noticed/bulk_delivery_method.rb
|
61
|
+
- lib/noticed/bulk_delivery_methods/bluesky.rb
|
61
62
|
- lib/noticed/bulk_delivery_methods/discord.rb
|
62
63
|
- lib/noticed/bulk_delivery_methods/slack.rb
|
63
64
|
- lib/noticed/bulk_delivery_methods/test.rb
|
@@ -85,7 +86,7 @@ homepage: https://github.com/excid3/noticed
|
|
85
86
|
licenses:
|
86
87
|
- MIT
|
87
88
|
metadata: {}
|
88
|
-
post_install_message:
|
89
|
+
post_install_message:
|
89
90
|
rdoc_options: []
|
90
91
|
require_paths:
|
91
92
|
- lib
|
@@ -100,8 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
101
|
- !ruby/object:Gem::Version
|
101
102
|
version: '0'
|
102
103
|
requirements: []
|
103
|
-
rubygems_version: 3.5.
|
104
|
-
signing_key:
|
104
|
+
rubygems_version: 3.5.23
|
105
|
+
signing_key:
|
105
106
|
specification_version: 4
|
106
107
|
summary: Notifications for Ruby on Rails applications
|
107
108
|
test_files: []
|