Class: FiveMobilePush::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/five_mobile_push/notifier.rb

Overview

TODO:

Validate provided platforms

TODO:

Simplify platform selection

Defined Under Namespace

Classes: Message

Constant Summary

ALL =

The following are platforms supported by the Five Mobile Push platform

"all"
IPHONE =
"iphone"
BLACKBERRY =
"blackberry"
ANDROID =
"android"

Instance Method Summary (collapse)

Constructor Details

- (Notifier) initialize(client)

A new instance of Notifier

Parameters:



15
16
17
# File 'lib/five_mobile_push/notifier.rb', line 15

def initialize(client)
  @client = client
end

Instance Method Details

- (Object) broadcast(platforms) {|message| ... }

Broadcast a notification to one or more platforms of an application.

Supported Platforms

  • all

  • iphone

  • blackberry

  • android

Examples:

Simple usage

n = FiveMobilePush::Notifier.new(client)
n.broadcast(FiveMobilePush::Notifier::ALL) do |message|
  message.body "Downtime this weekend"
end

Parameters:

  • platforms (Array<String>, String)

    Any of the supported platforms.

Yields:

  • (message)

    Provides a mini-DSL for constructing the message to broadcast.

Yield Parameters:

  • message (Message)

    (see Message)



40
41
42
43
44
# File 'lib/five_mobile_push/notifier.rb', line 40

def broadcast(platforms, &block)
  @client.post 'notify/broadcast',
    :platforms => build_platforms_string(platforms),
    :payload   => capture_message(&block).to_json
end

- (Object) notify_by_tags(platforms, tags) {|message| ... }

Notifies any device registered with the provided tags.

Supported Platforms

  • all

  • iphone

  • blackberry

  • android

Examples:

Simple usage

n = FiveMobilePush::Notifier.new(client)
n.notify_by_tags(FiveMobilePush::Notifier::ALL, ['muffin', 'bacon']) do |message|
  message.body "Downtime this weekend"
end

Parameters:

  • platforms (Array<String>, String)

    Any of the supported platforms.

  • tags (Array<String>)

    Any tag that is registered

Yields:

  • (message)

    Provides a mini-DSL for constructing the message to broadcast.

Yield Parameters:

  • message (Message)

    (see Message)



89
90
91
92
93
94
# File 'lib/five_mobile_push/notifier.rb', line 89

def notify_by_tags(platforms, tags, &block)
  @client.post 'notify/toTags',
    :platforms => build_platforms_string(platforms),
    :tags      => tags.join(','),
    :payload   => capture_message(&block).to_json
end

- (Object) notify_devices(devices) {|message| ... }

Send a notification to any number of specified devices

Examples:

Simple usage

n = FiveMobilePush::Notifier.new(client)
n.notify_devices(['1234']) do |message|
  message.body "Downtime this weekend"
end

Parameters:

  • devices (Array<String>)

    A list of device ID values

Yields:

  • (message)

    Provides a mini-DSL for constructing the message to broadcast.

Yield Parameters:

  • message (Message)

    (see Message)



60
61
62
63
64
65
# File 'lib/five_mobile_push/notifier.rb', line 60

def notify_devices(devices, &block)
  @client.post 'notify/toDevices',
    :id_type   => FiveMobilePush::DEFAULT_ID_TYPE,
    :id_values => devices.join(','),
    :payload   => capture_message(&block).to_json
end