starkinfra 0.4.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/lib/{brcodepreview/brcodepreview.rb → brcode_preview/brcode_preview.rb} +2 -5
  3. data/lib/{cardmethod/cardmethod.rb → card_method/card_method.rb} +2 -2
  4. data/lib/{creditholmes/creditholmes.rb → credit_holmes/credit_holmes.rb} +8 -11
  5. data/lib/{creditnote/creditnote.rb → credit_note/credit_note.rb} +11 -12
  6. data/lib/{creditnote → credit_note}/invoice/description.rb +3 -5
  7. data/lib/{creditnote → credit_note}/invoice/discount.rb +3 -4
  8. data/lib/{creditnote → credit_note}/invoice/invoice.rb +5 -6
  9. data/lib/{creditnote → credit_note}/log.rb +9 -10
  10. data/lib/{creditnote → credit_note}/transfer.rb +4 -5
  11. data/lib/{creditpreview/creditnotepreview.rb → credit_preview/credit_note_preview.rb} +2 -3
  12. data/lib/{creditpreview/creditpreview.rb → credit_preview/credit_preview.rb} +3 -4
  13. data/lib/{creditsigner/creditsigner.rb → credit_signer/credit_signer.rb} +3 -6
  14. data/lib/{dynamicbrcode/dynamicbrcode.rb → dynamic_brcode/dynamic_brcode.rb} +17 -19
  15. data/lib/error.rb +7 -40
  16. data/lib/event/attempt.rb +7 -8
  17. data/lib/event/event.rb +10 -13
  18. data/lib/{individualdocument/individualdocument.rb → individual_document/individual_document.rb} +7 -8
  19. data/lib/{individualdocument → individual_document}/log.rb +9 -10
  20. data/lib/{individualidentity/individualidentity.rb → individual_identity/individual_identity.rb} +7 -8
  21. data/lib/{individualidentity → individual_identity}/log.rb +9 -10
  22. data/lib/{issuingbalance/issuingbalance.rb → issuing_balance/issuing_balance.rb} +2 -3
  23. data/lib/{issuingcard/issuingcard.rb → issuing_card/issuing_card.rb} +9 -10
  24. data/lib/{issuingcard → issuing_card}/log.rb +9 -10
  25. data/lib/{issuingdesign/issuingdesign.rb → issuing_design/issuing_design.rb} +5 -6
  26. data/lib/{issuingembossingkit/issuingembossingkit.rb → issuing_embossing_kit/issuing_embossing_kit.rb} +4 -5
  27. data/lib/{issuingembossingrequest/issuingembossingrequest.rb → issuing_embossing_request/issuing_embossing_request.rb} +8 -9
  28. data/lib/{issuingembossingrequest → issuing_embossing_request}/log.rb +9 -10
  29. data/lib/{issuingholder/issuingholder.rb → issuing_holder/issuing_holder.rb} +9 -10
  30. data/lib/{issuingholder → issuing_holder}/log.rb +9 -10
  31. data/lib/{issuinginvoice/issuinginvoice.rb → issuing_invoice/issuing_invoice.rb} +8 -9
  32. data/lib/{issuinginvoice → issuing_invoice}/log.rb +9 -10
  33. data/lib/{issuingproduct/issuingproduct.rb → issuing_product/issuing_product.rb} +3 -4
  34. data/lib/{issuingpurchase/issuingpurchase.rb → issuing_purchase/issuing_purchase.rb} +32 -24
  35. data/lib/{issuingpurchase → issuing_purchase}/log.rb +9 -10
  36. data/lib/{issuingrestock/issuingrestock.rb → issuing_restock/issuing_restock.rb} +8 -9
  37. data/lib/{issuingrestock → issuing_restock}/log.rb +9 -10
  38. data/lib/{issuingrule/issuingrule.rb → issuing_rule/issuing_rule.rb} +6 -7
  39. data/lib/{issuingstock/issuingstock.rb → issuing_stock/issuing_stock.rb} +8 -9
  40. data/lib/{issuingstock → issuing_stock}/log.rb +9 -10
  41. data/lib/{issuingtransaction/issuingtransaction.rb → issuing_transaction/issuing_transaction.rb} +7 -8
  42. data/lib/{issuingwithdrawal/issuingwithdrawal.rb → issuing_withdrawal/issuing_withdrawal.rb} +8 -9
  43. data/lib/{merchantcategory/merchantcategory.rb → merchant_category/merchant_category.rb} +2 -2
  44. data/lib/{merchantcountry/merchantcountry.rb → merchant_country/merchant_country.rb} +2 -2
  45. data/lib/{pixbalance/pixbalance.rb → pix_balance/pix_balance.rb} +2 -3
  46. data/lib/{pixchargeback → pix_chargeback}/log.rb +9 -10
  47. data/lib/{pixchargeback/pixchargeback.rb → pix_chargeback/pix_chargeback.rb} +8 -9
  48. data/lib/{pixclaim → pix_claim}/log.rb +9 -10
  49. data/lib/{pixclaim/pixclaim.rb → pix_claim/pix_claim.rb} +8 -9
  50. data/lib/{pixdirector/pixdirector.rb → pix_director/pix_director.rb} +2 -2
  51. data/lib/{pixdomain → pix_domain}/certificate.rb +2 -2
  52. data/lib/{pixdomain/pixdomain.rb → pix_domain/pix_domain.rb} +3 -3
  53. data/lib/{pixinfraction → pix_infraction}/log.rb +9 -10
  54. data/lib/{pixinfraction/pixinfraction.rb → pix_infraction/pix_infraction.rb} +8 -9
  55. data/lib/{pixkey → pix_key}/log.rb +9 -10
  56. data/lib/{pixkey/pixkey.rb → pix_key/pix_key.rb} +8 -9
  57. data/lib/{pixrequest → pix_request}/log.rb +9 -10
  58. data/lib/{pixrequest/pixrequest.rb → pix_request/pix_request.rb} +9 -10
  59. data/lib/{pixreversal → pix_reversal}/log.rb +8 -10
  60. data/lib/{pixreversal/pixreversal.rb → pix_reversal/pix_reversal.rb} +9 -10
  61. data/lib/{pixstatement/pixstatement.rb → pix_statement/pix_statement.rb} +6 -7
  62. data/lib/request/request.rb +152 -0
  63. data/lib/starkinfra.rb +71 -63
  64. data/lib/{staticbrcode/staticbrcode.rb → static_brcode/static_brcode.rb} +8 -9
  65. data/lib/utils/parse.rb +23 -42
  66. data/lib/utils/rest.rb +211 -110
  67. data/lib/webhook/webhook.rb +2 -3
  68. metadata +70 -85
  69. data/lib/key.rb +0 -33
  70. data/lib/user/organization.rb +0 -54
  71. data/lib/user/project.rb +0 -37
  72. data/lib/user/user.rb +0 -20
  73. data/lib/utils/api.rb +0 -89
  74. data/lib/utils/bacenid.rb +0 -19
  75. data/lib/utils/cache.rb +0 -10
  76. data/lib/utils/case.rb +0 -21
  77. data/lib/utils/checks.rb +0 -100
  78. data/lib/utils/endtoendid.rb +0 -11
  79. data/lib/utils/environment.rb +0 -14
  80. data/lib/utils/request.rb +0 -79
  81. data/lib/utils/resource.rb +0 -13
  82. data/lib/utils/returnid.rb +0 -11
  83. data/lib/utils/sub_resource.rb +0 -27
  84. data/lib/utils/url.rb +0 -28
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starkinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - starkinfra
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-20 00:00:00.000000000 Z
11
+ date: 2024-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: starkbank-ecdsa
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.5
19
+ version: 0.2.2
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.5
26
+ version: 0.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,98 +66,83 @@ 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: []
74
74
  files:
75
- - lib/brcodepreview/brcodepreview.rb
76
- - lib/cardmethod/cardmethod.rb
77
- - lib/creditholmes/creditholmes.rb
78
- - lib/creditnote/creditnote.rb
79
- - lib/creditnote/invoice/description.rb
80
- - lib/creditnote/invoice/discount.rb
81
- - lib/creditnote/invoice/invoice.rb
82
- - lib/creditnote/log.rb
83
- - lib/creditnote/transfer.rb
84
- - lib/creditpreview/creditnotepreview.rb
85
- - lib/creditpreview/creditpreview.rb
86
- - lib/creditsigner/creditsigner.rb
87
- - lib/dynamicbrcode/dynamicbrcode.rb
75
+ - lib/brcode_preview/brcode_preview.rb
76
+ - lib/card_method/card_method.rb
77
+ - lib/credit_holmes/credit_holmes.rb
78
+ - lib/credit_note/credit_note.rb
79
+ - lib/credit_note/invoice/description.rb
80
+ - lib/credit_note/invoice/discount.rb
81
+ - lib/credit_note/invoice/invoice.rb
82
+ - lib/credit_note/log.rb
83
+ - lib/credit_note/transfer.rb
84
+ - lib/credit_preview/credit_note_preview.rb
85
+ - lib/credit_preview/credit_preview.rb
86
+ - lib/credit_signer/credit_signer.rb
87
+ - lib/dynamic_brcode/dynamic_brcode.rb
88
88
  - lib/error.rb
89
89
  - lib/event/attempt.rb
90
90
  - lib/event/event.rb
91
- - lib/individualdocument/individualdocument.rb
92
- - lib/individualdocument/log.rb
93
- - lib/individualidentity/individualidentity.rb
94
- - lib/individualidentity/log.rb
95
- - lib/issuingbalance/issuingbalance.rb
96
- - lib/issuingcard/issuingcard.rb
97
- - lib/issuingcard/log.rb
98
- - lib/issuingdesign/issuingdesign.rb
99
- - lib/issuingembossingkit/issuingembossingkit.rb
100
- - lib/issuingembossingrequest/issuingembossingrequest.rb
101
- - lib/issuingembossingrequest/log.rb
102
- - lib/issuingholder/issuingholder.rb
103
- - lib/issuingholder/log.rb
104
- - lib/issuinginvoice/issuinginvoice.rb
105
- - lib/issuinginvoice/log.rb
106
- - lib/issuingproduct/issuingproduct.rb
107
- - lib/issuingpurchase/issuingpurchase.rb
108
- - lib/issuingpurchase/log.rb
109
- - lib/issuingrestock/issuingrestock.rb
110
- - lib/issuingrestock/log.rb
111
- - lib/issuingrule/issuingrule.rb
112
- - lib/issuingstock/issuingstock.rb
113
- - lib/issuingstock/log.rb
114
- - lib/issuingtransaction/issuingtransaction.rb
115
- - lib/issuingwithdrawal/issuingwithdrawal.rb
116
- - lib/key.rb
117
- - lib/merchantcategory/merchantcategory.rb
118
- - lib/merchantcountry/merchantcountry.rb
119
- - lib/pixbalance/pixbalance.rb
120
- - lib/pixchargeback/log.rb
121
- - lib/pixchargeback/pixchargeback.rb
122
- - lib/pixclaim/log.rb
123
- - lib/pixclaim/pixclaim.rb
124
- - lib/pixdirector/pixdirector.rb
125
- - lib/pixdomain/certificate.rb
126
- - lib/pixdomain/pixdomain.rb
127
- - lib/pixinfraction/log.rb
128
- - lib/pixinfraction/pixinfraction.rb
129
- - lib/pixkey/log.rb
130
- - lib/pixkey/pixkey.rb
131
- - lib/pixrequest/log.rb
132
- - lib/pixrequest/pixrequest.rb
133
- - lib/pixreversal/log.rb
134
- - lib/pixreversal/pixreversal.rb
135
- - lib/pixstatement/pixstatement.rb
91
+ - lib/individual_document/individual_document.rb
92
+ - lib/individual_document/log.rb
93
+ - lib/individual_identity/individual_identity.rb
94
+ - lib/individual_identity/log.rb
95
+ - lib/issuing_balance/issuing_balance.rb
96
+ - lib/issuing_card/issuing_card.rb
97
+ - lib/issuing_card/log.rb
98
+ - lib/issuing_design/issuing_design.rb
99
+ - lib/issuing_embossing_kit/issuing_embossing_kit.rb
100
+ - lib/issuing_embossing_request/issuing_embossing_request.rb
101
+ - lib/issuing_embossing_request/log.rb
102
+ - lib/issuing_holder/issuing_holder.rb
103
+ - lib/issuing_holder/log.rb
104
+ - lib/issuing_invoice/issuing_invoice.rb
105
+ - lib/issuing_invoice/log.rb
106
+ - lib/issuing_product/issuing_product.rb
107
+ - lib/issuing_purchase/issuing_purchase.rb
108
+ - lib/issuing_purchase/log.rb
109
+ - lib/issuing_restock/issuing_restock.rb
110
+ - lib/issuing_restock/log.rb
111
+ - lib/issuing_rule/issuing_rule.rb
112
+ - lib/issuing_stock/issuing_stock.rb
113
+ - lib/issuing_stock/log.rb
114
+ - lib/issuing_transaction/issuing_transaction.rb
115
+ - lib/issuing_withdrawal/issuing_withdrawal.rb
116
+ - lib/merchant_category/merchant_category.rb
117
+ - lib/merchant_country/merchant_country.rb
118
+ - lib/pix_balance/pix_balance.rb
119
+ - lib/pix_chargeback/log.rb
120
+ - lib/pix_chargeback/pix_chargeback.rb
121
+ - lib/pix_claim/log.rb
122
+ - lib/pix_claim/pix_claim.rb
123
+ - lib/pix_director/pix_director.rb
124
+ - lib/pix_domain/certificate.rb
125
+ - lib/pix_domain/pix_domain.rb
126
+ - lib/pix_infraction/log.rb
127
+ - lib/pix_infraction/pix_infraction.rb
128
+ - lib/pix_key/log.rb
129
+ - lib/pix_key/pix_key.rb
130
+ - lib/pix_request/log.rb
131
+ - lib/pix_request/pix_request.rb
132
+ - lib/pix_reversal/log.rb
133
+ - lib/pix_reversal/pix_reversal.rb
134
+ - lib/pix_statement/pix_statement.rb
135
+ - lib/request/request.rb
136
136
  - lib/starkinfra.rb
137
- - lib/staticbrcode/staticbrcode.rb
138
- - lib/user/organization.rb
139
- - lib/user/project.rb
140
- - lib/user/user.rb
141
- - lib/utils/api.rb
142
- - lib/utils/bacenid.rb
143
- - lib/utils/cache.rb
144
- - lib/utils/case.rb
145
- - lib/utils/checks.rb
146
- - lib/utils/endtoendid.rb
147
- - lib/utils/environment.rb
137
+ - lib/static_brcode/static_brcode.rb
148
138
  - lib/utils/parse.rb
149
- - lib/utils/request.rb
150
- - lib/utils/resource.rb
151
139
  - lib/utils/rest.rb
152
- - lib/utils/returnid.rb
153
- - lib/utils/sub_resource.rb
154
- - lib/utils/url.rb
155
140
  - lib/webhook/webhook.rb
156
141
  homepage: https://github.com/starkinfra/sdk-ruby
157
142
  licenses:
158
143
  - MIT
159
144
  metadata: {}
160
- post_install_message:
145
+ post_install_message:
161
146
  rdoc_options: []
162
147
  require_paths:
163
148
  - lib
@@ -172,8 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
157
  - !ruby/object:Gem::Version
173
158
  version: '0'
174
159
  requirements: []
175
- rubygems_version: 3.0.3.1
176
- signing_key:
160
+ rubygems_version: 3.5.16
161
+ signing_key:
177
162
  specification_version: 4
178
163
  summary: SDK to facilitate Ruby integrations with Stark Infra
179
164
  test_files: []
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 StarkInfra
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
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative('user')
4
-
5
- module StarkInfra
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 Infra API must be authenticated via an SDK user,
12
- # which must have been previously created at the Stark Infra website
13
- # [https://web.sandbox.starkinfra.com] or [https://web.starkinfra.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 < StarkInfra::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 StarkInfra
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 Infra API must be authenticated via an SDK user,
11
- # which must have been previously created at the Stark Infra website
12
- # [https://web.sandbox.starkinfra.com] or [https://web.starkinfra.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 nil]: 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 < StarkInfra::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 StarkInfra
7
- class User < StarkInfra::Utils::Resource
8
- attr_reader :pem, :environment
9
- def initialize(environment, id, private_key)
10
- require_relative('../utils/checks')
11
- super(id)
12
- @pem = StarkInfra::Utils::Checks.check_private_key(private_key)
13
- @environment = StarkInfra::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,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative('case')
4
-
5
- module StarkInfra
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?(StarkInfra::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[StarkInfra::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 api_json(value) if value.is_a?(SubResource)
38
- return value.strftime('%Y-%m-%d') if value.is_a?(Date)
39
- return value.strftime('%Y-%m-%dT%H:%M:%S+00:00') if value.is_a?(DateTime) || value.is_a?(Time)
40
- return cast_json_to_api_format(value) if value.is_a?(Hash)
41
- return value unless value.is_a?(Array)
42
-
43
- list = []
44
- value.each do |v|
45
- if v.is_a?(Hash)
46
- list << cast_json_to_api_format(v)
47
- next
48
- end
49
- if v.is_a?(SubResource)
50
- list << api_json(v)
51
- next
52
- end
53
- list << v
54
- end
55
- list
56
- end
57
-
58
- def self.from_api_json(resource_maker, json)
59
- snakes = {}
60
- json.each do |key, value|
61
- snakes[StarkInfra::Utils::Case.camel_to_snake(key)] = value
62
- end
63
-
64
- resource_maker.call(snakes)
65
- end
66
-
67
- def self.endpoint(resource_name)
68
- kebab = StarkInfra::Utils::Case.camel_to_kebab(resource_name)
69
- kebab.sub!('-log', '/log')
70
- kebab.sub!('-attempt', '/attempt')
71
- kebab
72
- end
73
-
74
- def self.last_name_plural(resource_name)
75
- base = last_name(resource_name)
76
-
77
- return base if base[-1].eql?('s')
78
- return "#{base}s" if base[-2..-1].eql?('ey')
79
- return "#{base[0...-1]}ies" if base[-1].eql?('y')
80
-
81
- "#{base}s"
82
- end
83
-
84
- def self.last_name(resource_name)
85
- StarkInfra::Utils::Case.camel_to_kebab(resource_name).split('-').last
86
- end
87
- end
88
- end
89
- end
data/lib/utils/bacenid.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: false
2
-
3
- require('date')
4
-
5
- module StarkInfra
6
- module Utils
7
- module BacenId
8
- def self._create(bank_code)
9
- random_source = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'.split('')
10
- random_string = ''
11
-
12
- 11.times do
13
- random_string << random_source[rand(random_source.length)]
14
- end
15
- bank_code + DateTime.now.strftime('%Y%m%d%H%M').to_s << random_string
16
- end
17
- end
18
- end
19
- end
data/lib/utils/cache.rb DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module StarkInfra
4
- module Utils
5
- module Cache
6
- @starkinfra_public_key = nil
7
- class << self; attr_accessor :starkinfra_public_key; end
8
- end
9
- end
10
- end
data/lib/utils/case.rb DELETED
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module StarkInfra
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,100 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require('date')
4
- require('starkbank-ecdsa')
5
- require_relative('environment')
6
-
7
- module StarkInfra
8
- module Utils
9
- class Checks
10
- def self.check_user(user)
11
- return user if user.is_a?(StarkInfra::User)
12
-
13
- user = user.nil? ? StarkInfra.user : user
14
- raise(ArgumentError, 'A user is required to access our API. Check our README: https://github.com/starkinfra/sdk-ruby/') if user.nil?
15
-
16
- user
17
- end
18
-
19
- def self.check_language
20
- language = StarkInfra.language
21
- accepted_languages = %w[en-US pt-BR]
22
- raise(ArgumentError, "Select a valid language: #{accepted_languages.join(', ')}") unless accepted_languages.include?(language)
23
-
24
- language
25
- end
26
-
27
- def self.check_environment(environment)
28
- environments = StarkInfra::Utils::Environment.constants(false).map { |c| StarkInfra::Utils::Environment.const_get(c) }
29
- raise(ArgumentError, "Select a valid environment: #{environments.join(', ')}") unless environments.include?(environment)
30
-
31
- environment
32
- end
33
-
34
- def self.check_private_key(pem)
35
- EllipticCurve::PrivateKey.fromPem(pem)
36
- pem
37
- rescue
38
- raise(ArgumentError, 'Private-key must be a valid secp256k1 ECDSA string in pem format')
39
- end
40
-
41
- def self.check_date_or_datetime(data)
42
- return if data.nil?
43
-
44
- return data if data.is_a?(Time) || data.is_a?(DateTime)
45
-
46
- return data if data.is_a?(Date)
47
-
48
- data, type = check_datetime_string(data)
49
- type == 'date' ? Date.new(data.year, data.month, data.day) : data
50
- end
51
-
52
- def self.check_datetime(data)
53
- return if data.nil?
54
-
55
- return data if data.is_a?(Time) || data.is_a?(DateTime)
56
-
57
- return Time.new(data.year, data.month, data.day) if data.is_a?(Date)
58
-
59
- data, _type = check_datetime_string(data)
60
- data
61
- end
62
-
63
- def self.check_date(data)
64
- return if data.nil?
65
-
66
- return Date.new(data.year, data.month, data.day) if data.is_a?(Time) || data.is_a?(DateTime)
67
-
68
- return data if data.is_a?(Date)
69
-
70
- data, type = check_datetime_string(data)
71
-
72
- type == 'date' ? Date.new(data.year, data.month, data.day) : data
73
- end
74
-
75
- class << self
76
- private
77
-
78
- def check_datetime_string(data)
79
- data = data.to_s
80
-
81
- begin
82
- return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S.%L+00:00'), 'datetime']
83
- rescue ArgumentError
84
- end
85
-
86
- begin
87
- return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S+00:00'), 'datetime']
88
- rescue ArgumentError
89
- end
90
-
91
- begin
92
- [DateTime.strptime(data, '%Y-%m-%d'), 'date']
93
- rescue ArgumentError
94
- raise(ArgumentError, 'invalid datetime string ' + data)
95
- end
96
- end
97
- end
98
- end
99
- end
100
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: false
2
-
3
- require_relative('bacenid')
4
-
5
- module StarkInfra
6
- module EndToEndId
7
- def self.create(bank_code)
8
- 'E' << StarkInfra::Utils::BacenId._create(bank_code)
9
- end
10
- end
11
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module StarkInfra
4
- module Utils
5
- class Environment
6
- PRODUCTION = 'production'
7
- public_constant :PRODUCTION
8
-
9
- SANDBOX = 'sandbox'
10
- public_constant :SANDBOX
11
-
12
- end
13
- end
14
- end