anyfetch 0.1.2 → 0.1.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: 64448adfab299c1b4c89f9ab347e00412226cd19
4
- data.tar.gz: 162903ef49a02492561791aa1a3ab2db3fcfd49e
3
+ metadata.gz: 29264ad4fdfd44d9a845fdba58e65c5a208b5419
4
+ data.tar.gz: 5de3fa9d7eb26bc116aae3da86234f2dd2a7ec99
5
5
  SHA512:
6
- metadata.gz: 440b8dee4e48bf7e74d272870778c1fb6d9747e58c3a61c12353e46777855fb95bafbbcfcc598150c3857a566ff39012734915f669301fd6274542a30b9ca083
7
- data.tar.gz: 52b3be162cb4d24ffea775c9dfe7688e5ec6efc3ea4349a9c93ca4b6d538acdeae192a96b8c06ed5aeea57ec1d47e22cbb66457c86877fee077c72a99e0482ee
6
+ metadata.gz: 25f7793a98e193b1be087c8eabc7f6407cea71dcbe0597c2b694b56ab79de592685bfdc265793ce99fb75cb28ed3dc4c00041a291ff45cd0f58f88f066bae844
7
+ data.tar.gz: f42a89850d2425adc1c9e797186ec0cc18d0d30e9bae5269e0bc403355182baa89d390ff6ce64cef96aecacae1e5e5fcc254cfab81c61fe76e4d56b53e8001e3
@@ -1,5 +1,14 @@
1
1
  # Anyfetch Changelog
2
2
 
3
+ ## 0.1.3
4
+
5
+ * Remove automating URI-encoding altogether as it probably should not be responsibility of the library.
6
+ * Always return `Tempfile` from HTTP and FTP handlers.
7
+
8
+ ## 0.1.2
9
+
10
+ * Prepare URI for parsing by decoding and re-encoding
11
+
3
12
  ## 0.1.1
4
13
 
5
14
  * Use old hash notation to support ruby 1.8
@@ -15,8 +15,7 @@ module Anyfetch extend self
15
15
  private
16
16
 
17
17
  def to_uri(uri)
18
- encoded = URI.encode(URI.decode(uri.to_s))
19
- URI.parse(encoded)
18
+ URI.parse(uri.to_s)
20
19
  end
21
20
 
22
21
  def handler(uri, options = {})
@@ -1,19 +1,14 @@
1
+ require "anyfetch/open_uri"
1
2
  require "anyfetch/original_filename/content_type"
2
3
 
3
4
  module Anyfetch
4
- class FTP
5
+ class FTP < OpenURI
5
6
  def initialize(uri, options = {})
6
7
  @uri = uri
7
8
  @options = options
8
9
  setup_auth
9
10
  end
10
11
 
11
- def open
12
- file = super(@uri)
13
- file.extend(OriginalFilename::ContentType)
14
- file
15
- end
16
-
17
12
  private
18
13
 
19
14
  def setup_auth
@@ -1,7 +1,7 @@
1
- require "anyfetch/original_filename/content_type"
1
+ require "anyfetch/open_uri"
2
2
 
3
3
  module Anyfetch
4
- class HTTP
4
+ class HTTP < OpenURI
5
5
  OPTIONS = {
6
6
  "User-Agent" => "Mozilla/5.0 (X11; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0",
7
7
  :allow_redirections => :safe,
@@ -13,12 +13,6 @@ module Anyfetch
13
13
  setup_basic_auth
14
14
  end
15
15
 
16
- def open
17
- file = super(@uri, @options)
18
- file.extend(OriginalFilename::ContentType)
19
- file
20
- end
21
-
22
16
  private
23
17
 
24
18
  def setup_basic_auth
@@ -0,0 +1,33 @@
1
+ require "tempfile"
2
+ require "anyfetch/original_filename/content_type"
3
+
4
+ module Anyfetch
5
+ class OpenURI
6
+ def initialize(*args)
7
+ raise NotImplementedError
8
+ end
9
+
10
+ def open
11
+ file = super(@uri, @options)
12
+
13
+ if file.is_a?(StringIO)
14
+ file = to_tempfile(file)
15
+ end
16
+
17
+ file.extend(OriginalFilename::ContentType)
18
+ file
19
+ end
20
+
21
+ private
22
+
23
+ # OpenURI returns either Tempfile or StringIO depending of the size of
24
+ # the response. We want to unify this and always return Tempfile.
25
+ def to_tempfile(io)
26
+ tempfile = Tempfile.new('open-uri')
27
+ tempfile.binmode
28
+ ::OpenURI::Meta.init(tempfile, io)
29
+ tempfile << io.string
30
+ tempfile
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module Anyfetch
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Szajbe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-15 00:00:00.000000000 Z
11
+ date: 2017-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocaine
@@ -117,6 +117,7 @@ files:
117
117
  - lib/anyfetch/file.rb
118
118
  - lib/anyfetch/ftp.rb
119
119
  - lib/anyfetch/http.rb
120
+ - lib/anyfetch/open_uri.rb
120
121
  - lib/anyfetch/original_filename/content_type.rb
121
122
  - lib/anyfetch/original_filename/path.rb
122
123
  - lib/anyfetch/version.rb