Module: Webpush

Defined in:
lib/webpush.rb,
lib/webpush/request.rb,
lib/webpush/version.rb,
lib/webpush/encryption.rb

Defined Under Namespace

Modules: Encryption Classes: InvalidSubscription, Request, ResponseError

Constant Summary collapse

GCM_URL =

It is temporary URL until supported by the GCM server.

'https://android.googleapis.com/gcm/send'
TEMP_GCM_URL =
'https://gcm-http.googleapis.com/gcm'
VERSION =
"0.2.3"

Class Method Summary collapse

Class Method Details

.payload_send(endpoint:, message: "", p256dh: "", auth: "", **options) ⇒ Object

Deliver the payload to the required endpoint given by the JavaScript PushSubscription. Including an optional message requires p256dh and auth keys from the PushSubscription.

Parameters:

  • endpoint (String)

    the required PushSubscription url

  • message (String) (defaults to: "")

    the optional payload

  • p256dh (String) (defaults to: "")

    the user’s public ECDH key given by the PushSubscription

  • auth (String) (defaults to: "")

    the user’s private ECDH key given by the PushSubscription

  • options (Hash<Symbol,String>)

    additional options for the notification

Options Hash (**options):

  • :api_key (String)

    required for Google, omit for Firefox

  • :ttl (#to_s)

    Time-to-live in seconds



29
30
31
32
33
34
35
# File 'lib/webpush.rb', line 29

def payload_send(endpoint:, message: "", p256dh: "", auth: "", **options)
  endpoint = endpoint.gsub(GCM_URL, TEMP_GCM_URL)

  payload = build_payload(message, p256dh, auth)

  Webpush::Request.new(endpoint, options.merge(payload: payload)).perform
end