Sha256: 38308f1bf63a80019f315ced0e882fa0691940601f83e9f5908e5742ec4d6129
Contents?: true
Size: 925 Bytes
Versions: 2
Compression:
Stored size: 925 Bytes
Contents
# encoding: utf-8 module ApnsPolite require 'json' class Message # 初期化 def initialize(device_token, message) t = package_device_token device_token if message.is_a? Hash m = package_message message[:alert], message[:badge], message[:sound], message[:other] else m = package_message message.to_s end @pack = [0, 0, 32, t, 0, m.bytesize, m].pack("ccca*cca*") end # パックしたメッセージ取得 def pack @pack end private # device token パッケージ化 def package_device_token(device_token) [device_token.gsub(/[\s|<|>]/,'')].pack('H*') end # message パッケージ化 def package_message(alert, badge=nil, sound=nil, options=nil) a = { 'aps' => {} } a['aps']['alert'] = alert if alert a['aps']['badge'] = badge if badge a['aps']['sound'] = sound if sound a.merge! options if options a.to_json end end end # end of module
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
apns_polite-0.9.1 | lib/apns_polite/message.rb |
apns_polite-0.9.0 | lib/apns_polite/message.rb |