anyfetch 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b8614a3c367c6df216d41f62d3ec7d16d20fd69
4
- data.tar.gz: 58d639c46a8f6383850f0817b84705408e482de0
3
+ metadata.gz: 2e379ebb02cd50de69b8226b4204b10bc6934e75
4
+ data.tar.gz: ccf621c36694d32a21d676d02ceeb37504d203a6
5
5
  SHA512:
6
- metadata.gz: 35983dbb0c7a611f683fd87bb895cc57519134f547ba035f23b47b4679dc03b204dbb36fef355cad41bf73772837dec021ade0223ea2822116c2aa1a16bed391
7
- data.tar.gz: cfb3567d76aab393225edb47959c853f071895c07c394ef25f7a07b2c222247b7978eaa41edcb7de4803adbd0b4ce753803310378289dce781a10e9f25fd3fdc
6
+ metadata.gz: 2f582439debbd69123c198079aadb557b18866932d92c40bb9dcabab424d7de63a874342a6ccab1eb8a5c49948deabc9cf9532363191981dc790e5008c466276
7
+ data.tar.gz: 3cdde898bb95dbff849ff7c73fc799ea14bae022c9c05702558be7ef8c0abcca8e39004f961fc81ea03b83211b0582e51690961cf0de10c4f5c74424ba405600
@@ -1,5 +1,13 @@
1
1
  # Anyfetch Changelog
2
2
 
3
+ ## 0.1.5
4
+
5
+ * Replace `cocaine` dependency with `terrapin` (the gem was renamed).
6
+
7
+ ## 0.1.4
8
+
9
+ * Don't URI-encode FTP usernames
10
+
3
11
  ## 0.1.3
4
12
 
5
13
  * Remove automating URI-encoding altogether as it probably should not be responsibility of the library.
data/README.md CHANGED
@@ -7,6 +7,7 @@ Current support:
7
7
  * local files (via path or `file:///` protocol)
8
8
  * HTTP(s)
9
9
  * FTP
10
+ * SFTP
10
11
 
11
12
  ## Installation
12
13
 
@@ -39,7 +40,7 @@ Anyfetch.open("/path/to/file")
39
40
  Anyfetch.open("file:///path/to/file")
40
41
  ```
41
42
 
42
- ### HTTP/HTTPS and FTP
43
+ ### HTTP/HTTPS, FTP and SFTP
43
44
 
44
45
  Internally `open-uri` (with extensions provided by `open_uri_redirections` gem) is used to fetch the file from HTTP and FTP servers. Feel free to pass any options recognized by `open-uri` or `open_uri_redirections`.
45
46
 
@@ -49,6 +50,13 @@ Anyfetch.open("https://user:password@example.org/file.html", { 'User-Agent' => '
49
50
  Anyfetch.open("ftp://user:password@example.org/file.html")
50
51
  ```
51
52
 
53
+ For SFTP, `net-ssh` is used under the hood, user and password can be provided as part of the URI or as options. Other methods of authentication are not supported yet.
54
+
55
+ ```
56
+ Anyfetch.open("sftp://user:password@example.org/file.html")
57
+ Anyfetch.open("sftp://example.org/file.html", user: "user", password: "password")
58
+ ```
59
+
52
60
  ### Original filenames
53
61
 
54
62
  It is not always possible to know the original filename and/or content type of the accessed file upfront, e.g. when fetching files from the URLs like `http://example.org/file?id=123` or when the file is streamed from the server. Anyfetch provides `original_filename` method to the file instance to handle this. Internally it checks `content-disposition` meta information returned by the server, file's content type or simply file's basename for local files. This method can also be handy when trying to assign the file to an uploader like Paperclip or Carrierwave.
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'terrapin'
25
25
  spec.add_dependency 'mime-types'
26
26
  spec.add_dependency 'open_uri_redirections'
27
+ spec.add_dependency 'net-sftp'
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.15"
29
30
  spec.add_development_dependency "rake", "~> 10.0"
@@ -4,6 +4,7 @@ require "open_uri_redirections"
4
4
  require "anyfetch/file"
5
5
  require "anyfetch/ftp"
6
6
  require "anyfetch/http"
7
+ require "anyfetch/sftp"
7
8
  require "anyfetch/version"
8
9
 
9
10
  module Anyfetch extend self
@@ -25,6 +26,7 @@ module Anyfetch extend self
25
26
  case scheme
26
27
  when "file" then File
27
28
  when "ftp" then FTP
29
+ when "sftp" then SFTP
28
30
  when /^https?/ then HTTP
29
31
  else
30
32
  raise "No handler for '#{scheme}' protocol."
@@ -0,0 +1,30 @@
1
+ require "net/sftp"
2
+
3
+ module Anyfetch
4
+ class SFTP
5
+ def initialize(uri, options = {})
6
+ @uri = uri
7
+ @options = options
8
+ end
9
+
10
+ def open
11
+ user = @options.delete(:user) || @uri.user
12
+ options = { password: @uri.password }.merge(@options)
13
+
14
+ filename = ::File.basename(@uri.path)
15
+
16
+ tempfile = Tempfile.new(filename)
17
+ tempfile.binmode
18
+
19
+ Net::SFTP.start(@uri.host, user, options) do |sftp|
20
+ sftp.file.open(@uri.path, "r") do |file|
21
+ while !file.eof? do
22
+ tempfile << file.read(32 * 1024 * 1024)
23
+ end
24
+ end
25
+ end
26
+
27
+ tempfile.extend(OriginalFilename::Path)
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Anyfetch
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anyfetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Szajbe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2019-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: terrapin
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-sftp
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +134,7 @@ files:
120
134
  - lib/anyfetch/open_uri.rb
121
135
  - lib/anyfetch/original_filename/content_type.rb
122
136
  - lib/anyfetch/original_filename/path.rb
137
+ - lib/anyfetch/sftp.rb
123
138
  - lib/anyfetch/version.rb
124
139
  homepage: https://github.com/szajbus/anyfetch
125
140
  licenses:
@@ -141,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
156
  version: '0'
142
157
  requirements: []
143
158
  rubyforge_project:
144
- rubygems_version: 2.5.1
159
+ rubygems_version: 2.6.11
145
160
  signing_key:
146
161
  specification_version: 4
147
162
  summary: Fetch files via any protocol.