Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ test/tmp
test/version_tmp
tmp
NEW_README.md
.idea/
.idea/
.ruby-*
Gemfile.lock
1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

10 changes: 8 additions & 2 deletions lib/pushmeup/apns/core.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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|
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/pushmeup/apns/notification.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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
if message.is_a?(Hash)
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
Expand All @@ -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
Expand All @@ -40,6 +42,7 @@ def ==(that)
alert == that.alert &&
badge == that.badge &&
sound == that.sound &&
content_available == that.content_available &&
other == that.other
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pushmeup/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Pushmeup
VERSION = "0.3.0"
VERSION = "0.3.2"
end
6 changes: 3 additions & 3 deletions pushmeup.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 13 additions & 9 deletions spec/lib/pushmeup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,7 +14,6 @@
end

describe "Notifications" do

describe "#==" do

it "should properly equate objects without caring about object identity" do
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down