pushr-apns2 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +7 -0
- data/lib/pushr-apns2/version.rb +3 -0
- data/lib/pushr/apns2.rb +21 -0
- data/lib/pushr/configuration_apns2.rb +41 -0
- data/lib/pushr/daemon/apns2.rb +32 -0
- data/lib/pushr/daemon/apns2_support/connection.rb +87 -0
- data/lib/pushr/daemon/apns2_support/push.rb +41 -0
- data/lib/pushr/daemon/apns2_support/request.rb +28 -0
- data/lib/pushr/daemon/apns2_support/response.rb +26 -0
- data/lib/pushr/daemon/apns2_support/token.rb +31 -0
- data/lib/pushr/feedback_apns2.rb +11 -0
- data/lib/pushr/message_apns2.rb +50 -0
- data/spec/lib/pushr/configuration_apns2_spec.rb +36 -0
- data/spec/lib/pushr/daemon/apns2_spec.rb +7 -0
- data/spec/lib/pushr/daemon/apns2_support/connection_spec.rb +28 -0
- data/spec/lib/pushr/feedback_apns2_spec.rb +25 -0
- data/spec/lib/pushr/message_apns2_spec.rb +82 -0
- data/spec/spec_helper.rb +30 -0
- metadata +251 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 01d1a82c7722c4af7a5448abe08083eb88e8f0fc
|
4
|
+
data.tar.gz: fbac8b94bd06ec2781ee99aa8e40fc96d4a2145e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92ff3fa4285dfaafa7db145f215979230ed60366eb1b2e36b7544310a0b7b5ce5891fa9592d3a5f08f26305c8eea31ae1cc4e62e03bf2ac2efc299e9f960573f
|
7
|
+
data.tar.gz: d763b198587277add9102970c81d1da984c021373a803af0ad11013d22cee6f213308d6fb94d2d9124c0b0dbce9d2c3c6ca921622ba0357ad0b62c074521371f
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# PushrApns
|
2
|
+
|
3
|
+
[](https://travis-ci.org/9to5/pushr-apns)
|
4
|
+
[](https://codeclimate.com/github/9to5/pushr-apns)
|
5
|
+
[](https://coveralls.io/r/9to5/pushr-apns)
|
6
|
+
|
7
|
+
Please see [pushr-core](https://github.com/9to5/pushr-core) for more information.
|
data/lib/pushr/apns2.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'pathname'
|
3
|
+
require 'openssl'
|
4
|
+
require 'jwt'
|
5
|
+
require 'json'
|
6
|
+
require 'net-http2'
|
7
|
+
require 'securerandom'
|
8
|
+
|
9
|
+
require 'pushr-apns2/version'
|
10
|
+
require 'pushr/configuration'
|
11
|
+
require 'pushr/configuration_apns2'
|
12
|
+
require 'pushr/message'
|
13
|
+
require 'pushr/message_apns2'
|
14
|
+
# require 'pushr/feedback'
|
15
|
+
# require 'pushr/feedback_apns2'
|
16
|
+
require 'pushr/daemon/apns2'
|
17
|
+
require 'pushr/daemon/apns2_support/token'
|
18
|
+
require 'pushr/daemon/apns2_support/push'
|
19
|
+
require 'pushr/daemon/apns2_support/request'
|
20
|
+
require 'pushr/daemon/apns2_support/response'
|
21
|
+
require 'pushr/daemon/apns2_support/connection'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Pushr
|
2
|
+
class ConfigurationApns2 < Pushr::Configuration
|
3
|
+
attr_accessor :private_key, :team_id, :key_id, :sandbox
|
4
|
+
validates :private_key, :team_id, :key_id, presence: true
|
5
|
+
validates :sandbox, inclusion: { in: [true, false] }
|
6
|
+
|
7
|
+
def name
|
8
|
+
:apns2
|
9
|
+
end
|
10
|
+
|
11
|
+
def certificate=(value)
|
12
|
+
if /BEGIN CERTIFICATE/.match(value)
|
13
|
+
@certificate = value
|
14
|
+
else
|
15
|
+
# assume it's the path to the certificate and try to read it:
|
16
|
+
@certificate = read_file(value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_hash
|
21
|
+
{ type: self.class.to_s, app: app, enabled: enabled, connections: connections, private_key: private_key,
|
22
|
+
team_id: team_id, key_id: key_id, sandbox: sandbox }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def read_file(filename)
|
28
|
+
File.read(build_filename(filename))
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_filename(filename)
|
32
|
+
if Pathname.new(filename).absolute?
|
33
|
+
filename
|
34
|
+
elsif Pushr::Core.configuration_file
|
35
|
+
File.join(File.dirname(Pushr::Core.configuration_file), filename)
|
36
|
+
else
|
37
|
+
File.join(Dir.pwd, filename)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Pushr
|
2
|
+
module Daemon
|
3
|
+
class Apns2
|
4
|
+
attr_accessor :configuration, :handlers
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@configuration = options
|
8
|
+
@handlers = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
configuration.connections.times do |i|
|
13
|
+
connection = Apns2Support::Connection.new(configuration, i + 1)
|
14
|
+
connection.connect
|
15
|
+
# connection.on(:error) do |exception|
|
16
|
+
# puts "Exception has been raised: #{exception}"
|
17
|
+
# connection.connect
|
18
|
+
# end
|
19
|
+
|
20
|
+
handler = MessageHandler.new("pushr:#{configuration.key}", connection, configuration.app, i + 1)
|
21
|
+
handler.start
|
22
|
+
@handlers << handler
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def stop
|
27
|
+
@handlers.map(&:stop)
|
28
|
+
@handlers.map { |handler| Thread.new { handler.connection.close } }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Pushr
|
2
|
+
module Daemon
|
3
|
+
module Apns2Support
|
4
|
+
class ConnectionError < StandardError; end
|
5
|
+
|
6
|
+
class Connection
|
7
|
+
TIMEOUT = 30
|
8
|
+
RENEW_TOKEN = 60 * 55
|
9
|
+
attr_reader :name, :configuration
|
10
|
+
|
11
|
+
def initialize(configuration, i)
|
12
|
+
@name = "#{configuration.app}: Connection #{i}"
|
13
|
+
@configuration = configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def connect
|
17
|
+
@client = NetHttp2::Client.new(url, connect_timeout: TIMEOUT)
|
18
|
+
end
|
19
|
+
|
20
|
+
def url
|
21
|
+
@configuration.sandbox ? 'https://api.development.push.apple.com' : 'https://api.push.apple.com'
|
22
|
+
end
|
23
|
+
|
24
|
+
def token
|
25
|
+
if !@token || (Time.now - @timestamp > RENEW_TOKEN)
|
26
|
+
@timestamp = Time.now
|
27
|
+
@token = Token.new(configuration).generate
|
28
|
+
end
|
29
|
+
@token
|
30
|
+
end
|
31
|
+
|
32
|
+
def write(notification)
|
33
|
+
retry_count = 0
|
34
|
+
|
35
|
+
request = Request.new(notification, token)
|
36
|
+
begin
|
37
|
+
response = @client.call(:post, request.path, body: request.body, headers: request.headers,
|
38
|
+
timeout: TIMEOUT)
|
39
|
+
puts response.inspect
|
40
|
+
Response.new(headers: response.headers, body: response.body) if response
|
41
|
+
rescue SocketError => e
|
42
|
+
retry_count += 1
|
43
|
+
|
44
|
+
if retry_count == 1
|
45
|
+
Pushr::Daemon.logger.error("[#{name}] Lost connection to #{url} (#{e.class.name}), reconnecting...")
|
46
|
+
end
|
47
|
+
|
48
|
+
if retry_count <= 3
|
49
|
+
Pushr::Daemon.logger.error("[#{name}] retrying #{retry_count}")
|
50
|
+
# connect
|
51
|
+
sleep 1
|
52
|
+
retry
|
53
|
+
end
|
54
|
+
|
55
|
+
raise ConnectionError, "#{name} tried #{retry_count - 1} times but failed (#{e.class.name})."
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# def write(notification)
|
60
|
+
# request = Request.new(notification, token)
|
61
|
+
# http2_request = @client.prepare_request(:post, request.path, body: request.body, headers: request.headers)
|
62
|
+
# push = Push.new(http2_request)
|
63
|
+
# push.on(:response) do |response|
|
64
|
+
# # read the response
|
65
|
+
# puts response.ok? # => true
|
66
|
+
# puts response.status # => '200'
|
67
|
+
# puts response.headers # => {":status"=>"200", "apns-id"=>"6f2cd350-bfad-4af0-a8bc-0d501e9e1799"}
|
68
|
+
# puts response.body # => ""
|
69
|
+
# end
|
70
|
+
# @client.call_async(push.http2_request)
|
71
|
+
# end
|
72
|
+
|
73
|
+
def close
|
74
|
+
@client.close
|
75
|
+
end
|
76
|
+
|
77
|
+
# def join
|
78
|
+
# @client.join
|
79
|
+
# end
|
80
|
+
|
81
|
+
def on(event, &block)
|
82
|
+
@client.on(event, &block)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Pushr
|
2
|
+
module Daemon
|
3
|
+
module Apns2Support
|
4
|
+
class Push
|
5
|
+
attr_reader :http2_request
|
6
|
+
|
7
|
+
def initialize(http2_request)
|
8
|
+
@http2_request = http2_request
|
9
|
+
@headers = {}
|
10
|
+
@data = ''
|
11
|
+
@events = {}
|
12
|
+
|
13
|
+
listen_for_http2_events
|
14
|
+
end
|
15
|
+
|
16
|
+
def on(event, &block)
|
17
|
+
raise ArgumentError, 'on event must provide a block' unless block_given?
|
18
|
+
|
19
|
+
@events[event] ||= []
|
20
|
+
@events[event] << block
|
21
|
+
end
|
22
|
+
|
23
|
+
def emit(event, arg)
|
24
|
+
return unless @events[event]
|
25
|
+
@events[event].each { |b| b.call(arg) }
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def listen_for_http2_events
|
31
|
+
@http2_request.on(:headers) { |headers| @headers.merge!(headers) }
|
32
|
+
@http2_request.on(:body_chunk) { |chunk| @data << chunk }
|
33
|
+
@http2_request.on(:close) do
|
34
|
+
response = Response.new(headers: @headers, body: @data)
|
35
|
+
emit(:response, response)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Pushr
|
2
|
+
module Daemon
|
3
|
+
module Apns2Support
|
4
|
+
class Request
|
5
|
+
attr_reader :path, :headers, :body
|
6
|
+
|
7
|
+
def initialize(notification, token)
|
8
|
+
@path = "/3/device/#{notification.token}"
|
9
|
+
@headers = build_headers_for(notification, token)
|
10
|
+
@body = notification.body
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def build_headers_for(notification, token)
|
16
|
+
h = {}
|
17
|
+
h['authorization'] = "bearer #{token}"
|
18
|
+
h['apns-id'] = notification.apns_id if notification.apns_id
|
19
|
+
h['apns-expiration'] = notification.apns_expiration if notification.apns_expiration
|
20
|
+
h['apns-priority'] = notification.apns_priority if notification.apns_priority
|
21
|
+
h['apns-topic'] = notification.apns_topic if notification.apns_topic
|
22
|
+
h['apns-collapse-id'] = notification.apns_collapse_id if notification.apns_collapse_id
|
23
|
+
h
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Pushr
|
2
|
+
module Daemon
|
3
|
+
module Apns2Support
|
4
|
+
class Response
|
5
|
+
attr_reader :headers
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@headers = options[:headers]
|
9
|
+
@body = options[:body]
|
10
|
+
end
|
11
|
+
|
12
|
+
def status
|
13
|
+
@headers[':status'] if @headers
|
14
|
+
end
|
15
|
+
|
16
|
+
def ok?
|
17
|
+
status == '200'
|
18
|
+
end
|
19
|
+
|
20
|
+
def body
|
21
|
+
JSON.parse(@body) rescue @body
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Pushr
|
2
|
+
module Daemon
|
3
|
+
module Apns2Support
|
4
|
+
class Token
|
5
|
+
ALGORITHM = 'ES256'
|
6
|
+
|
7
|
+
def initialize(configuration)
|
8
|
+
@configuration = configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate
|
12
|
+
JWT.encode(payload, ec_key, ALGORITHM, header_fields)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def ec_key
|
18
|
+
OpenSSL::PKey::EC.new(@configuration.private_key)
|
19
|
+
end
|
20
|
+
|
21
|
+
def payload
|
22
|
+
{ iss: @configuration.team_id, iat: Time.now.to_i }
|
23
|
+
end
|
24
|
+
|
25
|
+
def header_fields
|
26
|
+
{ kid: @configuration.key_id }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Pushr
|
2
|
+
class FeedbackApns2 < Pushr::Feedback
|
3
|
+
attr_accessor :device, :follow_up, :failed_at
|
4
|
+
validates :device, format: { with: /\A[a-z0-9]{64}\z/ }
|
5
|
+
validates :follow_up, inclusion: { in: %w(delete), message: '%{value} is not a valid follow-up' }
|
6
|
+
|
7
|
+
def to_hash
|
8
|
+
{ type: 'Pushr::FeedbackApns2', app: app, device: device, follow_up: follow_up, failed_at: failed_at }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Pushr
|
2
|
+
class MessageApns2 < Pushr::Message
|
3
|
+
POSTFIX = 'apns2'
|
4
|
+
|
5
|
+
attr_accessor :token, :alert, :badge, :sound, :category, :content_available, :mutable_content, :url_args, :apns_id,
|
6
|
+
:apns_expiration, :apns_priority, :apns_topic, :apns_collapse_id, :custom_payload
|
7
|
+
|
8
|
+
validate :priority_with_content_available
|
9
|
+
|
10
|
+
def apns_id
|
11
|
+
@apns_id ||= SecureRandom.uuid
|
12
|
+
end
|
13
|
+
|
14
|
+
def body
|
15
|
+
JSON.dump(to_message).force_encoding(Encoding::BINARY)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
hsh = { type: self.class.to_s, app: app, token: token, alert: alert, badge: badge, sound: sound,
|
20
|
+
category: category, content_available: content_available, mutable_content: mutable_content,
|
21
|
+
url_args: url_args, apns_id: apns_id, apns_expiration: apns_expiration, apns_priority: apns_priority,
|
22
|
+
apns_topic: apns_topic, apns_collapse_id: apns_collapse_id, custom_payload: custom_payload }
|
23
|
+
hsh[Pushr::Core.external_id_tag] = external_id if external_id
|
24
|
+
hsh
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def to_message
|
30
|
+
aps = {}
|
31
|
+
aps[:alert] = alert if alert
|
32
|
+
aps[:badge] = badge if badge
|
33
|
+
aps[:sound] = sound if sound
|
34
|
+
aps[:category] = category if category
|
35
|
+
aps['content-available'] = content_available if content_available
|
36
|
+
aps['url-args'] = url_args if url_args
|
37
|
+
aps['mutable-content'] = mutable_content if mutable_content
|
38
|
+
|
39
|
+
n = { aps: aps }
|
40
|
+
n.merge!(custom_payload) if custom_payload
|
41
|
+
n
|
42
|
+
end
|
43
|
+
|
44
|
+
def priority_with_content_available
|
45
|
+
if content_available == 1 && apns_priority != 5 && !(alert || badge || sound)
|
46
|
+
errors.add(:apns_priority, 'Priority should be 5 if content_available = 1 and no alert/badge/sound')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pushr/configuration_apns2'
|
3
|
+
|
4
|
+
describe Pushr::ConfigurationApns2 do
|
5
|
+
before(:each) do
|
6
|
+
Pushr::Core.configure do |config|
|
7
|
+
config.redis = ConnectionPool.new(size: 1, timeout: 1) { MockRedis.new }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'all' do
|
12
|
+
it 'returns all configurations' do
|
13
|
+
expect(Pushr::Configuration.all).to eql([])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'create' do
|
18
|
+
it 'should create a configuration' do
|
19
|
+
config = Pushr::ConfigurationApns2.new(app: 'app_name', connections: 2, enabled: true,
|
20
|
+
private_key: 'BEGIN CERTIFICATE', team_id: '1', sandbox: true, key_id: '1')
|
21
|
+
expect(config.key).to eql('app_name:apns2')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'save' do
|
26
|
+
let(:config) do
|
27
|
+
Pushr::ConfigurationApns2.new(app: 'app_name', connections: 2, enabled: true, private_key: 'BEGIN CERTIFICATE',
|
28
|
+
team_id: '1', sandbox: true, key_id: '1')
|
29
|
+
end
|
30
|
+
it 'should save a configuration' do
|
31
|
+
config.save
|
32
|
+
expect(Pushr::Configuration.all.count).to eql(1)
|
33
|
+
expect(Pushr::Configuration.all[0].class).to eql(Pushr::ConfigurationApns2)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pushr/configuration_apns2'
|
3
|
+
require 'pushr/message_apns2'
|
4
|
+
require 'pushr/daemon'
|
5
|
+
require 'pushr/daemon/apns2'
|
6
|
+
require 'pushr/daemon/apns2_support/connection'
|
7
|
+
|
8
|
+
describe Pushr::Daemon::Apns2Support::Connection do
|
9
|
+
before(:each) do
|
10
|
+
Pushr::Core.configure do |config|
|
11
|
+
config.redis = ConnectionPool.new(size: 1, timeout: 1) { MockRedis.new }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:config) do
|
16
|
+
Pushr::ConfigurationApns.new(app: 'app_name', connections: 2, enabled: true)
|
17
|
+
end
|
18
|
+
let(:message) do
|
19
|
+
hsh = { app: 'app_name', device: 'a' * 64, alert: 'message', badge: 1, sound: '1.aiff', expiry: 24 * 60 * 60,
|
20
|
+
attributes_for_device: { key: 'test' }, priority: 10 }
|
21
|
+
Pushr::MessageApns2.new(hsh)
|
22
|
+
end
|
23
|
+
let(:connection) { Pushr::Daemon::Apns2Support::Connection.new(config, 1) }
|
24
|
+
|
25
|
+
describe 'sends a message' do
|
26
|
+
it 'succesful'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pushr/feedback_apns2'
|
3
|
+
|
4
|
+
describe Pushr::FeedbackApns2 do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
Pushr::Core.configure do |config|
|
8
|
+
config.redis = ConnectionPool.new(size: 1, timeout: 1) { MockRedis.new }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'create' do
|
13
|
+
it 'should create a feedback' do
|
14
|
+
feedback = Pushr::FeedbackApns2.new(app: 'app_name', device: 'a' * 64, follow_up: 'delete', failed_at: Time.now)
|
15
|
+
expect(feedback.app).to eql('app_name')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'save' do
|
20
|
+
let!(:feedback) { Pushr::FeedbackApns2.create(app: 'app_name', device: 'a' * 64, follow_up: 'delete', failed_at: Time.now) }
|
21
|
+
it 'should save a feedback' do
|
22
|
+
expect(Pushr::Feedback.next.class).to eql(Pushr::FeedbackApns2)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pushr/message_apns2'
|
3
|
+
|
4
|
+
describe Pushr::MessageApns2 do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
Pushr::Core.configure do |config|
|
8
|
+
config.redis = ConnectionPool.new(size: 1, timeout: 1) { MockRedis.new }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'next' do
|
13
|
+
it 'returns next message' do
|
14
|
+
expect(Pushr::Message.next('pushr:app_name:apns2')).to eql(nil)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'save' do
|
19
|
+
let(:message) do
|
20
|
+
hsh = { app: 'app_name', token: 'a' * 64, alert: 'message', badge: 1, sound: '1.aiff',
|
21
|
+
expiry: 24 * 60 * 60, attributes_for_device: { key: 'test' }, priority: 10 }
|
22
|
+
Pushr::MessageApns2.new(hsh)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return true' do
|
26
|
+
expect(message.save).to eql true
|
27
|
+
end
|
28
|
+
it 'should save a message' do
|
29
|
+
message.save
|
30
|
+
expect(Pushr::Message.next('pushr:app_name:apns2')).to be_kind_of(Pushr::MessageApns2)
|
31
|
+
end
|
32
|
+
it 'should respond to body' do
|
33
|
+
expect(message.body).to be_kind_of(String)
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'content-available: 1' do
|
37
|
+
context 'with no alert/badge/sound' do
|
38
|
+
let(:message) do
|
39
|
+
hsh = { app: 'app_name', token: 'a' * 64, apns_expiry: 24 * 60 * 60, apns_priority: priority,
|
40
|
+
content_available: 1 }
|
41
|
+
Pushr::MessageApns2.new(hsh)
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with priority 5' do
|
45
|
+
let(:priority) { 5 }
|
46
|
+
it 'should have priority 5' do
|
47
|
+
expect(message.save).to eql true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with priority 10' do
|
52
|
+
let(:priority) { 10 }
|
53
|
+
it 'should be invalid if priority 10' do
|
54
|
+
expect(message.save).to eql false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with alert/badge/sound' do
|
60
|
+
let(:message) do
|
61
|
+
hsh = { app: 'app_name', alert: 'test', token: 'a' * 64, apns_expiry: 24 * 60 * 60, apns_priority: priority,
|
62
|
+
content_available: 1 }
|
63
|
+
Pushr::MessageApns2.new(hsh)
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'with priority 5' do
|
67
|
+
let(:priority) { 5 }
|
68
|
+
it 'should have priority 5' do
|
69
|
+
expect(message.save).to eql true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with priority 10' do
|
74
|
+
let(:priority) { 10 }
|
75
|
+
it 'should be valid if priority 10' do
|
76
|
+
expect(message.save).to eql true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
|
6
|
+
require 'simplecov'
|
7
|
+
require 'coveralls'
|
8
|
+
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
11
|
+
Coveralls::SimpleCov::Formatter
|
12
|
+
])
|
13
|
+
SimpleCov.start
|
14
|
+
|
15
|
+
require 'pushr/core'
|
16
|
+
require 'mock_redis'
|
17
|
+
|
18
|
+
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.raise_errors_for_deprecations!
|
22
|
+
config.run_all_when_everything_filtered = true
|
23
|
+
# config.filter_run :focus
|
24
|
+
|
25
|
+
# Run specs in random order to surface order dependencies. If you find an
|
26
|
+
# order dependency and want to debug it, you can fix the order by providing
|
27
|
+
# the seed, which is printed after each run.
|
28
|
+
# --seed 1234
|
29
|
+
config.order = 'random'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pushr-apns2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Pesman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pushr-core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activemodel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jwt
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: net-http2
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: mock_redis
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rake
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: coveralls
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rubocop
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
description: APNS support for the modular push daemon.
|
196
|
+
email:
|
197
|
+
- tom@tnux.net
|
198
|
+
executables: []
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files: []
|
201
|
+
files:
|
202
|
+
- MIT-LICENSE
|
203
|
+
- README.md
|
204
|
+
- lib/pushr-apns2/version.rb
|
205
|
+
- lib/pushr/apns2.rb
|
206
|
+
- lib/pushr/configuration_apns2.rb
|
207
|
+
- lib/pushr/daemon/apns2.rb
|
208
|
+
- lib/pushr/daemon/apns2_support/connection.rb
|
209
|
+
- lib/pushr/daemon/apns2_support/push.rb
|
210
|
+
- lib/pushr/daemon/apns2_support/request.rb
|
211
|
+
- lib/pushr/daemon/apns2_support/response.rb
|
212
|
+
- lib/pushr/daemon/apns2_support/token.rb
|
213
|
+
- lib/pushr/feedback_apns2.rb
|
214
|
+
- lib/pushr/message_apns2.rb
|
215
|
+
- spec/lib/pushr/configuration_apns2_spec.rb
|
216
|
+
- spec/lib/pushr/daemon/apns2_spec.rb
|
217
|
+
- spec/lib/pushr/daemon/apns2_support/connection_spec.rb
|
218
|
+
- spec/lib/pushr/feedback_apns2_spec.rb
|
219
|
+
- spec/lib/pushr/message_apns2_spec.rb
|
220
|
+
- spec/spec_helper.rb
|
221
|
+
homepage: https://github.com/9to5/pushr-apns2
|
222
|
+
licenses:
|
223
|
+
- MIT
|
224
|
+
metadata: {}
|
225
|
+
post_install_message:
|
226
|
+
rdoc_options: []
|
227
|
+
require_paths:
|
228
|
+
- lib
|
229
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
230
|
+
requirements:
|
231
|
+
- - ">="
|
232
|
+
- !ruby/object:Gem::Version
|
233
|
+
version: 2.2.0
|
234
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
|
+
requirements:
|
236
|
+
- - ">="
|
237
|
+
- !ruby/object:Gem::Version
|
238
|
+
version: '0'
|
239
|
+
requirements: []
|
240
|
+
rubyforge_project:
|
241
|
+
rubygems_version: 2.6.11
|
242
|
+
signing_key:
|
243
|
+
specification_version: 4
|
244
|
+
summary: APNS (iOS/Apple) part of the modular push daemon.
|
245
|
+
test_files:
|
246
|
+
- spec/lib/pushr/configuration_apns2_spec.rb
|
247
|
+
- spec/lib/pushr/daemon/apns2_spec.rb
|
248
|
+
- spec/lib/pushr/daemon/apns2_support/connection_spec.rb
|
249
|
+
- spec/lib/pushr/feedback_apns2_spec.rb
|
250
|
+
- spec/lib/pushr/message_apns2_spec.rb
|
251
|
+
- spec/spec_helper.rb
|