BAT_Notifications 0.0.0 → 0.0.4

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.
@@ -1,12 +1,12 @@
1
- require_relative 'A_User'
2
-
3
- module NotificationDb
4
- def self.get_sender
5
- return AUser.sender
6
- end
7
-
8
- def self.get_receiver
9
- return AUser.receiver
10
- end
11
-
1
+ require_relative 'A_User'
2
+
3
+ module NotificationDb
4
+ def self.get_sender
5
+ return AUser.sender
6
+ end
7
+
8
+ def self.get_receiver
9
+ return AUser.receiver
10
+ end
11
+
12
12
  end
@@ -1,66 +1,83 @@
1
- require_relative 'Notification'
2
- require_relative 'NotificationDb'
3
- require_relative "Content.rb"
4
-
5
- require "async"
6
-
7
-
8
- module ReviewNotificationDecorator
9
-
10
- def self.set_action(action)
11
- @action = action
12
- end
13
-
14
-
15
- def self.set_content
16
- @content = Content.review_content
17
- end
18
-
19
- def self.set_sender
20
- @sender = NotificationDb.get_sender
21
- end
22
-
23
- def self.set_receiver
24
- @receiver = NotificationDb.get_receiver
25
- end
26
-
27
-
28
- def self.init_review_decorator
29
- set_action("Review")
30
- set_content
31
- set_sender
32
- set_receiver
33
- @reviewNotification = ReviewNotification.new( @action, @sender, @receiver, @content )
34
- end
35
-
36
- def self.get_review_action
37
- init_review_decorator
38
- return @reviewNotification.get_action
39
- end
40
-
41
- def self.get_review_content
42
- init_review_decorator
43
- content = @reviewNotification.get_content
44
- content_stars = content["review_stars"]
45
- return content_stars
46
- end
47
-
48
- def self.get_review_sender
49
- init_review_decorator
50
- return @reviewNotification.get_sender["lastname"]
51
- end
52
-
53
- def self.get_review_receiver
54
- init_review_decorator
55
- return @reviewNotification.get_receiver["lastname"]
56
- end
57
-
58
- def self.send_notification
59
- init_review_decorator
60
- return @reviewNotification.send_notification
61
- end
62
-
63
- end
64
-
65
-
66
-
1
+ require_relative 'bat_notifications'
2
+ require_relative 'NotificationDb'
3
+ require_relative "Content.rb"
4
+
5
+ require "async"
6
+
7
+
8
+ module ReviewNotificationDecorator
9
+
10
+ def self.set_action(action)
11
+ @action = action
12
+ end
13
+
14
+
15
+ def self.set_content
16
+ @content = Content.review_content
17
+ end
18
+
19
+ def self.set_sender
20
+ @sender = NotificationDb.get_sender
21
+ end
22
+
23
+ def self.set_receiver
24
+ @receiver = NotificationDb.get_receiver
25
+ end
26
+
27
+
28
+ def self.init_review_decorator
29
+ set_content
30
+ set_sender
31
+ set_receiver
32
+ @notification = Notification.new(@sender, @receiver, @content)
33
+ @notification = ReviewNotification.new(@notification)
34
+ end
35
+
36
+ def self.get_review_action
37
+ init_review_decorator
38
+ return @notification.get_action
39
+ end
40
+
41
+ def self.get_review_content
42
+ init_review_decorator
43
+ content = @notification.get_content
44
+ content_stars = content["review_stars"]
45
+ return content_stars
46
+ end
47
+
48
+ def self.get_review_sender
49
+ init_review_decorator
50
+ return @notification.get_sender["lastname"]
51
+ end
52
+
53
+ def self.get_review_receiver
54
+ init_review_decorator
55
+ return @notification.get_receiver["lastname"]
56
+ end
57
+
58
+ def self.send_notification
59
+ init_review_decorator
60
+ return @notification.send_notification_to_receiver
61
+ end
62
+
63
+ def self.get_user_review_notification
64
+ init_review_decorator
65
+ @notification = UserReviewNotification.new(@notification)
66
+ end
67
+
68
+ def self.get_user_review_notification_subject
69
+ init_review_decorator
70
+ @notification = UserReviewNotification.new(@notification)
71
+ return @notification.get_subject
72
+ end
73
+
74
+ def self.user_send_notification
75
+ init_review_decorator
76
+ @notification = UserReviewNotification.new(@notification)
77
+ return @notification.send_notification_to_sender
78
+ end
79
+
80
+ end
81
+
82
+
83
+
@@ -1,90 +1,90 @@
1
- require_relative 'Notification'
2
-
3
-
4
- module SendNotification
5
- def self.sendBookingNotification
6
- set_base_and_action("Booking")
7
- @bookingsNotification = BookingsDecorator.new(@notificationBase, @action, "Femi", "Lanre", "I have booked you for a Session")
8
- puts @bookingsNotification.message
9
- puts @bookingsNotification.get_message
10
- end
11
-
12
- def self.sendReviewNotification(@sender, @receiver, @content)
13
- set_base_and_action("Review")
14
- @bookingsNotification = ReviewDecorator.new(@notificationBase, @action, @sender, @receiver, @content)
15
- puts @bookingsNotification.message
16
- puts @bookingsNotification.get_message
17
- end
18
-
19
- def self.sendMessageNotification
20
- set_base_and_action("Message")
21
- @bookingsNotification = InboxDecorator.new(@notificationBase, @action, "Femi", "Lanre", "I have sent you a message")
22
- puts @bookingsNotification.message
23
- puts @bookingsNotification.get_message
24
- end
25
-
26
- def self.sendAppNotification
27
- set_base_and_action("Message")
28
- @bookingsNotification = AppMessageDecorator.new(@notificationBase, @action, "Femi", "Lanre", "You have a message from BookATutor")
29
- puts @bookingsNotification.message
30
- puts @bookingsNotification.get_message
31
- end
32
-
33
-
34
-
35
- def self.get_notification_base
36
- @notificationBase = Notification.new
37
- return @notificationBase
38
- end
39
-
40
- def self.set_action(action)
41
- @action = action
42
- end
43
-
44
- def self.set_base_and_action(action)
45
- get_notification_base
46
- set_action(action)
47
- end
48
-
49
- def self.get_basic_notification_action
50
- init_basic_decorator
51
- return @basicNotification.get_action
52
- end
53
-
54
- def self.get_basic_notification_sender
55
- init_basic_decorator
56
- return @basicNotification.get_sender
57
- end
58
-
59
- def self.get_basic_notification_receiver
60
- init_basic_decorator
61
- return @basicNotification.get_receiver
62
- end
63
-
64
- def self.get_basic_notification_message
65
- init_basic_decorator
66
- return @basicNotification.get_message
67
- end
68
-
69
- def self.get_basic_notification_base
70
- init_basic_decorator
71
- return @basicNotification.get_notification_base
72
- end
73
-
74
- def self.init_basic_decorator
75
- set_base_and_action("Basic Notification")
76
- @basicNotification = BasicDecorator.new(@notificationBase, @action, "Sender", "Receiver", "Message" )
77
- end
78
-
79
-
80
- end
81
-
82
- SendNotification.init_basic_decorator
83
-
84
-
85
- #sendNotification = SendNotification.new
86
-
87
- # SendNotification.sendBookingNotification
88
- # SendNotification.sendReviewNotification
89
- # SendNotification.sendMessageNotification
90
- # SendNotification.sendAppNotification
1
+ require_relative 'bat_notifications'
2
+
3
+
4
+ module SendNotification
5
+ def self.sendBookingNotification
6
+ set_base_and_action("Booking")
7
+ @bookingsNotification = BookingsDecorator.new(@notificationBase, @action, "Femi", "Lanre", "I have booked you for a Session")
8
+ puts @bookingsNotification.message
9
+ puts @bookingsNotification.get_message
10
+ end
11
+
12
+ def self.sendReviewNotification(@sender, @receiver, @content)
13
+ set_base_and_action("Review")
14
+ @bookingsNotification = ReviewDecorator.new(@notificationBase, @action, @sender, @receiver, @content)
15
+ puts @bookingsNotification.message
16
+ puts @bookingsNotification.get_message
17
+ end
18
+
19
+ def self.sendMessageNotification
20
+ set_base_and_action("Message")
21
+ @bookingsNotification = InboxDecorator.new(@notificationBase, @action, "Femi", "Lanre", "I have sent you a message")
22
+ puts @bookingsNotification.message
23
+ puts @bookingsNotification.get_message
24
+ end
25
+
26
+ def self.sendAppNotification
27
+ set_base_and_action("Message")
28
+ @bookingsNotification = AppMessageDecorator.new(@notificationBase, @action, "Femi", "Lanre", "You have a message from BookATutor")
29
+ puts @bookingsNotification.message
30
+ puts @bookingsNotification.get_message
31
+ end
32
+
33
+
34
+
35
+ def self.get_notification_base
36
+ @notificationBase = Notification.new
37
+ return @notificationBase
38
+ end
39
+
40
+ def self.set_action(action)
41
+ @action = action
42
+ end
43
+
44
+ def self.set_base_and_action(action)
45
+ get_notification_base
46
+ set_action(action)
47
+ end
48
+
49
+ def self.get_basic_notification_action
50
+ init_basic_decorator
51
+ return @basicNotification.get_action
52
+ end
53
+
54
+ def self.get_basic_notification_sender
55
+ init_basic_decorator
56
+ return @basicNotification.get_sender
57
+ end
58
+
59
+ def self.get_basic_notification_receiver
60
+ init_basic_decorator
61
+ return @basicNotification.get_receiver
62
+ end
63
+
64
+ def self.get_basic_notification_message
65
+ init_basic_decorator
66
+ return @basicNotification.get_message
67
+ end
68
+
69
+ def self.get_basic_notification_base
70
+ init_basic_decorator
71
+ return @basicNotification.get_notification_base
72
+ end
73
+
74
+ def self.init_basic_decorator
75
+ set_base_and_action("Basic Notification")
76
+ @basicNotification = BasicDecorator.new(@notificationBase, @action, "Sender", "Receiver", "Message" )
77
+ end
78
+
79
+
80
+ end
81
+
82
+ SendNotification.init_basic_decorator
83
+
84
+
85
+ #sendNotification = SendNotification.new
86
+
87
+ # SendNotification.sendBookingNotification
88
+ # SendNotification.sendReviewNotification
89
+ # SendNotification.sendMessageNotification
90
+ # SendNotification.sendAppNotification
@@ -0,0 +1,254 @@
1
+ require 'delegate'
2
+ require 'pony'
3
+ require 'geocoder'
4
+ require 'time'
5
+ require_relative 'functions/BookingFunctions'
6
+ require_relative 'functions/ReviewFunctions'
7
+
8
+
9
+ # concrete component to be decorated.
10
+ # we have a notification class that we will like to decorate based on action
11
+ # action include booking, review, inbox.
12
+ class BAT_Notification
13
+ def initialize(sender, receiver, content)
14
+ @sender = sender
15
+ @receiver = receiver
16
+ @content = content
17
+ end
18
+
19
+ #get content
20
+ def get_content
21
+ return @content
22
+ end
23
+
24
+ #get sender information
25
+ def get_sender
26
+ return @sender
27
+ end
28
+
29
+ #get receiver information
30
+ def get_receiver
31
+ return @receiver
32
+ end
33
+
34
+ end
35
+
36
+ # decorator class that serves as super class for concrete decorators.
37
+ # includes functions that is common to all concrete decorators
38
+
39
+ class NotificationDecorator
40
+ #initialize our constructor
41
+ def initialize(notification)
42
+ @notification = notification
43
+ @action = ""
44
+ @sender = get_sender
45
+ @receiver = get_receiver
46
+ @content = get_content
47
+ end
48
+
49
+ def get_content
50
+ return @notification.get_content
51
+ end
52
+
53
+ def get_sender
54
+ return @notification.get_sender
55
+ end
56
+
57
+ def get_receiver
58
+ return @notification.get_receiver
59
+ end
60
+
61
+ def get_action
62
+ return @action
63
+ end
64
+
65
+
66
+ def message
67
+ return "You have a new #{@action} from #{get_sender}. Check out the details"
68
+ end
69
+
70
+ #send email using Pony
71
+ def send_email
72
+ begin
73
+ Pony.mail(
74
+ :to => @receiver_email,
75
+ :from => @sender_email,
76
+ :subject => @subject,
77
+ :html_body => self.message,
78
+ :body => self.message,
79
+ :via => :smtp,
80
+ :via_options => {
81
+ :address => 'smtp.gmail.com',
82
+ :port => '587',
83
+ :enable_starttls_auto => true,
84
+ :user_name => 'bookatutorapp@gmail.com',
85
+ :password => 'b00katut0r@123!',
86
+ :authentication => :plain,
87
+ :domain => "localhost.localdomain"
88
+ }
89
+ )
90
+
91
+ #return message-sent == true
92
+
93
+ rescue Exception => e
94
+ puts e.message
95
+ puts e.backtrace.inspect
96
+ end
97
+ end
98
+
99
+ def async_email
100
+ @mail_status = Async do
101
+ self.send_email
102
+ end
103
+ end
104
+
105
+ def get_sender_full_name
106
+ return "#{@sender['firstname']} #{@sender['lastname']}"
107
+ end
108
+
109
+ def get_receiver_full_name
110
+ return "#{@receiver['firstname']} #{@receiver['lastname']}"
111
+ end
112
+
113
+ def send_notification_to_sender
114
+ @sender_email = "bookatutorapp@gmail.com"
115
+ @receiver_email = self.get_sender["email"]
116
+
117
+ async_email
118
+
119
+ return @mail_status.wait.content_type.length
120
+ end
121
+
122
+ def send_notification_to_receiver
123
+ @sender_email = "bookatutorapp@gmail.com"
124
+ @receiver_email = self.get_receiver["email"]
125
+
126
+ async_email
127
+
128
+ return @mail_status.wait.content_type.length
129
+ end
130
+
131
+
132
+ end
133
+
134
+ class BasicNotification < NotificationDecorator
135
+
136
+ def initialize(notification)
137
+ super(notification)
138
+ @action = "Basic"
139
+ end
140
+ def message
141
+ return "You have a new #{@action} from #{@sender}. Check out the details"
142
+ end
143
+
144
+
145
+ end
146
+
147
+ #configure notification so send to student and tutor upon booking creation
148
+ #modify @action and message within this class
149
+ class BookingNotification < NotificationDecorator
150
+ def initialize(notification)
151
+ super(notification)
152
+ @action = "Booking"
153
+ @subject = "New #{@action}"
154
+ end
155
+
156
+ def message
157
+ return "<h1>You have a new #{get_action}. Check out the details below</h1> \r\n
158
+ <p>Booking from: #{get_sender_full_name}} </p>\r\n
159
+ #{BookingFunctions.get_booking_message(get_content)} "
160
+ end
161
+
162
+ #send notification using async
163
+ #self.send_notification_to_receiver
164
+
165
+ end
166
+
167
+
168
+ class UserBookingNotification < NotificationDecorator
169
+ def initialize(notification)
170
+ super(notification)
171
+ @action = "Booking"
172
+ @subject = "New #{@action} created"
173
+
174
+ end
175
+
176
+ def message
177
+ return "<h1>You have created a #{get_action}. Check out the details below </h1>\r\n
178
+ <p>Tutor Booked: #{get_receiver_full_name}</p> \r\n
179
+ #{BookingFunctions.get_booking_message(get_content)} \r\n
180
+ <p>Thank you for using bookatutor to create this booking</p>"
181
+ end
182
+
183
+ def get_subject
184
+ return @subject
185
+ end
186
+
187
+
188
+ end
189
+
190
+ #end of booking decoration
191
+
192
+
193
+ #Cconfigure notification to send email to user and user_reviewed when action is review
194
+ class ReviewNotification < NotificationDecorator
195
+ def initialize(notification)
196
+ super(notification)
197
+ @action = "Review"
198
+ @subject = "New #{@action} "
199
+ end
200
+
201
+ def message
202
+ return "<h1>You have a new #{get_action}. Check out the details below</h1>
203
+ <p>Review From: #{get_sender_full_name}</p>
204
+ #{ReviewFunctions.get_review_message(get_content)}"
205
+ end
206
+
207
+ def get_subject
208
+ return @subject
209
+ end
210
+ end
211
+
212
+ class UserReviewNotification < NotificationDecorator
213
+ def initialize(notification)
214
+ super(notification)
215
+ @action = "Review"
216
+ @subject = "New #{@action} created"
217
+ end
218
+
219
+ def message
220
+ return "<h1>You created a new #{get_action}. Check out the details below</h1>
221
+ <p>Reviewed: #{get_receiver_full_name}</p>
222
+ #{ReviewFunctions.get_review_message(get_content)}"
223
+ end
224
+
225
+ def get_subject
226
+ return @subject
227
+ end
228
+ end
229
+
230
+ # end Review decorators configuration
231
+
232
+ class InboxNotification < NotificationDecorator
233
+ def initialize(notification)
234
+ super(notification)
235
+ @action = "Message"
236
+ @subject = "New #{@action}"
237
+ end
238
+ def message
239
+ return "<h1>You have a new #{@action} from #{get_sender_full_name}</h1>.
240
+ <p><a href='localhost:3000/user/signin'>Login</a> to read</p>"
241
+ end
242
+
243
+ end
244
+
245
+ # class AppMessageNotification < NotificationDecorator
246
+ # def message
247
+ # return "You have a new #{@action} from #{@sender}. Check out the details"
248
+ # end
249
+
250
+ # def get_content
251
+ # return @content
252
+ # end
253
+ # end
254
+