Class: FiveMobilePush::Notifier

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

Overview

TODO:

Validate provided platforms

Defined Under Namespace

Classes: Message

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Notifier

Returns a new instance of Notifier.

Parameters:



6
7
8
# File 'lib/five_mobile_push/notifier.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#broadcast(platforms) {|message| ... } ⇒ Object

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

Examples:

Simple usage

n = FiveMobilePush::Notifier.new(client)
n.broadcast(FiveMobilePush::Platform::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)

See Also:

  • Platform.supported_platforms


26
27
28
29
30
# File 'lib/five_mobile_push/notifier.rb', line 26

def broadcast(platforms, &block)
  @client.post 'notify/broadcast',
    :platforms => Platform.new(platforms).build_list,
    :payload   => Message.dsl(&block).to_json
end

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

Notifies any device registered with the provided tags.

Examples:

Simple usage

n = FiveMobilePush::Notifier.new(client)
n.notify_by_tags(FiveMobilePush::Platform::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)

See Also:

  • Platform.supported_platforms


70
71
72
73
74
75
# File 'lib/five_mobile_push/notifier.rb', line 70

def notify_by_tags(platforms, tags, &block)
  @client.post 'notify/toTags',
    :platforms => Platform.new(platforms).build_list,
    :tags      => tags.join(','),
    :payload   => Message.dsl(&block).to_json
end

#notify_devices(devices) {|message| ... } ⇒ Object

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)



46
47
48
49
50
51
# File 'lib/five_mobile_push/notifier.rb', line 46

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