justintv/APNS — pull request #3 by remiprev (2012-01-21 10:58:20+00:00)
Title: Explicitly use String#bytes for Ruby 1.9 compatibility

Using Ruby 1.9, sending a message that contain Unicode caracters fails because APNS is using "size" to get the length of the string we send to the service. For example, `15` is the right size we want to get:

# ruby-1.8.7
'{"aps":"fooo"}'.size # 14
'{"aps":"rémi"}'.size # 15

# ruby-1.9
'{"aps":"fooo"}'.size # 14
'{"aps":"rémi"}'.size # 14

We have to use `String#bytes` in order to get the length of all the bytes in the string.

# ruby-1.8.7
'{"aps":"fooo"}'.bytes.to_a.size # 14
'{"aps":"rémi"}'.bytes.to_a.size # 15

# ruby-1.9
'{"aps":"fooo"}'.bytes.to_a.size # 14
'{"aps":"rémi"}'.bytes.to_a.size # 15

This commit changes `APNS.packaged_notification` to use `String#bytes` before packing the message.