Class: ApnsGatling::Message

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

Constant Summary collapse

MAXIMUM_PAYLOAD_SIZE =
4096

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Message

Returns a new instance of Message.



13
14
15
16
# File 'lib/apns_gatling/message.rb', line 13

def initialize(token)
  @token = token
  @apns_id = SecureRandom.uuid
end

Instance Attribute Details

#alertObject

Returns the value of attribute alert.



10
11
12
# File 'lib/apns_gatling/message.rb', line 10

def alert
  @alert
end

#apns_collapse_idObject

Returns the value of attribute apns_collapse_id.



11
12
13
# File 'lib/apns_gatling/message.rb', line 11

def apns_collapse_id
  @apns_collapse_id
end

#apns_idObject

Returns the value of attribute apns_id.



11
12
13
# File 'lib/apns_gatling/message.rb', line 11

def apns_id
  @apns_id
end

#badgeObject

Returns the value of attribute badge.



10
11
12
# File 'lib/apns_gatling/message.rb', line 10

def badge
  @badge
end

#categoryObject

Returns the value of attribute category.



10
11
12
# File 'lib/apns_gatling/message.rb', line 10

def category
  @category
end

#content_availableObject

Returns the value of attribute content_available.



10
11
12
# File 'lib/apns_gatling/message.rb', line 10

def content_available
  @content_available
end

#custom_payloadObject

Returns the value of attribute custom_payload.



10
11
12
# File 'lib/apns_gatling/message.rb', line 10

def custom_payload
  @custom_payload
end

#expirationObject

Returns the value of attribute expiration.



11
12
13
# File 'lib/apns_gatling/message.rb', line 11

def expiration
  @expiration
end

#mutable_contentObject

Returns the value of attribute mutable_content.



10
11
12
# File 'lib/apns_gatling/message.rb', line 10

def mutable_content
  @mutable_content
end

#priorityObject

Returns the value of attribute priority.



11
12
13
# File 'lib/apns_gatling/message.rb', line 11

def priority
  @priority
end

#soundObject

Returns the value of attribute sound.



10
11
12
# File 'lib/apns_gatling/message.rb', line 10

def sound
  @sound
end

#thread_idObject

Returns the value of attribute thread_id.



10
11
12
# File 'lib/apns_gatling/message.rb', line 10

def thread_id
  @thread_id
end

#tokenObject (readonly)

Returns the value of attribute token.



9
10
11
# File 'lib/apns_gatling/message.rb', line 9

def token
  @token
end

#topicObject

Returns the value of attribute topic.



11
12
13
# File 'lib/apns_gatling/message.rb', line 11

def topic
  @topic
end

Instance Method Details

#payloadObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/apns_gatling/message.rb', line 26

def payload
  aps = {}

  aps.merge!(alert: alert) if alert
  aps.merge!(badge: badge) if badge
  aps.merge!(sound: sound) if sound
  aps.merge!(category: category) if category
  aps.merge!('content-available' => content_available) if content_available
  aps.merge!('mutable-content' => mutable_content) if mutable_content
  aps.merge!('thread-id' => thread_id) if thread_id

  message = {aps: aps}
  message.merge!(custom_payload) if custom_payload
  message
end

#payload_dataObject



18
19
20
# File 'lib/apns_gatling/message.rb', line 18

def payload_data
  payload.to_json.force_encoding(Encoding::BINARY)
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/apns_gatling/message.rb', line 22

def valid?
  data.bytesize <= MAXIMUM_PAYLOAD_SIZE
end