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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +2 -0
- data/lib/bestchange/api.rb +27 -19
- 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: 99363eb68e71e5ca12cf33f1fb63560b320274402f1d5c0c0e7417f573929263
|
4
|
+
data.tar.gz: 5a1aa1d8806d507cf324256815252f11e83a53fbbc679e7c8aefa0fc5705398e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1370a2573f45154957c215a8994d03445650dca1fefab070059148369f22c57d1fd33c58d78d6b3cc06d2cb55cfabb0269ce06a81055e3fd9ce375ac61f568cc
|
7
|
+
data.tar.gz: de6f4885b1d02238392a11d49f90cf24821195e3767d476faf93689d409a894f5f3098e7b1ac1fdd8723e1f0968c560882bf9509a6f332218d205d4a021ec9d0
|
data/CHANGELOG.md
CHANGED
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
|
data/lib/bestchange/api.rb
CHANGED
@@ -7,36 +7,44 @@ require 'timeout'
|
|
7
7
|
require 'zip'
|
8
8
|
|
9
9
|
module Bestchange
|
10
|
-
|
11
|
-
|
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
|
-
|
19
|
-
|
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
|
-
|
24
|
-
response = Net::HTTP.get(URI(BASE_URI))
|
19
|
+
private
|
25
20
|
|
26
|
-
|
27
|
-
|
21
|
+
def fetch_files(filenames)
|
22
|
+
response = make_request
|
28
23
|
|
29
|
-
|
30
|
-
|
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
|
-
|
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
|
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.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-
|
11
|
+
date: 2023-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|