Exception: Ably::Models::PushChannelSubscription

Inherits:
Exceptions::BaseAblyException show all
Includes:
Ably::Modules::ModelCommon
Defined in:
lib/ably/models/push_channel_subscription.rb

Overview

An object representing a devices details, used currently for push notifications

Instance Attribute Summary collapse

Attributes included from Ably::Modules::ModelCommon

#hash

Attributes inherited from Exceptions::BaseAblyException

#code, #message, #request_id, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ably::Modules::ModelCommon

#==, #[], #as_json, included, #to_json, #to_s

Methods included from Ably::Modules::MessagePack

#to_msgpack

Methods inherited from Exceptions::BaseAblyException

#as_json, #to_s

Constructor Details

#initialize(hash_object = {}) ⇒ PushChannelSubscription

a

Parameters:

  • hash_object (Hash, nil) (defaults to: {})

    Device detail attributes


35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ably/models/push_channel_subscription.rb', line 35

def initialize(hash_object = {})
  @raw_hash_object = hash_object || {}
  @hash_object     = IdiomaticRubyWrapper(hash_object)

  if !attributes[:client_id] && !attributes[:device_id]
    raise ArgumentError, 'Either client_id or device_id must be provided'
  end
  if attributes[:client_id] && attributes[:device_id]
    raise ArgumentError, 'client_id and device_id cannot both be provided, they are mutually exclusive'
  end
  if !attributes[:channel]
    raise ArgumentError, 'channel is required'
  end
end

Instance Attribute Details

#channelString (readonly)

Returns The realtime pub/sub channel this subscription is registered to

Returns:

  • (String)

    The realtime pub/sub channel this subscription is registered to


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ably/models/push_channel_subscription.rb', line 30

class PushChannelSubscription < Ably::Exceptions::BaseAblyException
  include Ably::Modules::ModelCommon

  # @param hash_object   [Hash,nil]  Device detail attributes
  #a
  def initialize(hash_object = {})
    @raw_hash_object = hash_object || {}
    @hash_object     = IdiomaticRubyWrapper(hash_object)

    if !attributes[:client_id] && !attributes[:device_id]
      raise ArgumentError, 'Either client_id or device_id must be provided'
    end
    if attributes[:client_id] && attributes[:device_id]
      raise ArgumentError, 'client_id and device_id cannot both be provided, they are mutually exclusive'
    end
    if !attributes[:channel]
      raise ArgumentError, 'channel is required'
    end
  end

  # Constructor for channel subscription by device ID
  #
  # @param channel    [String]  the realtime pub/sub channel this subscription is registered to
  # @param device_id  [String]  Unique device identifier assigned to the push device
  #
  # @return [PushChannelSubscription]
  #
  def self.for_device(channel, device_id)
    PushChannelSubscription.new(channel: channel, device_id: device_id)
  end

  # Constructor for channel subscription by client ID
  #
  # @param channel    [String]  the realtime pub/sub channel this subscription is registered to
  # @param client_id  [String]  Client ID that is assigned to one or more registered push devices
  #
  # @return [PushChannelSubscription]
  #
  def self.for_client_id(channel, client_id)
    PushChannelSubscription.new(channel: channel, client_id: client_id)
  end

  %w(channel client_id device_id).each do |attribute|
    define_method attribute do
      attributes[attribute.to_sym]
    end

    define_method "#{attribute}=" do |val|
      unless val.nil? || val.kind_of?(String)
        raise ArgumentError, "#{attribute} must be nil or a string value"
      end
      attributes[attribute.to_sym] = val
    end
  end

  def attributes
    @hash_object
  end
end

#client_idString (readonly)

Returns Client ID that is assigned to one or more registered push devices

Returns:

  • (String)

    Client ID that is assigned to one or more registered push devices


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ably/models/push_channel_subscription.rb', line 30

class PushChannelSubscription < Ably::Exceptions::BaseAblyException
  include Ably::Modules::ModelCommon

  # @param hash_object   [Hash,nil]  Device detail attributes
  #a
  def initialize(hash_object = {})
    @raw_hash_object = hash_object || {}
    @hash_object     = IdiomaticRubyWrapper(hash_object)

    if !attributes[:client_id] && !attributes[:device_id]
      raise ArgumentError, 'Either client_id or device_id must be provided'
    end
    if attributes[:client_id] && attributes[:device_id]
      raise ArgumentError, 'client_id and device_id cannot both be provided, they are mutually exclusive'
    end
    if !attributes[:channel]
      raise ArgumentError, 'channel is required'
    end
  end

  # Constructor for channel subscription by device ID
  #
  # @param channel    [String]  the realtime pub/sub channel this subscription is registered to
  # @param device_id  [String]  Unique device identifier assigned to the push device
  #
  # @return [PushChannelSubscription]
  #
  def self.for_device(channel, device_id)
    PushChannelSubscription.new(channel: channel, device_id: device_id)
  end

  # Constructor for channel subscription by client ID
  #
  # @param channel    [String]  the realtime pub/sub channel this subscription is registered to
  # @param client_id  [String]  Client ID that is assigned to one or more registered push devices
  #
  # @return [PushChannelSubscription]
  #
  def self.for_client_id(channel, client_id)
    PushChannelSubscription.new(channel: channel, client_id: client_id)
  end

  %w(channel client_id device_id).each do |attribute|
    define_method attribute do
      attributes[attribute.to_sym]
    end

    define_method "#{attribute}=" do |val|
      unless val.nil? || val.kind_of?(String)
        raise ArgumentError, "#{attribute} must be nil or a string value"
      end
      attributes[attribute.to_sym] = val
    end
  end

  def attributes
    @hash_object
  end
end

#device_idString (readonly)

Returns Unique device identifier assigned to the push device

Returns:

  • (String)

    Unique device identifier assigned to the push device


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ably/models/push_channel_subscription.rb', line 30

class PushChannelSubscription < Ably::Exceptions::BaseAblyException
  include Ably::Modules::ModelCommon

  # @param hash_object   [Hash,nil]  Device detail attributes
  #a
  def initialize(hash_object = {})
    @raw_hash_object = hash_object || {}
    @hash_object     = IdiomaticRubyWrapper(hash_object)

    if !attributes[:client_id] && !attributes[:device_id]
      raise ArgumentError, 'Either client_id or device_id must be provided'
    end
    if attributes[:client_id] && attributes[:device_id]
      raise ArgumentError, 'client_id and device_id cannot both be provided, they are mutually exclusive'
    end
    if !attributes[:channel]
      raise ArgumentError, 'channel is required'
    end
  end

  # Constructor for channel subscription by device ID
  #
  # @param channel    [String]  the realtime pub/sub channel this subscription is registered to
  # @param device_id  [String]  Unique device identifier assigned to the push device
  #
  # @return [PushChannelSubscription]
  #
  def self.for_device(channel, device_id)
    PushChannelSubscription.new(channel: channel, device_id: device_id)
  end

  # Constructor for channel subscription by client ID
  #
  # @param channel    [String]  the realtime pub/sub channel this subscription is registered to
  # @param client_id  [String]  Client ID that is assigned to one or more registered push devices
  #
  # @return [PushChannelSubscription]
  #
  def self.for_client_id(channel, client_id)
    PushChannelSubscription.new(channel: channel, client_id: client_id)
  end

  %w(channel client_id device_id).each do |attribute|
    define_method attribute do
      attributes[attribute.to_sym]
    end

    define_method "#{attribute}=" do |val|
      unless val.nil? || val.kind_of?(String)
        raise ArgumentError, "#{attribute} must be nil or a string value"
      end
      attributes[attribute.to_sym] = val
    end
  end

  def attributes
    @hash_object
  end
end

Class Method Details

.for_client_id(channel, client_id) ⇒ PushChannelSubscription

Constructor for channel subscription by client ID

Parameters:

  • channel (String)

    the realtime pub/sub channel this subscription is registered to

  • client_id (String)

    Client ID that is assigned to one or more registered push devices

Returns:

  • (PushChannelSubscription)

68
69
70
# File 'lib/ably/models/push_channel_subscription.rb', line 68

def self.for_client_id(channel, client_id)
  PushChannelSubscription.new(channel: channel, client_id: client_id)
end

.for_device(channel, device_id) ⇒ PushChannelSubscription

Constructor for channel subscription by device ID

Parameters:

  • channel (String)

    the realtime pub/sub channel this subscription is registered to

  • device_id (String)

    Unique device identifier assigned to the push device

Returns:

  • (PushChannelSubscription)

57
58
59
# File 'lib/ably/models/push_channel_subscription.rb', line 57

def self.for_device(channel, device_id)
  PushChannelSubscription.new(channel: channel, device_id: device_id)
end

Instance Method Details

#attributesObject


85
86
87
# File 'lib/ably/models/push_channel_subscription.rb', line 85

def attributes
  @hash_object
end