lowdown 0.3.2 → 1.0.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: 16ef8f3b50f11449f847661ccb4ec8e6778b8ccc
4
- data.tar.gz: 1488fbc454c97265901024487be28faf7eb7223c
3
+ metadata.gz: d2e108d10dee8fe2b683cc76da5f3c7514957699
4
+ data.tar.gz: dca96974b0b8bd162baf8df4d6dff344650a7c61
5
5
  SHA512:
6
- metadata.gz: e1b61b26414001f09fd20f36728095263c0d7d42f310cea0a745a0f41ca8e732115c81b3342ceaed205c084972484c4206d80a055e4a1943b2f6f668e7b565f9
7
- data.tar.gz: 018adda275d2796bfba301acd287cd54e6f6f5653121e0c2926502afcc533b0a1ebd40bcec8f62ae79520edaf1de711d7916896e955fafcd6a546b21512a5311
6
+ metadata.gz: 82d96f945d8234049c66a546bac040852446bb9db72c228775619f487fa7bab9d21e1ce5ce23e8584b0356da2c7ff72f3cd16aa811ac2ce9477cdcfdc823a314
7
+ data.tar.gz: d7082d411eb7e0e74ed63f091db0eab272763caeda71aceea2353f95cb4c92b8206799747db480069c100498cffe026933cd324543d252bc9bfe14c3f47bb000
@@ -3,6 +3,6 @@ rvm:
3
3
  - 2.1.1
4
4
  - 2.1
5
5
  - 2.2
6
- - 2.3.0
6
+ - 2.3.1
7
7
  before_install: gem install bundler
8
8
  install: bundle install --without doc
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lowdown (0.3.1)
4
+ lowdown (1.0.0)
5
5
  celluloid-io (>= 0.17.3)
6
6
  http-2 (>= 0.8)
7
7
 
data/README.md CHANGED
@@ -4,8 +4,6 @@
4
4
 
5
5
  [![Build Status](https://travis-ci.org/alloy/lowdown.svg?branch=master)](https://travis-ci.org/alloy/lowdown)
6
6
 
7
- ⚠︎ NOTE: _This is not battle-tested yet, which will follow over the next few weeks. A v1 will be released at that time._
8
-
9
7
  Lowdown is a Ruby client for the HTTP/2 version of the Apple Push Notification Service.
10
8
 
11
9
  For efficiency, multiple notification requests are multiplexed and a single client can manage a pool of connections.
@@ -66,7 +64,7 @@ After obtaining a client, the simplest way to open a connection for a short peri
66
64
  This will open the connection, yield the block, and close the connection by the end of the block:
67
65
 
68
66
  ```ruby
69
- client = Lowdown::Client.production(true, File.read("path/to/certificate.pem")
67
+ client = Lowdown::Client.production(true, certificate: File.read("path/to/certificate.pem")
70
68
  client.connect do |group|
71
69
  # ...
72
70
  end
@@ -79,7 +77,7 @@ end
79
77
  The trick to creating a persistent connection is to specify the `keep_alive: true` option when creating the client:
80
78
 
81
79
  ```ruby
82
- client = Lowdown::Client.production(true, File.read("path/to/certificate.pem"), keep_alive: true)
80
+ client = Lowdown::Client.production(true, certificate: File.read("path/to/certificate.pem"), keep_alive: true)
83
81
 
84
82
  # Send a batch of notifications
85
83
  client.group do |group|
@@ -160,7 +158,24 @@ connections to the remote service. By default Lowdown will initialize clients wi
160
158
  increase this with the `pool_size` option:
161
159
 
162
160
  ```ruby
163
- Lowdown::Client.production(true, File.read("path/to/certificate.pem"), pool_size: 3)
161
+ Lowdown::Client.production(true, certificate: File.read("path/to/certificate.pem"), pool_size: 3)
162
+ ```
163
+
164
+ ### Connect to APNS via proxy
165
+
166
+ `Lowdown::Connection#initialize` accepts a lambda to build TCPSocket. Build a duck type of TCPSocket which go through proxy.
167
+
168
+ ```ruby
169
+ socket_maker = lambda do |uri|
170
+ Proxifier::Proxy('http://127.0.0.1:3128').open \
171
+ uri.host, uri.port, nil, nil, Celluloid::IO::TCPSocket
172
+ end
173
+
174
+ connection_pool = Lowdown::Connection.pool \
175
+ size: 2,
176
+ args: [uri, cert.ssl_context, true, socket_maker]
177
+
178
+ client = Lowdown::Client.client_with_connection connection_pool, certificate: cert
164
179
  ```
165
180
 
166
181
  ## Gotchas
@@ -126,8 +126,9 @@ module Lowdown
126
126
  #
127
127
  def topics
128
128
  if universal?
129
- components = extension(UNIVERSAL_CERTIFICATE_EXTENSION).value.split(/0?\.{2,}/)
130
- components.select.with_index { |_, index| index.odd? }
129
+ ext = extension(UNIVERSAL_CERTIFICATE_EXTENSION)
130
+ seq = OpenSSL::ASN1.decode(OpenSSL::ASN1.decode(ext.to_der).value[1].value)
131
+ seq.select.with_index { |_, index| index.even? }.map(&:value)
131
132
  else
132
133
  [app_bundle_id]
133
134
  end
@@ -83,8 +83,25 @@ module Lowdown
83
83
  # @param [Boolean] connect
84
84
  # whether or not to immediately connect on initialization.
85
85
  #
86
- def initialize(uri, ssl_context, connect = true)
86
+ # @param [lambda] socket_maker
87
+ # a lambda takes uri and returns duck type of TCPSocket
88
+ # e.g.:
89
+ #
90
+ # @example Use `socket_maker` argument with modified ruby-proxifier
91
+ # socket_maker = lambda do |uri|
92
+ # Proxifier::Proxy('http://127.0.0.1:3128').open \
93
+ # uri.host, uri.port, nil, nil, Celluloid::IO::TCPSocket
94
+ # end
95
+ #
96
+ # connection_pool = Lowdown::Connection.pool \
97
+ # size: 2,
98
+ # args: [uri, cert.ssl_context, true, socket_maker]
99
+ #
100
+ # client = Lowdown::Client.client_with_connection connection_pool, certificate: cert
101
+ #
102
+ def initialize(uri, ssl_context, connect = true, socket_maker = nil)
87
103
  @uri, @ssl_context = URI(uri), ssl_context
104
+ @socket_maker = socket_maker
88
105
  reset_state!
89
106
 
90
107
  if connect
@@ -165,7 +182,11 @@ module Lowdown
165
182
  # 2. This tries to `NilClass#send` the hostname:
166
183
  # https://github.com/celluloid/celluloid-io/blob/85cee9da22ef5e94ba0abfd46454a2d56572aff4/lib/celluloid/io/dns_resolver.rb#L44
167
184
  begin
168
- socket = TCPSocket.new(@uri.host, @uri.port)
185
+ socket = if @socket_maker.respond_to? :call
186
+ @socket_maker.call @uri
187
+ else
188
+ TCPSocket.new(@uri.host, @uri.port)
189
+ end
169
190
  rescue NoMethodError
170
191
  raise SocketError, "(Probably) getaddrinfo: nodename nor servname provided, or not known"
171
192
  end
@@ -240,6 +261,8 @@ module Lowdown
240
261
  # @return [void]
241
262
  #
242
263
  def change_to_connected_state
264
+ return unless @http
265
+
243
266
  @max_stream_count = @http.remote_settings[:settings_max_concurrent_streams]
244
267
  @connected = true
245
268
 
@@ -327,14 +350,14 @@ module Lowdown
327
350
  end
328
351
 
329
352
  def try_to_perform_request!
330
- unless @connected
353
+ if @connected
354
+ @warned_about_not_connected = false
355
+ else
331
356
  unless @warned_about_not_connected
332
357
  warn "Defer performing request, because the connection has not been established yet."
333
358
  @warned_about_not_connected = true
334
359
  end
335
360
  return
336
- else
337
- @warned_about_not_connected = false
338
361
  end
339
362
 
340
363
  unless @http.active_stream_count < @max_stream_count
@@ -30,7 +30,13 @@ module Lowdown
30
30
 
31
31
  # Make it a Universal Certificate
32
32
  ext_name = Lowdown::Certificate::UNIVERSAL_CERTIFICATE_EXTENSION
33
- cert.extensions = [OpenSSL::X509::Extension.new(ext_name, "0d..#{app_bundle_id}0...app")]
33
+ ext_value = OpenSSL::ASN1::Sequence.new(
34
+ [
35
+ OpenSSL::ASN1::UTF8String.new(app_bundle_id),
36
+ OpenSSL::ASN1::Sequence.new([OpenSSL::ASN1::UTF8String.new("app")]),
37
+ ]
38
+ ).to_der
39
+ cert.extensions = [OpenSSL::X509::Extension.new(ext_name, ext_value)]
34
40
 
35
41
  [cert, key]
36
42
  end
@@ -95,7 +95,7 @@ module Lowdown
95
95
  # in case of an inactive token, the time at which the service last verified it.
96
96
  #
97
97
  def activity_last_checked_at
98
- Time.at(body["timestamp"].to_i) if inactive_token?
98
+ Time.at(body["timestamp"].to_i / 1000) if inactive_token?
99
99
  end
100
100
 
101
101
  # @return [String]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lowdown
4
- VERSION = "0.3.2".freeze
4
+ VERSION = "1.0.0".freeze
5
5
  end
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lowdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Durán
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-14 00:00:00.000000000 Z
11
+ date: 2016-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2