Module: Pling

Defined in:
lib/pling.rb,
lib/pling/gcm.rb,
lib/pling/apn.rb,
lib/pling/c2dm.rb,
lib/pling/device.rb,
lib/pling/gateway.rb,
lib/pling/message.rb,
lib/pling/version.rb,
lib/pling/adapter.rb,
lib/pling/middleware.rb,
lib/pling/gcm/gateway.rb,
lib/pling/apn/gateway.rb,
lib/pling/configurable.rb,
lib/pling/c2dm/gateway.rb,
lib/pling/apn/feedback.rb,
lib/pling/adapter/base.rb,
lib/pling/apn/connection.rb,
lib/pling/middleware/base.rb,
lib/pling/delayed_initializer.rb

Defined Under Namespace

Modules: APN, Adapter, C2DM, Configurable, GCM, Middleware Classes: AuthenticationFailed, DelayedInitializer, DeliveryFailed, Device, Error, Gateway, Message, NoGatewayFound

Constant Summary

VERSION =
"0.3.1"

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Class Attribute Details

+ (Pling::Adapter) adapter

Stores the adapter

Returns:



62
63
64
# File 'lib/pling.rb', line 62

def adapter
  @adapter
end

+ (Array) gateways

Stores the list of available gateway instances

Returns:

  • (Array)

    list of available gateways



42
43
44
# File 'lib/pling.rb', line 42

def gateways
  @gateways
end

+ (Logger) logger

Stores the logger. Defaults to Logger.new(nil)

Returns:

  • (Logger)


68
69
70
# File 'lib/pling.rb', line 68

def logger
  @logger
end

+ (Array) middlewares

Stores the list of avaiable middleware instances

Returns:

  • (Array)

    list of available middleware



52
53
54
# File 'lib/pling.rb', line 52

def middlewares
  @middlewares
end

Class Method Details

+ (Object) _convert(object, type)

INTERNAL METHOD

Converts the given object to the given pling type

Parameters:

  • object (Object)

    The object that needs to be converted

  • type (Symbol, String)

    #to_pling_ method suffix

Raises:

  • (ArgumentError)

    The object does not implement a #to_pling_ + type method



106
107
108
109
110
# File 'lib/pling.rb', line 106

def _convert(object, type)
  method = :to_pling_#{type}"
  raise ArgumentError, "Instances of #{object.class} do not implement ##{method}" unless object.respond_to?(method)
  object && object.send(method)
end

+ (Object) configure {|config| ... }

Allows configuration of Pling by passing a config object to the given block

Yields:

  • (config)

Raises:

  • (ArgumentError)

    Raised when no block is given



75
76
77
78
# File 'lib/pling.rb', line 75

def configure
  raise ArgumentError, 'No block given for Pling.configure' unless block_given?
  yield self
end

+ (Object) deliver(message, device, stack = nil)

Delivers the given message to the given device using the given stack.

Parameters:

  • message (#to_pling_message)
  • device (#to_pling_device)
  • stack (Array) (defaults to: nil)

    The stack to use (Default: middlewares + [adapter])



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pling.rb', line 86

def deliver(message, device, stack = nil)
  message = Pling._convert(message, :message)
  device  = Pling._convert(device, :device)

  Pling.logger.info "#{self.class} -- Delivering #{message.inspect} to #{device.inspect}"

  stack ||= middlewares.initialize! + [adapter]

  stack.shift.deliver(message, device) do |m, d|
    deliver(m, d, stack)
  end
end