Class: ApnsGatling::Message
- Inherits:
-
Object
- Object
- ApnsGatling::Message
- Defined in:
- lib/apns_gatling/message.rb
Constant Summary collapse
- MAXIMUM_PAYLOAD_SIZE =
4096
Instance Attribute Summary collapse
-
#alert ⇒ Object
Returns the value of attribute alert.
-
#apns_collapse_id ⇒ Object
Returns the value of attribute apns_collapse_id.
-
#apns_id ⇒ Object
Returns the value of attribute apns_id.
-
#badge ⇒ Object
Returns the value of attribute badge.
-
#category ⇒ Object
Returns the value of attribute category.
-
#content_available ⇒ Object
Returns the value of attribute content_available.
-
#custom_payload ⇒ Object
Returns the value of attribute custom_payload.
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#mutable_content ⇒ Object
Returns the value of attribute mutable_content.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#sound ⇒ Object
Returns the value of attribute sound.
-
#thread_id ⇒ Object
Returns the value of attribute thread_id.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#topic ⇒ Object
Returns the value of attribute topic.
Instance Method Summary collapse
-
#initialize(token) ⇒ Message
constructor
A new instance of Message.
- #payload ⇒ Object
- #payload_data ⇒ Object
- #valid? ⇒ Boolean
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
#alert ⇒ Object
Returns the value of attribute alert.
10 11 12 |
# File 'lib/apns_gatling/message.rb', line 10 def alert @alert end |
#apns_collapse_id ⇒ Object
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_id ⇒ Object
Returns the value of attribute apns_id.
11 12 13 |
# File 'lib/apns_gatling/message.rb', line 11 def apns_id @apns_id end |
#badge ⇒ Object
Returns the value of attribute badge.
10 11 12 |
# File 'lib/apns_gatling/message.rb', line 10 def badge @badge end |
#category ⇒ Object
Returns the value of attribute category.
10 11 12 |
# File 'lib/apns_gatling/message.rb', line 10 def category @category end |
#content_available ⇒ Object
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_payload ⇒ Object
Returns the value of attribute custom_payload.
10 11 12 |
# File 'lib/apns_gatling/message.rb', line 10 def custom_payload @custom_payload end |
#expiration ⇒ Object
Returns the value of attribute expiration.
11 12 13 |
# File 'lib/apns_gatling/message.rb', line 11 def expiration @expiration end |
#mutable_content ⇒ Object
Returns the value of attribute mutable_content.
10 11 12 |
# File 'lib/apns_gatling/message.rb', line 10 def mutable_content @mutable_content end |
#priority ⇒ Object
Returns the value of attribute priority.
11 12 13 |
# File 'lib/apns_gatling/message.rb', line 11 def priority @priority end |
#sound ⇒ Object
Returns the value of attribute sound.
10 11 12 |
# File 'lib/apns_gatling/message.rb', line 10 def sound @sound end |
#thread_id ⇒ Object
Returns the value of attribute thread_id.
10 11 12 |
# File 'lib/apns_gatling/message.rb', line 10 def thread_id @thread_id end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/apns_gatling/message.rb', line 9 def token @token end |
#topic ⇒ Object
Returns the value of attribute topic.
11 12 13 |
# File 'lib/apns_gatling/message.rb', line 11 def topic @topic end |
Instance Method Details
#payload ⇒ Object
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 = {aps: aps} .merge!(custom_payload) if custom_payload end |
#payload_data ⇒ Object
18 19 20 |
# File 'lib/apns_gatling/message.rb', line 18 def payload_data payload.to_json.force_encoding(Encoding::BINARY) end |
#valid? ⇒ Boolean
22 23 24 |
# File 'lib/apns_gatling/message.rb', line 22 def valid? data.bytesize <= MAXIMUM_PAYLOAD_SIZE end |