Class: Pling::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/pling/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Device

Creates a new Pling::Device instance with the given identifier and type

Parameters:

  • attributes (Hash) (defaults to: {})

Options Hash (attributes):

  • :identifier (#to_s)
  • :type (#to_sym)


36
37
38
39
40
41
# File 'lib/pling/device.rb', line 36

def initialize(attributes = {})
  attributes.each_pair do |key, value|
    method = "#{key}="
    send(method, value) if respond_to?(method)
  end
end

Instance Attribute Details

#identifierObject #identifier=(identifier) ⇒ Object

The device identifier

Overloads:

  • #identifier=(identifier) ⇒ Object

    Parameters:

    • identifier (#to_s)


10
11
12
# File 'lib/pling/device.rb', line 10

def identifier
  @identifier
end

#typeObject #type=(type) ⇒ Object

The device type

Overloads:

  • #type=(type) ⇒ Object

    Parameters:

    • type (#to_sym)


23
24
25
# File 'lib/pling/device.rb', line 23

def type
  @type
end

Instance Method Details

#deliver(message) ⇒ Object

Delivers the given message using an appropriate gateway.

Parameters:

  • message (#to_pling_message)


55
56
57
# File 'lib/pling/device.rb', line 55

def deliver(message)
  Pling.deliver(message, self)
end

#to_pling_devicePling::Device

Returns the object itself as it is already a Pling::Device.

Returns:



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

def to_pling_device
  self
end

#valid?Boolean

A device is valid if it has a type and an identifier.

Returns:

  • (Boolean)


47
48
49
# File 'lib/pling/device.rb', line 47

def valid?
  !!(type && identifier)
end