Class: PushyNotifier::PushyService

Inherits:
Object
  • Object
show all
Defined in:
lib/pushy_notifier/pushy_service.rb

Overview

This class provides functionality for sending push notifications using the Pushy service.

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ PushyService

Returns a new instance of PushyService.



7
8
9
# File 'lib/pushy_notifier/pushy_service.rb', line 7

def initialize(api_key)
  @api_key = api_key
end

Instance Method Details

#send_notification(device_token, message) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/pushy_notifier/pushy_service.rb', line 11

def send_notification(device_token, message)
  headers = { 'Content-Type' => 'application/json' }
  body = { to: device_token, data: { message: message } }.to_json
  HTTParty.post("https://api.pushy.me/push?api_key=#{@api_key}", body: body, headers: headers)
rescue StandardError => e
  Rails.logger.info "Something went wrong while sending notification: #{e.message}"
end