push_kit-apns 1.0.0.pre.beta1 → 1.0.0.pre.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -4
- data/lib/push_kit/apns.rb +28 -8
- data/lib/push_kit/apns/constants.rb +1 -1
- data/spec/push_kit/apns/notification/localization_spec.rb +41 -30
- data/spec/push_kit/apns_spec.rb +35 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4f29c8b7460101c8ec4600ce6022417c69d3376d1aee4549ba71a58ac162559
|
4
|
+
data.tar.gz: ead2f9a335f5f4fc1466c94dbf6d8baf3963159c9827308dc67eee3ba8f3a7ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4df1526f02a8b544cd79d222c8aaf2719423d81b001db0f58a828d2c71cc57a32d3c6e39045ad4d76a51e2acdde0723aef8b09921d3fc2c7f1df83eff2a9a543
|
7
|
+
data.tar.gz: 1e50eaefee64b92302f2328eec3c9d146af40212c864209134f4db19650cc8ec142de1bca32984b83eaf62d5e9e946a626b99938a1ed4331b76ae6d3e088f8aa
|
data/README.md
CHANGED
@@ -38,6 +38,26 @@ This allows us to maintain a connection to the Apple Push Notification service a
|
|
38
38
|
|
39
39
|
See [Communicating with APNs - Best Practices for Managing Connections](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW8) for more info on this.
|
40
40
|
|
41
|
+
---
|
42
|
+
|
43
|
+
PushKit also provides a couple of convenience helper methods to create and store clients for use anywhere the PushKit::APNS model is accessible.
|
44
|
+
|
45
|
+
For example, in a Rails app you could create an initializer and add the following:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
PushKit::APNS.prepare(
|
49
|
+
:default,
|
50
|
+
key: PushKit::APNS.load_key('/path/to/APNsAuthKey_XXXXXXXXXX.p8'),
|
51
|
+
key_id: 'XXXXXXXXXX',
|
52
|
+
team_id: 'XXXXXXXXXX',
|
53
|
+
topic: 'com.example.app'
|
54
|
+
)
|
55
|
+
```
|
56
|
+
|
57
|
+
Later, when you're ready to send a notification you can use ```PushKit::APNS.clients[:default]``` to retrieve the client instance.
|
58
|
+
|
59
|
+
You can specify any arbitrary value as the key instead of *:default* which allows you to create multiple instance if required.
|
60
|
+
|
41
61
|
### Additional Options
|
42
62
|
|
43
63
|
There are a few additional options you can specify when creating a client.
|
@@ -77,11 +97,11 @@ notification.device_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
77
97
|
Then using our `PushKit::APNS` instance we created earlier, deliver the notification:
|
78
98
|
|
79
99
|
```ruby
|
80
|
-
|
100
|
+
client.deliver(notification) do |notification, success, response|
|
101
|
+
# ...
|
102
|
+
end
|
81
103
|
```
|
82
104
|
|
83
|
-
EXPLAIN_ASYNC_NEEDS_WAIT
|
84
|
-
|
85
105
|
---
|
86
106
|
|
87
107
|
The `PushKit::APNS::Notification` instance has a *:device_token* attribute which needs to be set to the token of the device you're sending the notification to.
|
@@ -106,7 +126,7 @@ notifications = notification.for_tokens(*tokens)
|
|
106
126
|
When you're ready, you can just deliver the array of notifications:
|
107
127
|
|
108
128
|
```ruby
|
109
|
-
client.deliver(notifications) do |notification,
|
129
|
+
client.deliver(*notifications) do |notification, success, response|
|
110
130
|
# ...
|
111
131
|
end
|
112
132
|
```
|
data/lib/push_kit/apns.rb
CHANGED
@@ -33,14 +33,15 @@ module PushKit
|
|
33
33
|
|
34
34
|
# Create a new PushClient instance.
|
35
35
|
#
|
36
|
-
# @param
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
36
|
+
# @param options [Hash]
|
37
|
+
# host [String|Symbol] The host (can also be :production or :development).
|
38
|
+
# port [Integer|Symbol] The port number (can also be :default or :alternative).
|
39
|
+
# topic [String] The APNS topic (matches the app's bundle identifier).
|
40
|
+
# key [OpenSSL::PKey::EC] The elliptic curve key to use for authentication.
|
41
|
+
# key_id [String] The identifier for the elliptic curve key.
|
42
|
+
# team_id [String] The identifier for the Apple Developer team.
|
43
|
+
# topic [String] The topic for your application (usually the bundle identifier).
|
44
|
+
# @return [PushKit::APNS::PushClient] A client.
|
44
45
|
#
|
45
46
|
def self.client(options = {})
|
46
47
|
options = {
|
@@ -61,5 +62,24 @@ module PushKit
|
|
61
62
|
token_generator: token_generator
|
62
63
|
)
|
63
64
|
end
|
65
|
+
|
66
|
+
# @return [Hash] A collection of `PushKit::APNS::PushClient` instances.
|
67
|
+
#
|
68
|
+
def self.clients
|
69
|
+
@clients ||= {}
|
70
|
+
end
|
71
|
+
|
72
|
+
# Prepare a client.
|
73
|
+
#
|
74
|
+
# This method creates a `PushKit::APNS::PushClient` instance using the #client method, then stores it in the
|
75
|
+
# #clients Hash using an identifier you specify.
|
76
|
+
# Storing the clients in this way provides on-demand access without requiring the use of global variables.
|
77
|
+
#
|
78
|
+
# @param identifier [Symbol] The key to use within the #clients Hash.
|
79
|
+
# @param options [Hash] The options to pass to the #client method.
|
80
|
+
#
|
81
|
+
def self.prepare(identifier, options = {})
|
82
|
+
clients[identifier] = client(options)
|
83
|
+
end
|
64
84
|
end
|
65
85
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'push_kit/apns/notification/localization'
|
4
4
|
|
5
5
|
RSpec.describe PushKit::APNS::Notification::Localization, :unit do
|
6
|
-
def
|
6
|
+
def build(params = {})
|
7
7
|
default_params = {
|
8
8
|
key: 'HELLO_WORLD',
|
9
9
|
arguments: nil
|
@@ -12,16 +12,16 @@ RSpec.describe PushKit::APNS::Notification::Localization, :unit do
|
|
12
12
|
described_class.new(**default_params.merge(params))
|
13
13
|
end
|
14
14
|
|
15
|
-
subject {
|
15
|
+
subject(:localization) { build }
|
16
16
|
|
17
17
|
it { is_expected.to have_accessor(:key) }
|
18
18
|
it { is_expected.to have_accessor(:arguments) }
|
19
19
|
|
20
20
|
describe '#initialize' do
|
21
21
|
let(:key) { 'A_KEY' }
|
22
|
-
let(:arguments) { ['An
|
22
|
+
let(:arguments) { ['An argument'] }
|
23
23
|
|
24
|
-
subject {
|
24
|
+
subject { build(key: key, arguments: arguments) }
|
25
25
|
|
26
26
|
it 'sets #key' do
|
27
27
|
expect(subject.key).to eq(key)
|
@@ -34,56 +34,67 @@ RSpec.describe PushKit::APNS::Notification::Localization, :unit do
|
|
34
34
|
|
35
35
|
describe '#payload' do
|
36
36
|
context 'when localizing a supported attribute' do
|
37
|
-
|
37
|
+
subject { localization.payload(:title) }
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
context 'when #key is set' do
|
40
|
+
before { localization.key = 'TITLE_KEY' }
|
41
|
+
|
42
|
+
it 'includes the correct loc-key attribute and value' do
|
43
|
+
expect(subject).to include('title-loc-key' => 'TITLE_KEY')
|
44
|
+
end
|
42
45
|
end
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
context 'when #arguments is set' do
|
48
|
+
before { localization.arguments = ['An argument'] }
|
49
|
+
|
50
|
+
it 'includes the correct loc-args attribute and value' do
|
51
|
+
expect(subject).to include('title-loc-args' => ['An argument'])
|
52
|
+
end
|
47
53
|
end
|
48
54
|
|
49
|
-
context '
|
50
|
-
before {
|
55
|
+
context 'when #arguments is nil' do
|
56
|
+
before { localization.arguments = nil }
|
51
57
|
|
52
|
-
it 'excludes the
|
53
|
-
expect(
|
58
|
+
it 'excludes the correct loc-args attribute' do
|
59
|
+
expect(subject).not_to have_key('title-loc-args')
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
57
63
|
|
58
64
|
context 'when localizing an unsupported attribute' do
|
59
|
-
|
60
|
-
let(:payload) { subject.payload(attribute) }
|
65
|
+
subject { localization.payload(:some_unknown_attribute) }
|
61
66
|
|
62
67
|
it 'returns nil' do
|
63
|
-
expect(
|
68
|
+
expect(subject).to be nil
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
68
73
|
describe '#prefix' do
|
69
|
-
def prefix
|
70
|
-
|
71
|
-
|
74
|
+
def self.it_returns(prefix, with: nil)
|
75
|
+
context "with :#{with}" do
|
76
|
+
subject { prefix(with) }
|
72
77
|
|
73
|
-
|
74
|
-
|
78
|
+
it "returns '#{prefix}'" do
|
79
|
+
expect(subject).to eq(prefix)
|
80
|
+
end
|
81
|
+
end
|
75
82
|
end
|
76
83
|
|
77
|
-
|
78
|
-
|
84
|
+
def prefix(*args)
|
85
|
+
localization.instance_eval { prefix(*args) }
|
79
86
|
end
|
80
87
|
|
81
|
-
|
82
|
-
|
83
|
-
|
88
|
+
it_returns 'title-', with: :title
|
89
|
+
it_returns 'subtitle-', with: :subtitle
|
90
|
+
it_returns '', with: :body
|
84
91
|
|
85
|
-
|
86
|
-
|
92
|
+
context 'with an unknown attribute' do
|
93
|
+
subject { prefix(:some_unknown_attribute) }
|
94
|
+
|
95
|
+
it 'returns nil' do
|
96
|
+
expect(subject).to be nil
|
97
|
+
end
|
87
98
|
end
|
88
99
|
end
|
89
100
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'push_kit/apns'
|
4
|
+
|
5
|
+
RSpec.describe PushKit::APNS do
|
6
|
+
subject { described_class }
|
7
|
+
|
8
|
+
describe '.load_key' do
|
9
|
+
context 'when the file does not exist' do
|
10
|
+
let(:path) { '/path/to/key' }
|
11
|
+
|
12
|
+
before do
|
13
|
+
expect(File).to receive(:file?).with(path).and_return(false)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'raises an ArgumentError' do
|
17
|
+
expect { subject.load_key(path) }.to raise_exception(ArgumentError)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.clients' do
|
23
|
+
it 'returns a Hash' do
|
24
|
+
expect(subject.clients).to be_a(Hash)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.prepare' do
|
29
|
+
it 'stores the client in #clients' do
|
30
|
+
expect(subject).to receive(:client).and_return(:a_client_object)
|
31
|
+
subject.prepare(:default)
|
32
|
+
expect(subject.clients).to include(default: :a_client_object)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: push_kit-apns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.
|
4
|
+
version: 1.0.0.pre.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nialto Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- spec/push_kit/apns/constants_spec.rb
|
156
156
|
- spec/push_kit/apns/notification/localization_spec.rb
|
157
157
|
- spec/push_kit/apns/notification_spec.rb
|
158
|
+
- spec/push_kit/apns_spec.rb
|
158
159
|
- spec/spec_helper.rb
|
159
160
|
- spec/support/have_accessor.rb
|
160
161
|
homepage: https://github.com/nialtoservices/push_kit-apns
|
@@ -185,5 +186,6 @@ test_files:
|
|
185
186
|
- spec/push_kit/apns/constants_spec.rb
|
186
187
|
- spec/push_kit/apns/notification/localization_spec.rb
|
187
188
|
- spec/push_kit/apns/notification_spec.rb
|
189
|
+
- spec/push_kit/apns_spec.rb
|
188
190
|
- spec/spec_helper.rb
|
189
191
|
- spec/support/have_accessor.rb
|