bestchange-api 0.3 → 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: 04f8a40e380db40689c09a837ee11046dc2db89aa57b4cb35e7f7f2a1491a1c3
4
- data.tar.gz: 71e0dfc4d65b38a3ce17c5a680a559e43b2370683eb31b1cb865feef921fe81a
3
+ metadata.gz: 99363eb68e71e5ca12cf33f1fb63560b320274402f1d5c0c0e7417f573929263
4
+ data.tar.gz: 5a1aa1d8806d507cf324256815252f11e83a53fbbc679e7c8aefa0fc5705398e
5
5
  SHA512:
6
- metadata.gz: 431c8546f41f151ae5c087ca373759e4f535921a951171b023c6a52e553d94a7a71ceea0ce28162971f758e90c1c48077fe57f16d780d7a0df6d6558577d6b72
7
- data.tar.gz: f2804fcd70e28c4ff26bc19a70651fc84d47d31d938b0e40fe1a4cc8bd45c3b15a381d531b93241c2dec1974578f8996621e2b4c349007d9839cb094f2b82fc4
6
+ metadata.gz: 1370a2573f45154957c215a8994d03445650dca1fefab070059148369f22c57d1fd33c58d78d6b3cc06d2cb55cfabb0269ce06a81055e3fd9ce375ac61f568cc
7
+ data.tar.gz: de6f4885b1d02238392a11d49f90cf24821195e3767d476faf93689d409a894f5f3098e7b1ac1fdd8723e1f0968c560882bf9509a6f332218d205d4a021ec9d0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Change log
2
2
 
3
+ ## [0.4]
4
+ Do not delete already existed files
5
+
3
6
  ## [0.3]
4
7
  Fix configuration access
5
8
 
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.3'
4
+ VERSION = '0.4'
5
5
  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.3'
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-05 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