bestchange-api 0.5 → 0.7

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
  SHA256:
3
- metadata.gz: b3e48dd22229d0446f26b047fd38fee4a9824be55e2981b7bcfeadb49ca4f044
4
- data.tar.gz: a098a7884b4b9668974acabc2f73df5837ad54b671c40dec14dc147e23e6d1aa
3
+ metadata.gz: a4519573ffcd91610bf68a30544ebd17c00506ab8c052b5412b74ff348f07d8a
4
+ data.tar.gz: c6e1e36c2ed0d7c35a374e00576c8c5de2f433e86edb986a0ceaf5e17a04e167
5
5
  SHA512:
6
- metadata.gz: 3d574c842366cc7429dc2f197e34767996d265eed053eae2a9f64f00bc5bbd1743bfde48da456e7501473b85acd467378c2223b766db9e11d509805d9994f075
7
- data.tar.gz: bd27f374b87e3e18b74e41d952e33e5eb740748d9ae7344dd1895538e477dfd6c5c9cd4f931c8c827d6dd284aa85928c9a96c29426505e91784d50e0e268487d
6
+ metadata.gz: 8677e25eb2333d11e437e0b06eb64bcc122994b12fba0b81693e10dee37a6f31ce71d47a3f124929dafd865d72280db7e37df2c3109c7f0c4d2231c7b7d89c84
7
+ data.tar.gz: 5459ab729ad2777e2981b8ba1b55fd37a88a8720d85ddbf18167dcb2587c095b0c5ba6e85f1a2583cad53446545ad569e77fcbc53491f71134cc53d867285e02
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ## [0.7]
4
+ Small improvements
5
+
6
+ ## [0.6]
7
+ Pass zip entry via before_extract block
8
+
3
9
  ## [0.5]
4
10
  Add before_extract block
5
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bestchange-api (0.4)
4
+ bestchange-api (0.7)
5
5
  rubyzip (= 2.3.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -19,6 +19,7 @@ Or install it yourself as:
19
19
  $ gem install bestchange-api
20
20
 
21
21
  ## Usage
22
+ [Bestchange api description](https://github.com/karpinovsky/bestchange-api/blob/master/API_DOC.txt)
22
23
 
23
24
  Add your own configuration or use the default one
24
25
 
@@ -35,8 +36,15 @@ Fetch data
35
36
  ```ruby
36
37
  Bestchange::Api.get_files(['bm_rates.dat']) # => [File]
37
38
  ```
39
+ ### &before_extract
40
+ You can also pass a block that will be called before `Zip::Entry#extract`. It might be helpful if you need to remove existed files or change files destination for example
41
+ ```ruby
42
+ before_extract = ->(_zip_entry, pathname) do
43
+ pathname.delete if pathname.exist?
44
+ end
38
45
 
39
- **NOTE**: API documentation is described here [API_DOC.txt](https://github.com/karpinovsky/bestchange-api/blob/master/API_DOC.txt)
46
+ Bestchange::Api.get_files(['bm_rates.dat'], &before_extract)
47
+ ```
40
48
 
41
49
  ## License
42
50
 
@@ -20,11 +20,8 @@ module Bestchange
20
20
 
21
21
  def fetch_files(filenames, &before_extract)
22
22
  response = make_request
23
-
24
- archive = Tempfile.new(ARCHIVE_DATA_FILENAME, encoding: ARCHIVE_DATA_ENCODING)
25
- archive.write(response)
26
-
27
- extract_files('info.zip', filenames, &before_extract)
23
+ archive = make_archive(response)
24
+ extract_files(archive, filenames, &before_extract)
28
25
  ensure
29
26
  archive.close if defined?(archive)
30
27
  end
@@ -33,6 +30,12 @@ module Bestchange
33
30
  Net::HTTP.get(URI(BASE_URI))
34
31
  end
35
32
 
33
+ def make_archive(response)
34
+ archive = Tempfile.new(ARCHIVE_DATA_FILENAME, encoding: ARCHIVE_DATA_ENCODING)
35
+ archive.write(response)
36
+ archive
37
+ end
38
+
36
39
  def extract_files(archive, filenames, &before_extract)
37
40
  Zip::File.open(archive) do |zip_file|
38
41
  filenames.map do |filename|
@@ -40,7 +43,7 @@ module Bestchange
40
43
 
41
44
  pathname = Pathname.new(Bestchange.configuration.dir).join(filename)
42
45
 
43
- before_extract&.call(filename, pathname)
46
+ before_extract&.call(entry, pathname)
44
47
 
45
48
  zip_file.extract(entry, pathname)
46
49
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bestchange
4
- VERSION = '0.5'
4
+ VERSION = '0.7'
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.5'
4
+ version: '0.7'
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-11 00:00:00.000000000 Z
11
+ date: 2023-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip