Class: Spacebunny::Device::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device, options, delivery_info, metadata, payload) ⇒ Message

Returns a new instance of Message.



6
7
8
9
10
11
12
13
14
15
# File 'lib/spacebunny/device/message.rb', line 6

def initialize(device, options, delivery_info, , payload)
  @device = device
  @options = options
  @delivery_info = delivery_info
  @metadata = 
  @payload = payload

  extract_options
  set_sender_id_and_channel
end

Instance Attribute Details

#channel_nameObject (readonly)

Returns the value of attribute channel_name.



4
5
6
# File 'lib/spacebunny/device/message.rb', line 4

def channel_name
  @channel_name
end

#delivery_infoObject (readonly)

Returns the value of attribute delivery_info.



4
5
6
# File 'lib/spacebunny/device/message.rb', line 4

def delivery_info
  @delivery_info
end

#deviceObject (readonly)

Returns the value of attribute device.



4
5
6
# File 'lib/spacebunny/device/message.rb', line 4

def device
  @device
end

#metadataObject (readonly)

Returns the value of attribute metadata.



4
5
6
# File 'lib/spacebunny/device/message.rb', line 4

def 
  @metadata
end

#payloadObject (readonly)

Returns the value of attribute payload.



4
5
6
# File 'lib/spacebunny/device/message.rb', line 4

def payload
  @payload
end

#sender_idObject (readonly)

Returns the value of attribute sender_id.



4
5
6
# File 'lib/spacebunny/device/message.rb', line 4

def sender_id
  @sender_id
end

Instance Method Details

#ack(options = {}) ⇒ Object



17
18
19
20
# File 'lib/spacebunny/device/message.rb', line 17

def ack(options = {})
  multiple = options.fetch :multiple, false
  @device.input_channel.acknowledge @delivery_info.delivery_tag, multiple
end

#blacklisted?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/spacebunny/device/message.rb', line 28

def blacklisted?
  # Discard packet if it has been sent from me
  if @discard_mine && @device.id.eql?(@sender_id) && !from_api?
    return true
  end
  # Discard packet if has been published from APIs
  if @discard_from_api && from_api?
    return true
  end
  false
end

#from_api?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/spacebunny/device/message.rb', line 40

def from_api?
  !@metadata[:headers].nil? && @metadata[:headers]['x-from-sb-api']
end

#nack(options = {}) ⇒ Object



22
23
24
25
26
# File 'lib/spacebunny/device/message.rb', line 22

def nack(options = {})
  multiple = options.fetch :multiple, false
  requeue = options.fetch :requeue, false
  @device.input_channel.nack @delivery_info.delivery_tag, multiple, requeue
end