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/version.rb,
lib/pling/adapter.rb,
lib/pling/message.rb,
lib/pling/gateway.rb,
lib/pling/middleware.rb,
lib/pling/apn/gateway.rb,
lib/pling/gcm/gateway.rb,
lib/pling/apn/feedback.rb,
lib/pling/adapter/base.rb,
lib/pling/c2dm/gateway.rb,
lib/pling/configurable.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

.adapterPling::Adapter

Stores the adapter



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

def adapter
  @adapter
end

.gatewaysArray

Stores the list of available gateway instances



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

def gateways
  @gateways
end

.loggerLogger

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



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

def logger
  @logger
end

.middlewaresArray

Stores the list of avaiable middleware instances



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

def middlewares
  @middlewares
end

Class Method Details

._convert(object, type) ⇒ Object

INTERNAL METHOD

Converts the given object to the given pling type

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

.configure {|config| ... } ⇒ Object

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

.deliver(message, device, stack = nil) ⇒ Object

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



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