bestchange-api 0.2

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: d4fa52ab370765f06a8ea106d4547fca3cc36edcd379827fa1b7abe57e0f0384
4
+ data.tar.gz: d282e1a33a6e49ebe0179d4042304639e3f277c4999d0c8843cae500cbcad0bd
5
+ SHA512:
6
+ metadata.gz: dd099097f90da89ce098e417252e7eca73f3432c623b1fc89e1674f4f6e44a4bfc24da5557417b12fa6b055ab1a18ef087b9c692c50b3ab3d97ed3dc8912aede
7
+ data.tar.gz: e7f9176098122689fb80453d0c9215580215daf7773bc4024846ada491727883af9fe1dc142a8886fd80448d14a377c23c906a6090452c01e3e897b25e8b35e5
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+ Metrics/MethodLength:
4
+ 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,7 @@
1
+ # Change log
2
+
3
+ ## [0.2]
4
+ Fix missing dependencies. Move requirements to Api class
5
+
6
+ ## [0.1]
7
+ 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,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bestchange-api (0.1)
5
+ rubyzip (= 2.3.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ coderay (1.1.3)
12
+ json (2.6.3)
13
+ method_source (1.0.0)
14
+ minitest (5.17.0)
15
+ parallel (1.22.1)
16
+ parser (3.2.1.0)
17
+ ast (~> 2.4.1)
18
+ pry (0.14.2)
19
+ coderay (~> 1.1)
20
+ method_source (~> 1.0)
21
+ rainbow (3.1.1)
22
+ regexp_parser (2.7.0)
23
+ rexml (3.2.5)
24
+ rubocop (1.47.0)
25
+ json (~> 2.3)
26
+ parallel (~> 1.10)
27
+ parser (>= 3.2.0.0)
28
+ rainbow (>= 2.2.2, < 4.0)
29
+ regexp_parser (>= 1.8, < 3.0)
30
+ rexml (>= 3.2.5, < 4.0)
31
+ rubocop-ast (>= 1.26.0, < 2.0)
32
+ ruby-progressbar (~> 1.7)
33
+ unicode-display_width (>= 2.4.0, < 3.0)
34
+ rubocop-ast (1.27.0)
35
+ parser (>= 3.2.1.0)
36
+ ruby-progressbar (1.13.0)
37
+ rubyzip (2.3.2)
38
+ unicode-display_width (2.4.2)
39
+
40
+ PLATFORMS
41
+ arm64-darwin-22
42
+
43
+ DEPENDENCIES
44
+ bestchange-api!
45
+ minitest (= 5.17.0)
46
+ pry (= 0.14.2)
47
+ rubocop (= 1.47.0)
48
+
49
+ BUNDLED WITH
50
+ 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,45 @@
1
+ # bestchange-api
2
+
3
+ bestchange-api is a simple library for getting data from Bestchange aggregator
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bestchange-api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bestchange-api
20
+
21
+ ## Usage
22
+
23
+ Add your own configuration or use the default one
24
+
25
+ ```ruby
26
+ Bestchange.configure do |config|
27
+ config.dir = "path/to/your/custom/folder" # default is Dir.pwd
28
+ config.timeout = 20 # Timeout for getting & parsing data, default is 40
29
+ end
30
+ ```
31
+
32
+ Fetch data
33
+ ```ruby
34
+ Bestchange::Api.get_files(['bm_rates.dat']) # => [File]
35
+ ```
36
+
37
+ **NOTE**: API documentation is described here [API_DOC.txt](https://github.com/karpinovsky/bestchange-api/blob/master/API_DOC.txt)
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ 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
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/bestchange/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'bestchange-api'
7
+ spec.summary = 'Bestchange api client'
8
+ spec.description = 'A simple library for getting data from Bestchange aggregator'
9
+
10
+ spec.version = Bestchange::VERSION
11
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.1.3')
12
+
13
+ spec.authors = ['Kirill Karpinovsky']
14
+ spec.email = 'karpinovsky@gmail.com'
15
+
16
+ spec.homepage = 'https://github.com/karpinovsky/bestchange-api'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = spec.homepage
20
+ spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
21
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
22
+
23
+ spec.extra_rdoc_files = Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt']
24
+
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.add_dependency 'rubyzip', '2.3.2'
32
+
33
+ spec.add_development_dependency 'minitest', '5.17.0'
34
+ spec.add_development_dependency 'pry', '0.14.2'
35
+ spec.add_development_dependency 'rubocop', '1.47.0'
36
+
37
+ spec.license = 'MIT'
38
+ end
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,42 @@
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
+ def self.get_files(filenames)
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) }
17
+
18
+ pathnames.map do |pathname|
19
+ File.open(pathname)
20
+ end
21
+ end
22
+
23
+ def self.fetch_data(pathnames)
24
+ response = Net::HTTP.get(URI(BASE_URI))
25
+
26
+ temp_file = Tempfile.new(ARCHIVE_DATA_FILENAME, encoding: ARCHIVE_DATA_ENCODING)
27
+ temp_file.write(response)
28
+
29
+ Zip::File.open(temp_file) do |zip_file|
30
+ pathnames.each do |pathname|
31
+ entry = zip_file.find_entry(pathname.basename)
32
+
33
+ pathname.delete if pathname.exist?
34
+
35
+ zip_file.extract(entry, pathname)
36
+ end
37
+ end
38
+
39
+ temp_file.close
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bestchange
4
+ class Configuration
5
+ def dir
6
+ @dir || Bestchange::DIRECTORY
7
+ end
8
+
9
+ def timeout
10
+ @timeout || Bestchange::TIMEOUT
11
+ end
12
+
13
+ attr_writer :dir, :timeout
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bestchange
4
+ VERSION = '0.2'
5
+ end
data/lib/bestchange.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'bestchange/api'
4
+ require_relative 'bestchange/configuration'
5
+
6
+ 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
+ class << self
16
+ def configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def configure
21
+ return configuration unless block_given?
22
+
23
+ yield(configuration)
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bestchange-api
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ platform: ruby
6
+ authors:
7
+ - Kirill Karpinovsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-04 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: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.14.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.14.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.47.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.47.0
69
+ description: A simple library for getting data from Bestchange aggregator
70
+ email: karpinovsky@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - README.md
75
+ - CHANGELOG.md
76
+ files:
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - API_DOC.txt
80
+ - CHANGELOG.md
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - bestchange-api.gemspec
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/bestchange.rb
91
+ - lib/bestchange/api.rb
92
+ - lib/bestchange/configuration.rb
93
+ - lib/bestchange/version.rb
94
+ homepage: https://github.com/karpinovsky/bestchange-api
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ homepage_uri: https://github.com/karpinovsky/bestchange-api
99
+ source_code_uri: https://github.com/karpinovsky/bestchange-api
100
+ bug_tracker_uri: https://github.com/karpinovsky/bestchange-api/issues
101
+ changelog_uri: https://github.com/karpinovsky/bestchange-api/blob/master/CHANGELOG.md
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.1.3
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.3.26
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Bestchange api client
121
+ test_files: []