Class: Moogle::Handlers::AcceptNotification
- Inherits:
-
Object
- Object
- Moogle::Handlers::AcceptNotification
- Includes:
- Serf::Command, Serf::Util::ErrorHandling
- Defined in:
- lib/moogle/handlers/accept_notification.rb
Overview
Handler that accepts Moogle::Messges::Notifications and creates actual push requests to relay the notification to each found target.
Constant Summary collapse
- DEFAULT_PUSH_OPTIONS =
{ 'from' => '[email protected]' }.freeze
Instance Attribute Summary collapse
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
-
#pusher_queue ⇒ Object
readonly
Returns the value of attribute pusher_queue.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize ⇒ AcceptNotification
constructor
A new instance of AcceptNotification.
- #request_factory_for(target_type) ⇒ Object
Constructor Details
#initialize ⇒ AcceptNotification
Returns a new instance of AcceptNotification.
34 35 36 37 |
# File 'lib/moogle/handlers/accept_notification.rb', line 34 def initialize @pusher_queue = opts! :pusher_queue @default_options = opts :default_push_options, DEFAULT_PUSH_OPTIONS end |
Instance Attribute Details
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
28 29 30 |
# File 'lib/moogle/handlers/accept_notification.rb', line 28 def @default_options end |
#pusher_queue ⇒ Object (readonly)
Returns the value of attribute pusher_queue.
27 28 29 |
# File 'lib/moogle/handlers/accept_notification.rb', line 27 def pusher_queue @pusher_queue end |
Instance Method Details
#call ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/moogle/handlers/accept_notification.rb', line 39 def call return nil if request.receiver_refs.blank? || request..blank? # Get all targets whose links' kinds + receivers match. model = opts :model, Moogle::Target targets = model.all( model.links. => request., model.links.receiver_ref => request.receiver_refs) # Create a new push request for each target found. # Push each request to the pusher queue, and errors are caught # and pushed to the error channel. targets.each do |target| with_error_handling( kind: 'moogle/handlers/accept_notification', request: request.to_hash, target_id: target.id) do request_factory = request_factory_for target.type push_data = [ request.attributes, , target., { target_id: target.id, message_origin: "#{request.}:#{request.uuid}:" } ].reduce(&:merge) push_request = request_factory.build push_data pusher_queue.push push_request.to_hash end end return nil rescue => e e.extend Moogle::Error raise e end |
#request_factory_for(target_type) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/moogle/handlers/accept_notification.rb', line 77 def request_factory_for(target_type) case target_type.to_s when 'Moogle::BlogTarget' Moogle::Requests::PushBlogEntry when 'Moogle::EmailTarget' Moogle::Requests::PushEmail #when 'Moogle::FacebookTarget' # Moogle::Requests::PushFacebookAction #when 'Moogle::TwitterTarget' # Moogle::Requests::PushTweet when 'Moogle::WebhookTarget' Moogle::Requests::PushWebhookPing else raise ArgumentError, "Unsupported Target #{target_type}" end end |