bestchange-api 0.4 → 0.6
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 +1 -1
- data/README.md +10 -1
- data/lib/bestchange/api.rb +7 -5
- data/lib/bestchange/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8da60c9f91d2fac5ff9899af64181c5715b668baa92dd5789dfcf508a92a286
|
4
|
+
data.tar.gz: c8259d19fd314094146ad62d60507ca4eb3279af5d481105fb6e57aac929dd57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fc1081e2b6e436b0fc1659dae92a3c48396d51ee562310d6a0433979a576e173c7025fa19aed0b3941a020e889a26f4beef94b13c68af6cad27ef43bcee3b50
|
7
|
+
data.tar.gz: 5c891ca4e54319a4a542472daea41fcf00d349f5c4e130854e9650259029c04f31a1ca375ccb9d2fab1156dd1c114235e166db240fca0eae8726bfc58601dcdb
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
# bestchange-api
|
2
3
|
|
3
4
|
bestchange-api is a simple library for getting data from Bestchange aggregator
|
@@ -19,6 +20,7 @@ Or install it yourself as:
|
|
19
20
|
$ gem install bestchange-api
|
20
21
|
|
21
22
|
## Usage
|
23
|
+
[Bestchange api description](https://github.com/karpinovsky/bestchange-api/blob/master/API_DOC.txt)
|
22
24
|
|
23
25
|
Add your own configuration or use the default one
|
24
26
|
|
@@ -35,8 +37,15 @@ Fetch data
|
|
35
37
|
```ruby
|
36
38
|
Bestchange::Api.get_files(['bm_rates.dat']) # => [File]
|
37
39
|
```
|
40
|
+
### &before_extract
|
41
|
+
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
|
42
|
+
```ruby
|
43
|
+
before_extract = ->(_zip_entry, pathname) do
|
44
|
+
pathname.delete if pathname.exist?
|
45
|
+
end
|
38
46
|
|
39
|
-
|
47
|
+
Bestchange::Api.get_files(['bm_rates.dat'], &before_extract)
|
48
|
+
```
|
40
49
|
|
41
50
|
## License
|
42
51
|
|
data/lib/bestchange/api.rb
CHANGED
@@ -10,21 +10,21 @@ module Bestchange
|
|
10
10
|
module Api
|
11
11
|
extend self
|
12
12
|
|
13
|
-
def get_files(filenames)
|
13
|
+
def get_files(filenames, &before_extract)
|
14
14
|
Timeout.timeout(Bestchange.configuration.timeout) do
|
15
|
-
fetch_files(filenames)
|
15
|
+
fetch_files(filenames, &before_extract)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def fetch_files(filenames)
|
21
|
+
def fetch_files(filenames, &before_extract)
|
22
22
|
response = make_request
|
23
23
|
|
24
24
|
archive = Tempfile.new(ARCHIVE_DATA_FILENAME, encoding: ARCHIVE_DATA_ENCODING)
|
25
25
|
archive.write(response)
|
26
26
|
|
27
|
-
extract_files(
|
27
|
+
extract_files('info.zip', filenames, &before_extract)
|
28
28
|
ensure
|
29
29
|
archive.close if defined?(archive)
|
30
30
|
end
|
@@ -33,13 +33,15 @@ module Bestchange
|
|
33
33
|
Net::HTTP.get(URI(BASE_URI))
|
34
34
|
end
|
35
35
|
|
36
|
-
def extract_files(archive, filenames)
|
36
|
+
def extract_files(archive, filenames, &before_extract)
|
37
37
|
Zip::File.open(archive) do |zip_file|
|
38
38
|
filenames.map do |filename|
|
39
39
|
entry = zip_file.find_entry(filename)
|
40
40
|
|
41
41
|
pathname = Pathname.new(Bestchange.configuration.dir).join(filename)
|
42
42
|
|
43
|
+
before_extract&.call(entry, pathname)
|
44
|
+
|
43
45
|
zip_file.extract(entry, pathname)
|
44
46
|
|
45
47
|
pathname.open
|
data/lib/bestchange/version.rb
CHANGED
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.
|
4
|
+
version: '0.6'
|
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
|
+
date: 2023-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|