euromail 0.4.1 → 0.5.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 681fed0406570f2d0611fbc0cec27e340f8fdbf4
4
+ data.tar.gz: 889b36e9dff7dc703072f7e74fe1c59f8219d328
5
+ SHA512:
6
+ metadata.gz: 7aa8eed727a2ba83c434bd27cfe2c1c966e1643ab16669c9326eed539a367fdb38031af1a2c95443d024e60d8b57a6e7ee67118b056f016b531308efbf40840e
7
+ data.tar.gz: 3e5442d4d27aaf9c91d2dde95686bb521a052c6171b1c181554b6366996845001547f05424247accae4d3d32e8dd02e6c13aa71735848ec2693a200006bea615
@@ -7,9 +7,8 @@ module Euromail
7
7
  end
8
8
 
9
9
  def upload pdf_data, identifier
10
- @sftp.file.open( @service.filename(identifier) , "w") do |f|
11
- f.write pdf_data
12
- end
10
+ io = StringIO.new(pdf_data)
11
+ @sftp.upload!(io, @service.filename(identifier))
13
12
  end
14
13
 
15
14
  def remove identifier
@@ -3,7 +3,7 @@ require 'net/sftp'
3
3
  module Euromail
4
4
  class SFTPService
5
5
 
6
- attr_reader :application, :customer, :host, :username, :password
6
+ attr_reader :application, :customer, :host, :username, :password, :current_mode
7
7
 
8
8
  def initialize application, customer, host, username, password
9
9
  @application = application
@@ -11,14 +11,17 @@ module Euromail
11
11
  @host = host
12
12
  @username = username
13
13
  @password = password
14
+ @current_mode = :production
14
15
  end
15
16
 
16
17
  def test_mode!
17
18
  self.extend(Euromail::SFTPTest::ServiceMethods)
19
+ @current_mode = :test
18
20
  end
19
21
 
20
22
  def development_mode!
21
23
  self.extend(Euromail::SFTPDevelopment::ServiceMethods)
24
+ @current_mode = :development
22
25
  end
23
26
 
24
27
  # Attempt to remove the file for the given identifier. If the upload fails or is aborted,
@@ -13,7 +13,7 @@ describe Euromail::SFTPConnection do
13
13
 
14
14
  describe "#upload" do
15
15
  it "use the generated filename" do
16
- @net_sftp_session.file.should receive(:open).with( euromail.filename('1'), 'w')
16
+ @net_sftp_session.should receive(:upload!).with( @string_io, euromail.filename('1') )
17
17
  euromail.connect do |connection|
18
18
  connection.upload('some-client-code', '1')
19
19
  end
@@ -28,9 +28,9 @@ describe Euromail::SFTPConnection do
28
28
  end
29
29
 
30
30
  it "can upload several pdf files within the same connection" do
31
- expect(@net_sftp_session.file).to receive(:open).exactly(2).times
32
- @file_hander.should receive(:write).with('some-client-code-1')
33
- @file_hander.should receive(:write).with('some-client-code-2')
31
+ expect(@net_sftp_session).to receive(:upload!).exactly(2).times
32
+ StringIO.should receive(:new).with('some-client-code-1')
33
+ StringIO.should receive(:new).with('some-client-code-2')
34
34
 
35
35
  euromail.connect do |connection|
36
36
  connection.upload("some-client-code-1", '1')
@@ -16,6 +16,10 @@ describe Euromail::SFTPService do
16
16
  euromail.development_mode!
17
17
  end
18
18
 
19
+ it "the current mode is development" do
20
+ euromail.current_mode.should eql :development
21
+ end
22
+
19
23
  describe "#upload" do
20
24
  it "does not upload anything" do
21
25
  @file_hander.should_not receive(:write)
@@ -19,6 +19,10 @@ describe Euromail::SFTPService do
19
19
  euromail.username.should eql('stefan')
20
20
  euromail.password.should eql('super_secret')
21
21
  end
22
+
23
+ it "the current mode is production" do
24
+ euromail.current_mode.should eql :production
25
+ end
22
26
  end
23
27
 
24
28
  describe "#connect" do
@@ -30,7 +34,8 @@ describe Euromail::SFTPService do
30
34
 
31
35
  describe "#upload!" do
32
36
  it "uploads pdf data" do
33
- @file_hander.should receive(:write).with('some-client-code')
37
+ StringIO.should receive(:new).with('some-client-code')
38
+ @net_sftp_session.should receive(:upload!).with(@string_io, euromail.filename('1'))
34
39
  euromail.upload!('some-client-code', '1')
35
40
  end
36
41
 
@@ -40,13 +45,13 @@ describe Euromail::SFTPService do
40
45
  end
41
46
 
42
47
  it "tries to remove the remote file after an upload fails" do
43
- @file_hander.stub(:write).and_raise("Connection dropped")
48
+ @net_sftp_session.stub(:upload!).and_raise("Connection dropped")
44
49
  euromail.should receive(:remove!).with('1')
45
50
  expect{ euromail.upload!('some-client-code', '1') }.to raise_error
46
51
  end
47
52
 
48
53
  it "raises if some error occurs" do
49
- @net_sftp_session.stub_chain(:file, :open).and_raise("Some error")
54
+ @net_sftp_session.stub(:upload!).and_raise("Some error")
50
55
  expect{ euromail.upload!('some-client-code', '2') }.to raise_error
51
56
  end
52
57
  end
@@ -54,7 +59,6 @@ describe Euromail::SFTPService do
54
59
  describe "#remove!" do
55
60
  it "removes the file from the sftp server" do
56
61
  @net_sftp_session.should receive(:remove!).with( euromail.filename('2') )
57
- @net_sftp_session.file.should_not receive(:open)
58
62
  euromail.remove!('2')
59
63
  end
60
64
 
@@ -16,6 +16,10 @@ describe Euromail::SFTPService do
16
16
  euromail.test_mode!
17
17
  end
18
18
 
19
+ it "the current mode is test" do
20
+ euromail.current_mode.should eql :test
21
+ end
22
+
19
23
  describe "#upload" do
20
24
  it "does not upload anything" do
21
25
  @file_hander.should_not receive(:write)
@@ -1,7 +1,7 @@
1
1
  module SFTPMock
2
2
  def mock_sftp
3
3
  @net_sftp_session = double("Net::SFTP::Session")
4
- @file_hander = double("Net::SFTP::Operations::File")
4
+ @string_io = double("StringIO")
5
5
 
6
6
  @file_hander.stub(:write) do |data|
7
7
  end
@@ -9,10 +9,11 @@ module SFTPMock
9
9
  @net_sftp_session.stub(:remove!) do |filename|
10
10
  end
11
11
 
12
- @net_sftp_session.stub_chain(:file, :open) do |filename, method, &block|
13
- block.call(@file_hander) if block
12
+ @net_sftp_session.stub(:upload!) do |filename|
14
13
  end
15
14
 
15
+ StringIO.stub(:new).and_return(@string_io)
16
+
16
17
  Net::SFTP.stub(:start) do |host, username, password_hash, &block|
17
18
  block.call(@net_sftp_session) if block
18
19
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: euromail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stefan Teijgeler
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-30 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: net-sftp
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.1.2
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 2.1.2
30
27
  description: Euromail SFTP service
@@ -33,11 +30,11 @@ executables: []
33
30
  extensions: []
34
31
  extra_rdoc_files: []
35
32
  files:
33
+ - lib/euromail.rb
36
34
  - lib/euromail/sftp_connection.rb
37
35
  - lib/euromail/sftp_development.rb
38
36
  - lib/euromail/sftp_service.rb
39
37
  - lib/euromail/sftp_test.rb
40
- - lib/euromail.rb
41
38
  - spec/euromail/sftp_connection_spec.rb
42
39
  - spec/euromail/sftp_development_spec.rb
43
40
  - spec/euromail/sftp_service_spec.rb
@@ -45,27 +42,27 @@ files:
45
42
  - spec/sftp_mock.rb
46
43
  - spec/spec_helper.rb
47
44
  homepage: https://github.com/steijgeler/euromail
48
- licenses: []
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
49
48
  post_install_message:
50
49
  rdoc_options: []
51
50
  require_paths:
52
51
  - lib
53
52
  required_ruby_version: !ruby/object:Gem::Requirement
54
- none: false
55
53
  requirements:
56
- - - ! '>='
54
+ - - ">="
57
55
  - !ruby/object:Gem::Version
58
56
  version: '0'
59
57
  required_rubygems_version: !ruby/object:Gem::Requirement
60
- none: false
61
58
  requirements:
62
- - - ! '>='
59
+ - - ">="
63
60
  - !ruby/object:Gem::Version
64
61
  version: '0'
65
62
  requirements: []
66
63
  rubyforge_project:
67
- rubygems_version: 1.8.25
64
+ rubygems_version: 2.2.2
68
65
  signing_key:
69
- specification_version: 3
66
+ specification_version: 4
70
67
  summary: Gem to upload pdf data to an SFTP server
71
68
  test_files: []