bestchange-api 0.2 → 0.4

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: d4fa52ab370765f06a8ea106d4547fca3cc36edcd379827fa1b7abe57e0f0384
4
- data.tar.gz: d282e1a33a6e49ebe0179d4042304639e3f277c4999d0c8843cae500cbcad0bd
3
+ metadata.gz: 99363eb68e71e5ca12cf33f1fb63560b320274402f1d5c0c0e7417f573929263
4
+ data.tar.gz: 5a1aa1d8806d507cf324256815252f11e83a53fbbc679e7c8aefa0fc5705398e
5
5
  SHA512:
6
- metadata.gz: dd099097f90da89ce098e417252e7eca73f3432c623b1fc89e1674f4f6e44a4bfc24da5557417b12fa6b055ab1a18ef087b9c692c50b3ab3d97ed3dc8912aede
7
- data.tar.gz: e7f9176098122689fb80453d0c9215580215daf7773bc4024846ada491727883af9fe1dc142a8886fd80448d14a377c23c906a6090452c01e3e897b25e8b35e5
6
+ metadata.gz: 1370a2573f45154957c215a8994d03445650dca1fefab070059148369f22c57d1fd33c58d78d6b3cc06d2cb55cfabb0269ce06a81055e3fd9ce375ac61f568cc
7
+ data.tar.gz: de6f4885b1d02238392a11d49f90cf24821195e3767d476faf93689d409a894f5f3098e7b1ac1fdd8723e1f0968c560882bf9509a6f332218d205d4a021ec9d0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ## [0.4]
4
+ Do not delete already existed files
5
+
6
+ ## [0.3]
7
+ Fix configuration access
8
+
3
9
  ## [0.2]
4
10
  Fix missing dependencies. Move requirements to Api class
5
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bestchange-api (0.1)
4
+ bestchange-api (0.3)
5
5
  rubyzip (= 2.3.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -23,6 +23,8 @@ Or install it yourself as:
23
23
  Add your own configuration or use the default one
24
24
 
25
25
  ```ruby
26
+ require 'bestchange'
27
+
26
28
  Bestchange.configure do |config|
27
29
  config.dir = "path/to/your/custom/folder" # default is Dir.pwd
28
30
  config.timeout = 20 # Timeout for getting & parsing data, default is 40
@@ -7,36 +7,44 @@ require 'timeout'
7
7
  require 'zip'
8
8
 
9
9
  module Bestchange
10
- class Api
11
- def self.get_files(filenames)
12
- pathnames = filenames.map do |filename|
13
- Pathname.new(Bestchange.configuration.dir).join(filename)
14
- end
15
-
16
- Timeout.timeout(Bestchange.configuration.timeout) { fetch_data(pathnames) }
10
+ module Api
11
+ extend self
17
12
 
18
- pathnames.map do |pathname|
19
- File.open(pathname)
13
+ def get_files(filenames)
14
+ Timeout.timeout(Bestchange.configuration.timeout) do
15
+ fetch_files(filenames)
20
16
  end
21
17
  end
22
18
 
23
- def self.fetch_data(pathnames)
24
- response = Net::HTTP.get(URI(BASE_URI))
19
+ private
25
20
 
26
- temp_file = Tempfile.new(ARCHIVE_DATA_FILENAME, encoding: ARCHIVE_DATA_ENCODING)
27
- temp_file.write(response)
21
+ def fetch_files(filenames)
22
+ response = make_request
28
23
 
29
- Zip::File.open(temp_file) do |zip_file|
30
- pathnames.each do |pathname|
31
- entry = zip_file.find_entry(pathname.basename)
24
+ archive = Tempfile.new(ARCHIVE_DATA_FILENAME, encoding: ARCHIVE_DATA_ENCODING)
25
+ archive.write(response)
32
26
 
33
- pathname.delete if pathname.exist?
27
+ extract_files(archive, filenames)
28
+ ensure
29
+ archive.close if defined?(archive)
30
+ end
31
+
32
+ def make_request
33
+ Net::HTTP.get(URI(BASE_URI))
34
+ end
35
+
36
+ def extract_files(archive, filenames)
37
+ Zip::File.open(archive) do |zip_file|
38
+ filenames.map do |filename|
39
+ entry = zip_file.find_entry(filename)
40
+
41
+ pathname = Pathname.new(Bestchange.configuration.dir).join(filename)
34
42
 
35
43
  zip_file.extract(entry, pathname)
44
+
45
+ pathname.open
36
46
  end
37
47
  end
38
-
39
- temp_file.close
40
48
  end
41
49
  end
42
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bestchange
4
- VERSION = '0.2'
4
+ VERSION = '0.4'
5
5
  end
data/lib/bestchange.rb CHANGED
@@ -12,15 +12,13 @@ module Bestchange
12
12
  DIRECTORY = Dir.pwd
13
13
  TIMEOUT = 40
14
14
 
15
- class << self
16
- def configuration
17
- @configuration ||= Configuration.new
18
- end
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
19
18
 
20
- def configure
21
- return configuration unless block_given?
19
+ def self.configure
20
+ return configuration unless block_given?
22
21
 
23
- yield(configuration)
24
- end
22
+ yield(configuration)
25
23
  end
26
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bestchange-api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Karpinovsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-04 00:00:00.000000000 Z
11
+ date: 2023-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip