starkbank 2.2.1 → 2.6.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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/balance/balance.rb +2 -2
  3. data/lib/boleto/boleto.rb +53 -14
  4. data/lib/boleto/log.rb +36 -5
  5. data/lib/boleto_holmes/boleto_holmes.rb +41 -6
  6. data/lib/boleto_holmes/log.rb +36 -5
  7. data/lib/boleto_payment/boleto_payment.rb +42 -9
  8. data/lib/boleto_payment/log.rb +36 -5
  9. data/lib/brcode_payment/brcode_payment.rb +56 -17
  10. data/lib/brcode_payment/log.rb +36 -5
  11. data/lib/brcode_preview/brcode_preview.rb +5 -3
  12. data/lib/darf_payment/darf_payment.rb +218 -0
  13. data/lib/darf_payment/log.rb +125 -0
  14. data/lib/deposit/deposit.rb +46 -8
  15. data/lib/deposit/log.rb +36 -5
  16. data/lib/dict_key/dict_key.rb +45 -9
  17. data/lib/error.rb +13 -5
  18. data/lib/event/attempt.rb +125 -0
  19. data/lib/event/event.rb +44 -8
  20. data/lib/institution/institution.rb +67 -0
  21. data/lib/invoice/invoice.rb +81 -15
  22. data/lib/invoice/log.rb +52 -5
  23. data/lib/invoice/payment.rb +57 -0
  24. data/lib/payment_preview/boleto_preview.rb +75 -0
  25. data/lib/payment_preview/brcode_preview.rb +75 -0
  26. data/lib/payment_preview/payment_preview.rb +67 -0
  27. data/lib/payment_preview/tax_preview.rb +45 -0
  28. data/lib/payment_preview/utility_preview.rb +45 -0
  29. data/lib/payment_request/payment_request.rb +53 -11
  30. data/lib/starkbank.rb +14 -0
  31. data/lib/tax_payment/log.rb +125 -0
  32. data/lib/tax_payment/tax_payment.rb +203 -0
  33. data/lib/transaction/transaction.rb +39 -6
  34. data/lib/transfer/log.rb +36 -5
  35. data/lib/transfer/transfer.rb +59 -14
  36. data/lib/user/organization.rb +54 -0
  37. data/lib/user/project.rb +11 -6
  38. data/lib/user/user.rb +0 -4
  39. data/lib/utility_payment/log.rb +36 -5
  40. data/lib/utility_payment/utility_payment.rb +42 -9
  41. data/lib/utils/api.rb +1 -0
  42. data/lib/utils/request.rb +1 -1
  43. data/lib/utils/resource.rb +2 -21
  44. data/lib/utils/rest.rb +29 -14
  45. data/lib/utils/sub_resource.rb +28 -0
  46. data/lib/utils/url.rb +3 -1
  47. data/lib/webhook/webhook.rb +30 -9
  48. data/lib/workspace/workspace.rb +141 -0
  49. metadata +22 -7
@@ -1,32 +1,13 @@
1
1
  # frozen_string_literal: true
2
+ require_relative("sub_resource")
2
3
 
3
4
  module StarkBank
4
5
  module Utils
5
- class Resource
6
+ class Resource < StarkBank::Utils::SubResource
6
7
  attr_reader :id
7
8
  def initialize(id = nil)
8
9
  @id = id
9
10
  end
10
-
11
- def to_s
12
- string_vars = []
13
- instance_variables.each do |key|
14
- value = instance_variable_get(key).to_s.lines.map(&:chomp).join("\n ")
15
- string_vars << "#{key[1..-1]}: #{value}"
16
- end
17
- fields = string_vars.join(",\n ")
18
- "#{class_name}(\n #{fields}\n)"
19
- end
20
-
21
- def inspect
22
- "#{class_name}[#{@id}]"
23
- end
24
-
25
- private
26
-
27
- def class_name
28
- self.class.name.split('::').last.downcase
29
- end
30
11
  end
31
12
  end
32
13
  end
data/lib/utils/rest.rb CHANGED
@@ -6,7 +6,21 @@ require_relative('api')
6
6
  module StarkBank
7
7
  module Utils
8
8
  module Rest
9
- def self.get_list(resource_name:, resource_maker:, user: nil, **query)
9
+ def self.get_page(resource_name:, resource_maker:, user: nil, **query)
10
+ json = StarkBank::Utils::Request.fetch(
11
+ method: 'GET',
12
+ path: StarkBank::Utils::API.endpoint(resource_name),
13
+ query: query,
14
+ user: user
15
+ ).json
16
+ entities = []
17
+ json[StarkBank::Utils::API.last_name_plural(resource_name)].each do |entity_json|
18
+ entities << StarkBank::Utils::API.from_api_json(resource_maker, entity_json)
19
+ end
20
+ return entities, json['cursor']
21
+ end
22
+
23
+ def self.get_stream(resource_name:, resource_maker:, user: nil, **query)
10
24
  limit = query[:limit]
11
25
  query[:limit] = limit.nil? ? limit : [limit, 100].min
12
26
 
@@ -31,8 +45,7 @@ module StarkBank
31
45
 
32
46
  cursor = json['cursor']
33
47
  query['cursor'] = cursor
34
-
35
- break if cursor.nil? || (!limit.nil? && limit <= 0)
48
+ break if cursor.nil? || cursor.empty? || (!limit.nil? && limit <= 0)
36
49
  end
37
50
  end
38
51
  end
@@ -47,19 +60,10 @@ module StarkBank
47
60
  StarkBank::Utils::API.from_api_json(resource_maker, entity)
48
61
  end
49
62
 
50
- def self.get_pdf(resource_name:, resource_maker:, id:, user: nil, **query)
63
+ def self.get_content(resource_name:, resource_maker:, sub_resource_name:, id:, user: nil, **query)
51
64
  StarkBank::Utils::Request.fetch(
52
65
  method: 'GET',
53
- path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}/pdf",
54
- query: StarkBank::Utils::API.cast_json_to_api_format(query),
55
- user: user
56
- ).content
57
- end
58
-
59
- def self.get_qrcode(resource_name:, resource_maker:, id:, user: nil, **query)
60
- StarkBank::Utils::Request.fetch(
61
- method: 'GET',
62
- path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}/qrcode",
66
+ path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}/#{sub_resource_name}",
63
67
  query: StarkBank::Utils::API.cast_json_to_api_format(query),
64
68
  user: user
65
69
  ).content
@@ -116,6 +120,17 @@ module StarkBank
116
120
  entity = json[StarkBank::Utils::API.last_name(resource_name)]
117
121
  StarkBank::Utils::API.from_api_json(resource_maker, entity)
118
122
  end
123
+
124
+ def self.get_sub_resource(resource_name:, sub_resource_maker:, sub_resource_name:, id:, user: nil, **query)
125
+ json = StarkBank::Utils::Request.fetch(
126
+ method: 'GET',
127
+ path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}/#{StarkBank::Utils::API.endpoint(sub_resource_name)}",
128
+ user: user,
129
+ query: StarkBank::Utils::API.cast_json_to_api_format(query)
130
+ ).json
131
+ entity = json[StarkBank::Utils::API.last_name(sub_resource_name)]
132
+ StarkBank::Utils::API.from_api_json(sub_resource_maker, entity)
133
+ end
119
134
  end
120
135
  end
121
136
  end
@@ -0,0 +1,28 @@
1
+
2
+
3
+ module StarkBank
4
+ module Utils
5
+ class SubResource
6
+ def to_s
7
+ string_vars = []
8
+ instance_variables.each do |key|
9
+ value = instance_variable_get(key).to_s.lines.map(&:chomp).join("\n ")
10
+ string_vars << "#{key[1..-1]}: #{value}"
11
+ end
12
+ fields = string_vars.join(",\n ")
13
+ "#{class_name}(\n #{fields}\n)"
14
+ end
15
+
16
+ def inspect
17
+ "#{class_name}[#{@id}]"
18
+ end
19
+
20
+ private
21
+
22
+ def class_name
23
+ self.class.name.split('::').last.downcase
24
+ end
25
+ end
26
+ end
27
+ end
28
+
data/lib/utils/url.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
+ require 'erb'
3
+
2
4
 
3
5
  module StarkBank
4
6
  module Utils
@@ -17,7 +19,7 @@ module StarkBank
17
19
 
18
20
  query_list = []
19
21
  string_params.each do |key, value|
20
- query_list << "#{key}=#{value}"
22
+ query_list << "#{key}=#{ERB::Util.url_encode(value)}"
21
23
  end
22
24
  '?' + query_list.join('&')
23
25
  end
@@ -8,12 +8,12 @@ module StarkBank
8
8
  # # Webhook subscription object
9
9
  #
10
10
  # A Webhook is used to subscribe to notification events on a user-selected endpoint.
11
- # Currently available services for subscription are transfer, boleto, boleto-payment,
12
- # and utility-payment
11
+ # Currently available services for subscription are transfer, invoice, deposit, brcode-payment,
12
+ # boleto, boleto-payment and utility-payment
13
13
  #
14
14
  # ## Parameters (required):
15
15
  # - url [string]: Url that will be notified when an event occurs.
16
- # - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['transfer', 'boleto-payment']
16
+ # - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['transfer', 'deposit']
17
17
  #
18
18
  # ## Attributes:
19
19
  # - id [string, default nil]: unique id returned when the webhook is created. ex: '5656565656565656'
@@ -31,10 +31,10 @@ module StarkBank
31
31
  #
32
32
  # ## Parameters (required):
33
33
  # - url [string]: url to which notification events will be sent to. ex: 'https://webhook.site/60e9c18e-4b5c-4369-bda1-ab5fcd8e1b29'
34
- # - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['transfer', 'boleto-payment']
34
+ # - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['transfer', 'invoice']
35
35
  #
36
36
  # ## Parameters (optional):
37
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
37
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
38
38
  #
39
39
  # ## Return:
40
40
  # - Webhook object with updated attributes
@@ -50,7 +50,7 @@ module StarkBank
50
50
  # - id [string]: object unique id. ex: '5656565656565656'
51
51
  #
52
52
  # ## Parameters (optional):
53
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
53
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
54
54
  #
55
55
  # ## Return:
56
56
  # - Webhook object with updated attributes
@@ -64,12 +64,33 @@ module StarkBank
64
64
  #
65
65
  # ## Parameters (optional):
66
66
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
67
- # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
67
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
68
68
  #
69
69
  # ## Return:
70
70
  # - generator of Webhook objects with updated attributes
71
71
  def self.query(limit: nil, user: nil)
72
- StarkBank::Utils::Rest.get_list(user: user, limit: limit, **resource)
72
+ StarkBank::Utils::Rest.get_stream(user: user, limit: limit, **resource)
73
+ end
74
+
75
+ # # Retrieve paged Webhooks
76
+ #
77
+ # Receive a list of up to 100 Webhook objects previously created in the Stark Bank API and the cursor to the next page.
78
+ # Use this function instead of query if you want to manually page your requests.
79
+ #
80
+ # ## Parameters (optional):
81
+ # - cursor [string, default nil]: cursor returned on the previous page function call
82
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
83
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
84
+ #
85
+ # ## Return:
86
+ # - list of Webhook objects with updated attributes and cursor to retrieve the next page of Webhook objects
87
+ def self.page(cursor: nil, limit: nil, user: nil)
88
+ return StarkBank::Utils::Rest.get_page(
89
+ cursor: cursor,
90
+ limit: limit,
91
+ user: user,
92
+ **resource
93
+ )
73
94
  end
74
95
 
75
96
  # # Delete a Webhook entity
@@ -80,7 +101,7 @@ module StarkBank
80
101
  # - id [string]: Webhook unique id. ex: '5656565656565656'
81
102
  #
82
103
  # ## Parameters (optional):
83
- # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
104
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
84
105
  #
85
106
  # ## Return:
86
107
  # - deleted Webhook object
@@ -0,0 +1,141 @@
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
+ # # Workspace object
9
+ #
10
+ # Workspaces are bank accounts. They have independent balances, statements, operations and permissions.
11
+ # The only property that is shared between your workspaces is that they are linked to your organization,
12
+ # which carries your basic informations, such as tax ID, name, etc..
13
+ #
14
+ # ## Parameters (required):
15
+ # - username [string]: Simplified name to define the workspace URL. This name must be unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
16
+ # - name [string]: Full name that identifies the Workspace. This name will appear when people access the Workspace on our platform, for example. Ex: 'Stark Bank Workspace'
17
+ #
18
+ # ## Parameters (optional):
19
+ # - 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
+ # ## Attributes:
22
+ # - id [string, default nil]: unique id returned when the workspace is created. ex: '5656565656565656'
23
+ class Workspace < StarkBank::Utils::Resource
24
+ attr_reader :username, :name, :allowed_tax_ids, :id
25
+ def initialize(username:, name:, allowed_tax_ids: nil, id: nil)
26
+ super(id)
27
+ @username = username
28
+ @name = name
29
+ @allowed_tax_ids = allowed_tax_ids
30
+ end
31
+
32
+ # # Create Workspace
33
+ #
34
+ # Send a Workspace for creation in the Stark Bank API
35
+ #
36
+ # ## Parameters (required):
37
+ # - username [string]: Simplified name to define the workspace URL. This name must be unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
38
+ # - name [string]: Full name that identifies the Workspace. This name will appear when people access the Workspace on our platform, for example. Ex: 'Stark Bank Workspace'
39
+ #
40
+ # ## Parameters (optional):
41
+ # - user [Organization object]: Organization object. Not necessary if StarkBank.user was set before function call
42
+ #
43
+ # ## Return:
44
+ # - Workspace object with updated attributes
45
+ def self.create(username:, name:, user: nil, allowed_tax_ids: nil)
46
+ StarkBank::Utils::Rest.post_single(entity: Workspace.new(username: username, name: name, allowed_tax_ids: allowed_tax_ids), user: user, **resource)
47
+ end
48
+
49
+ # # Retrieve a specific Workspace
50
+ #
51
+ # Receive a single Workspace object previously created in the Stark Bank API by passing its id
52
+ #
53
+ # ## Parameters (required):
54
+ # - id [string]: object unique id. ex: '5656565656565656'
55
+ #
56
+ # ## Parameters (optional):
57
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
58
+ #
59
+ # ## Return:
60
+ # - Workspace object with updated attributes
61
+ def self.get(id, user: nil)
62
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
63
+ end
64
+
65
+ # # Retrieve Workspaces
66
+ #
67
+ # Receive a generator of Workspace objects previously created in the Stark Bank API.
68
+ # If no filters are passed and the user is an Organization, all of the Organization Workspaces
69
+ # will be retrieved.
70
+ #
71
+ # ## Parameters (optional):
72
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
73
+ # - username [string]: query by the simplified name that defines the workspace URL. This name is always unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
74
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
75
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
76
+ #
77
+ # ## Return:
78
+ # - generator of Workspace objects with updated attributes
79
+ def self.query(limit: nil, username: nil, ids: nil, user: nil)
80
+ StarkBank::Utils::Rest.get_stream(limit: limit, username: username, ids: ids, user: user, **resource)
81
+ end
82
+
83
+ # # Retrieve paged Workspaces
84
+ #
85
+ # Receive a list of up to 100 Workspace objects previously created in the Stark Bank API and the cursor to the next page.
86
+ # Use this function instead of query if you want to manually page your requests.
87
+ #
88
+ # ## Parameters (optional):
89
+ # - cursor [string, default nil]: cursor returned on the previous page function call
90
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
91
+ # - username [string]: query by the simplified name that defines the workspace URL. This name is always unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
92
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
93
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
94
+ #
95
+ # ## Return:
96
+ # - list of Workspace objects with updated attributes and cursor to retrieve the next page of Workspace objects
97
+ def self.page(cursor: nil, limit: nil, username: nil, ids: nil, user: nil)
98
+ return StarkBank::Utils::Rest.get_page(
99
+ cursor: cursor,
100
+ limit: limit,
101
+ username: username,
102
+ ids: ids,
103
+ user: user,
104
+ **resource
105
+ )
106
+ end
107
+
108
+ # # Update an Workspace entity
109
+ #
110
+ # Update an Workspace entity previously created in the Stark Bank API
111
+ #
112
+ # ## Parameters (required):
113
+ # - id [string]: Workspace unique id. ex: '5656565656565656'
114
+ #
115
+ # ## Parameters (optional):
116
+ # - 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
+ # - 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
+ # - 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']
119
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
120
+ #
121
+ # ## Return:
122
+ # - updated Workspace object
123
+ def self.update(id, user: nil, username: nil, name: nil, allowed_tax_ids: nil)
124
+ StarkBank::Utils::Rest.patch_id(id: id, user: user, username: username, name: name, allowed_tax_ids: allowed_tax_ids, **resource)
125
+ end
126
+
127
+ def self.resource
128
+ {
129
+ resource_name: 'Workspace',
130
+ resource_maker: proc { |json|
131
+ Workspace.new(
132
+ id: json['id'],
133
+ username: json['username'],
134
+ name: json['name'],
135
+ allowed_tax_ids: json['allowed_tax_ids']
136
+ )
137
+ }
138
+ }
139
+ end
140
+ end
141
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starkbank
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.6.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: 2020-04-06 00:00:00.000000000 Z
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: starkbank-ecdsa
@@ -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: []
@@ -82,19 +82,32 @@ files:
82
82
  - lib/brcode_payment/brcode_payment.rb
83
83
  - lib/brcode_payment/log.rb
84
84
  - lib/brcode_preview/brcode_preview.rb
85
+ - lib/darf_payment/darf_payment.rb
86
+ - lib/darf_payment/log.rb
85
87
  - lib/deposit/deposit.rb
86
88
  - lib/deposit/log.rb
87
89
  - lib/dict_key/dict_key.rb
88
90
  - lib/error.rb
91
+ - lib/event/attempt.rb
89
92
  - lib/event/event.rb
93
+ - lib/institution/institution.rb
90
94
  - lib/invoice/invoice.rb
91
95
  - lib/invoice/log.rb
96
+ - lib/invoice/payment.rb
92
97
  - lib/key.rb
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
93
103
  - lib/payment_request/payment_request.rb
94
104
  - lib/starkbank.rb
105
+ - lib/tax_payment/log.rb
106
+ - lib/tax_payment/tax_payment.rb
95
107
  - lib/transaction/transaction.rb
96
108
  - lib/transfer/log.rb
97
109
  - lib/transfer/transfer.rb
110
+ - lib/user/organization.rb
98
111
  - lib/user/project.rb
99
112
  - lib/user/user.rb
100
113
  - lib/utility_payment/log.rb
@@ -107,13 +120,15 @@ files:
107
120
  - lib/utils/request.rb
108
121
  - lib/utils/resource.rb
109
122
  - lib/utils/rest.rb
123
+ - lib/utils/sub_resource.rb
110
124
  - lib/utils/url.rb
111
125
  - lib/webhook/webhook.rb
126
+ - lib/workspace/workspace.rb
112
127
  homepage: https://github.com/starkbank/sdk-ruby
113
128
  licenses:
114
129
  - MIT
115
130
  metadata: {}
116
- post_install_message:
131
+ post_install_message:
117
132
  rdoc_options: []
118
133
  require_paths:
119
134
  - lib
@@ -129,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
144
  version: '0'
130
145
  requirements: []
131
146
  rubygems_version: 3.1.4
132
- signing_key:
147
+ signing_key:
133
148
  specification_version: 4
134
149
  summary: SDK to facilitate Ruby integrations with Stark Bank
135
150
  test_files: []