push-core 0.0.1.pre → 0.0.1.pre2
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.
- data/README.md +86 -1
- data/lib/push-core.rb +1 -0
- data/lib/push/daemon/feeder.rb +1 -1
- data/lib/push/daemon/logger.rb +3 -2
- data/lib/push/railtie.rb +11 -0
- data/lib/push/version.rb +1 -1
- data/lib/tasks/push_tasks.rake +11 -0
- metadata +9 -6
data/README.md
CHANGED
@@ -1,3 +1,88 @@
|
|
1
1
|
# Push
|
2
2
|
|
3
|
-
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add to your `GemFile`
|
6
|
+
|
7
|
+
gem push-core
|
8
|
+
|
9
|
+
and add the push provider to you Gemfile:
|
10
|
+
|
11
|
+
For __APNS__ (iOS: Apple Push Notification Services):
|
12
|
+
|
13
|
+
gem push-apns
|
14
|
+
|
15
|
+
For __C2DM__ (Android: Cloud to Device Messaging):
|
16
|
+
|
17
|
+
gem push-c2dm
|
18
|
+
|
19
|
+
And run `bundle install` to install the gems.
|
20
|
+
|
21
|
+
To generate the migration and the configuration files run:
|
22
|
+
|
23
|
+
rails g push
|
24
|
+
bundle exec rake db:migrate
|
25
|
+
|
26
|
+
## Configuration
|
27
|
+
A default configuration file looks like this:
|
28
|
+
```ruby
|
29
|
+
Push::Daemon::Builder.new do
|
30
|
+
daemon({ :poll => 2, :pid_file => "tmp/pids/push.pid", :airbrake_notify => false })
|
31
|
+
|
32
|
+
provider :apns,
|
33
|
+
{
|
34
|
+
:certificate => "production.pem",
|
35
|
+
:certificate_password => "",
|
36
|
+
:sandbox => false,
|
37
|
+
:connections => 3,
|
38
|
+
:feedback_poll => 60
|
39
|
+
}
|
40
|
+
|
41
|
+
provider :c2dm,
|
42
|
+
{
|
43
|
+
:connections => 2,
|
44
|
+
:email => "",
|
45
|
+
:password => ""
|
46
|
+
}
|
47
|
+
end
|
48
|
+
```
|
49
|
+
Remove the provider you're not using. Add your email and password to enable C2DM. For APNS follow the 'Generating Certificates' below.
|
50
|
+
|
51
|
+
|
52
|
+
### Generating Certificates
|
53
|
+
|
54
|
+
1. Open up Keychain Access and select the `Certificates` category in the sidebar.
|
55
|
+
2. Expand the disclosure arrow next to the iOS Push Services certificate you want to export.
|
56
|
+
3. Select both the certificate and private key.
|
57
|
+
4. Right click and select `Export 2 items...`.
|
58
|
+
5. Save the file as `cert.p12`, make sure the File Format is `Personal Information Exchange (p12)`.
|
59
|
+
6. If you decide to set a password for your exported certificate, please read the Configuration section below.
|
60
|
+
7. Convert the certificate to a .pem, where `<environment>` should be `development` or `production`, depending on the certificate you exported.
|
61
|
+
|
62
|
+
`openssl pkcs12 -nodes -clcerts -in cert.p12 -out <environment>.pem`
|
63
|
+
|
64
|
+
8. Move the .pem file into your Rails application under `config/push`.
|
65
|
+
|
66
|
+
|
67
|
+
## Daemon
|
68
|
+
|
69
|
+
To start the daemon:
|
70
|
+
|
71
|
+
bundle exec push <environment> <options>
|
72
|
+
|
73
|
+
Where `<environment>` is your Rails environment and `<options>` can be `--foreground`, `--version` or `--help`.
|
74
|
+
|
75
|
+
## Sending notifications
|
76
|
+
APNS:
|
77
|
+
```ruby
|
78
|
+
Push::MessageApns.new(device: "<APNS device_token here>", alert: 'Hello World', expiry: 1.day.to_i, attributes_for_device: {key: 'MSG'}).save
|
79
|
+
```
|
80
|
+
C2DM:
|
81
|
+
```ruby
|
82
|
+
Push::MessageC2dm.new(device: "<C2DM registration_id here>", payload: { message: "Hello World" }, collapse_key: "MSG").save
|
83
|
+
```
|
84
|
+
|
85
|
+
## Thanks
|
86
|
+
|
87
|
+
This project started as a fork of Ian Leitch [RAPNS](https://github.com/ileitch/rapns) project. The differences between this project and RAPNS is the support for C2DM and the modularity of the push providers.
|
88
|
+
|
data/lib/push-core.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'push/railtie' if defined?(Rails)
|
data/lib/push/daemon/feeder.rb
CHANGED
@@ -29,7 +29,7 @@ module Push
|
|
29
29
|
begin
|
30
30
|
with_database_reconnect_and_retry(name) do
|
31
31
|
if Push::Daemon.delivery_queue.notifications_processed?
|
32
|
-
Push::Message.ready_for_delivery.
|
32
|
+
Push::Message.ready_for_delivery.find_each do |notification|
|
33
33
|
Push::Daemon.delivery_queue.push(notification)
|
34
34
|
end
|
35
35
|
end
|
data/lib/push/daemon/logger.rb
CHANGED
@@ -3,8 +3,9 @@ module Push
|
|
3
3
|
class Logger
|
4
4
|
def initialize(options)
|
5
5
|
@options = options
|
6
|
-
|
7
|
-
|
6
|
+
log_file = File.open(File.join(Rails.root, 'log', 'push.log'), 'w')
|
7
|
+
log_file.sync = true
|
8
|
+
@logger = ActiveSupport::BufferedLogger.new(log_file, Rails.logger.level)
|
8
9
|
@logger.auto_flushing = Rails.logger.respond_to?(:auto_flushing) ? Rails.logger.auto_flushing : true
|
9
10
|
end
|
10
11
|
|
data/lib/push/railtie.rb
ADDED
data/lib/push/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Push Rake Tasks
|
2
|
+
namespace :push do
|
3
|
+
desc "Delete all push messages and feedback older than 7 days or DAYS=x if defined (where x is an integer)"
|
4
|
+
task :clean => :environment do
|
5
|
+
days = ENV["DAYS"].to_i || 7
|
6
|
+
puts "Removing #{days} days of push messages and feedback"
|
7
|
+
feedback = Push::Feedback.where("created_at < ?", days.days.ago).delete_all
|
8
|
+
messages = Push::Message.where("created_at < ?", days.days.ago).delete_all
|
9
|
+
puts "Done, messages=#{messages} feedback=#{feedback}"
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: push-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.pre2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70357910508440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.2.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70357910508440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &70357910506440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70357910506440
|
36
36
|
description: Push daemon for push notification services like APNS and C2DM.
|
37
37
|
email:
|
38
38
|
- tom@tnux.net
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/generators/templates/development.rb
|
47
47
|
- lib/generators/templates/production.rb
|
48
48
|
- lib/generators/templates/staging.rb
|
49
|
+
- lib/push-core.rb
|
49
50
|
- lib/push.rb
|
50
51
|
- lib/push/daemon.rb
|
51
52
|
- lib/push/daemon/builder.rb
|
@@ -62,7 +63,9 @@ files:
|
|
62
63
|
- lib/push/daemon/pool.rb
|
63
64
|
- lib/push/feedback.rb
|
64
65
|
- lib/push/message.rb
|
66
|
+
- lib/push/railtie.rb
|
65
67
|
- lib/push/version.rb
|
68
|
+
- lib/tasks/push_tasks.rake
|
66
69
|
- README.md
|
67
70
|
- MIT-LICENSE
|
68
71
|
- bin/push
|