Class: DeviceCloud::PushNotification::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/device_cloud/push_notification/message.rb

Defined Under Namespace

Classes: FileData

Constant Summary collapse

KNOWN_TOPICS =
%w{ event data alert }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Message

Returns a new instance of Message.



16
17
18
19
20
21
22
23
24
25
# File 'lib/device_cloud/push_notification/message.rb', line 16

def initialize(attributes = {})
  attributes.each do |name, value|
    if name == 'FileData'
      @file_data = value
    else
      send("#{name}=", value)
    end
  end
  DeviceCloud.logger.info "DeviceCloud::PushNotification::Message Invalid (no FileData) - #{topic}" unless valid?
end

Instance Attribute Details

#file_dataObject

Returns the value of attribute file_data.



3
4
5
# File 'lib/device_cloud/push_notification/message.rb', line 3

def file_data
  @file_data
end

#groupObject

Returns the value of attribute group.



3
4
5
# File 'lib/device_cloud/push_notification/message.rb', line 3

def group
  @group
end

#operationObject

Returns the value of attribute operation.



3
4
5
# File 'lib/device_cloud/push_notification/message.rb', line 3

def operation
  @operation
end

#replayObject

Returns the value of attribute replay.



3
4
5
# File 'lib/device_cloud/push_notification/message.rb', line 3

def replay
  @replay
end

#timestampObject

Returns the value of attribute timestamp.



3
4
5
# File 'lib/device_cloud/push_notification/message.rb', line 3

def timestamp
  @timestamp
end

#topicObject

Returns the value of attribute topic.



3
4
5
# File 'lib/device_cloud/push_notification/message.rb', line 3

def topic
  @topic
end

Class Method Details

.parse_raw_messages(raw_message_data) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/device_cloud/push_notification/message.rb', line 7

def self.parse_raw_messages(raw_message_data)
  if raw_message_data.is_a? Array
    messages = raw_message_data.map {|message| new(message) }
  else
    messages = [new(raw_message_data)]
  end
  messages
end

Instance Method Details

#no_content?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/device_cloud/push_notification/message.rb', line 36

def no_content?
  parsed_file_data.no_content?
end

#parsed_file_dataObject



31
32
33
34
# File 'lib/device_cloud/push_notification/message.rb', line 31

def parsed_file_data
  return false unless valid?
  @parsed_file_data ||= FileData.new file_data
end

#topic_typeObject



27
28
29
# File 'lib/device_cloud/push_notification/message.rb', line 27

def topic_type
  topic_matches.first
end

#valid?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/device_cloud/push_notification/message.rb', line 40

def valid?
  !!file_data
end