houston 0.2.4 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5aecadd372ded4ba46d1ae9eca31fbcab168644
4
- data.tar.gz: f39b14600dbfe3610cc3b6d6024b5cdee0941471
3
+ metadata.gz: 2779c81aef10465328535550a02a23fd203ffa76
4
+ data.tar.gz: 1bd1a54558740b30391811d0741a08954bb081c1
5
5
  SHA512:
6
- metadata.gz: 22539e7ac680df2138dc00a1e1688dbeb1e7c7c0973687f6c1bad64b1e64676cf7b8ecf88e3b209fcc49f743b7acc778c23d5a8e470d72d877815d86e7a55c3a
7
- data.tar.gz: f95928800e51dda1313e1df4aeec8da7a1b0fb8543e6d124e7ff162dd01f7dfbd0307ede39ea56b6eff4c3ae2c2677dab98e891cbd52d00517a632506ece07cf
6
+ metadata.gz: d09615023d3d9fcb563eae42b3c716e77d21be746d3c491a1a6e5286fc5415cb212fbe27ac07a3e3269a7612e551b808d8b126079cd8838a6c59048e452b541e
7
+ data.tar.gz: accfa444cdd9b3adf3f998274350429b1823bdcef5dca4b20c6e214eff9ff656db327c65dfcac677dbe952ebf49d1d9d36aef5c712856e4593b1c744302c645c
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- houston (0.2.4)
4
+ houston (0.3.0)
5
5
  commander (~> 4.1)
6
6
  json
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- commander (4.1.3)
11
+ commander (4.1.4)
12
12
  highline (~> 1.6.11)
13
13
  highline (1.6.19)
14
14
  json (1.8.0)
data/houston-0.2.4.gem ADDED
Binary file
data/lib/houston.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Houston
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
4
4
 
5
5
  require 'houston/client'
@@ -6,7 +6,7 @@ module Houston
6
6
  APPLE_DEVELOPMENT_FEEDBACK_URI = "apn://feedback.sandbox.push.apple.com:2196"
7
7
 
8
8
  class Client
9
- attr_accessor :gateway_uri, :feedback_uri, :certificate, :passphrase
9
+ attr_accessor :gateway_uri, :feedback_uri, :certificate, :passphrase, :timeout
10
10
 
11
11
  class << self
12
12
  def development
@@ -29,19 +29,51 @@ module Houston
29
29
  @feedback_uri = ENV['APN_FEEDBACK_URI']
30
30
  @certificate = ENV['APN_CERTIFICATE']
31
31
  @passphrase = ENV['APN_CERTIFICATE_PASSPHRASE']
32
+ @timeout = ENV['APN_TIMEOUT'] || 0.5
32
33
  end
33
34
 
34
35
  def push(*notifications)
35
36
  return if notifications.empty?
36
37
 
38
+ notifications.flatten!
39
+ error = nil
40
+
37
41
  Connection.open(@gateway_uri, @certificate, @passphrase) do |connection|
38
- notifications.flatten.each do |notification|
42
+ ssl = connection.ssl
43
+
44
+ notifications.each_with_index do |notification, index|
39
45
  next unless notification.kind_of?(Notification)
40
46
  next if notification.sent?
41
47
 
48
+ notification.id = index
49
+
42
50
  connection.write(notification.message)
43
51
  notification.mark_as_sent!
52
+
53
+ break if notifications.count == 1 || notification == notifications.last
54
+
55
+ read_socket, write_socket = IO.select([ssl], [ssl], [ssl], nil)
56
+ if (read_socket && read_socket[0])
57
+ error = connection.read(6)
58
+ break
59
+ end
44
60
  end
61
+
62
+ return if notifications.count == 1
63
+
64
+ unless error
65
+ read_socket, write_socket = IO.select([ssl], nil, [ssl], timeout)
66
+ if (read_socket && read_socket[0])
67
+ error = connection.read(6)
68
+ end
69
+ end
70
+ end
71
+
72
+ if error
73
+ command, status, index = error.unpack("cci")
74
+ notifications.slice!(0..index)
75
+ notifications.each(&:mark_as_unsent!)
76
+ push(*notifications)
45
77
  end
46
78
  end
47
79
 
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module Houston
4
4
  class Notification
5
- attr_accessor :token, :alert, :badge, :sound, :content_available, :custom_data
5
+ attr_accessor :token, :alert, :badge, :sound, :content_available, :custom_data, :id, :expiry
6
6
  attr_reader :sent_at
7
7
 
8
8
  alias :device :token
@@ -13,6 +13,8 @@ module Houston
13
13
  @alert = options.delete(:alert)
14
14
  @badge = options.delete(:badge)
15
15
  @sound = options.delete(:sound)
16
+ @expiry = options.delete(:expiry)
17
+ @id = options.delete(:id)
16
18
  @content_available = options.delete(:content_available)
17
19
 
18
20
  @custom_data = options
@@ -31,15 +33,21 @@ module Houston
31
33
 
32
34
  def message
33
35
  json = payload.to_json
34
- hex_token = [@token.gsub(/[<\s>]/, '')].pack('H*')
36
+ device_token = [@token.gsub(/[<\s>]/, '')].pack('H*')
37
+ @expiry ||= Time.now + 86400
38
+ @id ||= 0
35
39
 
36
- [0, 0, 32, hex_token, 0, json.bytes.count, json].pack('ccca*cca*')
40
+ [1, @id, @expiry.to_i, 0, 32, device_token, 0, json.bytes.count, json].pack('ciicca*cca*')
37
41
  end
38
42
 
39
43
  def mark_as_sent!
40
44
  @sent_at = Time.now
41
45
  end
42
46
 
47
+ def mark_as_unsent!
48
+ @sent_at = nil
49
+ end
50
+
43
51
  def sent?
44
52
  !!@sent_at
45
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: houston
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattt Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-30 00:00:00.000000000 Z
11
+ date: 2013-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
@@ -77,6 +77,7 @@ files:
77
77
  - ./apple_push_notification_production.pem
78
78
  - ./Gemfile
79
79
  - ./Gemfile.lock
80
+ - ./houston-0.2.4.gem
80
81
  - ./houston.gemspec
81
82
  - ./lib/houston/client.rb
82
83
  - ./lib/houston/connection.rb
@@ -96,12 +97,12 @@ require_paths:
96
97
  - lib
97
98
  required_ruby_version: !ruby/object:Gem::Requirement
98
99
  requirements:
99
- - - ! '>='
100
+ - - '>='
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
103
  required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  requirements:
104
- - - ! '>='
105
+ - - '>='
105
106
  - !ruby/object:Gem::Version
106
107
  version: '0'
107
108
  requirements: []