starkbank 2.1.0 → 2.4.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 +1 -1
- data/lib/boleto/boleto.rb +9 -8
- data/lib/boleto/log.rb +2 -2
- data/lib/boleto_holmes/boleto_holmes.rb +3 -3
- data/lib/boleto_holmes/log.rb +2 -2
- data/lib/boleto_payment/boleto_payment.rb +6 -6
- data/lib/boleto_payment/log.rb +3 -3
- data/lib/brcode_payment/brcode_payment.rb +167 -0
- data/lib/brcode_payment/log.rb +94 -0
- data/lib/brcode_preview/brcode_preview.rb +77 -0
- data/lib/deposit/deposit.rb +121 -0
- data/lib/deposit/log.rb +94 -0
- data/lib/dict_key/dict_key.rb +118 -0
- data/lib/event/event.rb +12 -6
- data/lib/invoice/invoice.rb +211 -0
- data/lib/invoice/log.rb +94 -0
- data/lib/payment_request/payment_request.rb +9 -7
- data/lib/starkbank.rb +10 -0
- data/lib/transaction/transaction.rb +3 -3
- data/lib/transfer/log.rb +2 -2
- data/lib/transfer/transfer.rb +18 -12
- data/lib/user/organization.rb +54 -0
- data/lib/user/project.rb +10 -5
- data/lib/user/user.rb +0 -4
- data/lib/utility_payment/log.rb +2 -2
- data/lib/utility_payment/utility_payment.rb +6 -6
- data/lib/utils/api.rb +14 -12
- data/lib/utils/checks.rb +18 -6
- data/lib/utils/request.rb +1 -1
- data/lib/utils/rest.rb +10 -2
- data/lib/webhook/webhook.rb +8 -8
- data/lib/workspace/workspace.rb +92 -0
- metadata +11 -1
@@ -0,0 +1,54 @@
|
|
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://sandbox.web.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
CHANGED
@@ -5,20 +5,21 @@ require_relative('user')
|
|
5
5
|
module StarkBank
|
6
6
|
# # Project object
|
7
7
|
#
|
8
|
-
# The Project object is
|
9
|
-
#
|
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,
|
10
11
|
# which must have been previously created at the Stark Bank website
|
11
12
|
# [https://sandbox.web.starkbank.com] or [https://web.starkbank.com]
|
12
|
-
# before you can use it in this SDK. Projects may be passed as
|
13
|
+
# before you can use it in this SDK. Projects may be passed as the user parameter on
|
13
14
|
# each request or may be defined as the default user at the start (See README).
|
14
15
|
#
|
15
16
|
# ## Parameters (required):
|
16
17
|
# - id [string]: unique id required to identify project. ex: '5656565656565656'
|
17
|
-
# - private_key [
|
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-----'
|
18
19
|
# - environment [string]: environment where the project is being used. ex: 'sandbox' or 'production'
|
19
20
|
#
|
20
21
|
# ## Attributes (return-only):
|
21
|
-
# - name [string, default ']: project name. ex: 'MyProject'
|
22
|
+
# - name [string, default '']: project name. ex: 'MyProject'
|
22
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']
|
23
24
|
# - pem [string]: private key in pem format. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
|
24
25
|
class Project < StarkBank::User
|
@@ -28,5 +29,9 @@ module StarkBank
|
|
28
29
|
@name = name
|
29
30
|
@allowed_ips = allowed_ips
|
30
31
|
end
|
32
|
+
|
33
|
+
def access_id
|
34
|
+
"project/#{@id}"
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
data/lib/user/user.rb
CHANGED
data/lib/utility_payment/log.rb
CHANGED
@@ -37,7 +37,7 @@ module StarkBank
|
|
37
37
|
# - id [string]: object unique id. ex: '5656565656565656'
|
38
38
|
#
|
39
39
|
# ## Parameters (optional):
|
40
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
40
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
41
41
|
#
|
42
42
|
# ## Return:
|
43
43
|
# - Log object with updated attributes
|
@@ -55,7 +55,7 @@ module StarkBank
|
|
55
55
|
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
56
56
|
# - types [list of strings, default nil]: filter retrieved objects by event types. ex: 'paid' or 'registered'
|
57
57
|
# - payment_ids [list of strings, default nil]: list of UtilityPayment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
58
|
-
# - user [Project object
|
58
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
59
59
|
#
|
60
60
|
# ## Return:
|
61
61
|
# - list of Log objects with updated attributes
|
@@ -36,7 +36,7 @@ module StarkBank
|
|
36
36
|
@line = line
|
37
37
|
@bar_code = bar_code
|
38
38
|
@tags = tags
|
39
|
-
@scheduled = StarkBank::Utils::Checks.
|
39
|
+
@scheduled = StarkBank::Utils::Checks.check_date(scheduled)
|
40
40
|
@amount = amount
|
41
41
|
@fee = fee
|
42
42
|
@status = status
|
@@ -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,7 +84,7 @@ 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
|
@@ -103,7 +103,7 @@ module StarkBank
|
|
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
|
@@ -130,7 +130,7 @@ module StarkBank
|
|
130
130
|
# - id [string]: UtilityPayment unique id. ex:'5656565656565656'
|
131
131
|
#
|
132
132
|
# ## Parameters (optional):
|
133
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
133
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
134
134
|
#
|
135
135
|
# ## Return:
|
136
136
|
# - deleted UtilityPayment object
|
data/lib/utils/api.rb
CHANGED
@@ -28,21 +28,22 @@ module StarkBank
|
|
28
28
|
hash.each do |key, value|
|
29
29
|
next if value.nil?
|
30
30
|
|
31
|
-
|
31
|
+
entity_hash[StarkBank::Utils::Case.snake_to_camel(key)] = parse_value(value)
|
32
|
+
end
|
33
|
+
entity_hash
|
34
|
+
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
value = list
|
39
|
-
elsif value.is_a?(Hash)
|
40
|
-
value = cast_json_to_api_format(value)
|
41
|
-
end
|
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)
|
42
41
|
|
43
|
-
|
42
|
+
list = []
|
43
|
+
value.each do |v|
|
44
|
+
list << (v.is_a?(Hash) ? cast_json_to_api_format(v) : v)
|
44
45
|
end
|
45
|
-
|
46
|
+
list
|
46
47
|
end
|
47
48
|
|
48
49
|
def self.from_api_json(resource_maker, json)
|
@@ -63,6 +64,7 @@ module StarkBank
|
|
63
64
|
base = last_name(resource_name)
|
64
65
|
|
65
66
|
return base if base[-1].eql?('s')
|
67
|
+
return "#{base}s" if base[-2..-1].eql?('ey')
|
66
68
|
return "#{base[0...-1]}ies" if base[-1].eql?('y')
|
67
69
|
|
68
70
|
"#{base}s"
|
data/lib/utils/checks.rb
CHANGED
@@ -39,6 +39,17 @@ module StarkBank
|
|
39
39
|
raise(ArgumentError, 'Private-key must be a valid secp256k1 ECDSA string in pem format')
|
40
40
|
end
|
41
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
|
+
|
42
53
|
def self.check_datetime(data)
|
43
54
|
return if data.nil?
|
44
55
|
|
@@ -46,7 +57,8 @@ module StarkBank
|
|
46
57
|
|
47
58
|
return Time.new(data.year, data.month, data.day) if data.is_a?(Date)
|
48
59
|
|
49
|
-
check_datetime_string(data)
|
60
|
+
data, _type = check_datetime_string(data)
|
61
|
+
data
|
50
62
|
end
|
51
63
|
|
52
64
|
def self.check_date(data)
|
@@ -56,9 +68,9 @@ module StarkBank
|
|
56
68
|
|
57
69
|
return data if data.is_a?(Date)
|
58
70
|
|
59
|
-
data = check_datetime_string(data)
|
71
|
+
data, type = check_datetime_string(data)
|
60
72
|
|
61
|
-
Date.new(data.year, data.month, data.day)
|
73
|
+
type == 'date' ? Date.new(data.year, data.month, data.day) : data
|
62
74
|
end
|
63
75
|
|
64
76
|
class << self
|
@@ -68,17 +80,17 @@ module StarkBank
|
|
68
80
|
data = data.to_s
|
69
81
|
|
70
82
|
begin
|
71
|
-
return DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S.%L+00:00')
|
83
|
+
return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S.%L+00:00'), 'datetime']
|
72
84
|
rescue ArgumentError
|
73
85
|
end
|
74
86
|
|
75
87
|
begin
|
76
|
-
return DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S+00:00')
|
88
|
+
return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S+00:00'), 'datetime']
|
77
89
|
rescue ArgumentError
|
78
90
|
end
|
79
91
|
|
80
92
|
begin
|
81
|
-
return DateTime.strptime(data, '%Y-%m-%d')
|
93
|
+
return [DateTime.strptime(data, '%Y-%m-%d'), 'date']
|
82
94
|
rescue ArgumentError
|
83
95
|
raise(ArgumentError, 'invalid datetime string ' + data)
|
84
96
|
end
|
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.4.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/rest.rb
CHANGED
@@ -31,8 +31,7 @@ module StarkBank
|
|
31
31
|
|
32
32
|
cursor = json['cursor']
|
33
33
|
query['cursor'] = cursor
|
34
|
-
|
35
|
-
break if cursor.nil? || (!limit.nil? && limit <= 0)
|
34
|
+
break if cursor.nil? || cursor.empty? || (!limit.nil? && limit <= 0)
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -56,6 +55,15 @@ module StarkBank
|
|
56
55
|
).content
|
57
56
|
end
|
58
57
|
|
58
|
+
def self.get_qrcode(resource_name:, resource_maker:, id:, user: nil, **query)
|
59
|
+
StarkBank::Utils::Request.fetch(
|
60
|
+
method: 'GET',
|
61
|
+
path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}/qrcode",
|
62
|
+
query: StarkBank::Utils::API.cast_json_to_api_format(query),
|
63
|
+
user: user
|
64
|
+
).content
|
65
|
+
end
|
66
|
+
|
59
67
|
def self.post(resource_name:, resource_maker:, entities:, user: nil)
|
60
68
|
jsons = []
|
61
69
|
entities.each do |entity|
|
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,7 +64,7 @@ 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
|
@@ -80,7 +80,7 @@ module StarkBank
|
|
80
80
|
# - id [string]: Webhook unique id. ex: '5656565656565656'
|
81
81
|
#
|
82
82
|
# ## Parameters (optional):
|
83
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
83
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
84
84
|
#
|
85
85
|
# ## Return:
|
86
86
|
# - deleted Webhook object
|
@@ -0,0 +1,92 @@
|
|
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
|
+
# ## Attributes:
|
19
|
+
# - id [string, default nil]: unique id returned when the workspace is created. ex: '5656565656565656'
|
20
|
+
class Workspace < StarkBank::Utils::Resource
|
21
|
+
attr_reader :username, :name, :id
|
22
|
+
def initialize(username:, name:, id: nil)
|
23
|
+
super(id)
|
24
|
+
@username = username
|
25
|
+
@name = name
|
26
|
+
end
|
27
|
+
|
28
|
+
# # Create Workspace
|
29
|
+
#
|
30
|
+
# Send a Workspace for creation in the Stark Bank API
|
31
|
+
#
|
32
|
+
# ## Parameters (required):
|
33
|
+
# - username [string]: Simplified name to define the workspace URL. This name must be unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
|
34
|
+
# - 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'
|
35
|
+
#
|
36
|
+
# ## Parameters (optional):
|
37
|
+
# - user [Organization object]: Organization object. Not necessary if StarkBank.user was set before function call
|
38
|
+
#
|
39
|
+
# ## Return:
|
40
|
+
# - Workspace object with updated attributes
|
41
|
+
def self.create(username:, name:, user: nil)
|
42
|
+
StarkBank::Utils::Rest.post_single(entity: Workspace.new(username: username, name: name), user: user, **resource)
|
43
|
+
end
|
44
|
+
|
45
|
+
# # Retrieve a specific Workspace
|
46
|
+
#
|
47
|
+
# Receive a single Workspace object previously created in the Stark Bank API by passing its id
|
48
|
+
#
|
49
|
+
# ## Parameters (required):
|
50
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
51
|
+
#
|
52
|
+
# ## Parameters (optional):
|
53
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
54
|
+
#
|
55
|
+
# ## Return:
|
56
|
+
# - Workspace object with updated attributes
|
57
|
+
def self.get(id, user: nil)
|
58
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
59
|
+
end
|
60
|
+
|
61
|
+
# # Retrieve Workspaces
|
62
|
+
#
|
63
|
+
# Receive a generator of Workspace objects previously created in the Stark Bank API.
|
64
|
+
# If no filters are passed and the user is an Organization, all of the Organization Workspaces
|
65
|
+
# will be retrieved.
|
66
|
+
#
|
67
|
+
# ## Parameters (optional):
|
68
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
69
|
+
# - username [string]: query by the simplified name that defines the workspace URL. This name is always unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
|
70
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
71
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
72
|
+
#
|
73
|
+
# ## Return:
|
74
|
+
# - generator of Workspace objects with updated attributes
|
75
|
+
def self.query(limit: nil, username: nil, ids: nil, user: nil)
|
76
|
+
StarkBank::Utils::Rest.get_list(limit: limit, username: username, ids: ids, user: user, **resource)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.resource
|
80
|
+
{
|
81
|
+
resource_name: 'Workspace',
|
82
|
+
resource_maker: proc { |json|
|
83
|
+
Workspace.new(
|
84
|
+
id: json['id'],
|
85
|
+
username: json['username'],
|
86
|
+
name: json['name']
|
87
|
+
)
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|