module PusherNotification
Constants
- INTERESTS_MAX_LENGTH
- VERSION
Attributes
config[RW]
Public Class Methods
publish(payload = {})
click to toggle source
# File lib/pusher_notification.rb, line 10 def publish(payload = {}) validate_payload(payload) Faraday.post( base_url + path, payload.to_json, { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{config[:secret]}" } ) end
Private Class Methods
base_url()
click to toggle source
# File lib/pusher_notification.rb, line 39 def base_url "https://#{config[:instance_id]}.pushnotifications.pusher.com/" end
path()
click to toggle source
# File lib/pusher_notification.rb, line 43 def path "publish_api/v1/instances/#{config[:instance_id]}/publishes" end
validate_payload(payload = {})
click to toggle source
# File lib/pusher_notification.rb, line 25 def validate_payload(payload = {}) unless config.key?(:instance_id) && config.key?(:secret_key) raise 'Config must be provided before publishing' end unless payload.key?(:interests) raise 'Interests is a required parameter.' end if payload[:interests].any? {|interest| interest.length > INTERESTS_MAX_LENGTH } raise "Interests can not be longer than the maximum of #{INTERESTS_MAX_LENGTH}." end end