apnotic 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bfb47d774564845182d268e32f8820017d0ba32
4
- data.tar.gz: 47334f8ffb95809e4c224570c4d4f5ba1b747eb7
3
+ metadata.gz: f37b786ef147c1553a73571851e796091f9ed2c8
4
+ data.tar.gz: 80eea7c2ccbe00fb57b8327ef911d6f0c0eeab11
5
5
  SHA512:
6
- metadata.gz: 84259061d8e09e4ba609b0ae4e99980236984570c64207eed01f0cd3102aa361ec276829609891bc84c237f99df344dac232a69dabeb6672e67150b67c8cde03
7
- data.tar.gz: fdb1ba71863a3520f3005817980dcc0e06073791b4958488517053b458a52bec3a22fa32704da7588cfe25b7b7cab0e4e9422671d0354be4b8fe107e1dc8830a
6
+ metadata.gz: 687b7ab85bbfbbcd125fc6bcfc435cdcf11df33e74635d631d698d5b94682f2dc0e9481bd6887c480b4e587a395a33b3c2b91a21f93606457b822d303fb9282f
7
+ data.tar.gz: 8e8a154fb3cd33ab1113cfcb30477447d2d1c7fb689ff67a2a13078a6b7211e292099c3824cefc3c3a3ea3dcfe26f00fc4c5920d442a8aad6d0b06248a02a13e
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  .*.sw[a-z]
3
3
  *.un~
4
4
  Session.vim
5
+ .tags
5
6
 
6
7
  # mine
7
8
  .idea
data/README.md CHANGED
@@ -92,6 +92,37 @@ connection.join
92
92
  connection.close
93
93
  ```
94
94
 
95
+ #### Mobile Device Management (MDM) notifications
96
+
97
+ If you are building an iOS MDM solution, you can as well use apnotic to send mdm push notifications with the `Apnotic::MdmNotification` class. Sending a MDM notification requires a token and a push magic value, which is sent by the iOS device during its MDM enrollment:
98
+
99
+ ```ruby
100
+ require 'apnotic'
101
+
102
+ # create a persistent connection
103
+ connection = Apnotic::Connection.new(cert_path: "apns_certificate.pem", cert_pass: "pass")
104
+
105
+ # create a notification for a specific device token
106
+ token = '6c267f26b173cd9595ae2f6702b1ab560371a60e7c8a9e27419bd0fa4a42e58f'
107
+
108
+ # push magic value given by the iOS device during enrollment
109
+ push_magic = '7F399691-C3D9-4795-ACF8-0B51D7073497'
110
+
111
+ notification = Apnotic::MdmNotification.new(token: token, push_magic: push_magic)
112
+
113
+ # send (this is a blocking call)
114
+ response = connection.push(notification)
115
+
116
+ # read the response
117
+ response.ok? # => true
118
+ response.status # => '200'
119
+ response.headers # => {":status"=>"200", "apns-id"=>"6f2cd350-bfad-4af0-a8bc-0d501e9e1799"}
120
+ response.body # => ""
121
+
122
+ # close the connection
123
+ connection.close
124
+ ```
125
+
95
126
  #### Token-based authentication
96
127
  Token-based authentication is supported. There are several advantages with token-based auth:
97
128
 
@@ -3,6 +3,7 @@ require 'apnotic/provider_token'
3
3
  require 'apnotic/connection'
4
4
  require 'apnotic/connection_pool'
5
5
  require 'apnotic/notification'
6
+ require 'apnotic/mdm_notification'
6
7
  require 'apnotic/push'
7
8
  require 'apnotic/request'
8
9
  require 'apnotic/response'
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ require 'json'
5
+
6
+ module Apnotic
7
+ class AbstractNotification
8
+ attr_reader :token
9
+ attr_accessor :apns_id,
10
+ :expiration,
11
+ :priority,
12
+ :topic,
13
+ :apns_collapse_id,
14
+ :authorization
15
+
16
+ def initialize(token)
17
+ @token = token
18
+ @apns_id = SecureRandom.uuid
19
+ end
20
+
21
+ def body
22
+ JSON.dump(to_hash).force_encoding(Encoding::BINARY)
23
+ end
24
+
25
+ def authorization_header
26
+ authorization ? "bearer #{authorization}" : nil
27
+ end
28
+
29
+ private
30
+
31
+ def to_hash
32
+ raise NotImplementedError, 'implement the to_hash method in a child class'
33
+ end
34
+ end
35
+ end
@@ -79,12 +79,10 @@ module Apnotic
79
79
  end
80
80
 
81
81
  def delayed_push_async(push)
82
- if streams_available?
83
- @client.call_async(push.http2_request)
84
- else
82
+ until streams_available? do
85
83
  sleep 0.001
86
- delayed_push_async(push)
87
84
  end
85
+ @client.call_async(push.http2_request)
88
86
  end
89
87
 
90
88
  def streams_available?
@@ -0,0 +1,19 @@
1
+ require 'apnotic/abstract_notification'
2
+
3
+ module Apnotic
4
+
5
+ class MdmNotification < AbstractNotification
6
+ attr_reader :push_magic
7
+
8
+ def initialize(push_magic:, token:)
9
+ super(token)
10
+ @push_magic = push_magic
11
+ end
12
+
13
+ private
14
+
15
+ def to_hash
16
+ { mdm: push_magic }
17
+ end
18
+ end
19
+ end
@@ -1,42 +1,28 @@
1
- require 'securerandom'
2
- require 'json'
1
+ require 'apnotic/abstract_notification'
3
2
 
4
3
  module Apnotic
5
4
 
6
- class Notification
7
- attr_reader :token
5
+ class Notification < AbstractNotification
8
6
  attr_accessor :alert, :badge, :sound, :content_available, :category, :custom_payload, :url_args, :mutable_content
9
- attr_accessor :apns_id, :expiration, :priority, :topic, :apns_collapse_id, :authorization
10
7
 
11
- def initialize(token)
12
- @token = token
13
- @apns_id = SecureRandom.uuid
14
- end
15
-
16
- def body
17
- JSON.dump(to_hash).force_encoding(Encoding::BINARY)
18
- end
8
+ private
19
9
 
20
- def authorization_header
21
- authorization ? "bearer #{authorization}" : nil
10
+ def aps
11
+ {}.tap do |result|
12
+ result.merge!(alert: alert) if alert
13
+ result.merge!(badge: badge) if badge
14
+ result.merge!(sound: sound) if sound
15
+ result.merge!(category: category) if category
16
+ result.merge!('content-available' => content_available) if content_available
17
+ result.merge!('url-args' => url_args) if url_args
18
+ result.merge!('mutable-content' => mutable_content) if mutable_content
19
+ end
22
20
  end
23
21
 
24
- private
25
-
26
22
  def to_hash
27
- aps = {}
28
-
29
- aps.merge!(alert: alert) if alert
30
- aps.merge!(badge: badge) if badge
31
- aps.merge!(sound: sound) if sound
32
- aps.merge!(category: category) if category
33
- aps.merge!('content-available' => content_available) if content_available
34
- aps.merge!('url-args' => url_args) if url_args
35
- aps.merge!('mutable-content' => mutable_content) if mutable_content
36
-
37
- n = { aps: aps }
38
- n.merge!(custom_payload) if custom_payload
39
- n
23
+ { aps: aps }.tap do |result|
24
+ result.merge!(custom_payload) if custom_payload
25
+ end
40
26
  end
41
27
  end
42
28
  end
@@ -1,3 +1,3 @@
1
1
  module Apnotic
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apnotic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Ostinelli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-13 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http2
@@ -106,9 +106,11 @@ files:
106
106
  - bin/console
107
107
  - bin/setup
108
108
  - lib/apnotic.rb
109
+ - lib/apnotic/abstract_notification.rb
109
110
  - lib/apnotic/connection.rb
110
111
  - lib/apnotic/connection_pool.rb
111
112
  - lib/apnotic/instance_cache.rb
113
+ - lib/apnotic/mdm_notification.rb
112
114
  - lib/apnotic/notification.rb
113
115
  - lib/apnotic/provider_token.rb
114
116
  - lib/apnotic/push.rb