Class: NotificationDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/bat_notifications.rb

Overview

decorator class that serves as super class for concrete decorators. includes functions that is common to all concrete decorators

Instance Method Summary collapse

Constructor Details

#initialize(notification) ⇒ NotificationDecorator

initialize our constructor



41
42
43
44
45
46
47
# File 'lib/bat_notifications.rb', line 41

def initialize(notification)
    @notification = notification
    @action = "" 
    @sender = get_sender
    @receiver = get_receiver
    @content = get_content
end

Instance Method Details

#async_emailObject



99
100
101
102
103
# File 'lib/bat_notifications.rb', line 99

def async_email
    @mail_status = Async do
        self.send_email
    end
end

#get_actionObject



61
62
63
# File 'lib/bat_notifications.rb', line 61

def get_action
    return @action
end

#get_contentObject



49
50
51
# File 'lib/bat_notifications.rb', line 49

def get_content
    return @notification.get_content
end

#get_receiverObject



57
58
59
# File 'lib/bat_notifications.rb', line 57

def get_receiver
    return @notification.get_receiver
end

#get_receiver_full_nameObject



109
110
111
# File 'lib/bat_notifications.rb', line 109

def get_receiver_full_name
     return "#{@receiver['firstname']} #{@receiver['lastname']}"   
end

#get_senderObject



53
54
55
# File 'lib/bat_notifications.rb', line 53

def get_sender
    return @notification.get_sender
end

#get_sender_full_nameObject



105
106
107
# File 'lib/bat_notifications.rb', line 105

def get_sender_full_name
    return "#{@sender['firstname']} #{@sender['lastname']}"   
end

#messageObject



66
67
68
# File 'lib/bat_notifications.rb', line 66

def message
    return "You have a new #{@action} from #{get_sender}. Check out the details"
end

#send_emailObject

send email using Pony



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bat_notifications.rb', line 71

def send_email
    begin
        Pony.mail(
            :to => @receiver_email, 
            :from => @sender_email,
            :subject => @subject,
            :html_body => self.message,
            :body => self.message,
            :via => :smtp,
            :via_options => {
                :address              => 'smtp.gmail.com',
                :port                 => '587',
                :enable_starttls_auto => true,
                :user_name            => '[email protected]',
                :password             => 'b00katut0r@123!',
                :authentication       => :plain, 
                :domain               => "localhost.localdomain" 
            }
        )
        
        #return message-sent == true
        
    rescue Exception => e
        puts e.message
        puts e.backtrace.inspect
    end
end

#send_notification_to_receiverObject



122
123
124
125
126
127
128
129
# File 'lib/bat_notifications.rb', line 122

def send_notification_to_receiver
    @sender_email = "[email protected]"
    @receiver_email = self.get_receiver["email"]
    
    async_email
    
    return @mail_status.wait.content_type.length
end

#send_notification_to_senderObject



113
114
115
116
117
118
119
120
# File 'lib/bat_notifications.rb', line 113

def send_notification_to_sender
    @sender_email = "[email protected]"
    @receiver_email = self.get_sender["email"]
    
    async_email
    
    return @mail_status.wait.content_type.length
end