Class: Pusher::PushNotifications::UseCases::Publish
- Inherits:
-
Object
- Object
- Pusher::PushNotifications::UseCases::Publish
- Defined in:
- lib/pusher/push_notifications/use_cases/publish.rb
Defined Under Namespace
Classes: PublishError
Class Method Summary collapse
-
.publish(client, interests:, payload: {}) ⇒ Object
Publish the given payload to the specified interests.
-
.publish_to_interests(client, interests:, payload: {}) ⇒ Object
Publish the given payload to the specified interests.
Class Method Details
.publish(client, interests:, payload: {}) ⇒ Object
Publish the given payload to the specified interests. DEPRECATED: Please use publish_to_interests
instead.
11 12 13 14 15 |
# File 'lib/pusher/push_notifications/use_cases/publish.rb', line 11 def self.publish(client, interests:, payload: {}) warn "[DEPRECATION] `publish` is deprecated. \ Please use `publish_to_interests` instead." publish_to_interests(client, interests: interests, payload: payload) end |
.publish_to_interests(client, interests:, payload: {}) ⇒ Object
Publish the given payload to the specified interests.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pusher/push_notifications/use_cases/publish.rb', line 18 def self.publish_to_interests(client, interests:, payload: {}) 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 data = { interests: interests }.merge!(payload) client.post('publishes', data) end |