starkbank 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/balance/balance.rb +8 -8
- data/lib/boleto/boleto.rb +22 -19
- data/lib/boleto/log.rb +10 -10
- data/lib/boleto_holmes/boleto_holmes.rb +14 -14
- data/lib/boleto_holmes/log.rb +16 -13
- data/lib/boleto_payment/boleto_payment.rb +21 -18
- data/lib/boleto_payment/log.rb +10 -10
- data/lib/brcode_payment/brcode_payment.rb +23 -20
- data/lib/brcode_payment/log.rb +10 -10
- data/lib/brcode_payment/rule.rb +49 -0
- data/lib/darf_payment/darf_payment.rb +23 -21
- data/lib/darf_payment/log.rb +10 -10
- data/lib/deposit/deposit.rb +9 -9
- data/lib/deposit/log.rb +10 -10
- data/lib/dict_key/dict_key.rb +26 -27
- data/lib/dynamic_brcode/dynamic_brcode.rb +155 -0
- data/lib/error.rb +7 -40
- data/lib/event/attempt.rb +9 -9
- data/lib/event/event.rb +30 -56
- data/lib/institution/institution.rb +2 -3
- data/lib/invoice/invoice.rb +33 -23
- data/lib/invoice/log.rb +10 -10
- data/lib/invoice/payment.rb +1 -2
- data/lib/payment_preview/boleto_preview.rb +74 -0
- data/lib/payment_preview/brcode_preview.rb +74 -0
- data/lib/payment_preview/payment_preview.rb +71 -0
- data/lib/payment_preview/tax_preview.rb +44 -0
- data/lib/payment_preview/utility_preview.rb +44 -0
- data/lib/payment_request/payment_request.rb +22 -16
- data/lib/starkbank.rb +21 -5
- data/lib/tax_payment/log.rb +10 -10
- data/lib/tax_payment/tax_payment.rb +22 -19
- data/lib/transaction/transaction.rb +13 -13
- data/lib/transfer/log.rb +10 -10
- data/lib/transfer/rule.rb +49 -0
- data/lib/transfer/transfer.rb +27 -24
- data/lib/utility_payment/log.rb +10 -10
- data/lib/utility_payment/utility_payment.rb +26 -17
- data/lib/utils/parse.rb +35 -0
- data/lib/utils/rest.rb +132 -109
- data/lib/webhook/webhook.rb +5 -5
- data/lib/workspace/workspace.rb +38 -10
- metadata +20 -25
- data/lib/brcode_preview/brcode_preview.rb +0 -77
- data/lib/key.rb +0 -33
- data/lib/user/organization.rb +0 -54
- data/lib/user/project.rb +0 -37
- data/lib/user/user.rb +0 -20
- data/lib/utils/api.rb +0 -79
- data/lib/utils/cache.rb +0 -10
- data/lib/utils/case.rb +0 -21
- data/lib/utils/checks.rb +0 -101
- data/lib/utils/environment.rb +0 -13
- data/lib/utils/request.rb +0 -79
- data/lib/utils/resource.rb +0 -13
- data/lib/utils/sub_resource.rb +0 -28
- data/lib/utils/url.rb +0 -28
data/lib/workspace/workspace.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
|
+
require('base64')
|
4
5
|
require_relative('../utils/rest')
|
5
|
-
|
6
|
+
|
6
7
|
|
7
8
|
module StarkBank
|
8
9
|
# # Workspace object
|
@@ -18,15 +19,23 @@ module StarkBank
|
|
18
19
|
# ## Parameters (optional):
|
19
20
|
# - allowed_tax_ids [list of strings]: list of tax IDs that will be allowed to send Deposits to this Workspace. ex: ['012.345.678-90', '20.018.183/0001-80']
|
20
21
|
#
|
21
|
-
# ## Attributes:
|
22
|
-
# - id [string
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
# ## Attributes (return-only):
|
23
|
+
# - id [string]: unique id returned when the workspace is created. ex: '5656565656565656'
|
24
|
+
# - status [string]: current Workspace status. Options: 'active', 'closed', 'frozen' or 'blocked'
|
25
|
+
# - organization_id [string]: unique organization id returned when the organization is created. ex: '5656565656565656'
|
26
|
+
# - picture_url [string]: public workspace image (png) URL. ex: 'https://storage.googleapis.com/api-ms-workspace-sbx.appspot.com/pictures/workspace/6284441752174592.png?20230208220551'
|
27
|
+
# - created [DateTime]: creation datetime for the Workspace. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
28
|
+
class Workspace < StarkCore::Utils::Resource
|
29
|
+
attr_reader :username, :name, :allowed_tax_ids, :id, :status, :organization_id, :picture_url, :created
|
30
|
+
def initialize(username:, name:, allowed_tax_ids: nil, id: nil, status: nil, organization_id: nil, picture_url: nil, created: nil)
|
26
31
|
super(id)
|
27
32
|
@username = username
|
28
33
|
@name = name
|
29
34
|
@allowed_tax_ids = allowed_tax_ids
|
35
|
+
@status = status
|
36
|
+
@organization_id = organization_id
|
37
|
+
@picture_url = picture_url
|
38
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
30
39
|
end
|
31
40
|
|
32
41
|
# # Create Workspace
|
@@ -112,16 +121,31 @@ module StarkBank
|
|
112
121
|
# ## Parameters (required):
|
113
122
|
# - id [string]: Workspace unique id. ex: '5656565656565656'
|
114
123
|
#
|
124
|
+
# ## Parameters (conditionally required):
|
125
|
+
# - picture_type [string]: picture MIME type. This parameter will be required if the picture parameter is informed ex: 'image/png' or 'image/jpeg'
|
126
|
+
#
|
115
127
|
# ## Parameters (optional):
|
116
128
|
# - username [string, default nil]: query by the simplified name that defines the workspace URL. This name is always unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
|
117
129
|
# - name [string, default nil]: Full name that identifies the Workspace. This name will appear when people access the Workspace on our platform, for example. Ex: 'Stark Bank Workspace'
|
118
130
|
# - allowed_tax_ids [list of strings, default nil]: list of tax IDs that will be allowed to send Deposits to this Workspace. If empty, all are allowed. ex: ['012.345.678-90', '20.018.183/0001-80']
|
131
|
+
# - status [string, default nil]: current Workspace status. Options: 'active' or 'blocked'
|
132
|
+
# - picture [bytes, default nil]: Binary buffer of the picture. ex: open('/path/to/file.png', 'rb').read()
|
119
133
|
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
120
134
|
#
|
121
135
|
# ## Return:
|
122
136
|
# - updated Workspace object
|
123
|
-
def self.update(id,
|
124
|
-
|
137
|
+
def self.update(id, username: nil, name: nil, allowed_tax_ids: nil, status: nil, picture: nil, picture_type: nil, user: nil)
|
138
|
+
|
139
|
+
payload = {
|
140
|
+
'allowed_tax_ids': allowed_tax_ids,
|
141
|
+
'status': status,
|
142
|
+
}
|
143
|
+
|
144
|
+
unless picture.nil?
|
145
|
+
payload['picture'] = "data:#{picture_type};base64,#{Base64.encode64(picture)}"
|
146
|
+
end
|
147
|
+
|
148
|
+
StarkBank::Utils::Rest.patch_id(id: id, user: user, username: username, name: name, **payload, **resource)
|
125
149
|
end
|
126
150
|
|
127
151
|
def self.resource
|
@@ -132,7 +156,11 @@ module StarkBank
|
|
132
156
|
id: json['id'],
|
133
157
|
username: json['username'],
|
134
158
|
name: json['name'],
|
135
|
-
allowed_tax_ids: json['allowed_tax_ids']
|
159
|
+
allowed_tax_ids: json['allowed_tax_ids'],
|
160
|
+
status: json['status'],
|
161
|
+
organization_id: json['organization_id'],
|
162
|
+
picture_url: json['picture_url'],
|
163
|
+
created: json['created']
|
136
164
|
)
|
137
165
|
}
|
138
166
|
}
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: starkbank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- starkbank
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: starkcore
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
19
|
+
version: 0.0.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
26
|
+
version: 0.0.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,8 +66,8 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.81'
|
69
|
-
description:
|
70
|
-
email:
|
69
|
+
description:
|
70
|
+
email:
|
71
71
|
executables: []
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
@@ -81,12 +81,13 @@ files:
|
|
81
81
|
- lib/boleto_payment/log.rb
|
82
82
|
- lib/brcode_payment/brcode_payment.rb
|
83
83
|
- lib/brcode_payment/log.rb
|
84
|
-
- lib/
|
84
|
+
- lib/brcode_payment/rule.rb
|
85
85
|
- lib/darf_payment/darf_payment.rb
|
86
86
|
- lib/darf_payment/log.rb
|
87
87
|
- lib/deposit/deposit.rb
|
88
88
|
- lib/deposit/log.rb
|
89
89
|
- lib/dict_key/dict_key.rb
|
90
|
+
- lib/dynamic_brcode/dynamic_brcode.rb
|
90
91
|
- lib/error.rb
|
91
92
|
- lib/event/attempt.rb
|
92
93
|
- lib/event/event.rb
|
@@ -94,36 +95,30 @@ files:
|
|
94
95
|
- lib/invoice/invoice.rb
|
95
96
|
- lib/invoice/log.rb
|
96
97
|
- lib/invoice/payment.rb
|
97
|
-
- lib/
|
98
|
+
- lib/payment_preview/boleto_preview.rb
|
99
|
+
- lib/payment_preview/brcode_preview.rb
|
100
|
+
- lib/payment_preview/payment_preview.rb
|
101
|
+
- lib/payment_preview/tax_preview.rb
|
102
|
+
- lib/payment_preview/utility_preview.rb
|
98
103
|
- lib/payment_request/payment_request.rb
|
99
104
|
- lib/starkbank.rb
|
100
105
|
- lib/tax_payment/log.rb
|
101
106
|
- lib/tax_payment/tax_payment.rb
|
102
107
|
- lib/transaction/transaction.rb
|
103
108
|
- lib/transfer/log.rb
|
109
|
+
- lib/transfer/rule.rb
|
104
110
|
- lib/transfer/transfer.rb
|
105
|
-
- lib/user/organization.rb
|
106
|
-
- lib/user/project.rb
|
107
|
-
- lib/user/user.rb
|
108
111
|
- lib/utility_payment/log.rb
|
109
112
|
- lib/utility_payment/utility_payment.rb
|
110
|
-
- lib/utils/
|
111
|
-
- lib/utils/cache.rb
|
112
|
-
- lib/utils/case.rb
|
113
|
-
- lib/utils/checks.rb
|
114
|
-
- lib/utils/environment.rb
|
115
|
-
- lib/utils/request.rb
|
116
|
-
- lib/utils/resource.rb
|
113
|
+
- lib/utils/parse.rb
|
117
114
|
- lib/utils/rest.rb
|
118
|
-
- lib/utils/sub_resource.rb
|
119
|
-
- lib/utils/url.rb
|
120
115
|
- lib/webhook/webhook.rb
|
121
116
|
- lib/workspace/workspace.rb
|
122
117
|
homepage: https://github.com/starkbank/sdk-ruby
|
123
118
|
licenses:
|
124
119
|
- MIT
|
125
120
|
metadata: {}
|
126
|
-
post_install_message:
|
121
|
+
post_install_message:
|
127
122
|
rdoc_options: []
|
128
123
|
require_paths:
|
129
124
|
- lib
|
@@ -138,8 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
133
|
- !ruby/object:Gem::Version
|
139
134
|
version: '0'
|
140
135
|
requirements: []
|
141
|
-
rubygems_version: 3.1
|
142
|
-
signing_key:
|
136
|
+
rubygems_version: 3.0.3.1
|
137
|
+
signing_key:
|
143
138
|
specification_version: 4
|
144
139
|
summary: SDK to facilitate Ruby integrations with Stark Bank
|
145
140
|
test_files: []
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative('../utils/resource')
|
4
|
-
require_relative('../utils/rest')
|
5
|
-
require_relative('../utils/checks')
|
6
|
-
|
7
|
-
module StarkBank
|
8
|
-
# # BrcodePreview object
|
9
|
-
#
|
10
|
-
# A BrcodePreview is used to get information from a BR Code you received to check the informations before paying it.
|
11
|
-
#
|
12
|
-
# ## Attributes (return-only):
|
13
|
-
# - status [string]: Payment status. ex: 'active', 'paid', 'canceled' or 'unknown'
|
14
|
-
# - name [string]: Payment receiver name. ex: 'Tony Stark'
|
15
|
-
# - tax_id [string]: Payment receiver tax ID. ex: '012.345.678-90'
|
16
|
-
# - bank_code [string]: Payment receiver bank code. ex: '20018183'
|
17
|
-
# - branch_code [string]: Payment receiver branch code. ex: '0001'
|
18
|
-
# - account_number [string]: Payment receiver account number. ex: '1234567'
|
19
|
-
# - account_type [string]: Payment receiver account type. ex: 'checking'
|
20
|
-
# - allow_change [bool]: If True, the payment is able to receive amounts that are diferent from the nominal one. ex: True or False
|
21
|
-
# - amount [integer]: Value in cents that this payment is expecting to receive. If 0, any value is accepted. ex: 123 (= R$1,23)
|
22
|
-
# - reconciliation_id [string]: Reconciliation ID linked to this payment. ex: 'txId', 'payment-123'
|
23
|
-
class BrcodePreview < StarkBank::Utils::Resource
|
24
|
-
attr_reader :status, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :allow_change, :amount, :reconciliation_id
|
25
|
-
def initialize(status:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, allow_change:, amount:, reconciliation_id:)
|
26
|
-
@status = status
|
27
|
-
@name = name
|
28
|
-
@tax_id = tax_id
|
29
|
-
@bank_code = bank_code
|
30
|
-
@branch_code = branch_code
|
31
|
-
@account_number = account_number
|
32
|
-
@account_type = account_type
|
33
|
-
@allow_change = allow_change
|
34
|
-
@amount = amount
|
35
|
-
@reconciliation_id = reconciliation_id
|
36
|
-
end
|
37
|
-
|
38
|
-
# # Retrieve BrcodePreviews
|
39
|
-
#
|
40
|
-
# Receive a generator of BrcodePreview objects previously created in the Stark Bank API
|
41
|
-
#
|
42
|
-
# ## Parameters (optional):
|
43
|
-
# - brcodes [list of strings]: List of brcodes to preview. ex: %w[00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A]
|
44
|
-
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
45
|
-
#
|
46
|
-
# ## Return:
|
47
|
-
# - generator of BrcodePreview objects with updated attributes
|
48
|
-
def self.query(limit: nil, brcodes: nil, user: nil)
|
49
|
-
StarkBank::Utils::Rest.get_stream(
|
50
|
-
user: user,
|
51
|
-
limit: nil,
|
52
|
-
brcodes: brcodes,
|
53
|
-
**resource
|
54
|
-
)
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.resource
|
58
|
-
{
|
59
|
-
resource_name: 'BrcodePreview',
|
60
|
-
resource_maker: proc { |json|
|
61
|
-
BrcodePreview.new(
|
62
|
-
status: json['status'],
|
63
|
-
name: json['name'],
|
64
|
-
tax_id: json['tax_id'],
|
65
|
-
bank_code: json['bank_code'],
|
66
|
-
branch_code: json['branch_code'],
|
67
|
-
account_number: json['account_number'],
|
68
|
-
account_type: json['account_type'],
|
69
|
-
allow_change: json['allow_change'],
|
70
|
-
amount: json['amount'],
|
71
|
-
reconciliation_id: json['reconciliation_id']
|
72
|
-
)
|
73
|
-
}
|
74
|
-
}
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
data/lib/key.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require('fileutils')
|
4
|
-
require('starkbank-ecdsa')
|
5
|
-
|
6
|
-
module StarkBank
|
7
|
-
module Key
|
8
|
-
# # Generate a new key pair
|
9
|
-
# Generates a secp256k1 ECDSA private/public key pair to be used in the API
|
10
|
-
# authentications
|
11
|
-
#
|
12
|
-
# ## Parameters (optional):
|
13
|
-
# - path [string]: path to save the keys .pem files. No files will be saved if this parameter isn't provided
|
14
|
-
#
|
15
|
-
# ## Return:
|
16
|
-
# - private and public key pems
|
17
|
-
def self.create(path = nil)
|
18
|
-
private_key = EllipticCurve::PrivateKey.new
|
19
|
-
public_key = private_key.publicKey
|
20
|
-
|
21
|
-
private_key_pem = private_key.toPem
|
22
|
-
public_key_pem = public_key.toPem
|
23
|
-
|
24
|
-
unless path.nil?
|
25
|
-
FileUtils.mkdir_p(path)
|
26
|
-
File.write(File.join(path, 'private.pem'), private_key_pem)
|
27
|
-
File.write(File.join(path, 'public.pem'), public_key_pem)
|
28
|
-
end
|
29
|
-
|
30
|
-
[private_key_pem, public_key_pem]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/user/organization.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative('user')
|
4
|
-
|
5
|
-
module StarkBank
|
6
|
-
# # Organization object
|
7
|
-
# The Organization object is an authentication entity for the SDK that
|
8
|
-
# represents your entire Organization, being able to access any Workspace
|
9
|
-
# underneath it and even create new Workspaces. Only a legal representative
|
10
|
-
# of your organization can register or change the Organization credentials.
|
11
|
-
# All requests to the Stark Bank API must be authenticated via an SDK user,
|
12
|
-
# which must have been previously created at the Stark Bank website
|
13
|
-
# [https://web.sandbox.starkbank.com] or [https://web.starkbank.com]
|
14
|
-
# before you can use it in this SDK. Organizations may be passed as the user parameter on
|
15
|
-
# each request or may be defined as the default user at the start (See README).
|
16
|
-
# If you are accessing a specific Workspace using Organization credentials, you should
|
17
|
-
# specify the workspace ID when building the Organization object or by request, using
|
18
|
-
# the Organization.replace(organization, workspace_id) method, which creates a copy of the organization
|
19
|
-
# object with the altered workspace ID. If you are listing or creating new Workspaces, the
|
20
|
-
# workspace_id should be nil.
|
21
|
-
#
|
22
|
-
# ## Parameters (required):
|
23
|
-
# - environment [string]: environment where the organization is being used. ex: 'sandbox' or 'production'
|
24
|
-
# - id [string]: unique id required to identify organization. ex: '5656565656565656'
|
25
|
-
# - private_key [string]: PEM string of the private key linked to the organization. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
|
26
|
-
# - workspace_id [string]: unique id of the accessed Workspace, if any. ex: nil or '4848484848484848'
|
27
|
-
#
|
28
|
-
# ## Attributes (return-only):
|
29
|
-
# - pem [string]: private key in pem format. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
|
30
|
-
class Organization < StarkBank::User
|
31
|
-
attr_reader :workspace_id
|
32
|
-
def initialize(id:, environment:, private_key:, workspace_id: nil)
|
33
|
-
super(environment, id, private_key)
|
34
|
-
@workspace_id = workspace_id
|
35
|
-
end
|
36
|
-
|
37
|
-
def access_id
|
38
|
-
if @workspace_id
|
39
|
-
"organization/#{@id}/workspace/#{@workspace_id}"
|
40
|
-
else
|
41
|
-
"organization/#{@id}"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.replace(organization, workspace_id)
|
46
|
-
Organization.new(
|
47
|
-
environment: organization.environment,
|
48
|
-
id: organization.id,
|
49
|
-
private_key: organization.pem,
|
50
|
-
workspace_id: workspace_id
|
51
|
-
)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/lib/user/project.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative('user')
|
4
|
-
|
5
|
-
module StarkBank
|
6
|
-
# # Project object
|
7
|
-
#
|
8
|
-
# The Project object is an authentication entity for the SDK that is permanently
|
9
|
-
# linked to a specific Workspace.
|
10
|
-
# All requests to the Stark Bank API must be authenticated via an SDK user,
|
11
|
-
# which must have been previously created at the Stark Bank website
|
12
|
-
# [https://web.sandbox.starkbank.com] or [https://web.starkbank.com]
|
13
|
-
# before you can use it in this SDK. Projects may be passed as the user parameter on
|
14
|
-
# each request or may be defined as the default user at the start (See README).
|
15
|
-
#
|
16
|
-
# ## Parameters (required):
|
17
|
-
# - id [string]: unique id required to identify project. ex: '5656565656565656'
|
18
|
-
# - private_key [string]: PEM string of the private key linked to the project. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
|
19
|
-
# - environment [string]: environment where the project is being used. ex: 'sandbox' or 'production'
|
20
|
-
#
|
21
|
-
# ## Attributes (return-only):
|
22
|
-
# - name [string, default '']: project name. ex: 'MyProject'
|
23
|
-
# - allowed_ips [list of strings]: list containing the strings of the ips allowed to make requests on behalf of this project. ex: ['190.190.0.50']
|
24
|
-
# - pem [string]: private key in pem format. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
|
25
|
-
class Project < StarkBank::User
|
26
|
-
attr_reader :name, :allowed_ips
|
27
|
-
def initialize(environment:, id:, private_key:, name: '', allowed_ips: nil)
|
28
|
-
super(environment, id, private_key)
|
29
|
-
@name = name
|
30
|
-
@allowed_ips = allowed_ips
|
31
|
-
end
|
32
|
-
|
33
|
-
def access_id
|
34
|
-
"project/#{@id}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/user/user.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require('starkbank-ecdsa')
|
4
|
-
require_relative('../utils/resource')
|
5
|
-
|
6
|
-
module StarkBank
|
7
|
-
class User < StarkBank::Utils::Resource
|
8
|
-
attr_reader :pem, :environment
|
9
|
-
def initialize(environment, id, private_key)
|
10
|
-
require_relative('../utils/checks')
|
11
|
-
super(id)
|
12
|
-
@pem = StarkBank::Utils::Checks.check_private_key(private_key)
|
13
|
-
@environment = StarkBank::Utils::Checks.check_environment(environment)
|
14
|
-
end
|
15
|
-
|
16
|
-
def private_key
|
17
|
-
EllipticCurve::PrivateKey.fromPem(@pem)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/utils/api.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative('case')
|
4
|
-
|
5
|
-
module StarkBank
|
6
|
-
module Utils
|
7
|
-
module API
|
8
|
-
def self.build_entity_hash(entity)
|
9
|
-
if entity.is_a?(Hash)
|
10
|
-
entity_hash = entity
|
11
|
-
else
|
12
|
-
entity_hash = {}
|
13
|
-
entity.instance_variables.each do |key|
|
14
|
-
variable = entity.instance_variable_get(key)
|
15
|
-
entity_hash[key[1..-1]] = variable.is_a?(StarkBank::Utils::Resource) ? build_entity_hash(variable) : entity.instance_variable_get(key)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
entity_hash
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.api_json(entity)
|
22
|
-
built_hash = build_entity_hash(entity)
|
23
|
-
cast_json_to_api_format(built_hash)
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.cast_json_to_api_format(hash)
|
27
|
-
entity_hash = {}
|
28
|
-
hash.each do |key, value|
|
29
|
-
next if value.nil?
|
30
|
-
|
31
|
-
entity_hash[StarkBank::Utils::Case.snake_to_camel(key)] = parse_value(value)
|
32
|
-
end
|
33
|
-
entity_hash
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.parse_value(value)
|
37
|
-
return value.strftime('%Y-%m-%d') if value.is_a?(Date)
|
38
|
-
return value.strftime('%Y-%m-%dT%H:%M:%S+00:00') if value.is_a?(DateTime) || value.is_a?(Time)
|
39
|
-
return cast_json_to_api_format(value) if value.is_a?(Hash)
|
40
|
-
return value unless value.is_a?(Array)
|
41
|
-
|
42
|
-
list = []
|
43
|
-
value.each do |v|
|
44
|
-
list << (v.is_a?(Hash) ? cast_json_to_api_format(v) : v)
|
45
|
-
end
|
46
|
-
list
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.from_api_json(resource_maker, json)
|
50
|
-
snakes = {}
|
51
|
-
json.each do |key, value|
|
52
|
-
snakes[StarkBank::Utils::Case.camel_to_snake(key)] = value
|
53
|
-
end
|
54
|
-
resource_maker.call(snakes)
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.endpoint(resource_name)
|
58
|
-
kebab = StarkBank::Utils::Case.camel_to_kebab(resource_name)
|
59
|
-
kebab.sub!('-log', '/log')
|
60
|
-
kebab.sub!('-attempt', '/attempt')
|
61
|
-
kebab
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.last_name_plural(resource_name)
|
65
|
-
base = last_name(resource_name)
|
66
|
-
|
67
|
-
return base if base[-1].eql?('s')
|
68
|
-
return "#{base}s" if base[-2..-1].eql?('ey')
|
69
|
-
return "#{base[0...-1]}ies" if base[-1].eql?('y')
|
70
|
-
|
71
|
-
"#{base}s"
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.last_name(resource_name)
|
75
|
-
StarkBank::Utils::Case.camel_to_kebab(resource_name).split('-').last
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
data/lib/utils/cache.rb
DELETED
data/lib/utils/case.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module StarkBank
|
4
|
-
module Utils
|
5
|
-
module Case
|
6
|
-
def self.camel_to_snake(camel)
|
7
|
-
camel.to_s.gsub(/([a-z])([A-Z\d])/, '\1_\2').downcase
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.snake_to_camel(snake)
|
11
|
-
camel = snake.to_s.split('_').map(&:capitalize).join
|
12
|
-
camel[0] = camel[0].downcase
|
13
|
-
camel
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.camel_to_kebab(camel)
|
17
|
-
camel_to_snake(camel).tr('_', '-')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/utils/checks.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require('date')
|
4
|
-
require('starkbank-ecdsa')
|
5
|
-
require_relative('environment')
|
6
|
-
require_relative('../user/user')
|
7
|
-
|
8
|
-
module StarkBank
|
9
|
-
module Utils
|
10
|
-
class Checks
|
11
|
-
def self.check_user(user)
|
12
|
-
return user if user.is_a?(StarkBank::User)
|
13
|
-
|
14
|
-
user = user.nil? ? StarkBank.user : user
|
15
|
-
raise(ArgumentError, 'A user is required to access our API. Check our README: https://github.com/starkbank/sdk-ruby/') if user.nil?
|
16
|
-
|
17
|
-
user
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.check_language
|
21
|
-
language = StarkBank.language
|
22
|
-
accepted_languages = %w[en-US pt-BR]
|
23
|
-
raise(ArgumentError, "Select a valid language: #{accepted_languages.join(', ')}") unless accepted_languages.include?(language)
|
24
|
-
|
25
|
-
language
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.check_environment(environment)
|
29
|
-
environments = StarkBank::Utils::Environment.constants(false).map { |c| StarkBank::Utils::Environment.const_get(c) }
|
30
|
-
raise(ArgumentError, "Select a valid environment: #{environments.join(', ')}") unless environments.include?(environment)
|
31
|
-
|
32
|
-
environment
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.check_private_key(pem)
|
36
|
-
EllipticCurve::PrivateKey.fromPem(pem)
|
37
|
-
pem
|
38
|
-
rescue
|
39
|
-
raise(ArgumentError, 'Private-key must be a valid secp256k1 ECDSA string in pem format')
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.check_date_or_datetime(data)
|
43
|
-
return if data.nil?
|
44
|
-
|
45
|
-
return data if data.is_a?(Time) || data.is_a?(DateTime)
|
46
|
-
|
47
|
-
return data if data.is_a?(Date)
|
48
|
-
|
49
|
-
data, type = check_datetime_string(data)
|
50
|
-
type == 'date' ? Date.new(data.year, data.month, data.day) : data
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.check_datetime(data)
|
54
|
-
return if data.nil?
|
55
|
-
|
56
|
-
return data if data.is_a?(Time) || data.is_a?(DateTime)
|
57
|
-
|
58
|
-
return Time.new(data.year, data.month, data.day) if data.is_a?(Date)
|
59
|
-
|
60
|
-
data, _type = check_datetime_string(data)
|
61
|
-
data
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.check_date(data)
|
65
|
-
return if data.nil?
|
66
|
-
|
67
|
-
return Date.new(data.year, data.month, data.day) if data.is_a?(Time) || data.is_a?(DateTime)
|
68
|
-
|
69
|
-
return data if data.is_a?(Date)
|
70
|
-
|
71
|
-
data, type = check_datetime_string(data)
|
72
|
-
|
73
|
-
type == 'date' ? Date.new(data.year, data.month, data.day) : data
|
74
|
-
end
|
75
|
-
|
76
|
-
class << self
|
77
|
-
private
|
78
|
-
|
79
|
-
def check_datetime_string(data)
|
80
|
-
data = data.to_s
|
81
|
-
|
82
|
-
begin
|
83
|
-
return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S.%L+00:00'), 'datetime']
|
84
|
-
rescue ArgumentError
|
85
|
-
end
|
86
|
-
|
87
|
-
begin
|
88
|
-
return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S+00:00'), 'datetime']
|
89
|
-
rescue ArgumentError
|
90
|
-
end
|
91
|
-
|
92
|
-
begin
|
93
|
-
return [DateTime.strptime(data, '%Y-%m-%d'), 'date']
|
94
|
-
rescue ArgumentError
|
95
|
-
raise(ArgumentError, 'invalid datetime string ' + data)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|