arh_archive 0.0.1.rc1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d69c35d21f8997c879109b0050ae879a400c9e9ad1c9c298743e43174d0c254c
4
+ data.tar.gz: 1420159c2d82f24bec0d3263ed46ff5a4f6bf408fdb4a01975645aa67309cae2
5
+ SHA512:
6
+ metadata.gz: 45480a4ee0b03a7367c38323987d32b0a99abd75a67de01a999969c61e86015ac2f25cb923fb58c7f4ab01e24b973e63c90b532038802ba953af4f8a5ba73800
7
+ data.tar.gz: f6d6ca53feb601addbacfad9bab06ea428af462e6b1fee47844c59838805a73d7b8b0f371d4f5c12ca5f0c9fc142d2ed1c733fa57a419fefcb1c84eccb21b43d
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.0.1.rc1 (17-02-2025)
4
+
5
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
4
+
5
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,3 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2025 Maksim Korelskii
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # ArhArchive API Ruby interface
2
+
3
+ This is a Ruby client that enables you to easily perform using [ArhArchive] for save images.
4
+
5
+ ## Prerequisites
6
+
7
+ [Ruby 2.7+](https://www.ruby-lang.org/en/) and [RubyGems subsystem](https://rubygems.org/) is required.
8
+
9
+ ## Installation
10
+
11
+ Install this gem by running:
12
+
13
+ ```
14
+ $ gem install arh_archive
15
+ ```
16
+
17
+ Or add it to your `Gemfile`:
18
+
19
+ ```ruby
20
+ gem 'arh_archive'
21
+ ```
22
+
23
+ And run:
24
+
25
+ ```
26
+ bundle install
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Include the client in your script:
32
+
33
+ ```ruby
34
+ require 'arh_archive'
35
+ ```
36
+
37
+ Next, instantiate the client:
38
+
39
+ ```ruby
40
+ client = ArhArchive.client
41
+ ```
42
+
43
+ And perform:
44
+
45
+ ```ruby
46
+ client.save_images(number_of_document, page_from, page_to)
47
+ ```
48
+
49
+ ### Additional request parameters
50
+
51
+ Directory for save images.
52
+
53
+ ```ruby
54
+ client.save_images(number_of_document, page_from, page_to, directory)
55
+ ```
56
+
57
+ Licensed under the [MIT license](./LICENSE.md).
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/arh_archive/version', __dir__)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'arh_archive'
7
+ spec.version = ArhArchive::VERSION
8
+ spec.authors = ['Maksim Korelskii']
9
+ spec.email = ['mkorelskii@gmail.com']
10
+ spec.summary = 'Ruby interface.'
11
+ spec.description = 'This is a Ruby client that enables you to easily perform using ' \
12
+ 'ArhArchive.'
13
+ spec.homepage = 'https://github.com/MaksimKorelskii/arh_archive'
14
+ spec.license = 'MIT'
15
+ spec.platform = Gem::Platform::RUBY
16
+ spec.required_ruby_version = '>= 2.7.0'
17
+
18
+ spec.files = Dir['README.md', 'LICENSE.md',
19
+ 'CHANGELOG.md', 'lib/**/*.rb',
20
+ 'arh_archive.gemspec',
21
+ 'Gemfile']
22
+ spec.extra_rdoc_files = ['README.md']
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'faraday', '~> 2.6'
26
+ spec.add_dependency 'zeitwerk', '~> 2.4'
27
+ spec.add_development_dependency 'rubocop', '~> 1.6'
28
+ spec.add_development_dependency 'rubocop-performance', '~> 1.5'
29
+
30
+ spec.metadata = {
31
+ 'source_code_uri' => 'https://github.com/MaksimKorelskii/arh_archive',
32
+ 'rubygems_mfa_required' => 'true'
33
+ }
34
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArhArchive
4
+ class Client
5
+ include ArhArchive::Request
6
+
7
+
8
+ def save_images(document, page_from, page_to, directory_path = "C://image_from_archive/#{document}", params = {})
9
+ while page_from <= page_to
10
+ save_image(document, page_from, page_to, directory_path, params)
11
+ page_from += 1
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def save_image(document, page_from, _page_to, directory_path, params)
18
+ ArhArchive::Saver.new(get("/archive1/image/#{document}", {n: page_from}.merge(params)),
19
+ document,
20
+ page_from,
21
+ directory_path)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArhArchive
4
+ module Connection
5
+ BASE_URL = 'https://archives.dvinaland.ru'
6
+ def connection
7
+ Faraday.new(options) do |faraday|
8
+ faraday.adapter Faraday.default_adapter
9
+ faraday.request :url_encoded
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def options
16
+ headers = {
17
+ accept: 'application',
18
+ user_agent: "arh_archieve gem/#{ArhArchive::VERSION}"
19
+ }
20
+
21
+ {
22
+ headers: headers,
23
+ url: BASE_URL
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArhArchive
4
+ module Request
5
+ include ArhArchive::Connection
6
+
7
+ def get(path, params = {})
8
+ connection.get(path, params)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArhArchive
4
+ class Saver
5
+ def initialize(response, document, page, directory_path)
6
+ file_name = "#{document}_#{page}.jpg"
7
+ file_path = File.join(directory_path, file_name)
8
+
9
+ FileUtils.mkdir_p(directory_path)
10
+
11
+ File.binwrite(file_path, response.body)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArhArchive
4
+ VERSION = '0.0.1.rc1'
5
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zeitwerk'
4
+ require 'faraday'
5
+
6
+ loader = Zeitwerk::Loader.for_gem
7
+ loader.setup
8
+
9
+ # This is a Ruby client that enables you to easily perform translations using ArhArchive API:
10
+ #
11
+ # client = ArhArchive.client
12
+ # result = client.save_images(number_of_document, page_from, page_to, directory, params)
13
+
14
+ module ArhArchive
15
+ class << self
16
+ # Initializes a new Client object
17
+ #
18
+ # @return [ArhArchive::Client]
19
+ def client
20
+ ArhArchive::Client.new
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arh_archive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Maksim Korelskii
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-02-17 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.6'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.6'
26
+ - !ruby/object:Gem::Dependency
27
+ name: zeitwerk
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.4'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.4'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rubocop
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.6'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.6'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rubocop-performance
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.5'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.5'
68
+ description: This is a Ruby client that enables you to easily perform using ArhArchive.
69
+ email:
70
+ - mkorelskii@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - README.md
75
+ files:
76
+ - CHANGELOG.md
77
+ - Gemfile
78
+ - LICENSE.md
79
+ - README.md
80
+ - arh_archive.gemspec
81
+ - lib/arh_archive.rb
82
+ - lib/arh_archive/client.rb
83
+ - lib/arh_archive/connection.rb
84
+ - lib/arh_archive/request.rb
85
+ - lib/arh_archive/saver.rb
86
+ - lib/arh_archive/version.rb
87
+ homepage: https://github.com/MaksimKorelskii/arh_archive
88
+ licenses:
89
+ - MIT
90
+ metadata:
91
+ source_code_uri: https://github.com/MaksimKorelskii/arh_archive
92
+ rubygems_mfa_required: 'true'
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.7.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.6.3
108
+ specification_version: 4
109
+ summary: Ruby interface.
110
+ test_files: []