actionpusher 0.0.1

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,5 @@
1
+ require 'action_pusher/base'
2
+ require 'action_pusher/apn_certificate'
3
+
4
+ module ActionPusher
5
+ end
@@ -0,0 +1,35 @@
1
+ require 'houston'
2
+
3
+ module ActionPusher
4
+ class APNCertificate
5
+ def self.instance
6
+ APNCertificate.apn.tap do |apn|
7
+ # Load required certificate
8
+ apn.certificate = File.read(
9
+ File.join(Rails.root, 'config', 'certificates', "push-notification-#{APNCertificate.environment_string}.pem"))
10
+ end
11
+ end
12
+
13
+ #######
14
+ private
15
+ #######
16
+
17
+ def self.environment_string
18
+ if Rails.env.production?
19
+ 'prod'
20
+ else
21
+ 'dev'
22
+ end
23
+ end
24
+
25
+ def self.apn
26
+ # Use the correct APN gateway
27
+ # See: https://github.com/nomad/houston/blob/master/lib/houston/client.rb#L2-L6
28
+ if Rails.env.production?
29
+ Houston::Client.production
30
+ else
31
+ Houston::Client.development
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,69 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext/object/blank'
3
+
4
+ module ActionPusher
5
+ class Base
6
+ def self.method_missing(method_name, *args)
7
+ if method_defined?(method_name)
8
+ new(method_name, *args).send(method_name, *args)
9
+ else
10
+ super
11
+ end
12
+ end
13
+
14
+ # Create apple push notifications to be sent out
15
+ #
16
+ # * *Args*
17
+ # - +tokens+ -> User's being sent to
18
+ # - +message+ -> Message sent to tokens
19
+ # - +data+ -> Custom data passed through the push notification
20
+ # - +badge_count+ -> Number to place in badge (default is 0)
21
+ def push(opts)
22
+ tokens = opts[:tokens] || []
23
+ message = opts[:message] || ''
24
+ data = opts[:data] || {}
25
+ badge_count = opts[:badge_count] || 0
26
+
27
+ return self if message.blank?
28
+
29
+ @_notifications = Array.new.tap do |notifications|
30
+ tokens.each do |token|
31
+ notifications << Houston::Notification.new(device: token).tap do |notification|
32
+ notification.alert = message
33
+ notification.badge = badge_count
34
+ notification.custom_data = data
35
+ end
36
+ end
37
+ end
38
+
39
+ self
40
+ end
41
+
42
+ # Returns the name of the method used to generate the push notification
43
+ def action_name
44
+ @_action_name
45
+ end
46
+
47
+ # Send out the push notifications
48
+ def deliver
49
+ return self if @_push_was_called
50
+
51
+ @_push_was_called = true
52
+
53
+ apn = APNCertificate.instance
54
+ @_notifications.each do |notification|
55
+ apn.push(notification)
56
+ end
57
+ end
58
+
59
+ #########
60
+ protected
61
+ #########
62
+
63
+ def initialize(method_name=nil, *args)
64
+ @_push_was_called = false
65
+ @_action_name = method_name.to_s
66
+ @_notifications = []
67
+ end
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: actionpusher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gavin Miller
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.14.1
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: 2.14.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: houston
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.0.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 4.0.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: 4.0.2
62
+ description: Apple Push Notifications for Rails. Compose and deliver push notifications
63
+ for iOS
64
+ email: gavin@petrofeed.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/action_pusher/apn_certificate.rb
70
+ - lib/action_pusher/base.rb
71
+ - lib/action_pusher.rb
72
+ homepage:
73
+ licenses:
74
+ - MIT
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: 1.9.3
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements:
92
+ - none
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.23
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Push notification composition and delivery framework (based on ActionMailer.)
98
+ test_files: []