tochka_cyclops_api 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +51 -17
  3. data/Rakefile +6 -0
  4. data/lib/tochka_cyclops_api/configuration.rb +4 -4
  5. data/lib/tochka_cyclops_api/data_processor.rb +21 -19
  6. data/lib/tochka_cyclops_api/generators/initializer_generator.rb +24 -0
  7. data/lib/tochka_cyclops_api/generators/models_generator.rb +44 -0
  8. data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_error_model_template.rb +6 -0
  9. data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_errors_migration_template.rb +13 -0
  10. data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_request_model_template.rb +7 -0
  11. data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_requests_migration_template.rb +16 -0
  12. data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_response_model_template.rb +6 -0
  13. data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_responses_migration_template.rb +12 -0
  14. data/lib/tochka_cyclops_api/methods.rb +9 -0
  15. data/lib/tochka_cyclops_api/request.rb +32 -7
  16. data/lib/tochka_cyclops_api/response.rb +61 -2
  17. data/lib/tochka_cyclops_api/schemas/requests/create_beneficiary_ip.rb +30 -0
  18. data/lib/tochka_cyclops_api/schemas/requests/create_beneficiary_ul.rb +30 -0
  19. data/lib/tochka_cyclops_api/schemas/requests/echo.rb +16 -0
  20. data/lib/tochka_cyclops_api/schemas/responses/create_beneficiary_ip.rb +13 -0
  21. data/lib/tochka_cyclops_api/schemas/responses/create_beneficiary_ul.rb +26 -0
  22. data/lib/tochka_cyclops_api/schemas/responses/echo.rb +18 -0
  23. data/lib/tochka_cyclops_api/schemas/responses/error.rb +16 -0
  24. data/lib/tochka_cyclops_api/version.rb +1 -1
  25. data/lib/tochka_cyclops_api.rb +12 -1
  26. metadata +47 -6
  27. data/lib/tochka_cyclops_api/schemas/create_beneficiary_ip.rb +0 -23
  28. data/lib/tochka_cyclops_api/schemas/create_beneficiary_ul.rb +0 -23
  29. data/lib/tochka_cyclops_api/schemas/echo.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfcc16cc61d70b9e261dd336aa555f5a088c0ee8b540971260575702a076157e
4
- data.tar.gz: 35ab29f1aab4e590a69e8a7e6c26debbeec2d6f498707aa7d8546706fcbe8a01
3
+ metadata.gz: 2844cc465020d8597bfa869d80e33d850a2a33c26bd4f302adb7a620a9a71321
4
+ data.tar.gz: 35ed83f97f6d37d24d72fdceff93f11ac2057ea8d3df5b20487e9cafeacb1155
5
5
  SHA512:
6
- metadata.gz: 1ee86394d1c3ef181968524e9cdc0c01a08b39cca570924bb80dedf4cc705c77e849cbfc0d21a4296573f010a84fbf046a4c4553634fc1b4837e033e7c7c25cd
7
- data.tar.gz: d42d3ddc12cd0898c3095ea2eb129e0533a2d2bfe3a9ab52201731834fb40fbeb44fbcb145f1fae2c9f4713875811ffb57c50da11432c48bb1e1692f98deadf2
6
+ metadata.gz: 3bf2d583aa03a2e6758e6f5cd9d04a34f97baf307bb83244e07524256b61b7ab94337ac2e05aff8206a10f3ff83a7ecffce77d156c6392879da02b1bd753d447
7
+ data.tar.gz: 8a9f1760504c78697fd2e9d9f7691530d7270e0ec9a2cab87bba1611b8dcc88e15eceaff60a297507330b1d09601cfd0f46b819525ab741c48a1edc69f62e103
data/README.md CHANGED
@@ -1,35 +1,69 @@
1
1
  # TochkaCyclopsApi
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ A simple way to interact with the ["Tochka" bank's api][api_source_page]
4
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.
5
+ ## Table of Contents
6
6
 
7
- ## Installation
7
+ - [Getting started](#getting-started)
8
+ - [Installation](#installation)
9
+ - [Settings](#settings)
10
+ - [Usage](#usage)
8
11
 
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.
12
+ ## Getting started
10
13
 
11
- Install the gem and add to the application's Gemfile by executing:
14
+ ### Installation
12
15
 
13
- ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```sh
19
+ bundle add tochka_cylops_api
15
20
  ```
16
21
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
22
+ and run commands bellow to create the initializer, models and migrations:
18
23
 
19
- ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
24
+ ```sh
25
+ rails generate tochka_cyclops_api:models
26
+ rails generate tochka_cyclops_api:initializer
21
27
  ```
22
28
 
23
- ## Usage
29
+ ### Settings
24
30
 
25
- TODO: Write usage instructions here
31
+ You have to set the settings in the initializer file (_config/initializers/healthcheck.rb_):
26
32
 
27
- ## Development
33
+ ```ruby
34
+ # frozen_string_literal: true
28
35
 
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.
36
+ TochkaCyclopsApi.configure do |config|
37
+ config.certificate = File.read(PATH TO TOCHKA CERTIFICATE)
38
+ config.private_key = File.read(PATH TO TOCHKA PRIVATE KEY)
39
+ config.sign_thumbprint = YOUR THUMBPRINT
40
+ config.sign_system = YOUR SYSTEM
41
+ end
42
+ ```
30
43
 
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).
44
+ ## Usage
32
45
 
33
- ## Contributing
46
+ To send a request use the following command:
47
+ ```ruby
48
+ TochkaCyclopsApi.send_request(method, data)
49
+ ```
50
+ method - name of the method defined on the bank side point;
51
+ data - hash of the value required to fulfill the request.
52
+
53
+ For example:
54
+ ```ruby
55
+ TochkaCyclopsApi.send(
56
+ inicialize_beneficiary_ul,
57
+ {
58
+ inn: "7925930371",
59
+ nominal_account_code: "000000000000000000000",
60
+ nominal_account_bic: "0000000000",
61
+ beneficiary_data: {
62
+ name: "ООО \"Рога и Копыта\"",
63
+ kpp: "246301001"
64
+ }
65
+ }
66
+ )
67
+ ```
34
68
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tochka_cyclops_api.
69
+ [api_source_page]: https://api.tochka.com/static/v1/tender-docs/cyclops/main/index.html
data/Rakefile CHANGED
@@ -3,6 +3,12 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rubocop/rake_task"
5
5
 
6
+ require_relative 'lib/tochka_cyclops_api/methods'
7
+
6
8
  RuboCop::RakeTask.new
7
9
 
8
10
  task default: :rubocop
11
+
12
+ task :methods do
13
+ puts TochkaCyclopsApi::METHODS
14
+ end
@@ -1,8 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TochkaCyclopsApi
4
+ # Configuration class
2
5
  class Configuration
3
- attr_accessor :certificate
4
- attr_accessor :private_key
5
- attr_accessor :sign_system
6
- attr_accessor :sign_thumbprint
6
+ attr_accessor :certificate, :private_key, :sign_system, :sign_thumbprint
7
7
  end
8
8
  end
@@ -1,29 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/inflector'
4
+ require 'active_support'
5
+ require 'securerandom'
2
6
  require 'json'
3
7
 
4
8
  require_relative 'request'
5
-
6
- require_relative 'schemas/echo'
7
- require_relative 'schemas/create_beneficiary_ul'
9
+ require_relative 'schemas/requests/echo'
8
10
 
9
11
  module TochkaCyclopsApi
12
+ # Module for input data validation and subsequent request invocation
10
13
  module DataProcessor
11
14
  def send_request(method, data)
12
15
  @method = method
13
16
  @data = data
17
+ @id = SecureRandom.uuid
14
18
 
15
- if valid_params?
16
- send_data
17
- else
18
- return @errors.map{ |k,v| [k, v].join(' ')}.join(', ')
19
- end
19
+ return @errors.map { |k, v| [k, v].join(' ') }.join(', ') unless valid_params?
20
+
21
+ send_data
20
22
  end
21
23
 
22
24
  private
23
25
 
24
26
  def valid_params?
25
27
  if shape
26
- result = shape.call(@data)
28
+ result = shape.call(@data.deep_symbolize_keys)
27
29
  @errors = result.errors.to_h
28
30
  end
29
31
 
@@ -31,17 +33,17 @@ module TochkaCyclopsApi
31
33
  end
32
34
 
33
35
  def send_data
34
- TochkaCyclopsApi::Request.send(body)
36
+ TochkaCyclopsApi::Request.send(body, @method)
35
37
  end
36
38
 
37
39
  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
40
+ require_relative "schemas/requests/#{@method}"
41
+ schema = ['TochkaCyclopsApi', 'Schemas', 'Requests', camel_case_method].join('::').constantize
42
+
43
+ schema.new
44
+ rescue => e
45
+ @errors = { error: e.message }
46
+ false
45
47
  end
46
48
 
47
49
  def camel_case_method
@@ -50,10 +52,10 @@ module TochkaCyclopsApi
50
52
 
51
53
  def body
52
54
  {
53
- "jsonrpc": "2.0",
55
+ "jsonrpc": '2.0',
54
56
  "method": @method,
55
57
  "params": @data,
56
- "id": "908ca508-f1f1-4256-9c43-9ba7ad9c45fb"
58
+ "id": @id
57
59
  }.to_json
58
60
  end
59
61
  end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators/base'
2
+
3
+ module TochkaCyclopsApi
4
+ module Generators
5
+ class InitializerGenerator < Rails::Generators::Base
6
+ desc 'It creates an initializer to set config data'
7
+ def create_initializer_file
8
+ create_file(
9
+ 'config/initializers/tochka_cyclops_api.rb',
10
+ <<~TOCHKA_CYCLOPS_API_INITIALIZER_TEXT
11
+ # frozen_string_literal: true
12
+
13
+ TochkaCyclopsApi.configure do |config|
14
+ config.certificate = File.read() # PATH TO TOCHKA CERTIFICATE
15
+ config.private_key = File.read() # PATH TO TOCHKA PRIVATE KEY
16
+ config.sign_thumbprint = '' # YOUR THUMBPRINT
17
+ config.sign_system = '' # YOUR SYSTEM
18
+ end
19
+ TOCHKA_CYCLOPS_API_INITIALIZER_TEXT
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/migration'
5
+
6
+ require_relative 'templates/tochka_cyclops_error_model_template'
7
+ require_relative 'templates/tochka_cyclops_request_model_template'
8
+ require_relative 'templates/tochka_cyclops_response_model_template'
9
+ require_relative 'templates/tochka_cyclops_errors_migration_template'
10
+ require_relative 'templates/tochka_cyclops_requests_migration_template'
11
+ require_relative 'templates/tochka_cyclops_responses_migration_template'
12
+
13
+ module TochkaCyclopsApi
14
+ module Generators
15
+ # Class for core generators
16
+ class ModelsGenerator < Rails::Generators::Base
17
+ include Rails::Generators::Migration
18
+
19
+ source_root File.expand_path('templates', __dir__)
20
+
21
+ def create_model_file
22
+ require 'active_record'
23
+
24
+ template 'tochka_cyclops_error_model_template.rb', 'app/models/tochka_cyclops_error.rb'
25
+ template 'tochka_cyclops_request_model_template.rb', 'app/models/tochka_cyclops_request.rb'
26
+ template 'tochka_cyclops_response_model_template.rb', 'app/models/tochka_cyclops_response.rb'
27
+ end
28
+
29
+ def create_migration_file
30
+ migration_template 'tochka_cyclops_errors_migration_template.rb',
31
+ 'db/migrate/create_tochka_cyclops_errors.rb'
32
+ migration_template 'tochka_cyclops_requests_migration_template.rb',
33
+ 'db/migrate/create_tochka_cyclops_requests.rb'
34
+ migration_template 'tochka_cyclops_responses_migration_template.rb',
35
+ 'db/migrate/create_tochka_cyclops_responses.rb'
36
+ end
37
+
38
+ def self.next_migration_number(_path)
39
+ sleep(1)
40
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ErrorModel generator
4
+ class TochkaCyclopsError < ActiveRecord::Base
5
+ has_one :request, class_name: 'TochkaCyclopsRequest', as: :result
6
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ErrorsMigration generator
4
+ class CreateTochkaCyclopsErrors < ActiveRecord::Migration[6.0]
5
+ def change
6
+ create_table :tochka_cyclops_errors do |t|
7
+ t.jsonb :body
8
+ t.integer :code
9
+ t.string :message
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RequestModel generator
4
+ class TochkaCyclopsRequest < ActiveRecord::Base
5
+ belongs_to :result, polymorphic: true
6
+ enum :status, %w[initialized failed finished]
7
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # RequestsMigration generator
4
+ class CreateTochkaCyclopsRequests < ActiveRecord::Migration[6.0]
5
+ def change
6
+ create_table :tochka_cyclops_requests do |t|
7
+ t.string :method
8
+ t.jsonb :body
9
+ t.integer :status
10
+ t.string :request_identifier
11
+ t.references :result, polymorphic: true, index: false, null: true
12
+ t.string :idempotency_key, null: true
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ResponseModel generator
4
+ class TochkaCyclopsResponse < ActiveRecord::Base
5
+ has_one :request, class_name: 'TochkaCyclopsRequest', as: :result
6
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ResponsesMigration generator
4
+ class CreateTochkaCyclopsResponses < ActiveRecord::Migration[6.0]
5
+ def change
6
+ create_table :tochka_cyclops_response do |t|
7
+ t.jsonb :body
8
+ t.jsonb :result
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TochkaCyclopsApi
4
+ METHODS = %w[
5
+ echo
6
+ create_beneficiary_ul
7
+ create_beneficiary_ip
8
+ ]
9
+ end
@@ -1,26 +1,41 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
  require 'net/http'
3
5
  require_relative 'response'
4
6
 
5
7
  module TochkaCyclopsApi
8
+ # Module for sending requests to the bank's api
6
9
  module Request
7
- def self.send(body)
10
+ def self.send(body, method)
11
+ @method = method
12
+ initialize_request(body)
13
+
8
14
  uri = URI('https://pre.tochka.com/api/v1/cyclops/v2/jsonrpc')
9
15
  http = Net::HTTP.new(uri.host, uri.port)
10
16
  http.use_ssl = true
11
17
 
12
18
  request = Net::HTTP::Post.new(uri, {
13
- 'sign-data' => signature(body),
19
+ 'sign-data' => signature(body),
14
20
  'sign-thumbprint' => TochkaCyclopsApi.configuration.sign_thumbprint,
15
- 'sign-system' => TochkaCyclopsApi.configuration.sign_system,
16
- 'Content-Type' => 'application/pdf'
21
+ 'sign-system' => TochkaCyclopsApi.configuration.sign_system,
22
+ 'Content-Type' => 'application/pdf'
17
23
  })
18
24
  request.body = body
19
25
 
20
- TochkaCyclopsApi::Response.new(http.request(request))
21
- end
26
+ response = http.request(request)
22
27
 
23
- private
28
+ case response.code.to_i
29
+ when (200..299)
30
+ @request.update(status: 'finished')
31
+ TochkaCyclopsApi::Response.create(@request, response, method)
32
+ when (400..499)
33
+ -> { 'Our server error' }[]
34
+ else
35
+ @request.update(status: 'failed')
36
+ -> { 'Their server error' }[]
37
+ end
38
+ end
24
39
 
25
40
  def self.signature(body)
26
41
  digest = OpenSSL::Digest.new('sha256')
@@ -29,5 +44,15 @@ module TochkaCyclopsApi
29
44
  base64_signature = Base64.strict_encode64(signature_key)
30
45
  base64_signature.gsub("\n", '')
31
46
  end
47
+
48
+ def self.initialize_request(body)
49
+ @request = TochkaCyclopsRequest.create(
50
+ method: @method,
51
+ body: body,
52
+ request_identifier: @id,
53
+ # idempotency_key:
54
+ status: 'initialized'
55
+ )
56
+ end
32
57
  end
33
58
  end
@@ -1,8 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'schemas/responses/echo'
4
+
1
5
  module TochkaCyclopsApi
6
+ # Class for processing the response received from the api bank
2
7
  class Response
3
- def initialize(response)
8
+ def self.create(request, response, method)
9
+ @method = method
10
+ @request = request
4
11
  @response = response
5
- @body = response.body
12
+ parse
13
+
14
+ {
15
+ response_struct: @response_struct,
16
+ result: @result
17
+ }
18
+ end
19
+
20
+ def self.parse
21
+ @body = JSON.parse(@response.body)
22
+ if @body.key? 'result'
23
+ parse_result
24
+ elsif @body.key? 'error'
25
+ parse_error
26
+ end
27
+ end
28
+
29
+ def self.parse_result
30
+ @result = @body['result']
31
+ response_schema = schema || -> { "Schema for #{@method} is not found" }[]
32
+
33
+ @response = TochkaCyclopsResponse.create(body: @body, result: @result)
34
+ @request.update(result: @response)
35
+ @result.deep_symbolize_keys if @result.is_a? Hash
36
+ @response_struct = response_schema.new(@result)
37
+ end
38
+
39
+ def self.parse_error
40
+ @error = @body['error']
41
+ require_relative 'schemas/responses/error'
42
+ response_schema = 'TochkaCyclopsApi::Schemas::Responses::Error'.constantize
43
+
44
+ @response = TochkaCyclopsError.create(
45
+ body: @body,
46
+ code: @error['code'],
47
+ message: @error['message']
48
+ )
49
+
50
+ @request.update(result: @response)
51
+
52
+ @response_struct = response_schema.new(@error.deep_symbolize_keys)
53
+ end
54
+
55
+ def self.schema
56
+ require_relative "schemas/responses/#{@method}"
57
+ "TochkaCyclopsApi::Schemas::Responses::#{camel_case_method}".constantize
58
+ rescue StandardError => e
59
+ @errors = { error: e.message }
60
+ false
61
+ end
62
+
63
+ def self.camel_case_method
64
+ @method.split('_').map(&:capitalize).join
6
65
  end
7
66
  end
8
67
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-validation'
4
+
5
+ module TochkaCyclopsApi
6
+ module Schemas
7
+ module Requests
8
+ # Schema for beneficiary_data field of main schema
9
+ class BeneficiaryData < Dry::Validation::Contract
10
+ params do
11
+ required(:first_name).value(:string)
12
+ required(:last_name).value(:string)
13
+ optional(:middle_name).value(:string)
14
+ end
15
+ end
16
+
17
+ # https://api.tochka.com/static/v1/tender-docs/cyclops/main/api_v2.html#api-v2-create-beneficiary-ip
18
+ class CreateBeneficiaryIp < Dry::Validation::Contract
19
+ schema do
20
+ required(:inn).value(:string)
21
+ optional(:nominal_account_code).value(:string)
22
+ optional(:nominal_account_bic).value(:string)
23
+ required(:beneficiary_data).schema(
24
+ TochkaCyclopsApi::Schemas::Reuqests::BeneficiaryData.schema
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-validation'
4
+
5
+ module TochkaCyclopsApi
6
+ module Schemas
7
+ module Requests
8
+ # Schema for beneficiary_data field of main schema
9
+ class BeneficiaryData < Dry::Validation::Contract
10
+ params do
11
+ required(:name).value(:string)
12
+ required(:kpp).value(:string)
13
+ optional(:ogrn).value(:string)
14
+ end
15
+ end
16
+
17
+ # https://api.tochka.com/static/v1/tender-docs/cyclops/main/api_v2.html#api-v2-create-beneficiary-ul
18
+ class CreateBeneficiaryUl < Dry::Validation::Contract
19
+ schema do
20
+ required(:inn).value(:string)
21
+ optional(:nominal_account_code).value(:string)
22
+ optional(:nominal_account_bic).value(:string)
23
+ required(:beneficiary_data).schema(
24
+ TochkaCyclopsApi::Schemas::Requests::BeneficiaryData.schema
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-validation'
4
+
5
+ module TochkaCyclopsApi
6
+ module Schemas
7
+ module Requests
8
+ # https://api.tochka.com/static/v1/tender-docs/cyclops/main/api_v2.html#echo
9
+ class Echo < Dry::Validation::Contract
10
+ schema do
11
+ required(:text).value(:string)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module TochkaCyclopsApi
6
+ module Schemas
7
+ module Responses
8
+ # Response chema for create_beneficiary_ip request
9
+ class CreateBeneficiaryIp < Dry::Struct
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module Types
6
+ include Dry.Types()
7
+ end
8
+
9
+ module TochkaCyclopsApi
10
+ module Schemas
11
+ module Responses
12
+ # Schema for beneficiary field of main response
13
+ class BeneficiaryData < Dry::Struct
14
+ attribute :inn, Types::Strict::String
15
+ attribute :id, Types::Strict::String
16
+ attribute :nominal_account_code, Types::Strict::String.optional
17
+ attribute :nominal_account_bic, Types::Strict::String.optional
18
+ end
19
+
20
+ # Response chema for create_beneficiary_ul request
21
+ class CreateBeneficiaryUl < Dry::Struct
22
+ attribute :beneficiary, BeneficiaryData
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module TochkaCyclopsApi
6
+ module Schemas
7
+ module Responses
8
+ # Response chema for echo request
9
+ class Echo
10
+ attr_accessor :text
11
+
12
+ def initialize(text)
13
+ @text = text
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-struct'
4
+
5
+ module TochkaCyclopsApi
6
+ module Schemas
7
+ module Responses
8
+ # Response chema for bank's api errors
9
+ class Error < Dry::Struct
10
+ attribute :code, Types::Strict::Integer
11
+ attribute :message, Types::Strict::String
12
+ attribute :meta, Types::Strict::Array
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TochkaCyclopsApi
4
- VERSION = "0.1.0"
4
+ VERSION = '0.3.0'
5
5
  end
@@ -1,12 +1,23 @@
1
1
  # frozen_string_literal: true
2
+ require 'dry-types'
3
+ require 'dry-validation'
4
+
5
+ require_relative 'tochka_cyclops_api/generators/models_generator'
6
+ require_relative 'tochka_cyclops_api/generators/initializer_generator'
2
7
 
3
8
  require_relative 'tochka_cyclops_api/data_processor'
4
9
  require_relative 'tochka_cyclops_api/configuration'
5
- require_relative "tochka_cyclops_api/version"
10
+ require_relative 'tochka_cyclops_api/version'
11
+ require_relative 'tochka_cyclops_api/methods'
6
12
 
13
+ # Core module of this gem
7
14
  module TochkaCyclopsApi
8
15
  class Error < StandardError; end
9
16
 
17
+ module Types
18
+ include Dry.Types()
19
+ end
20
+
10
21
  class << self
11
22
  include DataProcessor
12
23
 
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tochka_cyclops_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - andrewgavrick
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-22 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-validation
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-struct
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
13
41
  description: em for working with the api of the bank Point
14
42
  email:
15
43
  - andrewgavrick@yandex.ru
@@ -23,11 +51,24 @@ files:
23
51
  - lib/tochka_cyclops_api.rb
24
52
  - lib/tochka_cyclops_api/configuration.rb
25
53
  - lib/tochka_cyclops_api/data_processor.rb
54
+ - lib/tochka_cyclops_api/generators/initializer_generator.rb
55
+ - lib/tochka_cyclops_api/generators/models_generator.rb
56
+ - lib/tochka_cyclops_api/generators/templates/tochka_cyclops_error_model_template.rb
57
+ - lib/tochka_cyclops_api/generators/templates/tochka_cyclops_errors_migration_template.rb
58
+ - lib/tochka_cyclops_api/generators/templates/tochka_cyclops_request_model_template.rb
59
+ - lib/tochka_cyclops_api/generators/templates/tochka_cyclops_requests_migration_template.rb
60
+ - lib/tochka_cyclops_api/generators/templates/tochka_cyclops_response_model_template.rb
61
+ - lib/tochka_cyclops_api/generators/templates/tochka_cyclops_responses_migration_template.rb
62
+ - lib/tochka_cyclops_api/methods.rb
26
63
  - lib/tochka_cyclops_api/request.rb
27
64
  - 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
65
+ - lib/tochka_cyclops_api/schemas/requests/create_beneficiary_ip.rb
66
+ - lib/tochka_cyclops_api/schemas/requests/create_beneficiary_ul.rb
67
+ - lib/tochka_cyclops_api/schemas/requests/echo.rb
68
+ - lib/tochka_cyclops_api/schemas/responses/create_beneficiary_ip.rb
69
+ - lib/tochka_cyclops_api/schemas/responses/create_beneficiary_ul.rb
70
+ - lib/tochka_cyclops_api/schemas/responses/echo.rb
71
+ - lib/tochka_cyclops_api/schemas/responses/error.rb
31
72
  - lib/tochka_cyclops_api/version.rb
32
73
  - sig/tochka_cyclops_api.rbs
33
74
  homepage: https://gitlab.com/andrewgavrick/tochka_api
@@ -1,23 +0,0 @@
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
@@ -1,23 +0,0 @@
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
@@ -1,11 +0,0 @@
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