acts_as_notifiable 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/acts_as_notifiable.rb +3 -0
- data/lib/app/models/notification.rb +18 -0
- data/lib/app/models/notification_object.rb +38 -0
- metadata +65 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
class Notification < ActiveRecord::Base
|
2
|
+
|
3
|
+
attr_accessible :user_id, :notifiable_id, :notifiable_type, :delivered, :polymorphic_id, :polymorphic_type
|
4
|
+
|
5
|
+
# Validations
|
6
|
+
validates_presence_of :user_id, :notifiable_id, :notifiable_type
|
7
|
+
|
8
|
+
# Associations
|
9
|
+
belongs_to :notifiable, polymorphic: true
|
10
|
+
belongs_to :user
|
11
|
+
|
12
|
+
def as_json(options=nil)
|
13
|
+
super(options || {
|
14
|
+
except: [:updated_at, :created_at]
|
15
|
+
})
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class NotificationObject
|
2
|
+
include ActiveModel::Validations
|
3
|
+
include ActiveModel::Conversion
|
4
|
+
include ActiveModel::Naming
|
5
|
+
|
6
|
+
attr_accessor :alert, :badge, :sound, :token, :additional_object, :sendable_object
|
7
|
+
|
8
|
+
validates :alert, presence: true
|
9
|
+
validates :token, presence: true
|
10
|
+
validates_numericality_of :badge
|
11
|
+
|
12
|
+
def initialize(attributes = {})
|
13
|
+
attributes.each do |name, value|
|
14
|
+
send("#{name}=", value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_object
|
19
|
+
notification_array = Array.new
|
20
|
+
obj = Hash.new
|
21
|
+
obj[:aps] = Hash.new
|
22
|
+
obj[:aps][:alert] = self.alert
|
23
|
+
obj[:aps][:badge] = self.badge if self.badge
|
24
|
+
obj[:aps][:sound] = self.sound if self.sound
|
25
|
+
obj[self.additional_object.keys.first] = self.additional_object.values.first if self.additional_object
|
26
|
+
|
27
|
+
notification_array[0] = self.token
|
28
|
+
notification_array[1] = obj.symbolize_keys
|
29
|
+
notification_array[2] = self.additional_object.symbolize_keys if self.additional_object
|
30
|
+
|
31
|
+
self.sendable_object = notification_array
|
32
|
+
end
|
33
|
+
|
34
|
+
def persisted?
|
35
|
+
false
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_notifiable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nick Franken
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jtv-apns
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.1.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.2
|
30
|
+
description: This gem creates notifiable objects, and allows objects to be set as
|
31
|
+
read
|
32
|
+
email:
|
33
|
+
- nf@the42.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- lib/acts_as_notifiable.rb
|
39
|
+
- lib/app/models/notification.rb
|
40
|
+
- lib/app/models/notification_object.rb
|
41
|
+
homepage:
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.24
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Manages notifiable objects
|
65
|
+
test_files: []
|