file_transfer 0.0.10 → 0.0.11

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: d6e7704b3a187bdb4150db073a6d11f3e88faade
4
- data.tar.gz: 87bbb29f0feba5e47dbf7cf52158a90838118b46
3
+ metadata.gz: 3a9ad72a63b8e4e17293c8009ba688734a498954
4
+ data.tar.gz: 2485a79a659f02a0b04eecd72f163ae0b5c0887b
5
5
  SHA512:
6
- metadata.gz: b7592105dc8ccfbf3f165afa6b1be537fb23bab19db97f31f6a95e35bbbd715a2397e167a9fb94e9d33476313724275999931b70e8e7aae2d02bb79ac455fb0a
7
- data.tar.gz: b2d501534bc726cc44d8ed8dac713d3d759af1f1039dfaca0c9cfdf3266dd1cf82cf6e0c4cb9f7c1ed7dd3c7990b8a2c86cc0d785225813112263737d7c927c9
6
+ metadata.gz: 98813264baf77a0c73e28cae9950fe9954b1b8646686768977edae114a40a24bc8d042a3104d425e28f02cc45a96fd67c3cd3453b800cbbd8720faa42781e3b6
7
+ data.tar.gz: 88abbfe7624eb0efc882e4984386524bca596ad13b6eccfd34ec5b3649273731339a35feb9842e284fd8c64e34ccf6f3d06e2c9892404b1a9cd731e46bc94f7a
@@ -11,7 +11,12 @@ require 'file_transfer/sftp'
11
11
  # * REST
12
12
  module FileTransfer
13
13
 
14
- ##
14
+ def self.test_connection(type, options)
15
+ handler = FileTransferHandler.new type, options
16
+ handler.test_connection
17
+ handler.close
18
+ end
19
+
15
20
  # Uploads one or more files to a remote server. To upload files use the locale file paths, not the ruby class File.
16
21
  # Types are:
17
22
  # * <tt>:ftp</tt> - for FTP file upload
@@ -35,7 +40,6 @@ module FileTransfer
35
40
  # {:from => ["/local/1.txt", "/local/2.txt", "/local/txt/*.txt"], :to => "/remote/uploads/txt/"}
36
41
  # ]
37
42
  # </tt>
38
-
39
43
  def self.upload(type, options, paths)
40
44
  handler = FileTransferHandler.new type, options
41
45
  result = handler.upload paths
@@ -50,7 +54,6 @@ module FileTransfer
50
54
  # {:from => ["/remote/uploads/a_1.txt", "/remote/uploads/a_2.txt", "/remote/uploads/txt/*.txt"], :to => "/local/txt/"}
51
55
  # ]
52
56
  # </tt>
53
-
54
57
  def self.download(type, options, paths)
55
58
  handler = FileTransferHandler.new type, options
56
59
  result = handler.download paths
@@ -58,6 +61,10 @@ module FileTransfer
58
61
  result
59
62
  end
60
63
 
64
+ def self.connect(type, options)
65
+ handler = FileTransferHandler.new type, options
66
+ end
67
+
61
68
  def self.remove(type, options, paths)
62
69
  handler = FileTransferHandler.new type, options
63
70
  result = handler.remove paths
@@ -79,9 +86,9 @@ module FileTransfer
79
86
  result
80
87
  end
81
88
 
82
- def self.exists?(type, options, path)
89
+ def self.exist?(type, options, path)
83
90
  handler = FileTransferHandler.new type, options
84
- result = handler.exists? path
91
+ result = handler.exist? path
85
92
  handler.close
86
93
  result
87
94
  end
@@ -9,6 +9,10 @@ module FileTransfer
9
9
  @client = get_client type, options
10
10
  end
11
11
 
12
+ def test_connection
13
+ client.test_connection
14
+ end
15
+
12
16
  # Uploads data to server
13
17
  # @param paths [Array<Hash<Symbol, String>>] upload specification
14
18
  # @return [Array]
@@ -70,6 +74,10 @@ module FileTransfer
70
74
  client.rename from_path, to_path
71
75
  end
72
76
 
77
+ def exist?(path)
78
+ client.exist? path
79
+ end
80
+
73
81
  def close
74
82
  client.close
75
83
  end
@@ -8,6 +8,11 @@ module FileTransfer
8
8
  super(options)
9
9
  end
10
10
 
11
+ # Connects to server
12
+ def test_connection
13
+ open_connection
14
+ end
15
+
11
16
  # Gets directory listing from SFTP server
12
17
  # @param dir [String] remote directory
13
18
  # @param options [Hash<Symbol,String>] additional options
@@ -10,6 +10,11 @@ module FileTransfer
10
10
  super(options)
11
11
  end
12
12
 
13
+ # Connects to server
14
+ def test_connection
15
+ open_connection
16
+ end
17
+
13
18
  # Downloads data from SFTP server
14
19
  # @param from_path [String] locale directory
15
20
  # @param to_path [String] remote directory
@@ -54,6 +59,16 @@ module FileTransfer
54
59
  end
55
60
  end
56
61
 
62
+ # Checks if remote file exists
63
+ # @param path [String] remote directory
64
+ def exist?(path)
65
+ open_connection(60) do
66
+ sftp.stat(path) do |response|
67
+ response.ok?
68
+ end
69
+ end
70
+ end
71
+
57
72
  def close
58
73
  # do nothing
59
74
  end
@@ -1,3 +1,3 @@
1
1
  module FileTransfer # :nodoc:
2
- VERSION = '0.0.10' # :nodoc:
2
+ VERSION = '0.0.11' # :nodoc:
3
3
  end
@@ -87,6 +87,13 @@ module FileTransfer
87
87
  sftp_client.rename('from', 'to')
88
88
  end
89
89
  end
90
+
91
+ describe '#exist?' do
92
+ it 'checks if file exists on SFTP server' do
93
+ expect(sftp).to receive(:stat).with('test')
94
+ sftp_client.exist?('test')
95
+ end
96
+ end
90
97
  end
91
98
  end
92
99
  end
@@ -116,21 +116,21 @@ module FileTransfer
116
116
  describe '.exists?' do
117
117
  it 'initializes new FileTransferHandler object' do
118
118
  expect(FileTransferHandler).to receive(:new).with(:test, { :test => :test }) { transfer_handler }
119
- FileTransfer.exists?(:test, { :test => :test }, '/test')
119
+ FileTransfer.exist?(:test, { :test => :test }, '/test')
120
120
  end
121
121
 
122
122
  it 'executes exists? call' do
123
- expect(transfer_handler).to receive(:exists?).with('/test')
124
- FileTransfer.exists?(:test, { :test => :test }, '/test')
123
+ expect(transfer_handler).to receive(:exist?).with('/test')
124
+ FileTransfer.exist?(:test, { :test => :test }, '/test')
125
125
  end
126
126
  it 'closes handle' do
127
127
  expect(transfer_handler).to receive(:close)
128
- FileTransfer.exists?(:test, { :test => :test }, '/test')
128
+ FileTransfer.exist?(:test, { :test => :test }, '/test')
129
129
  end
130
130
 
131
131
  it 'gets result' do
132
- allow(transfer_handler).to receive(:exists?) { 'result' }
133
- expect(FileTransfer.exists?(:test, { :test => :test }, '/test')).to eq('result')
132
+ allow(transfer_handler).to receive(:exist?) { 'result' }
133
+ expect(FileTransfer.exist?(:test, { :test => :test }, '/test')).to eq('result')
134
134
  end
135
135
  end
136
136
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_transfer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - impac AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-12 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement