starkbank 2.6.0 → 2.8.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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/balance/balance.rb +8 -8
  3. data/lib/boleto/boleto.rb +22 -19
  4. data/lib/boleto/log.rb +10 -10
  5. data/lib/boleto_holmes/boleto_holmes.rb +14 -14
  6. data/lib/boleto_holmes/log.rb +16 -13
  7. data/lib/boleto_payment/boleto_payment.rb +21 -18
  8. data/lib/boleto_payment/log.rb +10 -10
  9. data/lib/brcode_payment/brcode_payment.rb +23 -20
  10. data/lib/brcode_payment/log.rb +10 -10
  11. data/lib/brcode_payment/rule.rb +49 -0
  12. data/lib/darf_payment/darf_payment.rb +23 -21
  13. data/lib/darf_payment/log.rb +10 -10
  14. data/lib/deposit/deposit.rb +9 -9
  15. data/lib/deposit/log.rb +10 -10
  16. data/lib/dict_key/dict_key.rb +26 -27
  17. data/lib/dynamic_brcode/dynamic_brcode.rb +155 -0
  18. data/lib/error.rb +7 -40
  19. data/lib/event/attempt.rb +9 -9
  20. data/lib/event/event.rb +30 -56
  21. data/lib/institution/institution.rb +2 -3
  22. data/lib/invoice/invoice.rb +24 -23
  23. data/lib/invoice/log.rb +10 -10
  24. data/lib/invoice/payment.rb +1 -2
  25. data/lib/payment_preview/boleto_preview.rb +4 -5
  26. data/lib/payment_preview/brcode_preview.rb +2 -3
  27. data/lib/payment_preview/payment_preview.rb +10 -6
  28. data/lib/payment_preview/tax_preview.rb +2 -3
  29. data/lib/payment_preview/utility_preview.rb +2 -3
  30. data/lib/payment_request/payment_request.rb +22 -16
  31. data/lib/starkbank.rb +16 -5
  32. data/lib/tax_payment/log.rb +10 -10
  33. data/lib/tax_payment/tax_payment.rb +22 -19
  34. data/lib/transaction/transaction.rb +13 -13
  35. data/lib/transfer/log.rb +10 -10
  36. data/lib/transfer/rule.rb +49 -0
  37. data/lib/transfer/transfer.rb +30 -24
  38. data/lib/utility_payment/log.rb +10 -10
  39. data/lib/utility_payment/utility_payment.rb +26 -17
  40. data/lib/utils/parse.rb +35 -0
  41. data/lib/utils/rest.rb +132 -109
  42. data/lib/webhook/webhook.rb +5 -5
  43. data/lib/workspace/workspace.rb +38 -10
  44. metadata +15 -25
  45. data/lib/brcode_preview/brcode_preview.rb +0 -79
  46. data/lib/key.rb +0 -33
  47. data/lib/user/organization.rb +0 -54
  48. data/lib/user/project.rb +0 -37
  49. data/lib/user/user.rb +0 -20
  50. data/lib/utils/api.rb +0 -79
  51. data/lib/utils/cache.rb +0 -10
  52. data/lib/utils/case.rb +0 -21
  53. data/lib/utils/checks.rb +0 -101
  54. data/lib/utils/environment.rb +0 -13
  55. data/lib/utils/request.rb +0 -79
  56. data/lib/utils/resource.rb +0 -13
  57. data/lib/utils/sub_resource.rb +0 -28
  58. data/lib/utils/url.rb +0 -28
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require('starkcore')
4
4
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
6
5
  require_relative('utility_payment')
7
6
 
7
+
8
8
  module StarkBank
9
9
  class UtilityPayment
10
10
  # # UtilityPayment::Log object
@@ -13,20 +13,20 @@ module StarkBank
13
13
  # is generated for the entity. This log is never generated by the user, but it can
14
14
  # be retrieved to check additional information on the UtilityPayment.
15
15
  #
16
- # ## Attributes:
16
+ # ## Attributes (return-only):
17
17
  # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
18
18
  # - payment [UtilityPayment]: UtilityPayment entity to which the log refers to.
19
19
  # - errors [list of strings]: list of errors linked to this UtilityPayment event.
20
20
  # - type [string]: type of the UtilityPayment event which triggered the log creation. ex: 'processing' or 'success'
21
21
  # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
22
- class Log < StarkBank::Utils::Resource
22
+ class Log < StarkCore::Utils::Resource
23
23
  attr_reader :id, :created, :type, :errors, :payment
24
24
  def initialize(id:, created:, type:, errors:, payment:)
25
25
  super(id)
26
26
  @type = type
27
27
  @errors = errors
28
28
  @payment = payment
29
- @created = StarkBank::Utils::Checks.check_datetime(created)
29
+ @created = StarkCore::Utils::Checks.check_datetime(created)
30
30
  end
31
31
 
32
32
  # # Retrieve a specific Log
@@ -60,8 +60,8 @@ module StarkBank
60
60
  # ## Return:
61
61
  # - list of Log objects with updated attributes
62
62
  def self.query(limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
63
- after = StarkBank::Utils::Checks.check_date(after)
64
- before = StarkBank::Utils::Checks.check_date(before)
63
+ after = StarkCore::Utils::Checks.check_date(after)
64
+ before = StarkCore::Utils::Checks.check_date(before)
65
65
  StarkBank::Utils::Rest.get_stream(
66
66
  limit: limit,
67
67
  after: after,
@@ -90,8 +90,8 @@ module StarkBank
90
90
  # ## Return:
91
91
  # - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
92
92
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
93
- after = StarkBank::Utils::Checks.check_date(after)
94
- before = StarkBank::Utils::Checks.check_date(before)
93
+ after = StarkCore::Utils::Checks.check_date(after)
94
+ before = StarkCore::Utils::Checks.check_date(before)
95
95
  return StarkBank::Utils::Rest.get_page(
96
96
  cursor: cursor,
97
97
  limit: limit,
@@ -114,7 +114,7 @@ module StarkBank
114
114
  created: json['created'],
115
115
  type: json['type'],
116
116
  errors: json['errors'],
117
- payment: StarkBank::Utils::API.from_api_json(payment_maker, json['payment'])
117
+ payment: StarkCore::Utils::API.from_api_json(payment_maker, json['payment'])
118
118
  )
119
119
  }
120
120
  }
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require('starkcore')
4
4
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
5
+
6
6
 
7
7
  module StarkBank
8
8
  # # UtilityPayment object
@@ -23,24 +23,30 @@ module StarkBank
23
23
  # - tags [list of strings]: list of strings for tagging
24
24
  #
25
25
  # ## Attributes (return-only):
26
- # - id [string, default nil]: unique id returned when payment is created. ex: '5656565656565656'
27
- # - status [string, default nil]: current payment status. ex: 'success' or 'failed'
28
- # - amount [int, default nil]: amount automatically calculated from line or bar_code. ex: 23456 (= R$ 234.56)
29
- # - fee [integer, default nil]: fee charged when utility payment is created. ex: 200 (= R$ 2.00)
30
- # - created [DateTime, default nil]: creation datetime for the payment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
31
- class UtilityPayment < StarkBank::Utils::Resource
32
- attr_reader :description, :line, :bar_code, :tags, :scheduled, :id, :amount, :fee, :status, :created
33
- def initialize(description:, line: nil, bar_code: nil, tags: nil, scheduled: nil, id: nil, amount: nil, fee: nil, status: nil, created: nil)
26
+ # - id [string]: unique id returned when payment is created. ex: '5656565656565656'
27
+ # - status [string]: current payment status. ex: 'success' or 'failed'
28
+ # - amount [int]: amount automatically calculated from line or bar_code. ex: 23456 (= R$ 234.56)
29
+ # - fee [integer]: fee charged when utility payment is created. ex: 200 (= R$ 2.00)
30
+ # - type [string]: payment type. ex: "utility"
31
+ # - transaction_ids [list of strings]: ledger transaction ids linked to this UtilityPayment. ex: ["19827356981273"]
32
+ # - created [DateTime]: creation datetime for the payment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
33
+ # - updated [DateTime]: latest update datetime for the payment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
+ class UtilityPayment < StarkCore::Utils::Resource
35
+ attr_reader :description, :line, :bar_code, :tags, :scheduled, :id, :amount, :fee, :type, :transaction_ids, :status, :created, :updated
36
+ def initialize(description:, line: nil, bar_code: nil, tags: nil, scheduled: nil, id: nil, amount: nil, fee: nil, type: nil, transaction_ids: nil, status: nil, created: nil, updated: nil)
34
37
  super(id)
35
38
  @description = description
36
39
  @line = line
37
40
  @bar_code = bar_code
38
41
  @tags = tags
39
- @scheduled = StarkBank::Utils::Checks.check_date(scheduled)
42
+ @scheduled = StarkCore::Utils::Checks.check_date(scheduled)
40
43
  @amount = amount
41
44
  @fee = fee
42
45
  @status = status
43
- @created = StarkBank::Utils::Checks.check_datetime(created)
46
+ @type = type
47
+ @transaction_ids = transaction_ids
48
+ @created = StarkCore::Utils::Checks.check_datetime(created)
49
+ @updated = StarkCore::Utils::Checks.check_datetime(updated)
44
50
  end
45
51
 
46
52
  # # Create UtilityPayments
@@ -108,8 +114,8 @@ module StarkBank
108
114
  # ## Return:
109
115
  # - generator of UtilityPayment objects with updated attributes
110
116
  def self.query(limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil)
111
- after = StarkBank::Utils::Checks.check_date(after)
112
- before = StarkBank::Utils::Checks.check_date(before)
117
+ after = StarkCore::Utils::Checks.check_date(after)
118
+ before = StarkCore::Utils::Checks.check_date(before)
113
119
  StarkBank::Utils::Rest.get_stream(
114
120
  limit: limit,
115
121
  after: after,
@@ -140,8 +146,8 @@ module StarkBank
140
146
  # ## Return:
141
147
  # - list of UtilityPayment objects with updated attributes and cursor to retrieve the next page of UtilityPayment objects
142
148
  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)
149
+ after = StarkCore::Utils::Checks.check_date(after)
150
+ before = StarkCore::Utils::Checks.check_date(before)
145
151
  return StarkBank::Utils::Rest.get_page(
146
152
  cursor: cursor,
147
153
  limit: limit,
@@ -184,8 +190,11 @@ module StarkBank
184
190
  scheduled: json['scheduled'],
185
191
  amount: json['amount'],
186
192
  fee: json['fee'],
193
+ type: json['type'],
194
+ transaction_ids: json['transaction_ids'],
187
195
  status: json['status'],
188
- created: json['created']
196
+ created: json['created'],
197
+ updated: json['updated']
189
198
  )
190
199
  }
191
200
  }
@@ -0,0 +1,35 @@
1
+ require('starkcore')
2
+
3
+ module StarkBank
4
+ module Utils
5
+ module Parse
6
+ def self.parse_and_verify(content:, signature:, user: nil, resource:, key: nil)
7
+ return StarkCore::Utils::Parse.parse_and_verify(
8
+ content: content,
9
+ signature: signature,
10
+ sdk_version: StarkBank::SDK_VERSION,
11
+ api_version: StarkBank::API_VERSION,
12
+ host: StarkBank::HOST,
13
+ resource: resource,
14
+ user: user ? user : StarkBank.user,
15
+ language: StarkBank.language,
16
+ timeout: StarkBank.language,
17
+ key: key
18
+ )
19
+ end
20
+
21
+ def self.verify(content:, signature:, user: nil)
22
+ return StarkCore::Utils::Parse.verify(
23
+ content: content,
24
+ signature: signature,
25
+ sdk_version: StarkBank::SDK_VERSION,
26
+ api_version: StarkBank::API_VERSION,
27
+ host: StarkBank::HOST,
28
+ user: user ? user : StarkBank.user,
29
+ language: StarkBank.language,
30
+ timeout: StarkBank.language
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
data/lib/utils/rest.rb CHANGED
@@ -1,135 +1,158 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('request')
4
- require_relative('api')
3
+ require('starkcore')
5
4
 
6
5
  module StarkBank
7
6
  module Utils
8
7
  module Rest
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)
24
- limit = query[:limit]
25
- query[:limit] = limit.nil? ? limit : [limit, 100].min
26
-
27
- Enumerator.new do |enum|
28
- loop do
29
- json = StarkBank::Utils::Request.fetch(
30
- method: 'GET',
31
- path: StarkBank::Utils::API.endpoint(resource_name),
32
- query: query,
33
- user: user
34
- ).json
35
- entities = json[StarkBank::Utils::API.last_name_plural(resource_name)]
36
8
 
37
- entities.each do |entity|
38
- enum << StarkBank::Utils::API.from_api_json(resource_maker, entity)
39
- end
9
+ def self.get_page(resource_name:, resource_maker:, user:, **query)
10
+ return StarkCore::Utils::Rest.get_page(
11
+ resource_name: resource_name,
12
+ resource_maker: resource_maker,
13
+ sdk_version: StarkBank::SDK_VERSION,
14
+ host: StarkBank::HOST,
15
+ api_version: StarkBank::API_VERSION,
16
+ user: user ? user : StarkBank.user,
17
+ language: StarkBank.language,
18
+ timeout: StarkBank.timeout,
19
+ **query
20
+ )
21
+ end
40
22
 
41
- unless limit.nil?
42
- limit -= 100
43
- query[:limit] = [limit, 100].min
44
- end
23
+ def self.get_stream(resource_name:, resource_maker:, user:, **query)
24
+ return StarkCore::Utils::Rest.get_stream(
25
+ resource_name: resource_name,
26
+ resource_maker: resource_maker,
27
+ sdk_version: StarkBank::SDK_VERSION,
28
+ host: StarkBank::HOST,
29
+ api_version: StarkBank::API_VERSION,
30
+ user: user ? user : StarkBank.user,
31
+ language: StarkBank.language,
32
+ timeout: StarkBank.timeout,
33
+ **query
34
+ )
35
+ end
45
36
 
46
- cursor = json['cursor']
47
- query['cursor'] = cursor
48
- break if cursor.nil? || cursor.empty? || (!limit.nil? && limit <= 0)
49
- end
50
- end
37
+ def self.get_id(resource_name:, resource_maker:, user:, id:, **query)
38
+ return StarkCore::Utils::Rest.get_id(
39
+ resource_name: resource_name,
40
+ resource_maker: resource_maker,
41
+ sdk_version: StarkBank::SDK_VERSION,
42
+ host: StarkBank::HOST,
43
+ api_version: StarkBank::API_VERSION,
44
+ user: user ? user : StarkBank.user,
45
+ language: StarkBank.language,
46
+ timeout: StarkBank.timeout,
47
+ id: id,
48
+ **query
49
+ )
51
50
  end
52
51
 
53
- def self.get_id(resource_name:, resource_maker:, id:, user: nil)
54
- json = StarkBank::Utils::Request.fetch(
55
- method: 'GET',
56
- path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}",
57
- user: user
58
- ).json
59
- entity = json[StarkBank::Utils::API.last_name(resource_name)]
60
- StarkBank::Utils::API.from_api_json(resource_maker, entity)
52
+ def self.get_content(resource_name:, resource_maker:, user:, sub_resource_name:, id:, **query)
53
+ return StarkCore::Utils::Rest.get_content(
54
+ resource_name: resource_name,
55
+ resource_maker: resource_maker,
56
+ sdk_version: StarkBank::SDK_VERSION,
57
+ host: StarkBank::HOST,
58
+ api_version: StarkBank::API_VERSION,
59
+ user: user ? user : StarkBank.user,
60
+ language: StarkBank.language,
61
+ timeout: StarkBank.timeout,
62
+ sub_resource_name: sub_resource_name,
63
+ id: id,
64
+ **query
65
+ )
61
66
  end
62
67
 
63
- def self.get_content(resource_name:, resource_maker:, sub_resource_name:, id:, user: nil, **query)
64
- StarkBank::Utils::Request.fetch(
65
- method: 'GET',
66
- path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}/#{sub_resource_name}",
67
- query: StarkBank::Utils::API.cast_json_to_api_format(query),
68
- user: user
69
- ).content
68
+ def self.get_sub_resource(resource_name:, sub_resource_maker:, sub_resource_name:, user:, id:, **query)
69
+ return StarkCore::Utils::Rest.get_sub_resource(
70
+ resource_name: resource_name,
71
+ sub_resource_maker: sub_resource_maker,
72
+ sub_resource_name: sub_resource_name,
73
+ sdk_version: StarkBank::SDK_VERSION,
74
+ host: StarkBank::HOST,
75
+ api_version: StarkBank::API_VERSION,
76
+ user: user ? user : StarkBank.user,
77
+ language: StarkBank.language,
78
+ timeout: StarkBank.timeout,
79
+ id: id,
80
+ **query
81
+ )
70
82
  end
71
83
 
72
- def self.post(resource_name:, resource_maker:, entities:, user: nil)
73
- jsons = []
74
- entities.each do |entity|
75
- jsons << StarkBank::Utils::API.api_json(entity)
76
- end
77
- payload = { StarkBank::Utils::API.last_name_plural(resource_name) => jsons }
78
- json = StarkBank::Utils::Request.fetch(
79
- method: 'POST',
80
- path: StarkBank::Utils::API.endpoint(resource_name),
81
- payload: payload,
82
- user: user
83
- ).json
84
- returned_jsons = json[StarkBank::Utils::API.last_name_plural(resource_name)]
85
- entities = []
86
- returned_jsons.each do |returned_json|
87
- entities << StarkBank::Utils::API.from_api_json(resource_maker, returned_json)
88
- end
89
- entities
84
+ def self.get_sub_resources(resource_name:, sub_resource_maker:, sub_resource_name:, user:, id:, **query)
85
+ return StarkCore::Utils::Rest.get_sub_resource(
86
+ resource_name: resource_name,
87
+ sub_resource_maker: sub_resource_maker,
88
+ sub_resource_name: sub_resource_name,
89
+ sdk_version: StarkBank::SDK_VERSION,
90
+ host: StarkBank::HOST,
91
+ api_version: StarkBank::API_VERSION,
92
+ user: user ? user : StarkBank.user,
93
+ language: StarkBank.language,
94
+ timeout: StarkBank.timeout,
95
+ id: id,
96
+ **query
97
+ )
90
98
  end
91
99
 
92
- def self.post_single(resource_name:, resource_maker:, entity:, user: nil)
93
- json = StarkBank::Utils::Request.fetch(
94
- method: 'POST',
95
- path: StarkBank::Utils::API.endpoint(resource_name),
96
- payload: StarkBank::Utils::API.api_json(entity),
97
- user: user
98
- ).json
99
- entity_json = json[StarkBank::Utils::API.last_name(resource_name)]
100
- StarkBank::Utils::API.from_api_json(resource_maker, entity_json)
100
+ def self.post(resource_name:, resource_maker:, user:, entities:, **query)
101
+ return StarkCore::Utils::Rest.post(
102
+ resource_name: resource_name,
103
+ resource_maker: resource_maker,
104
+ sdk_version: StarkBank::SDK_VERSION,
105
+ host: StarkBank::HOST,
106
+ api_version: StarkBank::API_VERSION,
107
+ user: user ? user : StarkBank.user,
108
+ language: StarkBank.language,
109
+ timeout: StarkBank.timeout,
110
+ entities: entities,
111
+ **query
112
+ )
101
113
  end
102
114
 
103
- def self.delete_id(resource_name:, resource_maker:, id:, user: nil)
104
- json = StarkBank::Utils::Request.fetch(
105
- method: 'DELETE',
106
- path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}",
107
- user: user
108
- ).json
109
- entity = json[StarkBank::Utils::API.last_name(resource_name)]
110
- StarkBank::Utils::API.from_api_json(resource_maker, entity)
115
+ def self.post_single(resource_name:, resource_maker:, user:, entity:)
116
+ return StarkCore::Utils::Rest.post_single(
117
+ resource_name: resource_name,
118
+ resource_maker: resource_maker,
119
+ sdk_version: StarkBank::SDK_VERSION,
120
+ host: StarkBank::HOST,
121
+ api_version: StarkBank::API_VERSION,
122
+ user: user ? user : StarkBank.user,
123
+ language: StarkBank.language,
124
+ timeout: StarkBank.timeout,
125
+ entity: entity
126
+ )
111
127
  end
112
128
 
113
- def self.patch_id(resource_name:, resource_maker:, id:, user: nil, **payload)
114
- json = StarkBank::Utils::Request.fetch(
115
- method: 'PATCH',
116
- path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}",
117
- user: user,
118
- payload: StarkBank::Utils::API.cast_json_to_api_format(payload)
119
- ).json
120
- entity = json[StarkBank::Utils::API.last_name(resource_name)]
121
- StarkBank::Utils::API.from_api_json(resource_maker, entity)
129
+ def self.delete_id(resource_name:, resource_maker:, user:, id:)
130
+ return StarkCore::Utils::Rest.delete_id(
131
+ resource_name: resource_name,
132
+ resource_maker: resource_maker,
133
+ sdk_version: StarkBank::SDK_VERSION,
134
+ host: StarkBank::HOST,
135
+ api_version: StarkBank::API_VERSION,
136
+ user: user ? user : StarkBank.user,
137
+ language: StarkBank.language,
138
+ timeout: StarkBank.timeout,
139
+ id: id
140
+ )
122
141
  end
123
142
 
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)
143
+ def self.patch_id(resource_name:, resource_maker:, user:, id:, **payload)
144
+ return StarkCore::Utils::Rest.patch_id(
145
+ resource_name: resource_name,
146
+ resource_maker: resource_maker,
147
+ sdk_version: StarkBank::SDK_VERSION,
148
+ host: StarkBank::HOST,
149
+ api_version: StarkBank::API_VERSION,
150
+ user: user ? user : StarkBank.user,
151
+ language: StarkBank.language,
152
+ timeout: StarkBank.timeout,
153
+ id: id,
154
+ **payload
155
+ )
133
156
  end
134
157
  end
135
158
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require('starkcore')
4
4
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
5
+
6
6
 
7
7
  module StarkBank
8
8
  # # Webhook subscription object
@@ -15,9 +15,9 @@ module StarkBank
15
15
  # - url [string]: Url that will be notified when an event occurs.
16
16
  # - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['transfer', 'deposit']
17
17
  #
18
- # ## Attributes:
19
- # - id [string, default nil]: unique id returned when the webhook is created. ex: '5656565656565656'
20
- class Webhook < StarkBank::Utils::Resource
18
+ # ## Attributes (return-only):
19
+ # - id [string]: unique id returned when the webhook is created. ex: '5656565656565656'
20
+ class Webhook < StarkCore::Utils::Resource
21
21
  attr_reader :url, :subscriptions, :id
22
22
  def initialize(url:, subscriptions:, id: nil)
23
23
  super(id)
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require('starkcore')
4
+ require('base64')
4
5
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
6
+
6
7
 
7
8
  module StarkBank
8
9
  # # Workspace object
@@ -18,15 +19,23 @@ module StarkBank
18
19
  # ## Parameters (optional):
19
20
  # - allowed_tax_ids [list of strings]: list of tax IDs that will be allowed to send Deposits to this Workspace. ex: ['012.345.678-90', '20.018.183/0001-80']
20
21
  #
21
- # ## Attributes:
22
- # - id [string, 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)
22
+ # ## Attributes (return-only):
23
+ # - id [string]: unique id returned when the workspace is created. ex: '5656565656565656'
24
+ # - status [string]: current Workspace status. Options: 'active', 'closed', 'frozen' or 'blocked'
25
+ # - organization_id [string]: unique organization id returned when the organization is created. ex: '5656565656565656'
26
+ # - picture_url [string]: public workspace image (png) URL. ex: 'https://storage.googleapis.com/api-ms-workspace-sbx.appspot.com/pictures/workspace/6284441752174592.png?20230208220551'
27
+ # - created [DateTime]: creation datetime for the Workspace. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
28
+ class Workspace < StarkCore::Utils::Resource
29
+ attr_reader :username, :name, :allowed_tax_ids, :id, :status, :organization_id, :picture_url, :created
30
+ def initialize(username:, name:, allowed_tax_ids: nil, id: nil, status: nil, organization_id: nil, picture_url: nil, created: nil)
26
31
  super(id)
27
32
  @username = username
28
33
  @name = name
29
34
  @allowed_tax_ids = allowed_tax_ids
35
+ @status = status
36
+ @organization_id = organization_id
37
+ @picture_url = picture_url
38
+ @created = StarkCore::Utils::Checks.check_datetime(created)
30
39
  end
31
40
 
32
41
  # # Create Workspace
@@ -112,16 +121,31 @@ module StarkBank
112
121
  # ## Parameters (required):
113
122
  # - id [string]: Workspace unique id. ex: '5656565656565656'
114
123
  #
124
+ # ## Parameters (conditionally required):
125
+ # - picture_type [string]: picture MIME type. This parameter will be required if the picture parameter is informed ex: 'image/png' or 'image/jpeg'
126
+ #
115
127
  # ## Parameters (optional):
116
128
  # - username [string, default nil]: query by the simplified name that defines the workspace URL. This name is always unique across all Stark Bank Workspaces. Ex: 'starkbankworkspace'
117
129
  # - name [string, default nil]: Full name that identifies the Workspace. This name will appear when people access the Workspace on our platform, for example. Ex: 'Stark Bank Workspace'
118
130
  # - allowed_tax_ids [list of strings, default nil]: list of tax IDs that will be allowed to send Deposits to this Workspace. If empty, all are allowed. ex: ['012.345.678-90', '20.018.183/0001-80']
131
+ # - status [string, default nil]: current Workspace status. Options: 'active' or 'blocked'
132
+ # - picture [bytes, default nil]: Binary buffer of the picture. ex: open('/path/to/file.png', 'rb').read()
119
133
  # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
120
134
  #
121
135
  # ## Return:
122
136
  # - updated Workspace object
123
- def self.update(id, 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)
137
+ def self.update(id, username: nil, name: nil, allowed_tax_ids: nil, status: nil, picture: nil, picture_type: nil, user: nil)
138
+
139
+ payload = {
140
+ 'allowed_tax_ids': allowed_tax_ids,
141
+ 'status': status,
142
+ }
143
+
144
+ unless picture.nil?
145
+ payload['picture'] = "data:#{picture_type};base64,#{Base64.encode64(picture)}"
146
+ end
147
+
148
+ StarkBank::Utils::Rest.patch_id(id: id, user: user, username: username, name: name, **payload, **resource)
125
149
  end
126
150
 
127
151
  def self.resource
@@ -132,7 +156,11 @@ module StarkBank
132
156
  id: json['id'],
133
157
  username: json['username'],
134
158
  name: json['name'],
135
- allowed_tax_ids: json['allowed_tax_ids']
159
+ allowed_tax_ids: json['allowed_tax_ids'],
160
+ status: json['status'],
161
+ organization_id: json['organization_id'],
162
+ picture_url: json['picture_url'],
163
+ created: json['created']
136
164
  )
137
165
  }
138
166
  }