Class: Verizon::DeviceRole

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/verizon/models/device_role.rb

Overview

The access rule (DeviceRole object) defines this topics the application or device can publish or subscribe to. It also defines how many parallel subscriptions one device or applications can have and how fast it can publish messages.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(name:, subscribe_limit: 50, publish_rate_limit: 15, publish: SKIP, subscribe: SKIP) ⇒ DeviceRole

Returns a new instance of DeviceRole.



65
66
67
68
69
70
71
72
# File 'lib/verizon/models/device_role.rb', line 65

def initialize(name:, subscribe_limit: 50, publish_rate_limit: 15,
               publish: SKIP, subscribe: SKIP)
  @name = name
  @subscribe_limit = subscribe_limit unless subscribe_limit == SKIP
  @publish_rate_limit = publish_rate_limit unless publish_rate_limit == SKIP
  @publish = publish unless publish == SKIP
  @subscribe = subscribe unless subscribe == SKIP
end

Instance Attribute Details

#nameString

The unique name of the access rule.

Returns:

  • (String)


17
18
19
# File 'lib/verizon/models/device_role.rb', line 17

def name
  @name
end

#publishArray[String]

The topics or topic patterns that the application or device is allowed to publish messages.

Returns:

  • (Array[String])


32
33
34
# File 'lib/verizon/models/device_role.rb', line 32

def publish
  @publish
end

#publish_rate_limitInteger

The maximum rate that one application or device can publish messages per seconds.

Returns:

  • (Integer)


27
28
29
# File 'lib/verizon/models/device_role.rb', line 27

def publish_rate_limit
  @publish_rate_limit
end

#subscribeArray[String]

The topics or topic patterns that the application or device is allowed to subscribe to.

Returns:

  • (Array[String])


37
38
39
# File 'lib/verizon/models/device_role.rb', line 37

def subscribe
  @subscribe
end

#subscribe_limitInteger

The maximum number of subscriptions that one application or device can make.

Returns:

  • (Integer)


22
23
24
# File 'lib/verizon/models/device_role.rb', line 22

def subscribe_limit
  @subscribe_limit
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/verizon/models/device_role.rb', line 75

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  subscribe_limit = hash['subscribeLimit'] ||= 50
  publish_rate_limit = hash['publishRateLimit'] ||= 15
  publish = hash.key?('publish') ? hash['publish'] : SKIP
  subscribe = hash.key?('subscribe') ? hash['subscribe'] : SKIP

  # Create object from extracted values.
  DeviceRole.new(name: name,
                 subscribe_limit: subscribe_limit,
                 publish_rate_limit: publish_rate_limit,
                 publish: publish,
                 subscribe: subscribe)
end

.namesObject

A mapping from model property names to API property names.



40
41
42
43
44
45
46
47
48
# File 'lib/verizon/models/device_role.rb', line 40

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['subscribe_limit'] = 'subscribeLimit'
  @_hash['publish_rate_limit'] = 'publishRateLimit'
  @_hash['publish'] = 'publish'
  @_hash['subscribe'] = 'subscribe'
  @_hash
end

.nullablesObject

An array for nullable fields



61
62
63
# File 'lib/verizon/models/device_role.rb', line 61

def self.nullables
  []
end

.optionalsObject

An array for optional fields



51
52
53
54
55
56
57
58
# File 'lib/verizon/models/device_role.rb', line 51

def self.optionals
  %w[
    subscribe_limit
    publish_rate_limit
    publish
    subscribe
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



101
102
103
104
105
106
# File 'lib/verizon/models/device_role.rb', line 101

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name.inspect}, subscribe_limit: #{@subscribe_limit.inspect},"\
  " publish_rate_limit: #{@publish_rate_limit.inspect}, publish: #{@publish.inspect},"\
  " subscribe: #{@subscribe.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



94
95
96
97
98
# File 'lib/verizon/models/device_role.rb', line 94

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name}, subscribe_limit: #{@subscribe_limit}, publish_rate_limit:"\
  " #{@publish_rate_limit}, publish: #{@publish}, subscribe: #{@subscribe}>"
end