postgarnet 1.0.4 → 1.0.6

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 +20 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9941e185008d258ea17607ab5b40881c84fa288f0fa2048d7eaefed20394d1d7
4
- data.tar.gz: 1b4b5c7d7cf62df9722044838e4f0ce1de792ed7080c09ebe98d621219b2da26
3
+ metadata.gz: a20076359cea5248f326df4b18f3506c328cc0e5784bdc09db9caad9882b49ac
4
+ data.tar.gz: 932a12ba077441f69ad5cf74958998e43c05c9d411c256c327f65714c8c0942a
5
5
  SHA512:
6
- metadata.gz: df75d7317b258d8d3e6a14a6c04fe9714298febfaad36931b90898146271755e7859f40184600e5e679afe4127bc8ac11d7c0bc89cd3212e536285d35bbd1954
7
- data.tar.gz: 26c445b1b0b2eb82d02e469f995f78bcedffbe79b4657c81ab50bf578ad311a180970647eec554f326646f245a3257e0fe448b17bea0e9d1df4e5c772971c2bb
6
+ metadata.gz: 99d6b3b8f81fb870fe9baab7155a6634f7bc5f0f6828e6cf543b9cda88f788d408cd8981ca217bd518a425661ec6af1bdbbeb14deefee5f796bc93e9f1e89c3b
7
+ data.tar.gz: 3535244da7d04081782d4258fb16c4f15e3dba474559e3a3b25a4c63a1fe32448fb453765eba7948294a96da951ec318515e52304aef5fccca09f3f8f77b842b
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.4"
16
+ @@version = "1.0.6"
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,6 +102,9 @@ 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
@@ -125,11 +130,21 @@ class Postgarnet
125
130
  return @username.clone
126
131
  end
127
132
 
133
+ def logout
134
+ if @username.nil? && @password.nil?
135
+ raise TransactionError, "No account to log out"
136
+ end
137
+ unless @smtp.nil?
138
+ raise TransactionError, "To log out, disconnect to the server first."
139
+ end
140
+ @username = nil
141
+ @password = nil
142
+ end
143
+
128
144
  def disconnect
129
145
  if @smtp.nil?
130
146
  raise TransactionError, "No connection to disconnect"
131
147
  end
132
- @smtp.finish
133
148
  @smtp = nil
134
149
  end
135
150
 
@@ -154,6 +169,7 @@ class Postgarnet
154
169
  if block_given?
155
170
  block.call
156
171
  end
172
+ true
157
173
  end
158
174
  rescue Exception => e
159
175
  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.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - trulyursdelv