diff --git a/.gitignore b/.gitignore index 10771f7..221195e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,6 @@ test/tmp test/version_tmp tmp NEW_README.md -.idea/ \ No newline at end of file +.idea/ +.ruby-* +Gemfile.lock diff --git a/.ruby-gemset b/.ruby-gemset deleted file mode 100644 index a38d0bf..0000000 --- a/.ruby-gemset +++ /dev/null @@ -1 +0,0 @@ -pushmeup diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 67b8bc0..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -ruby-1.9.3 diff --git a/lib/pushmeup/apns/core.rb b/lib/pushmeup/apns/core.rb index fe9d79a..a7fbd3f 100644 --- a/lib/pushmeup/apns/core.rb +++ b/lib/pushmeup/apns/core.rb @@ -1,9 +1,9 @@ require 'socket' require 'openssl' require 'json' +require 'logger' module APNS - @host = 'gateway.sandbox.push.apple.com' @port = 2195 # openssl pkcs12 -in mycert.p12 -out client-cert.pem -nodes -clcerts @@ -18,7 +18,7 @@ module APNS @ssl = nil class << self - attr_accessor :host, :pem, :port, :pass + attr_accessor :host, :pem, :port, :pass, :logger end def self.start_persistence @@ -38,6 +38,8 @@ def self.send_notification(device_token, message) end def self.send_notifications(notifications) + logger.info "Pushmeup: sending message(s): '#{notifications.map { |n| n.packaged_message}.join("|")}' to #{self.host}" + @mutex.synchronize do self.with_connection do notifications.each do |n| @@ -64,6 +66,10 @@ def self.feedback return apns_feedback end + def self.logger + defined?(Rails) ? Rails.logger : Logger.new(STDOUT) + end + protected def self.with_connection diff --git a/lib/pushmeup/apns/notification.rb b/lib/pushmeup/apns/notification.rb index 60d76f6..b65f83a 100644 --- a/lib/pushmeup/apns/notification.rb +++ b/lib/pushmeup/apns/notification.rb @@ -1,6 +1,6 @@ module APNS class Notification - attr_accessor :device_token, :alert, :badge, :sound, :other + attr_accessor :device_token, :alert, :badge, :sound, :other, :content_available def initialize(device_token, message) self.device_token = device_token @@ -8,6 +8,7 @@ def initialize(device_token, message) self.alert = message[:alert] self.badge = message[:badge] self.sound = message[:sound] + self.content_available = message[:"content-available"] self.other = message[:other] elsif message.is_a?(String) self.alert = message @@ -31,6 +32,7 @@ def packaged_message aps['aps']['alert'] = self.alert if self.alert aps['aps']['badge'] = self.badge if self.badge aps['aps']['sound'] = self.sound if self.sound + aps['aps']['content-available'] = self.content_available if self.content_available aps.merge!(self.other) if self.other aps.to_json.gsub(/\\u([\da-fA-F]{4})/) {|m| [$1].pack("H*").unpack("n*").pack("U*")} end @@ -40,6 +42,7 @@ def ==(that) alert == that.alert && badge == that.badge && sound == that.sound && + content_available == that.content_available && other == that.other end diff --git a/lib/pushmeup/version.rb b/lib/pushmeup/version.rb index 8d944ed..5aa2d49 100644 --- a/lib/pushmeup/version.rb +++ b/lib/pushmeup/version.rb @@ -1,3 +1,3 @@ module Pushmeup - VERSION = "0.3.0" + VERSION = "0.3.2" end diff --git a/pushmeup.gemspec b/pushmeup.gemspec index 303a26f..9c476a8 100644 --- a/pushmeup.gemspec +++ b/pushmeup.gemspec @@ -5,10 +5,10 @@ require "pushmeup/version" Gem::Specification.new do |s| s.name = 'pushmeup' s.version = Pushmeup::VERSION - s.authors = ["Nicos Karalis"] - s.email = ["nicoskaralis@me.com"] + s.authors = ["Nicos Karalis", "Michal Pawlowski"] + s.email = ["nicoskaralis@me.com", "misza222@gmail.com"] - s.homepage = "https://github.com/NicosKaralis/pushmeup" + s.homepage = "https://github.com/itsudo/pushmeup" s.summary = %q{Send push notifications to Apple devices through ANPS and Android devices through GCM} s.description = <<-DESC This gem is a wrapper to send push notifications to devices. diff --git a/spec/lib/pushmeup_spec.rb b/spec/lib/pushmeup_spec.rb index 80264af..1be6301 100644 --- a/spec/lib/pushmeup_spec.rb +++ b/spec/lib/pushmeup_spec.rb @@ -3,7 +3,7 @@ describe Pushmeup do describe "APNS" do it "should have a APNS object" do - defined?(APNS).should_not be_false + defined?(APNS).should_not be_nil end it "should not forget the APNS default parameters" do @@ -14,7 +14,6 @@ end describe "Notifications" do - describe "#==" do it "should properly equate objects without caring about object identity" do @@ -23,6 +22,11 @@ a.should eq(b) end + it "should add content-available to data" do + a = APNS::Notification.new("123", {:alert => "hi", :"content-available" => 1}) + + a.packaged_message.should == '{"aps":{"alert":"hi","content-available":1}}' + end end end @@ -31,7 +35,7 @@ describe "GCM" do it "should have a GCM object" do - defined?(GCM).should_not be_false + defined?(GCM).should_not be_nil end describe "Notifications" do @@ -42,27 +46,27 @@ it "should allow only notifications with device_tokens as array" do n = GCM::Notification.new("id", @options) - n.device_tokens.is_a?(Array).should be_true + expect(n.device_tokens.is_a?(Array)).to eq(true) n.device_tokens = ["a" "b", "c"] - n.device_tokens.is_a?(Array).should be_true + expect(n.device_tokens.is_a?(Array)).to eq(true) n.device_tokens = "a" - n.device_tokens.is_a?(Array).should be_true + expect(n.device_tokens.is_a?(Array)).to eq(true) end it "should allow only notifications with data as hash with :data root" do n = GCM::Notification.new("id", { :data => "data" }) - n.data.is_a?(Hash).should be_true + expect(n.data.is_a?(Hash)).to eq(true) n.data.should == {:data => "data"} n.data = {:a => ["a", "b", "c"]} - n.data.is_a?(Hash).should be_true + expect(n.data.is_a?(Hash)).to eq(true) n.data.should == {:a => ["a", "b", "c"]} n.data = {:a => "a"} - n.data.is_a?(Hash).should be_true + expect(n.data.is_a?(Hash)).to eq(true) n.data.should == {:a => "a"} end