Class: Foscam::Model::MailServer

Inherits:
Base
  • Object
show all
Includes:
Singleton
Defined in:
lib/foscam/model/mail_server.rb

Defined Under Namespace

Classes: Recipient

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#connect, #initialize, #persisted?

Constructor Details

This class inherits a constructor from Foscam::Model::Base

Instance Attribute Details

#addressObject

Returns the value of attribute address.



38
39
40
# File 'lib/foscam/model/mail_server.rb', line 38

def address
  @address
end

#passwordObject

Returns the value of attribute password.



38
39
40
# File 'lib/foscam/model/mail_server.rb', line 38

def password
  @password
end

#portObject

Returns the value of attribute port.



38
39
40
# File 'lib/foscam/model/mail_server.rb', line 38

def port
  @port
end

#recipientsObject (readonly)

Returns the value of attribute recipients.



38
39
40
# File 'lib/foscam/model/mail_server.rb', line 38

def recipients
  @recipients
end

#senderObject

Returns the value of attribute sender.



38
39
40
# File 'lib/foscam/model/mail_server.rb', line 38

def sender
  @sender
end

#usernameObject

Returns the value of attribute username.



38
39
40
# File 'lib/foscam/model/mail_server.rb', line 38

def username
  @username
end

Instance Method Details

#clearObject



98
99
100
101
102
103
104
105
106
# File 'lib/foscam/model/mail_server.rb', line 98

def clear
	run_callbacks :clear do
		flag = false
		params = {:sender => "", :user => "", :pwd => "", :svr => "", :port => 21, :receiver1 => "", :receiver2 => "", :receiver3 => "", :receiver4 => ""}
		flag = client.set_mail(params)
		@changed_attributes.clear if flag
		flag
	end
end

#client=(obj) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/foscam/model/mail_server.rb', line 66

def client=(obj)
	unless obj.nil?
		MailServer::client = obj
		params = client.get_params
		unless params.empty?
			self.sender = params[:mail_sender]
			self.address = params[:mail_svr]
			self.port = params[:mail_port]
			self.username = params[:mail_user]
			self.password = params[:mail_pwd]
			@recipients = []
			(1..4).each do |i|
				@recipients << Recipient.new(:id => i, :address => params["mail_receiver#{i}".to_sym]) if params.has_key?("mail_receiver#{i}".to_sym) && !params["mail_receiver#{i}".to_sym].empty?
			end
		end
	end
end

#saveObject



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/foscam/model/mail_server.rb', line 86

def save
	run_callbacks :save do
		flag = false
		if changed? && is_valid?
			@previously_changed = changes
			flag = client.set_mail(dirty_params_hash)
			@changed_attributes.clear if flag
		end
		flag
	end
end