dato 0.7.1 → 0.7.2

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
  SHA256:
3
- metadata.gz: 72cf7ee954d8a8d7cd830e96740e32cb6aa2bf3de95d6d665dcc9d59956313f4
4
- data.tar.gz: df97ce29199800559fcfef471a70e76cb75bc50d84175d55c9db35f8d53e685e
3
+ metadata.gz: 22be7e5b5bd13a7df1d3ebf63c52ce769b0333d0c8a90e0d8f5d3da7dda8712a
4
+ data.tar.gz: 4fda2a299ace4004514ed7727d789271a5a4d23361c02eaad3f59d7b9132e7c2
5
5
  SHA512:
6
- metadata.gz: 8605bfa3d4c080d249c13958e48fce6b39ecdf632269d8786b8c10767dc6f1ef53434b82bac04b2ef922a9fe6ddebda56848bb75387c7fb825c7fbf300d91a8a
7
- data.tar.gz: 2f0db7c66bfd1c84f0a93a6fdecdaaf5289401b92cef4644a2ee722e863866c40a3fe45337298e4adb1af342e2551173b1e3fd08535d178c74d8efde500d4ac2
6
+ metadata.gz: 5f6b5c6e85c74e541ea03b77da23c0284e6447386af8adc4e0918b699028666b0888c1df2f27d701013efec3c75ea8fbec9e8d7b97e0ab54b87945373086ce45
7
+ data.tar.gz: 285b84bdbcd3e1932fbf65ab72cb9a5519a59eaacde9b7b7150572849efb68dec1f7f0e1fd64ca7f09010e238deefe8d3073e23e3177293d5da980994791442b
@@ -36,7 +36,6 @@ Gem::Specification.new do |spec|
36
36
  spec.add_runtime_dependency 'faraday_middleware', ['>= 0.9.0']
37
37
  spec.add_runtime_dependency 'activesupport', ['>= 4.2.7']
38
38
  spec.add_runtime_dependency 'fastimage'
39
- spec.add_runtime_dependency 'downloadr'
40
39
  spec.add_runtime_dependency 'addressable'
41
40
  spec.add_runtime_dependency 'thor'
42
41
  spec.add_runtime_dependency 'imgix', ['>= 0.3.1']
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'downloadr'
3
+ require 'fastimage'
4
4
  require 'tempfile'
5
5
  require 'addressable'
6
6
  require 'net/http'
7
- require 'fastimage'
8
7
 
9
8
  module Dato
10
9
  module Upload
@@ -21,10 +20,12 @@ module Dato
21
20
  def file
22
21
  @file ||= if http_source?
23
22
  uri = Addressable::URI.parse(source)
24
- ext = ::File.extname(uri.path)
25
- Tempfile.new(['file', ext]).tap do |file|
26
- Downloadr::HTTP.new(source, file).download
27
- end
23
+ ext = ::File.extname(uri.path).downcase
24
+ tempfile = Tempfile.new(['file', ext])
25
+ tempfile.binmode
26
+ tempfile.write(download_file(source))
27
+ tempfile.rewind
28
+ tempfile
28
29
  else
29
30
  ::File.new(::File.expand_path(source))
30
31
  end
@@ -67,26 +68,39 @@ module Dato
67
68
  uploads['id']
68
69
  end
69
70
 
71
+ def download_file(url)
72
+ connection = Faraday.new do |c|
73
+ c.response :raise_error
74
+ c.use FaradayMiddleware::FollowRedirects
75
+ c.adapter :net_http
76
+ end
77
+ connection.get(url).body
78
+ rescue Faraday::Error => e
79
+ puts "Error during uploading #{url}"
80
+ raise e
81
+ end
82
+
70
83
  def format_resource(upload_request)
71
- extension = ::File.extname(::File.basename(file.path)).delete('.')
84
+ extension = FastImage.type(file.path).to_s
85
+ if extension.empty?
86
+ extension = ::File.extname(::File.basename(file.path)).delete('.').downcase
87
+ end
88
+
89
+ raise FastImage::UnknownImageType if extension.empty?
72
90
 
73
91
  base_format = {
74
92
  path: upload_request[:id],
75
93
  size: ::File.size(file.path),
76
94
  format: extension
77
95
  }
78
-
79
96
  if IMAGE_FORMATS.include?(extension)
80
97
  width, height = FastImage.size(file.path)
81
-
82
- base_format.merge(
98
+ base_format = base_format.merge(
83
99
  width: width,
84
- height: height,
85
- format: FastImage.type(file.path).to_s
100
+ height: height
86
101
  )
87
- else
88
- base_format
89
102
  end
103
+ base_format
90
104
  end
91
105
  end
92
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dato
4
- VERSION = '0.7.1'
4
+ VERSION = '0.7.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-25 00:00:00.000000000 Z
11
+ date: 2019-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -220,20 +220,6 @@ dependencies:
220
220
  - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
- - !ruby/object:Gem::Dependency
224
- name: downloadr
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - ">="
228
- - !ruby/object:Gem::Version
229
- version: '0'
230
- type: :runtime
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - ">="
235
- - !ruby/object:Gem::Version
236
- version: '0'
237
223
  - !ruby/object:Gem::Dependency
238
224
  name: addressable
239
225
  requirement: !ruby/object:Gem::Requirement