Class: SpigitOps::Utils

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

Class Method Summary collapse

Class Method Details

.send_email(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/spigit_ops/utils.rb', line 30

def self.send_email(options = {})
	# type lookup
	type    = { text: "text/plain", html: "text/html" }

  host    = options[:host]    ? options[:host]    : "localhost"

	from    = options[:from]    ? options[:from]    : "[email protected]"
	to      = options[:to]      ? options[:to]      : "[email protected]"
	subject = options[:subject] ? options[:subject] : raise("Must declare a subject for email")
	message = options[:message] ? options[:message] : raise("Must declare a message for email")
	format  = options[:format]  ? options[:format]  : "text"

	content_type  = type.has_key?(format.to_sym) ? type[format.to_sym] : type["text"]

  if Array === to
    to_header = to.join(', ')
  elsif String === to
    to_header = to
  else
    to_header = to
  end

message = <<MESSAGE_END
From: #{from}
To: #{to_header}
Subject: #{subject}
Mime-Version: 1.0
Content-Type: #{content_type}
Content-Disposition: inline

#{message}
MESSAGE_END

	Net::SMTP.start(host, 25) do |smtp|
	  smtp.send_message message, from, to
	end
end

.unix_to_win(time) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/spigit_ops/utils.rb', line 18

def self.unix_to_win(time)
  begin
  	time = time.to_i if String === time
    unix_time    = time
    windows_time = (unix_time + 11644473600) * 10000000

    windows_time
  rescue Exception => e
    puts "error: #{e.message}"
  end
end

.win_to_unix(time) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/spigit_ops/utils.rb', line 6

def self.win_to_unix(time)
  begin
  	time = time.to_i if String === time
    windows_time = time
    unix_time    = windows_time / 10000000 - 11644473600

    unix_time
  rescue Exception => e
    puts "error: #{e.message}"
  end
end