bestchange-api 0.6 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +0 -1
- data/lib/bestchange/api.rb +15 -30
- 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/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/bestchange/api.rb
CHANGED
@@ -7,46 +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
|
-
|
20
|
-
|
21
|
-
def fetch_files(filenames, &before_extract)
|
22
|
-
response = make_request
|
17
|
+
attr_reader :conn
|
23
18
|
|
24
|
-
|
25
|
-
|
19
|
+
def request(request = default_request)
|
20
|
+
response = conn.request(request)
|
26
21
|
|
27
|
-
|
28
|
-
ensure
|
29
|
-
archive.close if defined?(archive)
|
30
|
-
end
|
22
|
+
return response unless block_given?
|
31
23
|
|
32
|
-
|
33
|
-
Net::HTTP.get(URI(BASE_URI))
|
24
|
+
yield response
|
34
25
|
end
|
35
26
|
|
36
|
-
|
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)
|
42
|
-
|
43
|
-
before_extract&.call(entry, pathname)
|
27
|
+
private
|
44
28
|
|
45
|
-
|
29
|
+
def default_conn
|
30
|
+
Net::HTTP.new(URI(BASE_URI).host, URI(BASE_URI).port)
|
31
|
+
end
|
46
32
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
33
|
+
def default_request
|
34
|
+
Net::HTTP::Get.new(URI(BASE_URI))
|
50
35
|
end
|
51
36
|
end
|
52
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
|