bestchange 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d8081c2cc7f9b963ede0ad28cc64923c9a550f0b9cbd4f388bf17600ccfc6ade
4
+ data.tar.gz: f4813b0a6675c55e9c17c57a2ddbbe71f13706241eb21a43afcfb250cf305487
5
+ SHA512:
6
+ metadata.gz: 573465318a1d906fe83c98659ebbb4167d473bfeb3cafe4e07869133add1363077958026c3771c2f24afea9957db5b113dc6687055b63a771ce70e360d4fbf73
7
+ data.tar.gz: 477626b6f7183c6da3390c6e204755c42f26274f5b0bada6ae0fb671c511d3259ecf8e23376134cf231a84a4894dab3db8c5cdd21c8a5071dcefa7aac5d6f3db
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1.3
3
+ Style/Documentation:
4
+ Enabled: false
5
+ Metrics/MethodLength:
6
+ Max: 15
data/API_DOC.txt ADDED
@@ -0,0 +1,40 @@
1
+ Файл перемещен на адрес http://api.bestchange.ru/info.zip
2
+
3
+ Вы можете использовать курсы от нашего сервиса с учетом указания ссылок на сайт www.bestchange.ru
4
+
5
+ На данный момент у нас нет обычного API. Получать курсы обменных пунктов можно, загружая ZIP-архив — http://api.bestchange.ru/info.zip
6
+ Архив обновляется регулярно вместе с сайтом и содержит сразу всю выгрузку курсов обмена. Загружать его можно не чаще, чем раз в 30 секунд.
7
+
8
+ Внутри находится несколько CSV-файлов с данными в кодировке Windows-1251. Как их распарсить:
9
+
10
+ bm_cy.dat — список валют в формате:
11
+ • ID валюты
12
+ • Позиция валюты в табличном списке на сайте www.bestchange.ru
13
+ • Название валюты
14
+
15
+ bm_exch.dat — список обменных пунктов в формате:
16
+ • ID обменного пункта
17
+ • Название обменного пункта
18
+
19
+ bm_rates.dat — список курсов обмена в формате:
20
+ • ID отдаваемой валюты
21
+ • ID получаемой валюты
22
+ • ID обменного пункта
23
+ • Курс обмена (отдать)
24
+ • Курс обмена (получить)
25
+ • Резерв получаемой валюты
26
+ • Отзывы (претензии и положительные через символ ".")
27
+ • Не используется
28
+ • Минимальная сумма обмена
29
+ • Максимальная сумма обмена
30
+ • ID города (для направлений с наличными)
31
+
32
+ bm_cities.dat — список городов в формате:
33
+ • ID города
34
+ • Название города
35
+
36
+ Переходы на сайты обменных пунктов возможны через редирект по ID, пример:
37
+ https://www.bestchange.ru/click.php?id=1
38
+
39
+ Имеется готовый код для парсинга на языке PHP, вы можете скачать его по ссылке:
40
+ https://www.bestchange.ru/bm/zip_parsing.zip
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Change log
2
+
3
+ ## [1.1]
4
+ Fix tempfile location
5
+
6
+ ## [1.0]
7
+ Add new Api interface, introduce Zip objects
8
+
9
+ ## [0.7]
10
+ Minor improvements
11
+
12
+ ## [0.6]
13
+ Pass zip entry via before_extract block
14
+
15
+ ## [0.5]
16
+ Add before_extract block
17
+
18
+ ## [0.4]
19
+ Do not delete already existed files
20
+
21
+ ## [0.3]
22
+ Fix configuration access
23
+
24
+ ## [0.2]
25
+ Fix missing dependencies. Move requirements to Api class
26
+
27
+ ## [0.1]
28
+ Add basic functionality
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at karpinovsky@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bestchange-api (1.1)
5
+ rubyzip (= 2.3.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ansi (1.5.0)
11
+ ast (2.4.2)
12
+ builder (3.2.4)
13
+ coderay (1.1.3)
14
+ json (2.6.3)
15
+ method_source (1.0.0)
16
+ minitest (5.17.0)
17
+ minitest-reporters (1.6.0)
18
+ ansi
19
+ builder
20
+ minitest (>= 5.0)
21
+ ruby-progressbar
22
+ parallel (1.22.1)
23
+ parser (3.2.1.0)
24
+ ast (~> 2.4.1)
25
+ pry (0.14.2)
26
+ coderay (~> 1.1)
27
+ method_source (~> 1.0)
28
+ rainbow (3.1.1)
29
+ regexp_parser (2.7.0)
30
+ rexml (3.2.5)
31
+ rubocop (1.47.0)
32
+ json (~> 2.3)
33
+ parallel (~> 1.10)
34
+ parser (>= 3.2.0.0)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ regexp_parser (>= 1.8, < 3.0)
37
+ rexml (>= 3.2.5, < 4.0)
38
+ rubocop-ast (>= 1.26.0, < 2.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (>= 2.4.0, < 3.0)
41
+ rubocop-ast (1.27.0)
42
+ parser (>= 3.2.1.0)
43
+ ruby-progressbar (1.13.0)
44
+ rubyzip (2.3.2)
45
+ unicode-display_width (2.4.2)
46
+
47
+ PLATFORMS
48
+ arm64-darwin-22
49
+
50
+ DEPENDENCIES
51
+ bestchange-api!
52
+ minitest (= 5.17.0)
53
+ minitest-reporters
54
+ pry (= 0.14.2)
55
+ rubocop (= 1.47.0)
56
+
57
+ BUNDLED WITH
58
+ 2.3.26
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Kirill
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+
2
+ # bestchange-api
3
+
4
+ bestchange-api is a simple library for getting data from Bestchange aggregator
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'bestchange-api'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install bestchange-api
21
+
22
+ ## Usage
23
+ [Bestchange api description](https://github.com/karpinovsky/bestchange-api/blob/master/API_DOC.txt)
24
+
25
+ ### info.zip
26
+
27
+ ```ruby
28
+ require 'bestchange'
29
+
30
+ api_client = Bestchange::Api.new
31
+ response = api_client.request # this will call api.bestchange.ru/info.zip by default
32
+ archive = Bestchange::ZipBuilder.new(response.body).call
33
+ tempfile = Bestchange::ZipExtractor.new(archive).call('bm_rates.dat')
34
+ ```
35
+
36
+ **NOTE**: Do not forget to close and unlink files at the end
37
+ ```ruby
38
+ archive.close
39
+ tempfile.close
40
+ ```
41
+
42
+ ### Using blocks
43
+ The `Bestchange::ZipBuilder` and `Bestchange::ZipExtractor` classes support using blocks to ensure that tempfiles are closed automatically. This is useful when you want to avoid manual file management and prevent possible leaks
44
+ ```ruby
45
+ response = Bestchange::Api.new.request
46
+
47
+ Bestchange::ZipBuilder.new(response.body).call do |archive|
48
+ # Work with archive here
49
+ # archive will be closed automatically when the block finishes
50
+ Bestchange::ZipExtractor.new(archive).call('bm_rates.dat') do |bm_rates|
51
+ # Work with bm_rates here
52
+ # bm_rates will be closed automatically when the block finishes
53
+ end
54
+ end
55
+ ```
56
+
57
+ ### Custom connection
58
+ You can pass your own http connection object while initializing an api client. This can be useful if you want to set custom timeouts, for example
59
+ ```ruby
60
+ require 'bestchange'
61
+
62
+ uri = URI(Bestchange::Api::BASE_URI)
63
+ conn = Net::HTTP.new(uri.host, uri.port)
64
+ conn.open_timeout = 5
65
+ conn.read_timeout = 10
66
+ api_client = Bestchange::Api.new(conn)
67
+ ```
68
+
69
+ ### Custom request
70
+ You can provide your own http request object to the `#request` method
71
+ ```ruby
72
+ require 'bestchange'
73
+
74
+ request = Net::HTTP::Head.new(URI(Bestchange::Api::BASE_URI))
75
+ response = api_client.request(request)
76
+ created_at = response['Date']
77
+ ```
78
+
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
83
+
84
+ ## Code of Conduct
85
+
86
+ Everyone interacting in the bestchange-api project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/karpinovsky/bestchange-api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'bestchange'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require 'irb'
16
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open-uri'
4
+ require 'net/http'
5
+ require 'tempfile'
6
+ require 'timeout'
7
+ require 'zip'
8
+
9
+ module Bestchange
10
+ class Api
11
+ BASE_URI = 'http://api.bestchange.ru/info.zip'
12
+
13
+ def initialize(conn = default_conn)
14
+ @conn = conn
15
+ end
16
+
17
+ attr_reader :conn
18
+
19
+ def request(request = default_request)
20
+ conn.request(request)
21
+ end
22
+
23
+ private
24
+
25
+ def default_conn
26
+ Net::HTTP.new(URI(BASE_URI).host, URI(BASE_URI).port)
27
+ end
28
+
29
+ def default_request
30
+ Net::HTTP::Get.new(URI(BASE_URI))
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bestchange
4
+ VERSION = '1.1'
5
+ end
@@ -0,0 +1,27 @@
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
+
16
+ if block_given?
17
+ begin
18
+ yield zip_file
19
+ ensure
20
+ zip_file.close
21
+ end
22
+ else
23
+ zip_file
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
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
+ tempfile = Tempfile.new(filename)
13
+
14
+ Zip::File.open(@zip_file) do |zip_file|
15
+ entry = zip_file.find_entry(filename)
16
+
17
+ entry.extract(tempfile) { true }
18
+ end
19
+
20
+ tempfile.rewind
21
+
22
+ if block_given?
23
+ begin
24
+ yield tempfile
25
+ ensure
26
+ tempfile.close
27
+ end
28
+ else
29
+ tempfile
30
+ end
31
+ end
32
+ end
33
+ end
data/lib/bestchange.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'bestchange/api'
4
+ require_relative 'bestchange/zip_builder'
5
+ require_relative 'bestchange/zip_extractor'
6
+
7
+ module Bestchange
8
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bestchange
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
+ platform: ruby
6
+ authors:
7
+ - Kirill Karpinovsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 5.17.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 5.17.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-reporters
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.14.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.47.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.47.0
83
+ description: A simple library for getting data from Bestchange aggregator
84
+ email: karpinovsky@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files:
88
+ - README.md
89
+ - CHANGELOG.md
90
+ files:
91
+ - ".gitignore"
92
+ - ".rubocop.yml"
93
+ - API_DOC.txt
94
+ - CHANGELOG.md
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - LICENSE
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - lib/bestchange.rb
104
+ - lib/bestchange/api.rb
105
+ - lib/bestchange/version.rb
106
+ - lib/bestchange/zip_builder.rb
107
+ - lib/bestchange/zip_extractor.rb
108
+ homepage: https://github.com/karpinovsky/bestchange
109
+ licenses:
110
+ - MIT
111
+ metadata:
112
+ homepage_uri: https://github.com/karpinovsky/bestchange
113
+ source_code_uri: https://github.com/karpinovsky/bestchange
114
+ bug_tracker_uri: https://github.com/karpinovsky/bestchange/issues
115
+ changelog_uri: https://github.com/karpinovsky/bestchange/blob/master/CHANGELOG.md
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 3.1.3
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubygems_version: 3.3.26
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Bestchange client
135
+ test_files: []