Class: Pusher::PushNotifications::UseCases::PublishToUsers

Inherits:
Object
  • Object
show all
Defined in:
lib/pusher/push_notifications/use_cases/publish_to_users.rb

Defined Under Namespace

Classes: UsersPublishError

Class Method Summary collapse

Class Method Details

.publish_to_users(client, users:, payload: {}) ⇒ Object

Publish the given payload to the specified users.

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pusher/push_notifications/use_cases/publish_to_users.rb', line 10

def self.publish_to_users(client, users:, 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

  data = { users: users }.merge!(payload)
  client.post('publishes/users', data)
end