Class: APNS::ApnsJSON
- Inherits:
-
Object
- Object
- APNS::ApnsJSON
- Defined in:
- lib/apns/apns_json.rb
Class Method Summary collapse
-
.apns_json(object) ⇒ Object
generates JSON in a format acceptable to the APNS service (which is a subset of the JSON standard).
-
.apns_json_size(object) ⇒ Object
calculates the byte-length of an object when encoded with APNS friendly JSON encoding if a string is passed, the byte-size is calculated as if it were in an object structure.
Class Method Details
.apns_json(object) ⇒ Object
generates JSON in a format acceptable to the APNS service (which is a subset of the JSON standard)
30 31 32 33 |
# File 'lib/apns/apns_json.rb', line 30 def self.apns_json(object) JSON.generate(object, :ascii_only => false) end |
.apns_json_size(object) ⇒ Object
calculates the byte-length of an object when encoded with APNS friendly JSON encoding if a string is passed, the byte-size is calculated as if it were in an object structure
37 38 39 40 41 42 43 44 45 |
# File 'lib/apns/apns_json.rb', line 37 def self.apns_json_size(object) if object.is_a?(Hash) || object.is_a?(Array) return apns_json(object).bytesize else object.is_a?(String) # wraps string in an array but discounts the extra chars return apns_json([object]).bytesize - 4 end end |