postgarnet 1.0.3 → 1.0.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/postgarnet.rb +15 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 271a04be208146d3bb3c4e705d049d02ccdf6fbd104d171ff83ad548379bfc18
4
- data.tar.gz: 1b9b7ff07abe7f4314321409c8726cc433e11349c5727b424400ca48991c5988
3
+ metadata.gz: 50e9b339bd0beab74b01bd084f83ffebc12edd6cff5d87acd5351161ed794eb4
4
+ data.tar.gz: c7599a67576e8289dad00e0fb6ddf7066490341f3ad8b9c935c5a34752b0a2fc
5
5
  SHA512:
6
- metadata.gz: 1c89bef7166ffbd7ca165c08f1842944b62a8d5ea001d7865a568599f273108641ed35cfe571f3008b1221250723181a2be864daa9f225eaf490c784283b77b2
7
- data.tar.gz: c1093b6c03e7d6303b5990d5a813e6e4278ca6e2946e2efb0e2a5dba48e759f006d3bdac77681f24acf993314d254b92628f679cae5cf76438370086aec70af5
6
+ metadata.gz: 7a6018c2ca7e8a0921bf396f3d1fbfa7495681d18778370562e54347568b7b51a8c0e24c08e481999e1c26306ceea0c12a912717851e8c7214f721cac20cc07b
7
+ data.tar.gz: 1b59281dad022649f737f3c5fac56f3d1f2e66d5c8dcbdf6174a95097a5a64f213599d4362c10b7ac4b42b215d1e040f603b9034233ede2297fa414ddb5234b2
data/lib/postgarnet.rb CHANGED
@@ -13,11 +13,13 @@ class TransactionError < StandardError
13
13
  end
14
14
 
15
15
  class Postgarnet
16
- @@version = "1.0.3"
16
+ @@version = "1.0.5"
17
17
 
18
- def initialize(username:, password:)
18
+ def initialize(username: nil, password: nil)
19
19
  @username, @password, @subject, @content, @recipient, @author = @username, @smtp = nil
20
- login(username, password)
20
+ unless username.nil? || password.nil?
21
+ login(username: username, password: password)
22
+ end
21
23
  @headers = {
22
24
  "mime-version" => "1",
23
25
  "content-type" => "text/html"
@@ -100,9 +102,15 @@ class Postgarnet
100
102
  end
101
103
 
102
104
  def connect(host: "smtp.gmail.com", port: 587)
105
+ if @username.nil? || @password.nil?
106
+ raise TransactionError, "You need to login first"
107
+ end
103
108
  begin
104
109
  @smtp = Net::SMTP.new(host, port)
105
110
  @smtp.enable_starttls
111
+ if block_given?
112
+ block.call
113
+ end
106
114
  rescue Exception => e
107
115
  raise TransactionError, "Error when connecting: #{e}"
108
116
  else
@@ -137,7 +145,7 @@ class Postgarnet
137
145
  return @smtp
138
146
  end
139
147
 
140
- def send(client="localhost")
148
+ def send(client="localhost", &block)
141
149
  if [@username, @password, @author, @recipient, @subject, @content].any?(&:nil?)
142
150
  raise FormatError, "Incomplete parameters"
143
151
  end
@@ -148,6 +156,9 @@ class Postgarnet
148
156
  message = self.create_msg
149
157
  @smtp.start(client, @username, @password, :plain) do
150
158
  @smtp.send_message(message, @username, @recipient)
159
+ if block_given?
160
+ block.call
161
+ end
151
162
  end
152
163
  rescue Exception => e
153
164
  raise TransactionError, "Error when sending: #{e}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgarnet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - trulyursdelv