Class: JPush::PushPayload
- Inherits:
-
Object
- Object
- JPush::PushPayload
- Defined in:
- lib/jpush/model/push_payload.rb
Overview
The object you should build for sending a push.
Instance Attribute Summary collapse
-
#audience ⇒ Object
Returns the value of attribute audience.
-
#message ⇒ Object
Returns the value of attribute message.
-
#notification ⇒ Object
Returns the value of attribute notification.
-
#options ⇒ Object
Returns the value of attribute options.
-
#platform ⇒ Object
Returns the value of attribute platform.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ PushPayload
constructor
A new instance of PushPayload.
-
#isGlobalExceed ⇒ Object
Check if the length is too long.
-
#isIOSExceedLength ⇒ Object
used only the ios nitification is not nil.
- #toJSON ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ PushPayload
Returns a new instance of PushPayload.
8 9 10 11 12 13 14 |
# File 'lib/jpush/model/push_payload.rb', line 8 def initialize(opts = {}) @platform = opts[:platform] @audience = opts[:audience] @message = opts[:message] @options = opts[:options] @notification = opts[:notification] end |
Instance Attribute Details
#audience ⇒ Object
Returns the value of attribute audience.
7 8 9 |
# File 'lib/jpush/model/push_payload.rb', line 7 def audience @audience end |
#message ⇒ Object
Returns the value of attribute message.
7 8 9 |
# File 'lib/jpush/model/push_payload.rb', line 7 def @message end |
#notification ⇒ Object
Returns the value of attribute notification.
7 8 9 |
# File 'lib/jpush/model/push_payload.rb', line 7 def notification @notification end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/jpush/model/push_payload.rb', line 7 def @options end |
#platform ⇒ Object
Returns the value of attribute platform.
7 8 9 |
# File 'lib/jpush/model/push_payload.rb', line 7 def platform @platform end |
Class Method Details
.build(opts = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jpush/model/push_payload.rb', line 36 def self.build(opts = {}) payload = JPush::PushPayload.new(opts) if payload.audience == nil || payload.platform == nil raise ArgumentError.new(' audience and platform both should be set.') end if payload.notification == nil && payload. == nil raise ArgumentError.new('notification or message should be set at least one') end if payload.notification.to_s.bytesize + payload..to_s.bytesize > 1200 raise ArgumentError.new('notfication and message size is longer than 1200 ') end if payload. == nil = JPush::Options.build( :time_to_live=> 86400, :apns_production=> false) payload. = end return payload end |
Instance Method Details
#isGlobalExceed ⇒ Object
Check if the length is too long
67 68 69 70 71 72 73 |
# File 'lib/jpush/model/push_payload.rb', line 67 def isGlobalExceed if @notification.to_s.bytesize + @message.to_s.bytesize > 1200 return false else return true end end |
#isIOSExceedLength ⇒ Object
used only the ios nitification is not nil
58 59 60 61 62 63 64 |
# File 'lib/jpush/model/push_payload.rb', line 58 def isIOSExceedLength if @notification.ios.to_s.bytesize > 220 return false else return true end end |
#toJSON ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jpush/model/push_payload.rb', line 16 def toJSON array = {} if @platform != nil then array['platform'] = @platform.toJSON end if @audience != nil then array['audience'] = @audience.toJSON end if @message != nil then array['message'] = @message.toJSON end if @options != nil then array['options'] = @options.toJSON end if @notification != nil then array['notification'] = @notification.toJSON end return array end |