class Pusher::PushNotifications::UseCases::PublishToUsers
Attributes
payload[R]
users[R]
Public Class Methods
new(users:, payload: {})
click to toggle source
# File lib/pusher/push_notifications/use_cases/publish_to_users.rb, line 15 def initialize(users:, payload: {}) @users = users @user_id = Pusher::PushNotifications::UserId.new @payload = payload users.each do |user| raise UsersPublishError, 'User Id cannot be empty.' if user.empty? next unless user.length > UserId::MAX_USER_ID_LENGTH raise UsersPublishError, 'User id length too long ' \ "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1}" \ ' characters)' end raise UsersPublishError, 'Must supply at least one user id.' if users.count < 1 if users.length > UserId::MAX_NUM_USER_IDS raise UsersPublishError, "Number of user ids #{users.length} "\ "exceeds maximum of #{UserId::MAX_NUM_USER_IDS}." end end
publish_to_users(*args, **kwargs)
click to toggle source
# File lib/pusher/push_notifications/use_cases/publish_to_users.rb, line 10 def publish_to_users(*args, **kwargs) new(*args, **kwargs).publish_to_users end
Public Instance Methods
publish_to_users()
click to toggle source
Publish
the given payload to the specified users.
# File lib/pusher/push_notifications/use_cases/publish_to_users.rb, line 39 def publish_to_users data = { users: users }.merge!(payload) client.post('publishes/users', data) end
Private Instance Methods
client()
click to toggle source
# File lib/pusher/push_notifications/use_cases/publish_to_users.rb, line 48 def client @client ||= PushNotifications::Client.new end