bestchange-api 0.7 → 1.0
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/.rubocop.yml +2 -0
- data/CHANGELOG.md +1 -1
- data/lib/bestchange/api.rb +15 -33
- data/lib/bestchange/version.rb +1 -1
- data/lib/bestchange/zip_builder.rb +18 -0
- data/lib/bestchange/zip_extractor.rb +24 -0
- data/lib/bestchange.rb +2 -18
- metadata +4 -3
- data/lib/bestchange/configuration.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fefd2ae756cf40bfa5313e56c56bc473c0677dfc13873c5dea2a527ce901f551
|
4
|
+
data.tar.gz: 1c031422cbff5f5f610c750b9dd1fdbcbfa0fbf6c578aa7d15efabb1282f1d1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2626dd57b231e3e8450b29805bbb58de6994842546c9b2b2dde3e6a3aef0e064a5f0d2c7eff5a98840afc3122b38afdf2ea6439195409292543b3e386ea8c13c
|
7
|
+
data.tar.gz: b0bcf4bff9cce0413c69fdca33e90f0fd7c9a7949dc91633e561f5d6b2d18ad6ff958c5cc2463ca86b8109781a56249f00cf7a1d14dcda334053a30e44dc2649
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/bestchange/api.rb
CHANGED
@@ -7,49 +7,31 @@ require 'timeout'
|
|
7
7
|
require 'zip'
|
8
8
|
|
9
9
|
module Bestchange
|
10
|
-
|
11
|
-
|
10
|
+
class Api
|
11
|
+
BASE_URI = 'http://api.bestchange.ru/info.zip'
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
fetch_files(filenames, &before_extract)
|
16
|
-
end
|
13
|
+
def initialize(conn = default_conn)
|
14
|
+
@conn = conn
|
17
15
|
end
|
18
16
|
|
19
|
-
|
17
|
+
attr_reader :conn
|
20
18
|
|
21
|
-
def
|
22
|
-
response =
|
23
|
-
archive = make_archive(response)
|
24
|
-
extract_files(archive, filenames, &before_extract)
|
25
|
-
ensure
|
26
|
-
archive.close if defined?(archive)
|
27
|
-
end
|
19
|
+
def request(request = default_request)
|
20
|
+
response = conn.request(request)
|
28
21
|
|
29
|
-
|
30
|
-
Net::HTTP.get(URI(BASE_URI))
|
31
|
-
end
|
22
|
+
return response unless block_given?
|
32
23
|
|
33
|
-
|
34
|
-
archive = Tempfile.new(ARCHIVE_DATA_FILENAME, encoding: ARCHIVE_DATA_ENCODING)
|
35
|
-
archive.write(response)
|
36
|
-
archive
|
24
|
+
yield response
|
37
25
|
end
|
38
26
|
|
39
|
-
|
40
|
-
Zip::File.open(archive) do |zip_file|
|
41
|
-
filenames.map do |filename|
|
42
|
-
entry = zip_file.find_entry(filename)
|
43
|
-
|
44
|
-
pathname = Pathname.new(Bestchange.configuration.dir).join(filename)
|
45
|
-
|
46
|
-
before_extract&.call(entry, pathname)
|
27
|
+
private
|
47
28
|
|
48
|
-
|
29
|
+
def default_conn
|
30
|
+
Net::HTTP.new(URI(BASE_URI).host, URI(BASE_URI).port)
|
31
|
+
end
|
49
32
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
33
|
+
def default_request
|
34
|
+
Net::HTTP::Get.new(URI(BASE_URI))
|
53
35
|
end
|
54
36
|
end
|
55
37
|
end
|
data/lib/bestchange/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bestchange
|
4
|
+
class ZipBuilder
|
5
|
+
ARCHIVE_DATA_ENCODING = 'ASCII-8BIT'
|
6
|
+
|
7
|
+
def initialize(response_body)
|
8
|
+
@response_body = response_body
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
zip_file = Tempfile.new('', encoding: ARCHIVE_DATA_ENCODING)
|
13
|
+
zip_file.write(@response_body)
|
14
|
+
zip_file.rewind
|
15
|
+
zip_file
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zip'
|
4
|
+
|
5
|
+
module Bestchange
|
6
|
+
class ZipExtractor
|
7
|
+
def initialize(zip_file)
|
8
|
+
@zip_file = zip_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(filename)
|
12
|
+
Zip::File.open(@zip_file) do |zip_file|
|
13
|
+
entry = zip_file.find_entry(filename)
|
14
|
+
|
15
|
+
tempfile = Tempfile.new(filename)
|
16
|
+
|
17
|
+
entry.extract(tempfile) { true }
|
18
|
+
|
19
|
+
tempfile.rewind
|
20
|
+
tempfile
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/bestchange.rb
CHANGED
@@ -1,24 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'bestchange/api'
|
4
|
-
require_relative 'bestchange/
|
4
|
+
require_relative 'bestchange/zip_builder'
|
5
|
+
require_relative 'bestchange/zip_extractor'
|
5
6
|
|
6
7
|
module Bestchange
|
7
|
-
ARCHIVE_DATA_FILENAME = 'info.zip'
|
8
|
-
ARCHIVE_DATA_ENCODING = 'ASCII-8BIT'
|
9
|
-
|
10
|
-
BASE_URI = "http://api.bestchange.ru/#{ARCHIVE_DATA_FILENAME}".freeze
|
11
|
-
|
12
|
-
DIRECTORY = Dir.pwd
|
13
|
-
TIMEOUT = 40
|
14
|
-
|
15
|
-
def self.configuration
|
16
|
-
@configuration ||= Configuration.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.configure
|
20
|
-
return configuration unless block_given?
|
21
|
-
|
22
|
-
yield(configuration)
|
23
|
-
end
|
24
8
|
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
|
4
|
+
version: '1.0'
|
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-
|
11
|
+
date: 2023-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -89,8 +89,9 @@ files:
|
|
89
89
|
- bin/setup
|
90
90
|
- lib/bestchange.rb
|
91
91
|
- lib/bestchange/api.rb
|
92
|
-
- lib/bestchange/configuration.rb
|
93
92
|
- lib/bestchange/version.rb
|
93
|
+
- lib/bestchange/zip_builder.rb
|
94
|
+
- lib/bestchange/zip_extractor.rb
|
94
95
|
homepage: https://github.com/karpinovsky/bestchange-api
|
95
96
|
licenses:
|
96
97
|
- MIT
|