simple-images-downloader 1.0.2 → 1.0.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +3 -8
- data/lib/simple_images_downloader/client.rb +17 -0
- data/lib/simple_images_downloader/configuration.rb +7 -0
- data/lib/simple_images_downloader/dispenser.rb +8 -6
- data/lib/simple_images_downloader/downloader.rb +4 -19
- data/lib/simple_images_downloader/errors.rb +14 -0
- data/lib/simple_images_downloader/line.rb +6 -3
- data/lib/simple_images_downloader/source_file.rb +6 -4
- data/lib/simple_images_downloader/validatable/destination_validator.rb +12 -0
- data/lib/simple_images_downloader/validatable/file_accessibility_validator.rb +13 -0
- data/lib/simple_images_downloader/validatable/file_persistance_validator.rb +13 -0
- data/lib/simple_images_downloader/validatable/image_path_validator.rb +17 -0
- data/lib/simple_images_downloader/validatable/validator.rb +11 -0
- data/lib/simple_images_downloader/validatable.rb +9 -0
- data/lib/simple_images_downloader/version.rb +1 -1
- data/rubocop.yml +1 -1
- data/simple_images_downloader.gemspec +0 -1
- metadata +13 -22
- data/lib/simple_images_downloader/file_persistance_validator.rb +0 -13
- data/lib/simple_images_downloader/image_path_validator.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d6712c3ea229e3cb09526ef0f0144f79fa9dcf1d7af6f20b23a83502ea34be1
|
4
|
+
data.tar.gz: b1147429efdf91682067decf309aec22050f2ed835b0b0261560f93fd6a63aa6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3cf6db2633b3ebf0e094482079193fa2dbcb75e169c70ea3778e9c46b00abbdae4089378c36d8570630aa0698ca5343ee1a97e67f6e8e193c1d234c240bb35f
|
7
|
+
data.tar.gz: cd9645e49d0a1658c74a6acde0a5608bd5a79fea67acda6235057c018066aaee7b5352ca150a5bf77d926189cd41dfb43950e62f0257edab98f31fc25f7a3f1b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 1.0.3 - 2023-09-27
|
2
|
+
- Corrected destination validation in SimpleImagesDownloader::Dispenser
|
3
|
+
- Corrected source file validation in SimpleImagesDownloader::SourceFiles
|
4
|
+
- Refactored
|
5
|
+
- Fixed error message when destination is invalid
|
6
|
+
|
1
7
|
## 1.0.2 - 2020-09-25
|
2
8
|
- Refactored SimpleImagesDownloader::Dispenser keeping the same behaviour
|
3
9
|
- Updated README
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple-images-downloader (1.0.
|
4
|
+
simple-images-downloader (1.0.3)
|
5
5
|
zeitwerk (~> 2.4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -10,7 +10,6 @@ GEM
|
|
10
10
|
addressable (2.7.0)
|
11
11
|
public_suffix (>= 2.0.2, < 5.0)
|
12
12
|
ast (2.4.1)
|
13
|
-
byebug (11.1.3)
|
14
13
|
coderay (1.1.3)
|
15
14
|
concurrent-ruby (1.1.7)
|
16
15
|
crack (0.4.4)
|
@@ -29,9 +28,6 @@ GEM
|
|
29
28
|
pry (0.13.1)
|
30
29
|
coderay (~> 1.1)
|
31
30
|
method_source (~> 1.0)
|
32
|
-
pry-byebug (3.9.0)
|
33
|
-
byebug (~> 11.0)
|
34
|
-
pry (~> 0.13.0)
|
35
31
|
public_suffix (4.0.6)
|
36
32
|
rainbow (3.0.0)
|
37
33
|
rake (12.3.3)
|
@@ -80,7 +76,7 @@ GEM
|
|
80
76
|
addressable (>= 2.3.6)
|
81
77
|
crack (>= 0.3.2)
|
82
78
|
hashdiff (>= 0.4.0, < 2.0.0)
|
83
|
-
zeitwerk (2.4.
|
79
|
+
zeitwerk (2.4.2)
|
84
80
|
|
85
81
|
PLATFORMS
|
86
82
|
ruby
|
@@ -88,7 +84,6 @@ PLATFORMS
|
|
88
84
|
DEPENDENCIES
|
89
85
|
faker (~> 2.14)
|
90
86
|
pry (~> 0.13.1)
|
91
|
-
pry-byebug (~> 3.9.0)
|
92
87
|
rake (~> 12.0)
|
93
88
|
rspec (~> 3.0)
|
94
89
|
rspec_junit_formatter (~> 0.4.1)
|
@@ -104,4 +99,4 @@ RUBY VERSION
|
|
104
99
|
ruby 2.7.1p83
|
105
100
|
|
106
101
|
BUNDLED WITH
|
107
|
-
2.
|
102
|
+
2.2.19
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleImagesDownloader
|
4
|
+
class Client
|
5
|
+
def initialize(options = Configuration::REQUEST_OPTIONS)
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def open(uri)
|
10
|
+
uri.open(@options)
|
11
|
+
rescue OpenURI::HTTPRedirect
|
12
|
+
raise Errors::RedirectError, uri
|
13
|
+
rescue OpenURI::HTTPError
|
14
|
+
raise Errors::ConnectionError, uri
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -8,6 +8,13 @@ module SimpleImagesDownloader
|
|
8
8
|
destination
|
9
9
|
].freeze
|
10
10
|
|
11
|
+
REQUEST_OPTIONS = {
|
12
|
+
'User-Agent' => "SimpleImagesDownloader/#{SimpleImagesDownloader::VERSION}",
|
13
|
+
redirect: false,
|
14
|
+
open_timeout: 30,
|
15
|
+
read_timeout: 30
|
16
|
+
}.freeze
|
17
|
+
|
11
18
|
attr_accessor(*ACCESSORS)
|
12
19
|
|
13
20
|
def initialize
|
@@ -3,28 +3,30 @@
|
|
3
3
|
module SimpleImagesDownloader
|
4
4
|
class Dispenser
|
5
5
|
extend Forwardable
|
6
|
+
include Validatable
|
6
7
|
|
7
8
|
def_delegator 'SimpleImagesDownloader::Configuration', :destination, :destination_dir
|
8
9
|
|
9
|
-
def initialize(source, remote_path)
|
10
|
+
def initialize(source, remote_path, validators = [DestinationValidator.new])
|
10
11
|
@source = source
|
11
12
|
@remote_path = remote_path
|
13
|
+
@validators = validators
|
12
14
|
end
|
13
15
|
|
14
16
|
def place
|
15
|
-
|
17
|
+
validate!(destination_dir)
|
16
18
|
|
17
|
-
FileUtils.mv @source,
|
19
|
+
FileUtils.mv @source, target
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
21
|
-
@
|
22
|
+
def target
|
23
|
+
@target ||= destination_dir + file_name
|
22
24
|
end
|
23
25
|
|
24
26
|
def file_name
|
25
27
|
@file_name ||= File.basename(@source) + File.extname(@remote_path)
|
26
28
|
end
|
27
29
|
|
28
|
-
private :destination_dir, :
|
30
|
+
private :destination_dir, :target, :file_name
|
29
31
|
end
|
30
32
|
end
|
@@ -2,13 +2,6 @@
|
|
2
2
|
|
3
3
|
module SimpleImagesDownloader
|
4
4
|
class Downloader
|
5
|
-
REQUEST_OPTIONS = {
|
6
|
-
'User-Agent' => "SimpleImagesDownloader/#{SimpleImagesDownloader::VERSION}",
|
7
|
-
redirect: false,
|
8
|
-
open_timeout: 30,
|
9
|
-
read_timeout: 30
|
10
|
-
}.freeze
|
11
|
-
|
12
5
|
def initialize(uri)
|
13
6
|
@uri = uri
|
14
7
|
end
|
@@ -16,23 +9,15 @@ module SimpleImagesDownloader
|
|
16
9
|
def download
|
17
10
|
puts "Downloading #{@uri}"
|
18
11
|
|
19
|
-
|
12
|
+
io = Client.new.open(@uri)
|
13
|
+
|
14
|
+
downloaded_file = StringioToTempfile.convert(io) unless io.nil?
|
20
15
|
|
21
16
|
Dispenser.new(downloaded_file, @uri.path).place
|
22
17
|
|
23
18
|
puts 'Downloading is finished'
|
24
19
|
ensure
|
25
|
-
downloaded_file
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def downloaded_file
|
31
|
-
@downloaded_file ||= @uri.open(REQUEST_OPTIONS)
|
32
|
-
rescue OpenURI::HTTPRedirect
|
33
|
-
raise Errors::RedirectError, @uri
|
34
|
-
rescue OpenURI::HTTPError
|
35
|
-
raise Errors::ConnectionError, @uri
|
20
|
+
downloaded_file&.close
|
36
21
|
end
|
37
22
|
end
|
38
23
|
end
|
@@ -52,5 +52,19 @@ module SimpleImagesDownloader
|
|
52
52
|
super(message)
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
class DestinationIsNotDirectory < BaseError
|
57
|
+
def initialize(path)
|
58
|
+
message = "The destination - #{path} is not directory"
|
59
|
+
super(message)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class PermissionsError < BaseError
|
64
|
+
def initialize(path)
|
65
|
+
message = "Couldn't read file #{path} due to permissions error"
|
66
|
+
super(message)
|
67
|
+
end
|
68
|
+
end
|
55
69
|
end
|
56
70
|
end
|
@@ -2,14 +2,17 @@
|
|
2
2
|
|
3
3
|
module SimpleImagesDownloader
|
4
4
|
class Line
|
5
|
-
|
6
|
-
|
5
|
+
include Validatable
|
6
|
+
|
7
|
+
def initialize(string, validators = [ImagePathValidator.new])
|
8
|
+
@string = string
|
9
|
+
@validators = validators
|
7
10
|
end
|
8
11
|
|
9
12
|
def uri
|
10
13
|
parsed_uri = URI.parse(@string)
|
11
14
|
|
12
|
-
|
15
|
+
validate!(@string)
|
13
16
|
|
14
17
|
parsed_uri
|
15
18
|
rescue URI::Error
|
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
module SimpleImagesDownloader
|
4
4
|
class SourceFile
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
include Validatable
|
6
|
+
|
7
|
+
def initialize(path, validators = [FilePersistanceValidator.new, FileAccessibilityValidator.new])
|
8
|
+
@path = path
|
9
|
+
@validators = validators
|
8
10
|
end
|
9
11
|
|
10
12
|
def each_line(&block)
|
11
|
-
@
|
13
|
+
validate!(@path)
|
12
14
|
|
13
15
|
begin
|
14
16
|
file.each(chomp: true, &block)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleImagesDownloader
|
4
|
+
module Validatable
|
5
|
+
class DestinationValidator < Validator
|
6
|
+
def validate(destination_dir)
|
7
|
+
raise Errors::DestinationIsNotDirectory, destination_dir unless File.directory?(destination_dir)
|
8
|
+
raise Errors::DestinationIsNotWritable, destination_dir unless File.writable?(destination_dir)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleImagesDownloader
|
4
|
+
module Validatable
|
5
|
+
class ImagePathValidator < Validator
|
6
|
+
VALID_EXTENSIONS = %w[.png .jpg .gif .jpeg].freeze
|
7
|
+
|
8
|
+
def validate(path)
|
9
|
+
extension = File.extname(path)
|
10
|
+
|
11
|
+
return if VALID_EXTENSIONS.include?(extension)
|
12
|
+
|
13
|
+
raise Errors::MissingImageInPath, path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/rubocop.yml
CHANGED
@@ -34,7 +34,6 @@ Gem::Specification.new do |spec|
|
|
34
34
|
|
35
35
|
spec.add_development_dependency 'faker', '~> 2.14'
|
36
36
|
spec.add_development_dependency 'pry', '~> 0.13.1'
|
37
|
-
spec.add_development_dependency 'pry-byebug', '~> 3.9.0'
|
38
37
|
spec.add_development_dependency 'rake', '~> 12.0'
|
39
38
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
39
|
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4.1'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-images-downloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IlkhamGaysin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.13.1
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: pry-byebug
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 3.9.0
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 3.9.0
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rake
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,7 +178,7 @@ dependencies:
|
|
192
178
|
- - "~>"
|
193
179
|
- !ruby/object:Gem::Version
|
194
180
|
version: 3.9.1
|
195
|
-
description:
|
181
|
+
description:
|
196
182
|
email:
|
197
183
|
- ilgamgaysin@gmail.com
|
198
184
|
executables:
|
@@ -220,16 +206,21 @@ files:
|
|
220
206
|
- bin/setup
|
221
207
|
- exe/simple-images-downloader
|
222
208
|
- lib/simple_images_downloader.rb
|
209
|
+
- lib/simple_images_downloader/client.rb
|
223
210
|
- lib/simple_images_downloader/configuration.rb
|
224
211
|
- lib/simple_images_downloader/dispenser.rb
|
225
212
|
- lib/simple_images_downloader/downloader.rb
|
226
213
|
- lib/simple_images_downloader/errors.rb
|
227
|
-
- lib/simple_images_downloader/file_persistance_validator.rb
|
228
|
-
- lib/simple_images_downloader/image_path_validator.rb
|
229
214
|
- lib/simple_images_downloader/line.rb
|
230
215
|
- lib/simple_images_downloader/runner.rb
|
231
216
|
- lib/simple_images_downloader/source_file.rb
|
232
217
|
- lib/simple_images_downloader/stringio_to_tempfile.rb
|
218
|
+
- lib/simple_images_downloader/validatable.rb
|
219
|
+
- lib/simple_images_downloader/validatable/destination_validator.rb
|
220
|
+
- lib/simple_images_downloader/validatable/file_accessibility_validator.rb
|
221
|
+
- lib/simple_images_downloader/validatable/file_persistance_validator.rb
|
222
|
+
- lib/simple_images_downloader/validatable/image_path_validator.rb
|
223
|
+
- lib/simple_images_downloader/validatable/validator.rb
|
233
224
|
- lib/simple_images_downloader/version.rb
|
234
225
|
- rubocop.yml
|
235
226
|
- simple_images_downloader.gemspec
|
@@ -240,7 +231,7 @@ metadata:
|
|
240
231
|
homepage_uri: https://github.com/IlkhamGaysin/simple-images-downloader
|
241
232
|
source_code_uri: https://github.com/IlkhamGaysin/simple-images-downloader
|
242
233
|
changelog_uri: https://github.com/IlkhamGaysin/simple-images-downloader/blob/master/CHANGELOG.md
|
243
|
-
post_install_message:
|
234
|
+
post_install_message:
|
244
235
|
rdoc_options: []
|
245
236
|
require_paths:
|
246
237
|
- lib
|
@@ -256,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
256
247
|
version: '0'
|
257
248
|
requirements: []
|
258
249
|
rubygems_version: 3.1.2
|
259
|
-
signing_key:
|
250
|
+
signing_key:
|
260
251
|
specification_version: 4
|
261
252
|
summary: simple-images-downloader allows to download images from a file containing
|
262
253
|
list of urls to those images.
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SimpleImagesDownloader
|
4
|
-
class ImagePathValidator
|
5
|
-
VALID_EXTENSIONS = %w[.png .jpg .gif .jpeg].freeze
|
6
|
-
|
7
|
-
def initialize(path)
|
8
|
-
@path = path
|
9
|
-
end
|
10
|
-
|
11
|
-
def validate
|
12
|
-
raise Errors::MissingImageInPath, @path unless VALID_EXTENSIONS.include?(extension)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def extension
|
18
|
-
File.extname(@path)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|