Module: FirebaseCloudMessenger

Defined in:
lib/firebase_cloud_messenger.rb,
lib/firebase_cloud_messenger/error.rb,
lib/firebase_cloud_messenger/client.rb,
lib/firebase_cloud_messenger/schema.rb,
lib/firebase_cloud_messenger/message.rb,
lib/firebase_cloud_messenger/version.rb,
lib/firebase_cloud_messenger/apns/alert.rb,
lib/firebase_cloud_messenger/apns/config.rb,
lib/firebase_cloud_messenger/auth_client.rb,
lib/firebase_cloud_messenger/apns/payload.rb,
lib/firebase_cloud_messenger/notification.rb,
lib/firebase_cloud_messenger/android/config.rb,
lib/firebase_cloud_messenger/webpush/config.rb,
lib/firebase_cloud_messenger/firebase_object.rb,
lib/firebase_cloud_messenger/apns/apns_object.rb,
lib/firebase_cloud_messenger/android/notification.rb,
lib/firebase_cloud_messenger/webpush/notification.rb

Defined Under Namespace

Modules: Android, Apns, Webpush Classes: AuthClient, BadRequest, Client, Error, FirebaseObject, Forbidden, Message, Notification, Unauthorized

Constant Summary collapse

SCHEMA =
{
  "definitions" => {
    "data" => {
      "type" => "object",
      "additionalProperties" => { "type" => "string" }
    },
    "notification" => {
      "type" => "object",
      "properties" => {
        "title" => { "type" => "string" },
        "body"  => { "type" => "string" }
      },
      "additionalProperties" => false
    },
    "android_config" => {
      "type" => "object",
      "properties" => {
        "collapse_key"             => { "type" => "string" },
        "priority"                 => { "type" => "string", "enum" => ["NORMAL", "HIGH"] },
        "ttl"                      => { "type" => "string", "format" => "^[0-9]+\.[0-9]+s$" },
        "restricted_package_name"  => { "type" => "string" },
        "data"                     => { "$ref" => "#/definitions/data" },
        "notification"             => { "$ref" => "#/definitions/android_notification" }
      },
      "additionalProperties" => false
    },
    "android_notification" => {
      "type" => "object",
      "properties" => {
        "title"          => { "type" => "string" },
        "body"           => { "type" => "string" },
        "icon"           => { "type" => "string" },
        "color"          => { "type" => "string" },
        "sound"          => { "type" => "string" },
        "tag"            => { "type" => "string" },
        "click_action"   => { "type" => "string" },
        "body_loc_key"   => { "type" => "string" },
        "body_loc_args"  => { "type" => "array", "items" => { "type" => "string" } },
        "title_loc_key"  => { "type" => "string" },
        "title_loc_args" => { "type" => "array", "items" => { "type" => "string" } }
      },
      "additionalProperties" => false
    },
    "webpush_config" => {
      "type" => "object",
      "properties" => {
        "headers"      => { "$ref" => "#/definitions/data" },
        "data"         => { "$ref" => "#/definitions/data" },
        "notification" => { "$ref" => "#/definitions/webpush_notification" }
      },
      "additionalProperties" => false
    },
    "webpush_notification" => {
      "type" => "object",
      "properties" => {
        "title"          => { "type" => "string" },
        "body"           => { "type" => "string" },
        "icon"           => { "type" => "string" }
      },
      "additionalProperties" => false
    },
    "apns" => {
      "type" => "object",
      "properties" => {
        "headers" => { "$ref" => "#/definitions/data" },
        "payload" => { "$ref" => "#/definitions/apns_payload" }
      },
      "additionalProperties" => false
    },
    "apns_alert" => {
      "anyOf" => [
        { "type" => "string" },
        {
          "type" => "object",
          "properties" => {
            "title"          => { "type" => "string" },
            "body"           => { "type" => "string" },
            "title-loc-key " => { "anyOf" => [ { "type" => "string" }, { "type" => "null" } ] },
            "title-loc-args" => { "anyOf" => [ { "type" => "array", "items" => { "type" => "string" } }, { "type" => "null" }] },
            "action-loc-key" => { "anyOf" => [ { "type" => "string" }, { "type" => "null" } ] },
            "loc-key"        => { "type" => "string" },
            "loc-args"       => { "type" => "array", "items" => { "type" => "string" } },
            "launch-image"   => { "type" => "string" }
          },
          "additionalProperties" => false
        }
      ]
    },
    "apns_payload" => {
      "type" => "object",
      "properties" => {
        "alert"             => { "$ref" => "#/definitions/apns_alert" },
        "badge"             => { "type" => "number" },
        "sound"             => { "type" => "string" },
        "content-available" => { "type" => "number" },
        "category"          => { "type" => "string" },
        "thread-id"         => { "type" => "string" }
      },
      "additionalProperties" => false
    }
  },
  "type" => "object",
  "properties" => {
    "data"         => { "$ref" => "#/definitions/data" },
    "notification" => { "$ref" => "#/definitions/notification" },
    "android"      => { "$ref" => "#/definitions/android_config" },
    "webpush"      => { "$ref" => "#/definitions/webpush_config" },
    "apns"         => { "$ref" => "#/definitions/apns" },
    "token"        => { "type" => "string" },
    "topic"        => { "type" => "string" },
    "condition"    => { "type" => "string" }
  },
  "additionalProperties" => false,
  "oneOf" => [
    { "required" => ["token"] },
    { "required" => ["topic"] },
    { "required" => ["condition"] }
  ]
}
VERSION =
"0.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.credentials_pathObject

Returns the value of attribute credentials_path.



18
19
20
# File 'lib/firebase_cloud_messenger.rb', line 18

def credentials_path
  @credentials_path
end

Class Method Details

.send(message: {}, validate_only: false, conn: nil) ⇒ Object



21
22
23
# File 'lib/firebase_cloud_messenger.rb', line 21

def self.send(message: {}, validate_only: false, conn: nil)
  Client.new(credentials_path).send(message, validate_only, conn)
end

.validate_message(message, conn = nil, against_api: false) ⇒ Object



25
26
27
28
29
# File 'lib/firebase_cloud_messenger.rb', line 25

def self.validate_message(message, conn = nil, against_api: false)
  message = Message.new(message) if message.is_a?(Hash)

  message.valid?(conn, against_api: against_api)
end