BAT_Notifications 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 22e5b75d4dc1f212ed6be86164f0e2490c8a6ba816003acaffc97cad0cc52853
4
+ data.tar.gz: d5d8ebf0161746c08f73906c9dd1940d4c4f06855eb7d177b28036bd5eb414eb
5
+ SHA512:
6
+ metadata.gz: 8a4fc4d8830cbd408ed88d2a981b13d3b87a361ad41a2fa362f1d6d12ea62e2448fbc5e2f437684210a0ae84dfffd699eb368bda47e382d0ee6012c4afddedab
7
+ data.tar.gz: 6bec9f6eae2adcdeba367c5ab75529e7846b01d93262c22ed734dae74739b74f0334b1b47d97a78b0bac0cddf0c1999cc1ead2671ec2041f4367ffce059fb3cd
data/lib/A_User.rb ADDED
@@ -0,0 +1,29 @@
1
+ module AUser
2
+ def self.sender
3
+ return {
4
+ "id" => "3",
5
+ "email" => "bookatutorapp@gmail.com",
6
+ "firstname" => "John",
7
+ "lastname" => "Sender",
8
+ "role" => "Student",
9
+ "gender" => "Male",
10
+ "has_profile" => "true",
11
+ "location" => "Dublin"
12
+ }
13
+ end
14
+
15
+ def self.receiver
16
+ return {
17
+ "id" => "3",
18
+ "email" => "femi.abdul67@gmail.com",
19
+ "firstname" => "John",
20
+ "lastname" => "Receiver",
21
+ "role" => "Tutor",
22
+ "gender" => "Male",
23
+ "has_profile" => "true",
24
+ "location" => "Dublin"
25
+ }
26
+ end
27
+
28
+
29
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'Notification'
2
+
3
+
4
+ module BasicNotificationDecorator
5
+
6
+ def self.set_action(action)
7
+ @action = action
8
+ end
9
+
10
+ def self.init_basic_decorator
11
+ set_action("Basic Notification")
12
+ @basicNotification = BasicNotification.new(@action, "Sender", "Receiver", "Message" )
13
+ end
14
+
15
+
16
+ def self.get_basic_notification_action
17
+ init_basic_decorator
18
+ return @basicNotification.get_action
19
+ end
20
+
21
+ def self.get_basic_notification_sender
22
+ init_basic_decorator
23
+ return @basicNotification.get_sender
24
+ end
25
+
26
+ def self.get_basic_notification_receiver
27
+ init_basic_decorator
28
+ return @basicNotification.get_receiver
29
+ end
30
+
31
+ def self.get_basic_notification_content
32
+ init_basic_decorator
33
+ return @basicNotification.get_content
34
+ end
35
+
36
+ def self.get_basic_notification_base
37
+ init_basic_decorator
38
+ return @basicNotification.get_notification_base
39
+ end
40
+
41
+
42
+
43
+ end
44
+
@@ -0,0 +1,66 @@
1
+ require_relative 'Notification'
2
+ require_relative 'NotificationDb'
3
+ require_relative "Content.rb"
4
+
5
+ require "async"
6
+
7
+
8
+ module BookingNotificationDecorator
9
+
10
+ def self.set_action(action)
11
+ @action = action
12
+ end
13
+
14
+
15
+ def self.set_content
16
+ @content = Content.booking_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_booking_decorator
29
+ set_action("Booking")
30
+ set_content
31
+ set_sender
32
+ set_receiver
33
+ @bookingNotification = BookingNotification.new( @action, @sender, @receiver, @content )
34
+ end
35
+
36
+ def self.get_booking_action
37
+ init_booking_decorator
38
+ return @bookingNotification.get_action
39
+ end
40
+
41
+ def self.get_booking_content
42
+ init_booking_decorator
43
+ content = @bookingNotification.get_content
44
+ booking_location = content["location"]
45
+ return true if booking_location
46
+ end
47
+
48
+ def self.get_booking_creator
49
+ init_booking_decorator
50
+ return @bookingNotification.get_sender["lastname"]
51
+ end
52
+
53
+ def self.get_user_booked
54
+ init_booking_decorator
55
+ return @bookingNotification.get_receiver["lastname"]
56
+ end
57
+
58
+ def self.send_notification
59
+ init_booking_decorator
60
+ return @bookingNotification.send_notification
61
+ end
62
+
63
+ end
64
+
65
+
66
+
data/lib/Content.rb ADDED
@@ -0,0 +1,37 @@
1
+ require_relative 'A_User'
2
+
3
+ module Content
4
+ def self.review_content
5
+ return {
6
+ "id" => "3",
7
+ "reviewee" => AUser.receiver,
8
+ "content" => "Very good tutor",
9
+ "review_stars" => "4",
10
+ "user_id" => AUser.sender[:id]
11
+ }
12
+ end
13
+
14
+ def self.booking_content
15
+ return {
16
+ "id" => "4",
17
+ "date" => DateTime.now,
18
+ "location" => {
19
+ "longitude" => "-6.243153391200242",
20
+ "latitude" => "53.348738600000004"
21
+ },
22
+ "user_id" => AUser.sender[:id],
23
+ "user_booked" => AUser.receiver
24
+ }
25
+ end
26
+
27
+ def self.inbox_content
28
+ return {
29
+ "id" => "5",
30
+ "message_to" => AUser.receiver,
31
+ "message_from" => AUser.sender,
32
+ "status" => "unread",
33
+ "user_id" => AUser.sender[:id],
34
+ "message_content" => "Hi, I will like to book you for a session."
35
+ }
36
+ end
37
+ end
@@ -0,0 +1,66 @@
1
+ require_relative 'Notification'
2
+ require_relative 'NotificationDb'
3
+ require_relative "Content.rb"
4
+
5
+ require "async"
6
+
7
+
8
+ module InboxNotificationDecorator
9
+
10
+ def self.set_action(action)
11
+ @action = action
12
+ end
13
+
14
+
15
+ def self.set_content
16
+ @content = Content.inbox_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_inbox_decorator
29
+ set_action("Inbox")
30
+ set_content
31
+ set_sender
32
+ set_receiver
33
+ @inboxNotification = InboxNotification.new( @action, @sender, @receiver, @content )
34
+ end
35
+
36
+ def self.get_inbox_action
37
+ init_inbox_decorator
38
+ return @inboxNotification.get_action
39
+ end
40
+
41
+ def self.get_inbox_content
42
+ init_inbox_decorator
43
+ content = @inboxNotification.get_content
44
+ inbox_content = content["message_content"]
45
+ return true if inbox_content
46
+ end
47
+
48
+ def self.get_inbox_sender
49
+ init_inbox_decorator
50
+ return @inboxNotification.get_sender["lastname"]
51
+ end
52
+
53
+ def self.get_inbox_receiver
54
+ init_inbox_decorator
55
+ return @inboxNotification.get_receiver["lastname"]
56
+ end
57
+
58
+ def self.send_notification
59
+ init_inbox_decorator
60
+ return @inboxNotification.send_notification
61
+ end
62
+
63
+ end
64
+
65
+
66
+
@@ -0,0 +1,153 @@
1
+ require 'delegate'
2
+ require 'pony'
3
+
4
+ # class Notification
5
+
6
+
7
+ # def message
8
+ # return "This is get message from #{@action}"
9
+ # end
10
+
11
+ # def read_message
12
+ # return "this is read message"
13
+ # end
14
+
15
+ # def get_action
16
+ # return @action
17
+ # end
18
+
19
+
20
+
21
+ # end
22
+
23
+ class NotificationDecorator < SimpleDelegator
24
+ #initialize our constructor
25
+ def initialize(action, sender, receiver, content)
26
+ #super(notificationBase)
27
+ @action = action
28
+ @sender = sender
29
+ @receiver = receiver
30
+ @content = content
31
+ end
32
+
33
+ def booking_method
34
+ return "this is booking method"
35
+ end
36
+
37
+ #get content
38
+ def get_content
39
+ return @content
40
+ end
41
+
42
+ #get sender information
43
+ def get_sender
44
+ return @sender
45
+ end
46
+
47
+ #get receiver information
48
+ def get_receiver
49
+ return @receiver
50
+ end
51
+
52
+ #get action i.e review, booking etc
53
+ def get_action
54
+ return @action
55
+ end
56
+
57
+ #send email using Pony
58
+ def send_email
59
+ begin
60
+ Pony.mail(
61
+ :to => @receiver_email,
62
+ :from => @sender_email,
63
+ :subject => "You have a new #{@action}",
64
+ :html_body => "<h1>You have received a #{@action} from #{@sender["firstname"]}. Details Below</h1><p>#{@mail_content} " ,
65
+ :body => "You have received a #{@action} from #{@sender["firstname"]}. #{@mail_content}",
66
+ :via => :smtp,
67
+ :via_options => {
68
+ :address => 'smtp.gmail.com',
69
+ :port => '587',
70
+ :enable_starttls_auto => true,
71
+ :user_name => 'bookatutorapp@gmail.com',
72
+ :password => 'b00katut0r@123!',
73
+ :authentication => :plain,
74
+ :domain => "localhost.localdomain"
75
+ }
76
+ )
77
+
78
+ #return message-sent == true
79
+
80
+ rescue Exception => e
81
+ puts e.message
82
+ puts e.backtrace.inspect
83
+ end
84
+ end
85
+
86
+ #send notification using async
87
+ def send_notification
88
+ @sender_email = self.get_sender["email"]
89
+ @receiver_email = self.get_receiver["email"]
90
+ @mail_content = message
91
+
92
+ mail_status = Async do
93
+ self.send_email
94
+ end
95
+
96
+ return mail_status.wait.content_type.length
97
+
98
+
99
+
100
+
101
+ end
102
+
103
+
104
+ end
105
+
106
+ class BasicNotification < NotificationDecorator
107
+ def message
108
+ return "You have a new #{@action} from #{@sender}. Check out the details"
109
+ end
110
+
111
+
112
+ end
113
+
114
+ class BookingNotification < NotificationDecorator
115
+ def message
116
+ return "You have a new #{@action} from #{@sender}. Check out the details"
117
+ end
118
+
119
+ def get_content
120
+ return @content
121
+ end
122
+ end
123
+
124
+ class ReviewNotification < NotificationDecorator
125
+ def message
126
+ return "You have a new #{@action} from #{@sender}. Check out the details"
127
+ end
128
+
129
+ def get_content
130
+ return @content
131
+ end
132
+ end
133
+
134
+ class InboxNotification < NotificationDecorator
135
+ def message
136
+ return "You have a new #{@action} from #{@sender}. Check out the details"
137
+ end
138
+
139
+ def get_content
140
+ return @content
141
+ end
142
+ end
143
+
144
+ class AppMessageNotification < NotificationDecorator
145
+ def message
146
+ return "You have a new #{@action} from #{@sender}. Check out the details"
147
+ end
148
+
149
+ def get_content
150
+ return @content
151
+ end
152
+ end
153
+
@@ -0,0 +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
+
12
+ end
@@ -0,0 +1,66 @@
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
+
@@ -0,0 +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
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: BAT_Notifications
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Femi Abdul
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A library to send notification to users on actions such as reviews, bookings,
14
+ e.t.c
15
+ email: bookatutorapp@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/A_User.rb
21
+ - lib/BasicNotificationDecorator.rb
22
+ - lib/BookingNotificationDecorator.rb
23
+ - lib/Content.rb
24
+ - lib/InboxNotificationDecorator.rb
25
+ - lib/Notification.rb
26
+ - lib/NotificationDb.rb
27
+ - lib/ReviewNotificationDecorator.rb
28
+ - lib/SendNotification.rb
29
+ homepage: http://rubygems.org/gems/bat_notifications
30
+ licenses: []
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.0.3
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Send notification to users
51
+ test_files: []