Skip to content
This repository has been archived by the owner on Mar 9, 2018. It is now read-only.

Replace Hash#to_json and ActiveSupport::JSON to MultiJson #48

Merged
merged 1 commit into from Jun 20, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -9,6 +9,7 @@ gem 'mysql2'
gem 'mysql'
gem 'database_cleaner'
gem 'simplecov'
gem 'multi_json'
#gem 'perftools.rb'

gemspec
gemspec
3 changes: 2 additions & 1 deletion lib/rapns.rb
@@ -1,8 +1,9 @@
require 'active_record'
require 'multi_json'

require 'rapns/version'
require 'rapns/binary_notification_validator'
require 'rapns/device_token_format_validator'
require 'rapns/notification'
require 'rapns/feedback'
require 'rapns/app'
require 'rapns/app'
14 changes: 7 additions & 7 deletions lib/rapns/notification.rb
Expand Up @@ -17,7 +17,7 @@ def device_token=(token)

def alert=(alert)
if alert.is_a?(Hash)
write_attribute(:alert, ActiveSupport::JSON.encode(alert))
write_attribute(:alert, MultiJson.dump(alert))
self.alert_is_json = true if has_attribute?(:alert_is_json)
else
write_attribute(:alert, alert)
Expand All @@ -30,22 +30,22 @@ def alert

if has_attribute?(:alert_is_json)
if alert_is_json?
ActiveSupport::JSON.decode(string_or_json)
MultiJson.load(string_or_json)
else
string_or_json
end
else
ActiveSupport::JSON.decode(string_or_json) rescue string_or_json
MultiJson.load(string_or_json) rescue string_or_json
end
end

def attributes_for_device=(attrs)
raise ArgumentError, "attributes_for_device must be a Hash" if !attrs.is_a?(Hash)
write_attribute(:attributes_for_device, ActiveSupport::JSON.encode(attrs))
write_attribute(:attributes_for_device, MultiJson.dump(attrs))
end

def attributes_for_device
ActiveSupport::JSON.decode(read_attribute(:attributes_for_device)) if read_attribute(:attributes_for_device)
MultiJson.load(read_attribute(:attributes_for_device)) if read_attribute(:attributes_for_device)
end

MDM_OVERIDE_KEY = '__rapns_mdm__'
Expand All @@ -70,7 +70,7 @@ def as_json
end

def payload
as_json.to_json
MultiJson.dump(as_json)
end

def payload_size
Expand All @@ -84,4 +84,4 @@ def to_binary(options = {})
[1, id_for_pack, expiry, 0, 32, device_token, 0, payload_size, payload].pack("cNNccH*cca*")
end
end
end
end
2 changes: 2 additions & 0 deletions rapns.gemspec
Expand Up @@ -15,4 +15,6 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency "multi_json", "~> 1.0"
end