apn 1.0.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.
@@ -0,0 +1,46 @@
1
+ module APN
2
+ class FeedbackItem
3
+ attr_accessor :timestamp, :token
4
+
5
+ def initialize(time, token)
6
+ @timestamp = time
7
+ @token = token
8
+ end
9
+ end
10
+
11
+ class Feedback
12
+ def initialize(options = {})
13
+ options[:host] ||= 'feedback.push.apple.com'
14
+ options[:port] ||= 2196
15
+ options[:password] ||= ''
16
+
17
+ @cert = options[:cert]
18
+ @password = options[:password]
19
+ @host = options[:host]
20
+ @port = options[:port]
21
+
22
+ @logger = APN::Log.new.write
23
+ end
24
+
25
+ def data
26
+ @logger.info 'Trying to get feedback from Apple push notification server...'
27
+
28
+ @feedback ||= receive
29
+ end
30
+
31
+ def receive
32
+ feedbacks = []
33
+ while f = client.feedback
34
+ feedbacks << f
35
+ end
36
+
37
+ @logger.info 'Feedback received!'
38
+
39
+ return feedbacks
40
+ end
41
+
42
+ def client
43
+ @client ||= APN::Client.new(host: @host, port: @port, cert: APN.config.cert_file, password: APN.config.cert_password)
44
+ end
45
+ end
46
+ end
data/lib/apn/log.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'logger'
2
+
3
+ module APN
4
+ class Log
5
+ def initialize(options = {})
6
+ end
7
+
8
+ def write
9
+ @logger ||= set_logger
10
+ end
11
+
12
+ def set_logger
13
+ @logger = Logger.new(@logfile) if logfile
14
+ end
15
+
16
+ def logfile
17
+ @logfile = APN.config.logfile
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module APN
2
+ class Notification
3
+ attr_accessor :badge, :alert, :sound, :content_available, :custom_properties, :device_token
4
+
5
+ def initialize(hash)
6
+ [:badge, :alert, :sound, :device_token, :content_available, :custom_properties].each do |k|
7
+ self.instance_variable_set("@#{k}".to_sym, hash[k]) if hash[k]
8
+ end
9
+ raise "Must provide device token: #{hash}" if self.device_token.nil?
10
+ self.device_token = self.device_token.delete(' ')
11
+ end
12
+
13
+ def payload
14
+ p = Hash.new
15
+ [:badge, :alert, :sound, :content_available].each do |k|
16
+ p[k.to_s.gsub('_','-').to_sym] = send(k) if send(k)
17
+ end
18
+ aps = {:aps => p}
19
+ aps.merge!(custom_properties) if custom_properties
20
+ aps
21
+ end
22
+
23
+ def json_payload
24
+ j = ActiveSupport::JSON.encode(payload)
25
+ raise "The payload #{j} is larger than allowed: #{j.length}" if j.size > 256
26
+ j
27
+ end
28
+
29
+ def to_bytes
30
+ j = json_payload
31
+ [0, 0, 32, self.device_token, 0, j.bytesize, j].pack("cccH*cca*").force_encoding('ASCII-8BIT')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ module APN
2
+ class Railtie < Rails::Railtie
3
+ initializer "apn.setup" do |app|
4
+
5
+ APN.root = Rails.root
6
+ if Rails.env.development?
7
+ #APN.certificate_name = "apn_development.pem"
8
+ #APN.host = "gateway.sandbox.push.apple.com"
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module APN
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apn
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Peter Hrbacik
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: redis
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.2.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.2.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: activesupport
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: daemons
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.1.6
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.1.6
94
+ description: APN is a lightweight Apple Push Notification daemon for Ruby on Rails.
95
+ APN works asynchronously using Redis and run as a daemon.
96
+ email:
97
+ - info@itrinity.com
98
+ executables:
99
+ - apn
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - .idea/.name
105
+ - .idea/.rakeTasks
106
+ - .idea/apn.iml
107
+ - .idea/encodings.xml
108
+ - .idea/misc.xml
109
+ - .idea/modules.xml
110
+ - .idea/scopes/scope_settings.xml
111
+ - .idea/vcs.xml
112
+ - .idea/workspace.xml
113
+ - Gemfile
114
+ - LICENSE.txt
115
+ - README.md
116
+ - Rakefile
117
+ - apn.gemspec
118
+ - bin/apn
119
+ - lib/apn.rb
120
+ - lib/apn/client.rb
121
+ - lib/apn/config.rb
122
+ - lib/apn/daemon.rb
123
+ - lib/apn/feedback.rb
124
+ - lib/apn/log.rb
125
+ - lib/apn/notification.rb
126
+ - lib/apn/railtie.rb
127
+ - lib/apn/version.rb
128
+ homepage: http://github.com/itrinity/apn
129
+ licenses:
130
+ - MIT
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 1.8.23
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: Asynchronous Apple Push Notification daemon
153
+ test_files: []