tochka_cyclops_api 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -17
- data/Rakefile +6 -0
- data/lib/tochka_cyclops_api/configuration.rb +4 -4
- data/lib/tochka_cyclops_api/data_processor.rb +22 -19
- data/lib/tochka_cyclops_api/generators/initializer_generator.rb +24 -0
- data/lib/tochka_cyclops_api/generators/model_generator.rb +45 -0
- data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_error_model_template.rb +6 -0
- data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_errors_migration_template.rb +13 -0
- data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_request_model_template.rb +7 -0
- data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_requests_migration_template.rb +16 -0
- data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_response_model_template.rb +6 -0
- data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_responses_migration_template.rb +12 -0
- data/lib/tochka_cyclops_api/methods.rb +9 -0
- data/lib/tochka_cyclops_api/request.rb +32 -7
- data/lib/tochka_cyclops_api/response.rb +61 -2
- data/lib/tochka_cyclops_api/schemas/requests/create_beneficiary_ip.rb +30 -0
- data/lib/tochka_cyclops_api/schemas/requests/create_beneficiary_ul.rb +30 -0
- data/lib/tochka_cyclops_api/schemas/requests/echo.rb +16 -0
- data/lib/tochka_cyclops_api/schemas/responses/create_beneficiary_ip.rb +13 -0
- data/lib/tochka_cyclops_api/schemas/responses/create_beneficiary_ul.rb +26 -0
- data/lib/tochka_cyclops_api/schemas/responses/echo.rb +18 -0
- data/lib/tochka_cyclops_api/schemas/responses/error.rb +16 -0
- data/lib/tochka_cyclops_api/version.rb +1 -1
- data/lib/tochka_cyclops_api.rb +9 -1
- metadata +61 -6
- data/lib/tochka_cyclops_api/schemas/create_beneficiary_ip.rb +0 -23
- data/lib/tochka_cyclops_api/schemas/create_beneficiary_ul.rb +0 -23
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10886b78c145c11ca0b46a8cace5feba945151c490d78c911d1e518510482715
|
4
|
+
data.tar.gz: dbef2906adca80f41e94a4bfdeea6748b3f0d80bf16c75b48f0ae0c7a505c406
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7c7748fc288453db931217534fc95e9b4436e75804d35e9c47e4395b22a858f3806dcda67b0d1ad42e7c1d8137511b24edb90b0cf926396c7355301da28dc79
|
7
|
+
data.tar.gz: caffcea79baf5ca6e8ec9438d49e9bf829120544d014940143d1e9ca6cf7348624978ed12725b8bd14bc727927c30a84930c1726a92a5d2562142fd57c4e58d3
|
data/README.md
CHANGED
@@ -1,35 +1,69 @@
|
|
1
1
|
# TochkaCyclopsApi
|
2
2
|
|
3
|
-
|
3
|
+
A simple way to interact with the ["Tochka" bank's api][api_source_page]
|
4
4
|
|
5
|
-
|
5
|
+
## Table of Contents
|
6
6
|
|
7
|
-
|
7
|
+
- [Getting started](#getting-started)
|
8
|
+
- [Installation](#installation)
|
9
|
+
- [Settings](#settings)
|
10
|
+
- [Usage](#usage)
|
8
11
|
|
9
|
-
|
12
|
+
## Getting started
|
10
13
|
|
11
|
-
|
14
|
+
### Installation
|
12
15
|
|
13
|
-
|
14
|
-
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```sh
|
19
|
+
bundle add tochka_cylops_api
|
15
20
|
```
|
16
21
|
|
17
|
-
|
22
|
+
and run commands bellow to create the initializer, models and migrations:
|
18
23
|
|
19
|
-
```
|
20
|
-
|
24
|
+
```sh
|
25
|
+
rails generate tochka_cylops_api:initializer
|
26
|
+
rails generate tochka_cylops_api:model
|
21
27
|
```
|
22
28
|
|
23
|
-
|
29
|
+
### Settings
|
24
30
|
|
25
|
-
|
31
|
+
You have to set the settings in the initializer file (_config/initializers/healthcheck.rb_):
|
26
32
|
|
27
|
-
|
33
|
+
```ruby
|
34
|
+
# frozen_string_literal: true
|
28
35
|
|
29
|
-
|
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
|
-
|
44
|
+
## Usage
|
32
45
|
|
33
|
-
|
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
|
-
|
69
|
+
[api_source_page]: https://api.tochka.com/static/v1/tender-docs/cyclops/main/index.html
|
data/Rakefile
CHANGED
@@ -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,32 @@
|
|
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 './generators/model_generator'
|
10
|
+
require_relative './schemas/requests/echo'
|
8
11
|
|
9
12
|
module TochkaCyclopsApi
|
13
|
+
# Module for input data validation and subsequent request invocation
|
10
14
|
module DataProcessor
|
11
15
|
def send_request(method, data)
|
12
16
|
@method = method
|
13
17
|
@data = data
|
18
|
+
@id = SecureRandom.uuid
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
return @errors.map{ |k,v| [k, v].join(' ')}.join(', ')
|
19
|
-
end
|
20
|
+
return @errors.map { |k, v| [k, v].join(' ') }.join(', ') unless valid_params?
|
21
|
+
|
22
|
+
send_data
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
23
26
|
|
24
27
|
def valid_params?
|
25
28
|
if shape
|
26
|
-
result = shape.call(@data)
|
29
|
+
result = shape.call(@data.deep_symbolize_keys)
|
27
30
|
@errors = result.errors.to_h
|
28
31
|
end
|
29
32
|
|
@@ -31,17 +34,17 @@ module TochkaCyclopsApi
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def send_data
|
34
|
-
TochkaCyclopsApi::Request.send(body)
|
37
|
+
TochkaCyclopsApi::Request.send(body, @method)
|
35
38
|
end
|
36
39
|
|
37
40
|
def shape
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
require_relative "./schemas/requests/#{@method}"
|
42
|
+
schema = ['TochkaCyclopsApi', 'Schemas', 'Requests', camel_case_method].join('::').constantize
|
43
|
+
|
44
|
+
schema.new
|
45
|
+
rescue => e
|
46
|
+
@errors = { error: e.message }
|
47
|
+
false
|
45
48
|
end
|
46
49
|
|
47
50
|
def camel_case_method
|
@@ -50,10 +53,10 @@ module TochkaCyclopsApi
|
|
50
53
|
|
51
54
|
def body
|
52
55
|
{
|
53
|
-
"jsonrpc":
|
56
|
+
"jsonrpc": '2.0',
|
54
57
|
"method": @method,
|
55
58
|
"params": @data,
|
56
|
-
"id":
|
59
|
+
"id": @id
|
57
60
|
}.to_json
|
58
61
|
end
|
59
62
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module TochkaCyclopsApi
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < 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,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/generators/model_generator.rb
|
4
|
+
|
5
|
+
require 'rails/generators'
|
6
|
+
require 'rails/generators/migration'
|
7
|
+
|
8
|
+
require_relative './templates/tochka_cyclops_error_model_template'
|
9
|
+
require_relative './templates/tochka_cyclops_request_model_template'
|
10
|
+
require_relative './templates/tochka_cyclops_response_model_template'
|
11
|
+
require_relative './templates/tochka_cyclops_errors_migration_template'
|
12
|
+
require_relative './templates/tochka_cyclops_requests_migration_template'
|
13
|
+
require_relative './templates/tochka_cyclops_responses_migration_template'
|
14
|
+
|
15
|
+
module TochkaCyclopsApi
|
16
|
+
module Generators
|
17
|
+
# Class for core generators
|
18
|
+
class ModelsGenerator < Rails::Generators::Base
|
19
|
+
include Rails::Generators::Migration
|
20
|
+
|
21
|
+
source_root File.expand_path('templates', __dir__)
|
22
|
+
|
23
|
+
def create_model_file
|
24
|
+
require 'active_record'
|
25
|
+
|
26
|
+
template 'tochka_cyclops_error_model_template.rb', 'app/models/tochka_cyclops_error.rb'
|
27
|
+
template 'tochka_cyclops_request_model_template.rb', 'app/models/tochka_cyclops_request.rb'
|
28
|
+
template 'tochka_cyclops_response_model_template.rb', 'app/models/tochka_cyclops_response.rb'
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_migration_file
|
32
|
+
migration_template 'tochka_cyclops_errors_migration_template.rb', 'db/migrate/create_tochka_cyclops_errors.rb'
|
33
|
+
migration_template 'tochka_cyclops_requests_migration_template.rb',
|
34
|
+
'db/migrate/create_tochka_cyclops_requests.rb'
|
35
|
+
migration_template 'tochka_cyclops_responses_migration_template.rb',
|
36
|
+
'db/migrate/create_tochka_cyclops_responses.rb'
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.next_migration_number(_path)
|
40
|
+
sleep(1)
|
41
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
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
|
data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_requests_migration_template.rb
ADDED
@@ -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
|
data/lib/tochka_cyclops_api/generators/templates/tochka_cyclops_responses_migration_template.rb
ADDED
@@ -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
|
@@ -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'
|
19
|
+
'sign-data' => signature(body),
|
14
20
|
'sign-thumbprint' => TochkaCyclopsApi.configuration.sign_thumbprint,
|
15
|
-
'sign-system'
|
16
|
-
'Content-Type'
|
21
|
+
'sign-system' => TochkaCyclopsApi.configuration.sign_system,
|
22
|
+
'Content-Type' => 'application/pdf'
|
17
23
|
})
|
18
24
|
request.body = body
|
19
25
|
|
20
|
-
|
21
|
-
end
|
26
|
+
response = http.request(request)
|
22
27
|
|
23
|
-
|
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
|
8
|
+
def self.create(request, response, method)
|
9
|
+
@method = method
|
10
|
+
@request = request
|
4
11
|
@response = response
|
5
|
-
|
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,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
|
data/lib/tochka_cyclops_api.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'dry-types'
|
3
|
+
require 'dry-validation'
|
2
4
|
|
3
5
|
require_relative 'tochka_cyclops_api/data_processor'
|
4
6
|
require_relative 'tochka_cyclops_api/configuration'
|
5
|
-
require_relative
|
7
|
+
require_relative 'tochka_cyclops_api/version'
|
8
|
+
require_relative 'tochka_cyclops_api/methods'
|
6
9
|
|
10
|
+
# Core module of this gem
|
7
11
|
module TochkaCyclopsApi
|
8
12
|
class Error < StandardError; end
|
9
13
|
|
14
|
+
module Types
|
15
|
+
include Dry.Types()
|
16
|
+
end
|
17
|
+
|
10
18
|
class << self
|
11
19
|
include DataProcessor
|
12
20
|
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tochka_cyclops_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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-
|
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'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 7.2.1.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 7.2.1.1
|
13
55
|
description: em for working with the api of the bank Point
|
14
56
|
email:
|
15
57
|
- andrewgavrick@yandex.ru
|
@@ -23,11 +65,24 @@ files:
|
|
23
65
|
- lib/tochka_cyclops_api.rb
|
24
66
|
- lib/tochka_cyclops_api/configuration.rb
|
25
67
|
- lib/tochka_cyclops_api/data_processor.rb
|
68
|
+
- lib/tochka_cyclops_api/generators/initializer_generator.rb
|
69
|
+
- lib/tochka_cyclops_api/generators/model_generator.rb
|
70
|
+
- lib/tochka_cyclops_api/generators/templates/tochka_cyclops_error_model_template.rb
|
71
|
+
- lib/tochka_cyclops_api/generators/templates/tochka_cyclops_errors_migration_template.rb
|
72
|
+
- lib/tochka_cyclops_api/generators/templates/tochka_cyclops_request_model_template.rb
|
73
|
+
- lib/tochka_cyclops_api/generators/templates/tochka_cyclops_requests_migration_template.rb
|
74
|
+
- lib/tochka_cyclops_api/generators/templates/tochka_cyclops_response_model_template.rb
|
75
|
+
- lib/tochka_cyclops_api/generators/templates/tochka_cyclops_responses_migration_template.rb
|
76
|
+
- lib/tochka_cyclops_api/methods.rb
|
26
77
|
- lib/tochka_cyclops_api/request.rb
|
27
78
|
- 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
|
79
|
+
- lib/tochka_cyclops_api/schemas/requests/create_beneficiary_ip.rb
|
80
|
+
- lib/tochka_cyclops_api/schemas/requests/create_beneficiary_ul.rb
|
81
|
+
- lib/tochka_cyclops_api/schemas/requests/echo.rb
|
82
|
+
- lib/tochka_cyclops_api/schemas/responses/create_beneficiary_ip.rb
|
83
|
+
- lib/tochka_cyclops_api/schemas/responses/create_beneficiary_ul.rb
|
84
|
+
- lib/tochka_cyclops_api/schemas/responses/echo.rb
|
85
|
+
- lib/tochka_cyclops_api/schemas/responses/error.rb
|
31
86
|
- lib/tochka_cyclops_api/version.rb
|
32
87
|
- sig/tochka_cyclops_api.rbs
|
33
88
|
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
|