tochka_cyclops_api 0.1.0

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: bfcc16cc61d70b9e261dd336aa555f5a088c0ee8b540971260575702a076157e
4
+ data.tar.gz: 35ab29f1aab4e590a69e8a7e6c26debbeec2d6f498707aa7d8546706fcbe8a01
5
+ SHA512:
6
+ metadata.gz: 1ee86394d1c3ef181968524e9cdc0c01a08b39cca570924bb80dedf4cc705c77e849cbfc0d21a4296573f010a84fbf046a4c4553634fc1b4837e033e7c7c25cd
7
+ data.tar.gz: d42d3ddc12cd0898c3095ea2eb129e0533a2d2bfe3a9ab52201731834fb40fbeb44fbcb145f1fae2c9f4713875811ffb57c50da11432c48bb1e1692f98deadf2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-10-22
4
+
5
+ - Initial release
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # TochkaCyclopsApi
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tochka_cyclops_api`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tochka_cyclops_api.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -0,0 +1,8 @@
1
+ module TochkaCyclopsApi
2
+ class Configuration
3
+ attr_accessor :certificate
4
+ attr_accessor :private_key
5
+ attr_accessor :sign_system
6
+ attr_accessor :sign_thumbprint
7
+ end
8
+ end
@@ -0,0 +1,60 @@
1
+ require 'active_support/inflector'
2
+ require 'json'
3
+
4
+ require_relative 'request'
5
+
6
+ require_relative 'schemas/echo'
7
+ require_relative 'schemas/create_beneficiary_ul'
8
+
9
+ module TochkaCyclopsApi
10
+ module DataProcessor
11
+ def send_request(method, data)
12
+ @method = method
13
+ @data = data
14
+
15
+ if valid_params?
16
+ send_data
17
+ else
18
+ return @errors.map{ |k,v| [k, v].join(' ')}.join(', ')
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def valid_params?
25
+ if shape
26
+ result = shape.call(@data)
27
+ @errors = result.errors.to_h
28
+ end
29
+
30
+ @errors.empty?
31
+ end
32
+
33
+ def send_data
34
+ TochkaCyclopsApi::Request.send(body)
35
+ end
36
+
37
+ def shape
38
+ begin
39
+ schema = ('TochkaCyclopsApi::Schemas::' + camel_case_method).constantize
40
+ schema.new
41
+ rescue => e
42
+ @errors = {error: e.message}
43
+ false
44
+ end
45
+ end
46
+
47
+ def camel_case_method
48
+ @method.split('_').map(&:capitalize).join
49
+ end
50
+
51
+ def body
52
+ {
53
+ "jsonrpc": "2.0",
54
+ "method": @method,
55
+ "params": @data,
56
+ "id": "908ca508-f1f1-4256-9c43-9ba7ad9c45fb"
57
+ }.to_json
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,33 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require_relative 'response'
4
+
5
+ module TochkaCyclopsApi
6
+ module Request
7
+ def self.send(body)
8
+ uri = URI('https://pre.tochka.com/api/v1/cyclops/v2/jsonrpc')
9
+ http = Net::HTTP.new(uri.host, uri.port)
10
+ http.use_ssl = true
11
+
12
+ request = Net::HTTP::Post.new(uri, {
13
+ 'sign-data' => signature(body),
14
+ 'sign-thumbprint' => TochkaCyclopsApi.configuration.sign_thumbprint,
15
+ 'sign-system' => TochkaCyclopsApi.configuration.sign_system,
16
+ 'Content-Type' => 'application/pdf'
17
+ })
18
+ request.body = body
19
+
20
+ TochkaCyclopsApi::Response.new(http.request(request))
21
+ end
22
+
23
+ private
24
+
25
+ def self.signature(body)
26
+ digest = OpenSSL::Digest.new('sha256')
27
+ private_key = OpenSSL::PKey::RSA.new(TochkaCyclopsApi.configuration.private_key)
28
+ signature_key = private_key.sign(digest, body)
29
+ base64_signature = Base64.strict_encode64(signature_key)
30
+ base64_signature.gsub("\n", '')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ module TochkaCyclopsApi
2
+ class Response
3
+ def initialize(response)
4
+ @response = response
5
+ @body = response.body
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ require 'dry-validation'
2
+
3
+ module TochkaCyclopsApi
4
+ module Schemas
5
+ class BeneficiaryData < Dry::Validation::Contract
6
+ params do
7
+ required(:first_name).value(:string)
8
+ required(:last_name).value(:string)
9
+ optional(:middle_name).value(:string)
10
+ end
11
+ end
12
+
13
+ class CreateBeneficiaryIp < Dry::Validation::Contract
14
+ schema do
15
+ required(:inn).value(:string)
16
+ optional(:nominal_account_code).value(:string)
17
+ optional(:nominal_account_bic).value(:string)
18
+ required(:beneficiary_data).schema(
19
+ TochkaCyclopsApi::Schemas::BeneficiaryData.schema)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'dry-validation'
2
+
3
+ module TochkaCyclopsApi
4
+ module Schemas
5
+ class BeneficiaryData < Dry::Validation::Contract
6
+ params do
7
+ required(:name).value(:string)
8
+ required(:kpp).value(:string)
9
+ optional(:ogrn).value(:string)
10
+ end
11
+ end
12
+
13
+ class CreateBeneficiaryUl < Dry::Validation::Contract
14
+ schema do
15
+ required(:inn).value(:string)
16
+ optional(:nominal_account_code).value(:string)
17
+ optional(:nominal_account_bic).value(:string)
18
+ required(:beneficiary_data).schema(
19
+ TochkaCyclopsApi::Schemas::BeneficiaryData.schema)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ require 'dry-validation'
2
+
3
+ module TochkaCyclopsApi
4
+ module Schemas
5
+ class Echo < Dry::Validation::Contract
6
+ schema do
7
+ required(:text).value(:string)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TochkaCyclopsApi
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'tochka_cyclops_api/data_processor'
4
+ require_relative 'tochka_cyclops_api/configuration'
5
+ require_relative "tochka_cyclops_api/version"
6
+
7
+ module TochkaCyclopsApi
8
+ class Error < StandardError; end
9
+
10
+ class << self
11
+ include DataProcessor
12
+
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def configure
18
+ yield(configuration)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ module TochkaCyclopsApi
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tochka_cyclops_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - andrewgavrick
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: em for working with the api of the bank Point
14
+ email:
15
+ - andrewgavrick@yandex.ru
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - README.md
22
+ - Rakefile
23
+ - lib/tochka_cyclops_api.rb
24
+ - lib/tochka_cyclops_api/configuration.rb
25
+ - lib/tochka_cyclops_api/data_processor.rb
26
+ - lib/tochka_cyclops_api/request.rb
27
+ - lib/tochka_cyclops_api/response.rb
28
+ - lib/tochka_cyclops_api/schemas/create_beneficiary_ip.rb
29
+ - lib/tochka_cyclops_api/schemas/create_beneficiary_ul.rb
30
+ - lib/tochka_cyclops_api/schemas/echo.rb
31
+ - lib/tochka_cyclops_api/version.rb
32
+ - sig/tochka_cyclops_api.rbs
33
+ homepage: https://gitlab.com/andrewgavrick/tochka_api
34
+ licenses: []
35
+ metadata:
36
+ allowed_push_host: https://rubygems.org
37
+ homepage_uri: https://gitlab.com/andrewgavrick/tochka_api
38
+ source_code_uri: https://gitlab.com/andrewgavrick/tochka_api
39
+ changelog_uri: https://gitlab.com/andrewgavrick/tochka_api/-/blob/main/CHANGELOG.md?ref_type=heads
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 3.0.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.5.22
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Gem for working with the api of the Tochka bank
59
+ test_files: []