class Pusher::PushNotifications::UseCases::Publish
Attributes
interests[R]
payload[R]
Public Class Methods
new(interests:, payload: {})
click to toggle source
# File lib/pusher/push_notifications/use_cases/publish.rb, line 19 def initialize(interests:, payload: {}) @interests = interests @payload = payload @user_id = Pusher::PushNotifications::UserId.new valid_interest_pattern = /^(_|-|=|@|,|\.|:|[A-Z]|[a-z]|[0-9])*$/ interests.each do |interest| next if valid_interest_pattern.match?(interest) raise PublishError, "Invalid interest name \nMax #{UserId::MAX_USER_ID_LENGTH}" \ ' characters and can only contain ASCII upper/lower-case' \ ' letters, numbers or one of _-=@,.:' end raise PublishError, 'Must provide at least one interest' if interests.empty? if interests.length > 100 raise PublishError, "Number of interests #{interests.length}" \ ' exceeds maximum of 100' end end
publish(*args, **kwargs)
click to toggle source
# File lib/pusher/push_notifications/use_cases/publish.rb, line 10 def publish(*args, **kwargs) new(*args, **kwargs).publish end
publish_to_interests(*args, **kwargs)
click to toggle source
# File lib/pusher/push_notifications/use_cases/publish.rb, line 14 def publish_to_interests(*args, **kwargs) new(*args, **kwargs).publish_to_interests end
Public Instance Methods
publish()
click to toggle source
Publish
the given payload to the specified interests. DEPRECATED: Please use publish_to_interests
instead.
# File lib/pusher/push_notifications/use_cases/publish.rb, line 45 def publish warn "[DEPRECATION] `publish` is deprecated. \ Please use `publish_to_interests` instead." publish_to_interests end
publish_to_interests()
click to toggle source
Publish
the given payload to the specified interests.
# File lib/pusher/push_notifications/use_cases/publish.rb, line 52 def publish_to_interests data = { interests: interests }.merge!(payload) client.post('publishes', data) end
Private Instance Methods
client()
click to toggle source
# File lib/pusher/push_notifications/use_cases/publish.rb, line 61 def client @client ||= PushNotifications::Client.new end