anyfetch 0.1.3 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +8 -0
- data/README.md +9 -1
- data/anyfetch.gemspec +3 -2
- data/lib/anyfetch/ftp.rb +6 -0
- data/lib/anyfetch/open_uri.rb +1 -1
- data/lib/anyfetch/original_filename/content_type.rb +2 -2
- data/lib/anyfetch/sftp.rb +30 -0
- data/lib/anyfetch/version.rb +1 -1
- data/lib/anyfetch.rb +2 -0
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d4e86e655372d406dda0b40962608083c22fe2e8a14612fc48b170e862b00055
|
4
|
+
data.tar.gz: 2ec326fbaf57e509583c5ade63fb05408a76fd378aaee227b2dd3320483eba26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77c809218d7ead0b1276aa498a7d07047a726433ff65458c72e9589105f9d6159ec106ffe331c20c7954fa2a25cca61fbb4cbec36ddc23b60f3bd4322ab52e6a
|
7
|
+
data.tar.gz: fd838f9a07454b62e0b75cd6454380c4dc2227dce9cb3552324867b5153773c32e4399852f2d6eb292b5e1af3a2cb22b3a96e5f79332ad14ba42a039ffde97a4
|
data/CHANGELOG.md
CHANGED
@@ -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
|
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.
|
data/anyfetch.gemspec
CHANGED
@@ -21,11 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_dependency '
|
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
|
-
spec.add_development_dependency "bundler", "~>
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
29
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
32
|
end
|
data/lib/anyfetch/ftp.rb
CHANGED
@@ -12,6 +12,12 @@ module Anyfetch
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def setup_auth
|
15
|
+
if @uri.user
|
16
|
+
# URI-encoded user must be passed to open-uri
|
17
|
+
# Rollback URI-encoding of user here
|
18
|
+
@uri.instance_variable_set "@user", URI.decode(@uri.user)
|
19
|
+
end
|
20
|
+
|
15
21
|
if @uri.password
|
16
22
|
# Rollback URI-encoding of password by open-uri lib
|
17
23
|
@uri.instance_variable_set "@password", URI.decode(@uri.password)
|
data/lib/anyfetch/open_uri.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "terrapin"
|
2
2
|
require "mime-types"
|
3
3
|
|
4
4
|
module Anyfetch
|
@@ -13,7 +13,7 @@ module Anyfetch
|
|
13
13
|
filename = ::File.basename(base_uri.path)
|
14
14
|
ext = ::File.extname(filename)
|
15
15
|
|
16
|
-
cmd =
|
16
|
+
cmd = Terrapin::CommandLine.new('/usr/bin/file', '--mime-type -b :file')
|
17
17
|
begin
|
18
18
|
mime_type = cmd.run(:file => path)
|
19
19
|
rescue
|
@@ -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
|
data/lib/anyfetch/version.rb
CHANGED
data/lib/anyfetch.rb
CHANGED
@@ -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."
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anyfetch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michał Szajbe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: terrapin
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -52,20 +52,34 @@ 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
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '2.0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '2.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
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:
|
@@ -140,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
155
|
- !ruby/object:Gem::Version
|
141
156
|
version: '0'
|
142
157
|
requirements: []
|
143
|
-
|
144
|
-
rubygems_version: 2.5.1
|
158
|
+
rubygems_version: 3.3.3
|
145
159
|
signing_key:
|
146
160
|
specification_version: 4
|
147
161
|
summary: Fetch files via any protocol.
|