starkbank 2.2.0 → 2.5.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 +2 -2
- data/lib/boleto/boleto.rb +53 -14
- data/lib/boleto/log.rb +36 -5
- data/lib/boleto_holmes/boleto_holmes.rb +41 -6
- data/lib/boleto_holmes/log.rb +36 -5
- data/lib/boleto_payment/boleto_payment.rb +42 -9
- data/lib/boleto_payment/log.rb +36 -5
- data/lib/brcode_payment/brcode_payment.rb +56 -17
- data/lib/brcode_payment/log.rb +36 -5
- data/lib/brcode_preview/brcode_preview.rb +2 -2
- data/lib/darf_payment/darf_payment.rb +218 -0
- data/lib/darf_payment/log.rb +125 -0
- data/lib/deposit/deposit.rb +46 -8
- data/lib/deposit/log.rb +36 -5
- data/lib/dict_key/dict_key.rb +45 -9
- data/lib/error.rb +13 -5
- data/lib/event/attempt.rb +125 -0
- data/lib/event/event.rb +44 -8
- data/lib/institution/institution.rb +67 -0
- data/lib/invoice/invoice.rb +72 -15
- data/lib/invoice/log.rb +52 -5
- data/lib/invoice/payment.rb +57 -0
- data/lib/payment_request/payment_request.rb +53 -11
- data/lib/starkbank.rb +9 -0
- data/lib/tax_payment/log.rb +125 -0
- data/lib/tax_payment/tax_payment.rb +203 -0
- data/lib/transaction/transaction.rb +39 -6
- data/lib/transfer/log.rb +36 -5
- data/lib/transfer/transfer.rb +59 -14
- data/lib/user/organization.rb +54 -0
- data/lib/user/project.rb +11 -6
- data/lib/user/user.rb +0 -4
- data/lib/utility_payment/log.rb +36 -5
- data/lib/utility_payment/utility_payment.rb +42 -9
- data/lib/utils/api.rb +1 -0
- data/lib/utils/request.rb +1 -1
- data/lib/utils/resource.rb +2 -21
- data/lib/utils/rest.rb +29 -14
- data/lib/utils/sub_resource.rb +28 -0
- data/lib/utils/url.rb +3 -1
- data/lib/webhook/webhook.rb +30 -9
- data/lib/workspace/workspace.rb +141 -0
- metadata +17 -7
@@ -51,7 +51,7 @@ module StarkBank
|
|
51
51
|
# - payments [list of UtilityPayment objects]: list of UtilityPayment objects to be created in the API
|
52
52
|
#
|
53
53
|
# ## Parameters (optional):
|
54
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
54
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
55
55
|
#
|
56
56
|
# ## Return:
|
57
57
|
# - list of UtilityPayment objects with updated attributes
|
@@ -67,7 +67,7 @@ module StarkBank
|
|
67
67
|
# - id [string]: object unique id. ex: '5656565656565656'
|
68
68
|
#
|
69
69
|
# ## Parameters (optional):
|
70
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
70
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
71
71
|
#
|
72
72
|
# ## Return:
|
73
73
|
# - UtilityPayment object with updated attributes
|
@@ -84,12 +84,12 @@ module StarkBank
|
|
84
84
|
# - id [string]: object unique id. ex: '5656565656565656'
|
85
85
|
#
|
86
86
|
# ## Parameters (optional):
|
87
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
87
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
88
88
|
#
|
89
89
|
# ## Return:
|
90
90
|
# - UtilityPayment pdf file
|
91
91
|
def self.pdf(id, user: nil)
|
92
|
-
StarkBank::Utils::Rest.
|
92
|
+
StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource)
|
93
93
|
end
|
94
94
|
|
95
95
|
# # Retrieve UtilityPayments
|
@@ -98,26 +98,59 @@ module StarkBank
|
|
98
98
|
#
|
99
99
|
# ## Parameters (optional):
|
100
100
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
101
|
-
# - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
102
|
-
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
101
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
102
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
103
103
|
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
104
104
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
105
105
|
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid'
|
106
|
-
# - user [Project object
|
106
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
107
107
|
#
|
108
108
|
# ## Return:
|
109
109
|
# - generator of UtilityPayment objects with updated attributes
|
110
110
|
def self.query(limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil)
|
111
111
|
after = StarkBank::Utils::Checks.check_date(after)
|
112
112
|
before = StarkBank::Utils::Checks.check_date(before)
|
113
|
-
StarkBank::Utils::Rest.
|
113
|
+
StarkBank::Utils::Rest.get_stream(
|
114
|
+
limit: limit,
|
115
|
+
after: after,
|
116
|
+
before: before,
|
117
|
+
tags: tags,
|
118
|
+
ids: ids,
|
119
|
+
status: status,
|
114
120
|
user: user,
|
121
|
+
**resource
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
# # Retrieve paged UtilityPayments
|
126
|
+
#
|
127
|
+
# Receive a list of up to 100 UtilityPayment objects previously created in the Stark Bank API and the cursor to the next page.
|
128
|
+
# Use this function instead of query if you want to manually page your requests.
|
129
|
+
#
|
130
|
+
# ## Parameters (optional):
|
131
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
132
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
133
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
134
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
135
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
136
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
137
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid'
|
138
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
139
|
+
#
|
140
|
+
# ## Return:
|
141
|
+
# - list of UtilityPayment objects with updated attributes and cursor to retrieve the next page of UtilityPayment objects
|
142
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil)
|
143
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
144
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
145
|
+
return StarkBank::Utils::Rest.get_page(
|
146
|
+
cursor: cursor,
|
115
147
|
limit: limit,
|
116
148
|
after: after,
|
117
149
|
before: before,
|
118
150
|
tags: tags,
|
119
151
|
ids: ids,
|
120
152
|
status: status,
|
153
|
+
user: user,
|
121
154
|
**resource
|
122
155
|
)
|
123
156
|
end
|
@@ -130,7 +163,7 @@ module StarkBank
|
|
130
163
|
# - id [string]: UtilityPayment unique id. ex:'5656565656565656'
|
131
164
|
#
|
132
165
|
# ## Parameters (optional):
|
133
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
166
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
134
167
|
#
|
135
168
|
# ## Return:
|
136
169
|
# - deleted UtilityPayment object
|
data/lib/utils/api.rb
CHANGED
data/lib/utils/request.rb
CHANGED
@@ -61,7 +61,7 @@ module StarkBank
|
|
61
61
|
req['Access-Time'] = access_time
|
62
62
|
req['Access-Signature'] = signature
|
63
63
|
req['Content-Type'] = 'application/json'
|
64
|
-
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.
|
64
|
+
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.5.0"
|
65
65
|
req['Accept-Language'] = language
|
66
66
|
|
67
67
|
request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }
|
data/lib/utils/resource.rb
CHANGED
@@ -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.
|
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.
|
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}
|
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
|
data/lib/webhook/webhook.rb
CHANGED
@@ -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,
|
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', '
|
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', '
|
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
|
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.
|
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
|