mailhandler 1.0.2 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d007dfe2c9742d1099adc9d58f156bb147c9350
4
- data.tar.gz: 5d6a258c2706b9718379cf5ec101723f686010bd
3
+ metadata.gz: bb735413b99d1dbb127a886addf0a814bf20d8d8
4
+ data.tar.gz: 2d3b74018e100aa58f6542175c0565bb2de0ffb1
5
5
  SHA512:
6
- metadata.gz: ec4bee8fcdbcbc9444e9b12a0cc328128971836e6ec435f4309784d3c619afac4b250b9e9d71772a7cecef69993d2c0163be61f515a0d9de53f089831f3596ff
7
- data.tar.gz: 4b61c6b691b1c016ffd64c0411a91480f3fe5fa82744e6a6fd4a6d79ebea19c5cda1b2caa3ecff8b43bb04bc678926a6d41d0b08e052de4343d4420c6105e9ba
6
+ metadata.gz: 43b95161151654580c6d71594b69d20986e33e02a4f1a6e099f7522769f805a9836f3cae18005549587d0e59c73e5bd69ec90bdbf52865c9a355d37ebd08a53a
7
+ data.tar.gz: dfc10a479084b9339fb73157c9b03d1748983dd46842290c2baf983321888c555c9baea7218281ccdc88312e029b05ea937f2a18248c98690821b09f27ac0287
@@ -1,9 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.3
3
+ - 1.9.2
5
4
  - 2.0.0
6
5
  - 2.1.6
7
6
  - 2.2.2
8
7
 
9
- script: bundle exec rake spec
8
+ script: bundle exec rake
@@ -28,6 +28,7 @@ module MailHandler
28
28
 
29
29
  # Default number of email results to return, and whether to archive emails.
30
30
  @search_options = {:count => 50, :archive => false}
31
+ @found_emails = []
31
32
 
32
33
  end
33
34
 
@@ -49,7 +50,7 @@ module MailHandler
49
50
 
50
51
  def search_result
51
52
 
52
- found_emails != nil and !found_emails.empty?
53
+ !found_emails.empty?
53
54
 
54
55
  end
55
56
 
@@ -28,18 +28,14 @@ module MailHandler
28
28
  verify_and_set_search_options(options)
29
29
  email_files = find_files(search_options)
30
30
 
31
- if email_files.empty?
32
-
33
- @found_emails = []
34
-
35
- else
31
+ unless email_files.empty?
36
32
 
37
33
  @found_emails = read_found_emails(email_files, search_options[:count])
38
34
  move_files(email_files) if search_options[:archive]
39
35
 
40
36
  end
41
37
 
42
- !@found_emails.empty?
38
+ search_result
43
39
 
44
40
  end
45
41
 
@@ -42,20 +42,17 @@ module MailHandler
42
42
  validate_options(options)
43
43
  emails = find_emails(search_options)
44
44
 
45
- @found_emails = []
46
-
47
45
  unless emails.empty?
48
46
 
49
47
  emails.each do |email|
50
48
 
51
- found = email.subject.include? search_options[:by_subject]
52
- @found_emails << email if found
49
+ @found_emails << email if email.subject.include? search_options[:by_subject]
53
50
 
54
51
  end
55
52
 
56
53
  end
57
54
 
58
- !@found_emails.empty?
55
+ search_result
59
56
 
60
57
  end
61
58
 
@@ -6,6 +6,14 @@ module MailHandler
6
6
 
7
7
  attr_reader :type
8
8
 
9
+ protected
10
+
11
+ def verify_email(email)
12
+
13
+ raise StandardError, "Invalid type error, only #{Mail.new.class} object type for sending allowed" unless email.is_a? Mail.new.class
14
+
15
+ end
16
+
9
17
  end
10
18
 
11
19
  end
@@ -23,6 +23,8 @@ module MailHandler
23
23
 
24
24
  def send(email)
25
25
 
26
+ verify_email(email)
27
+
26
28
  client = setup_sending_client
27
29
  client.deliver_message(email)
28
30
 
@@ -8,11 +8,20 @@ module MailHandler
8
8
 
9
9
  def send(emails)
10
10
 
11
+ verify_email(emails)
11
12
  client = setup_sending_client
12
13
  client.deliver_messages(emails)
13
14
 
14
15
  end
15
16
 
17
+ protected
18
+
19
+ def verify_email(emails)
20
+
21
+ raise StandardError, "Invalid type error, only Array of Mail::Message object types for sending allowed" unless emails.is_a?(Array) && emails.all? { |e| e.is_a? Mail::Message }
22
+
23
+ end
24
+
16
25
  end
17
26
 
18
27
  end
@@ -30,6 +30,7 @@ module MailHandler
30
30
 
31
31
  def send(email)
32
32
 
33
+ verify_email(email)
33
34
  email = configure_sending(email)
34
35
 
35
36
  response = nil
@@ -1,5 +1,5 @@
1
1
  module MailHandler
2
2
 
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
 
5
5
  end
data/readme.md CHANGED
@@ -57,7 +57,7 @@ Email receiving handler will be referenced below as `email_receiver`
57
57
  Once you have setup mailbox checking type, you can search for email like this:
58
58
 
59
59
  ``` ruby
60
- email_receiver.find_email(:by_subject => email.subject, :archive => true)
60
+ email_receiver.find_email(:by_subject => subject, :archive => true)
61
61
  ```
62
62
 
63
63
  You can search imap mailbox by following options:
@@ -2,38 +2,74 @@ require 'spec_helper'
2
2
 
3
3
  describe MailHandler::Receiver do
4
4
 
5
- subject { MailHandler::Receiver }
6
- let(:default_search_option) { {:by_subject => 'test'} }
7
- let(:receiving_duration) { 5 }
8
- let(:checker) {
9
- checker = double('Checker')
5
+ context 'invalid receiver' do
10
6
 
11
- allow(checker).to receive(:find) { sleep receiving_duration ; true }
12
- allow(checker).to receive(:search_result) { true }
13
- allow(checker).to receive(:found_emails) { [] }
14
- checker
7
+ it 'create' do
15
8
 
16
- }
17
-
18
- it '.find_email' do
9
+ binding.pry
19
10
 
20
- receiver = subject.new(checker)
21
- expect(receiver.find_email(default_search_option)).to be true
11
+ end
22
12
 
23
13
  end
24
14
 
25
- it '.search object' do
15
+ context 'valid receiver' do
16
+
17
+ let(:default_search_option) { {:by_subject => 'test'} }
18
+ let(:receiving_duration) { 5 }
19
+ let(:found_email) { Mail.new { subject 'test email' } }
20
+ let(:checker) {
21
+ checker = double('Checker')
22
+
23
+ allow(checker).to receive(:find) { sleep receiving_duration; true }
24
+ allow(checker).to receive(:search_result) { true }
25
+ allow(checker).to receive(:found_emails) { [found_email] }
26
+ checker
27
+
28
+ }
29
+ subject(:receiver) { MailHandler::Receiver.new(checker) }
30
+
31
+ context 'att readers' do
32
+
33
+ it { is_expected.to respond_to(:checker) }
34
+ it { is_expected.to respond_to(:search) }
35
+ it { is_expected.to respond_to(:search_max_duration) }
36
+
37
+ end
38
+
39
+ context 'att writters' do
40
+
41
+ it { is_expected.to respond_to(:checker=) }
42
+ it { is_expected.to respond_to(:search=) }
43
+ it { is_expected.to respond_to(:search_max_duration=) }
44
+
45
+ end
46
+
47
+ it 'create' do
48
+
49
+ is_expected.to be_kind_of MailHandler::Receiver
50
+
51
+ end
52
+
53
+ it '.find_email' do
54
+
55
+ expect(receiver.find_email(default_search_option)).to be true
56
+
57
+ end
58
+
59
+ it '.search' do
60
+
61
+ receiver.find_email(default_search_option)
26
62
 
27
- receiver = subject.new(checker)
28
- receiver.find_email(default_search_option)
63
+ aggregate_failures "search details" do
64
+ expect(receiver.search.options).to eq default_search_option
65
+ expect(receiver.search.started_at).to be_within(1).of(Time.now - receiving_duration)
66
+ expect(receiver.search.finished_at).to be_within(1).of(Time.now)
67
+ expect(receiver.search.duration).to be_within(0.5).of(receiving_duration)
68
+ expect(receiver.search.result).to be true
69
+ expect(receiver.search.emails).to eq [found_email]
70
+ expect(receiver.search.email).to eq found_email
71
+ end
29
72
 
30
- aggregate_failures "search details" do
31
- expect(receiver.search.options).to eq default_search_option
32
- expect(receiver.search.started_at).to be_within(1).of(Time.now - receiving_duration)
33
- expect(receiver.search.finished_at).to be_within(1).of(Time.now)
34
- expect(receiver.search.duration).to be_within(0.5).of(receiving_duration)
35
- expect(receiver.search.result).to be true
36
- expect(receiver.search.emails).to eq []
37
73
  end
38
74
 
39
75
  end
@@ -23,15 +23,15 @@ describe MailHandler::Sender do
23
23
 
24
24
  }
25
25
 
26
- it '.sending' do
26
+ let(:sender) { subject.new(dispatcher) }
27
27
 
28
- expect(subject.new(dispatcher)).not_to be nil
28
+ it 'create' do
29
29
 
30
- end
30
+ expect(sender).not_to be nil
31
31
 
32
- it '.sending init' do
32
+ end
33
33
 
34
- sender = subject.new(dispatcher)
34
+ it 'init details' do
35
35
 
36
36
  aggregate_failures "sending details" do
37
37
  expect(sender.sending.started_at).to be nil
@@ -45,7 +45,6 @@ describe MailHandler::Sender do
45
45
 
46
46
  it '.send_email' do
47
47
 
48
- sender = subject.new(dispatcher)
49
48
  sender.send_email(mail)
50
49
 
51
50
  aggregate_failures "sending details" do
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailHandler::Sending::PostmarkBatchAPISender do
4
+
5
+ subject { MailHandler::Sending::PostmarkBatchAPISender }
6
+
7
+ let(:api_token) { '122878782' }
8
+
9
+ it 'create' do
10
+
11
+ sender = subject.new(api_token)
12
+
13
+ aggregate_failures "init details" do
14
+ expect(sender.api_token).to eq api_token
15
+ expect(sender.type).to eq :postmark_api
16
+ expect(sender.use_ssl).to be false
17
+ expect(sender.host).to eq 'api.postmarkapp.com'
18
+ end
19
+
20
+ end
21
+
22
+ it '.send' do
23
+
24
+ sender = subject.new(api_token)
25
+ expect{sender.send([Mail.new])}.to raise_error Postmark::InvalidApiKeyError
26
+
27
+ end
28
+
29
+ context 'invalid sending object' do
30
+
31
+ it '.send with string parameter' do
32
+
33
+ sender = subject.new(api_token)
34
+ expect{sender.send('test')}.
35
+ to raise_error StandardError, 'Invalid type error, only Array of Mail::Message object types for sending allowed'
36
+
37
+ end
38
+
39
+ it '.send with incorrect array parameter' do
40
+
41
+ sender = subject.new(api_token)
42
+ expect{sender.send([1,2,2])}.
43
+ to raise_error StandardError, 'Invalid type error, only Array of Mail::Message object types for sending allowed'
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailHandler::Sending::PostmarkAPISender do
4
+
5
+ subject { MailHandler::Sending::PostmarkAPISender }
6
+
7
+ let(:api_token) { '122878782' }
8
+
9
+ it 'create' do
10
+
11
+ sender = subject.new(api_token)
12
+
13
+ aggregate_failures "init details" do
14
+ expect(sender.api_token).to eq api_token
15
+ expect(sender.type).to eq :postmark_api
16
+ expect(sender.use_ssl).to be false
17
+ expect(sender.host).to eq 'api.postmarkapp.com'
18
+ end
19
+
20
+ end
21
+
22
+ it '.send' do
23
+
24
+ sender = subject.new(api_token)
25
+ expect{sender.send(Mail.new)}.to raise_error Postmark::InvalidApiKeyError
26
+
27
+ end
28
+
29
+ context 'invalid sending object' do
30
+
31
+ it '.send' do
32
+
33
+ sender = subject.new(api_token)
34
+ expect{sender.send('test')}.to raise_error StandardError
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -6,56 +6,51 @@ describe MailHandler::Handler do
6
6
 
7
7
  context 'receiver' do
8
8
 
9
- let(:receiver_folder) {
9
+ it 'create - invalid type' do
10
10
 
11
- subject.receiver(:folder)
12
-
13
- }
14
-
15
- it 'invalid type' do
16
-
17
- expect{subject.receiver(:test)}.
11
+ expect { subject.receiver(:test) }.
18
12
  to raise_error(StandardError, 'Unknown type - test, possible options: [:folder, :imap]')
19
13
 
20
14
  end
21
15
 
22
- context 'folder check' do
16
+ it 'create - folder' do
23
17
 
24
- it 'object type' do
18
+ expect(subject.receiver(:folder)).to be_kind_of MailHandler::Receiver
25
19
 
26
- expect(receiver_folder).to match MailHandler::Receiver
20
+ end
27
21
 
28
- end
22
+ it 'create - imap' do
29
23
 
30
- end
24
+ expect(subject.receiver(:imap)).to be_kind_of MailHandler::Receiver
31
25
 
26
+ end
32
27
 
33
28
  end
34
29
 
35
30
  context 'sender' do
36
31
 
37
- it 'invalid type' do
32
+ it 'create - invalid type' do
38
33
 
39
- expect{subject.sender(:test)}.
34
+ expect { subject.sender(:test) }.
40
35
  to raise_error(StandardError, 'Unknown type - test, possible options: [:postmark_api, :postmark_batch_api, :smtp]')
41
36
 
42
37
  end
43
38
 
44
- it 'create sender - postmark api' do
39
+ it 'create - postmark api' do
45
40
 
46
- expect(subject.sender(:postmark_api)).to match MailHandler::Sender
41
+ expect(subject.sender(:postmark_api)).to be_kind_of MailHandler::Sender
47
42
 
48
43
  end
49
44
 
50
- it 'create sender - postmark batch api' do
45
+ it 'create - postmark batch api' do
51
46
 
52
- expect(subject.sender(:postmark_batch_api)).to match MailHandler::Sender
47
+ expect(subject.sender(:postmark_batch_api)).to be_kind_of MailHandler::Sender
53
48
 
54
49
  end
55
50
 
56
- it 'create sender - smtp' do
51
+ it 'create - smtp' do
57
52
 
58
- expect(subject.sender(:smtp)).to match MailHandler::Sender
53
+ expect(subject.sender(:smtp)).to be_kind_of MailHandler::Sender
59
54
 
60
55
  end
61
56
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailhandler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Balos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-08 00:00:00.000000000 Z
11
+ date: 2015-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -52,6 +52,7 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - ".gitignore"
55
+ - ".travis.yml"
55
56
  - Gemfile
56
57
  - Gemfile.lock
57
58
  - Rakefile
@@ -80,8 +81,9 @@ files:
80
81
  - spec/unit/mailhandler/receiving/notification/email/content_spec.rb
81
82
  - spec/unit/mailhandler/receiving/notification/email_spec.rb
82
83
  - spec/unit/mailhandler/sender_spec.rb
84
+ - spec/unit/mailhandler/sending/sender_api_batch_spec.rb
85
+ - spec/unit/mailhandler/sending/sender_api_spec.rb
83
86
  - spec/unit/mailhandler_spec.rb
84
- - travis.yml
85
87
  homepage: https://github.com/ibalosh
86
88
  licenses:
87
89
  - MIT