Module: WebPush
- Defined in:
- lib/web_push.rb,
lib/web_push/errors.rb,
lib/web_push/request.rb,
lib/web_push/version.rb,
lib/web_push/vapid_key.rb,
lib/web_push/encryption.rb
Overview
Push API implementation
Defined Under Namespace
Modules: Encryption Classes: ConfigurationError, Error, ExpiredSubscription, InvalidSubscription, PayloadTooLarge, PushServiceError, Request, ResponseError, TooManyRequests, Unauthorized, VapidKey
Constant Summary collapse
- VERSION =
'2.0.0'.freeze
Class Method Summary collapse
- .decode64(str) ⇒ Object
- .encode64(bytes) ⇒ Object
-
.generate_key ⇒ WebPush::VapidKey
Generate a VapidKey instance to obtain base64 encoded public and private keys suitable for VAPID protocol JSON web token signing.
-
.payload_send(message: '', endpoint:, p256dh: '', auth: '', vapid: {}, **options) ⇒ Object
Deliver the payload to the required endpoint given by the JavaScript PushSubscription.
Class Method Details
.decode64(str) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/web_push.rb', line 59 def decode64(str) # For Ruby < 2.3, Base64.urlsafe_decode64 strict decodes and will raise errors if encoded value is not properly padded # Implementation: http://ruby-doc.org/stdlib-2.3.0/libdoc/base64/rdoc/Base64.html#method-i-urlsafe_decode64 str = str.ljust((str.length + 3) & ~3, '=') if !str.end_with?('=') && str.length % 4 != 0 Base64.urlsafe_decode64(str) end |
.encode64(bytes) ⇒ Object
55 56 57 |
# File 'lib/web_push.rb', line 55 def encode64(bytes) Base64.urlsafe_encode64(bytes) end |
.generate_key ⇒ WebPush::VapidKey
Generate a VapidKey instance to obtain base64 encoded public and private keys suitable for VAPID protocol JSON web token signing
51 52 53 |
# File 'lib/web_push.rb', line 51 def generate_key VapidKey.new end |
.payload_send(message: '', endpoint:, p256dh: '', auth: '', vapid: {}, **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.
38 39 40 41 42 43 44 45 |
# File 'lib/web_push.rb', line 38 def payload_send(message: '', endpoint:, p256dh: '', auth: '', vapid: {}, **) WebPush::Request.new( message: , subscription: subscription(endpoint, p256dh, auth), vapid: vapid, ** ).perform end |