starkinfra 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/creditnote/creditnote.rb +583 -0
  3. data/lib/creditnote/log.rb +126 -0
  4. data/lib/event/attempt.rb +126 -0
  5. data/lib/event/event.rb +125 -7
  6. data/lib/issuingauthorization/issuingauthorization.rb +141 -0
  7. data/lib/issuingbalance/issuingbalance.rb +55 -0
  8. data/lib/issuingbin/issuingbin.rb +89 -0
  9. data/lib/issuingcard/issuingcard.rb +261 -0
  10. data/lib/issuingcard/log.rb +123 -0
  11. data/lib/issuingholder/issuingholder.rb +206 -0
  12. data/lib/issuingholder/log.rb +123 -0
  13. data/lib/issuinginvoice/issuinginvoice.rb +152 -0
  14. data/lib/issuinginvoice/log.rb +120 -0
  15. data/lib/issuingpurchase/issuingpurchase.rb +209 -0
  16. data/lib/issuingpurchase/log.rb +131 -0
  17. data/lib/issuingrule/issuingrule.rb +79 -0
  18. data/lib/issuingtransaction/issuingtransaction.rb +136 -0
  19. data/lib/issuingwithdrawal/issuingwithdrawal.rb +153 -0
  20. data/lib/pixbalance/pixbalance.rb +15 -15
  21. data/lib/pixchargeback/log.rb +129 -0
  22. data/lib/pixchargeback/pixchargeback.rb +225 -0
  23. data/lib/pixclaim/log.rb +135 -0
  24. data/lib/pixclaim/pixclaim.rb +226 -0
  25. data/lib/pixdirector/pixdirector.rb +76 -0
  26. data/lib/pixdomain/certificate.rb +30 -0
  27. data/lib/pixdomain/pixdomain.rb +58 -0
  28. data/lib/pixinfraction/log.rb +129 -0
  29. data/lib/pixinfraction/pixinfraction.rb +212 -0
  30. data/lib/pixkey/log.rb +128 -0
  31. data/lib/pixkey/pixkey.rb +240 -0
  32. data/lib/pixrequest/log.rb +16 -16
  33. data/lib/pixrequest/pixrequest.rb +66 -67
  34. data/lib/pixreversal/log.rb +13 -12
  35. data/lib/pixreversal/pixreversal.rb +74 -72
  36. data/lib/pixstatement/pixstatement.rb +24 -25
  37. data/lib/starkinfra.rb +32 -3
  38. data/lib/user/organization.rb +54 -0
  39. data/lib/user/project.rb +37 -0
  40. data/lib/user/user.rb +20 -0
  41. data/lib/utils/api.rb +10 -2
  42. data/lib/utils/bacenid.rb +19 -0
  43. data/lib/utils/checks.rb +2 -3
  44. data/lib/utils/endtoendid.rb +11 -0
  45. data/lib/utils/parse.rb +13 -13
  46. data/lib/utils/request.rb +2 -2
  47. data/lib/utils/rest.rb +6 -5
  48. data/lib/utils/returnid.rb +11 -0
  49. data/lib/webhook/webhook.rb +124 -0
  50. metadata +45 -24
@@ -0,0 +1,226 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkInfra
8
+ # # PixClaim object
9
+ #
10
+ # PixClaims intend to transfer a PixClaim from one account to another.
11
+ # When you initialize a PixClaim, the entity will not be automatically
12
+ # created in the Stark Infra API. The 'create' function sends the objects
13
+ # to the Stark Infra API and returns the created object.
14
+ #
15
+ # ## Parameters (required):
16
+ # - account_created [Date, DateTime or string]: opening Date or DateTime for the account claiming the PixClaim. ex: '2022-01-01'.
17
+ # - account_number [string]: number of the account claiming the PixClaim. ex: '76543'.
18
+ # - account_type [string]: type of the account claiming the PixClaim. Options: 'checking', 'savings', 'salary' or 'payment'.
19
+ # - branch_code [string]: branch code of the account claiming the PixClaim. ex: 1234'.
20
+ # - name [string]: holder's name of the account claiming the PixClaim. ex: 'Jamie Lannister'.
21
+ # - tax_id [string]: holder's taxId of the account claiming the PixClaim (CPF/CNPJ). ex: '012.345.678-90'.
22
+ # - key_id [string]: id of the registered Pix Key to be claimed. Allowed keyTypes are CPF, CNPJ, phone number or email. ex: '+5511989898989'.
23
+ #
24
+ # ## Attributes (return-only):
25
+ # - id [string]: unique id returned when the PixClaim is created. ex: '5656565656565656'
26
+ # - status [string]: current PixClaim status. Options: 'created', 'failed', 'delivered', 'confirmed', 'success', 'canceled'
27
+ # - type [string]: type of Pix Claim. Options: 'ownership', 'portability'.
28
+ # - key_type [string]: keyType of the claimed Pix Key. Options: 'CPF', 'CNPJ', 'phone' or 'email'
29
+ # - agent [string]: Options: 'claimer' if you requested the PixClaim or 'claimed' if you received a PixClaim request.
30
+ # - bank_code [string]: bank_code of the account linked to the PixClaim being claimed. ex: '20018183'.
31
+ # - claimed_bank_code [string]: bank_code of the account donating the PixClaim. ex: '20018183'.
32
+ # - created [DateTime]: creation datetime for the PixClaim. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
33
+ # - updated [DateTime]: update datetime for the PixClaim. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
+ class PixClaim < StarkInfra::Utils::Resource
35
+ attr_reader :account_created, :account_number, :account_type, :branch_code, :name, :tax_id, :key_id,
36
+ :id, :status, :type, :key_type, :agent, :bank_code, :claimed_bank_code, :created, :updated
37
+ def initialize(
38
+ account_created:, account_number:, account_type:, branch_code:, name:,
39
+ tax_id:, key_id:, id: nil, status: nil, type: nil, key_type: nil, agent: nil,
40
+ bank_code: nil, claimed_bank_code: nil, created: nil, updated: nil
41
+ )
42
+ super(id)
43
+ @account_created = account_created
44
+ @account_number = account_number
45
+ @account_type = account_type
46
+ @branch_code = branch_code
47
+ @name = name
48
+ @tax_id = tax_id
49
+ @key_id = key_id
50
+ @status = status
51
+ @type = type
52
+ @key_type = key_type
53
+ @agent = agent
54
+ @bank_code = bank_code
55
+ @claimed_bank_code = claimed_bank_code
56
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
57
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
58
+ end
59
+
60
+ # # Create a PixClaim
61
+ #
62
+ # Send a PixClaim object for creation in the Stark Infra API
63
+ #
64
+ # ## Parameters (required):
65
+ # - claim [PixClaim object]: PixClaim object to be created in the API. ex: PixClaim.new()
66
+ #
67
+ # ## Parameters (optional):
68
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
69
+ #
70
+ # ## Return:
71
+ # - PixClaim object with updated attributes
72
+ def self.create(claim, user: nil)
73
+ StarkInfra::Utils::Rest.post_single(entity: claim, user: user, **resource)
74
+ end
75
+
76
+ # # Retrieve a specific PixClaim
77
+ #
78
+ # Receive a single PixClaim object previously created in the Stark Infra API by passing its id
79
+ #
80
+ # ## Parameters (required):
81
+ # - id [string]: object unique id. ex: '5656565656565656'
82
+ #
83
+ # ## Parameters (optional):
84
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
85
+ #
86
+ # ## Return:
87
+ # - PixClaim object with updated attributes
88
+ def self.get(id, user: nil)
89
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
90
+ end
91
+
92
+ # # Retrieve PixClaims
93
+ #
94
+ # Receive a generator of PixClaim objects previously created in the Stark Infra API
95
+ #
96
+ # ## Parameters (optional):
97
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
98
+ # - after [Date or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
99
+ # - before [Date or string, default nil]: date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
100
+ # - status [string, default nil]: filter for status of retrieved objects. Options: 'created', 'failed', 'delivered', 'confirmed', 'success', 'canceled'
101
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
102
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
103
+ # - type [string, default nil]: filter for the type of retrieved PixClaims. Options: 'ownership' or 'portability'
104
+ # - agent [string, default nil]: filter for the agent of retrieved PixClaims. Options: 'claimer' or 'claimed'.
105
+ # - key_type [string, default nil]: filter for the PixKey type of retrieved PixClaims. Options: 'cpf', 'cnpj', 'phone', 'email' and 'evp',
106
+ # - key_id [string, default nil]: filter PixClaims linked to a specific PixKey id. Example: '+5511989898989'.
107
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
108
+ #
109
+ # ## Return:
110
+ # - generator of PixClaim objects with updated attributes
111
+ def self.query(
112
+ limit: nil, after: nil, before: nil, status: nil, ids: nil,
113
+ type: nil, agent: nil, key_type: nil, key_id: nil, user: nil
114
+ )
115
+ after = StarkInfra::Utils::Checks.check_date(after)
116
+ before = StarkInfra::Utils::Checks.check_date(before)
117
+ StarkInfra::Utils::Rest.get_stream(
118
+ limit: limit,
119
+ after: after,
120
+ before: before,
121
+ status: status,
122
+ ids: ids,
123
+ type: type,
124
+ agent: agent,
125
+ key_type: key_type,
126
+ key_id: key_id,
127
+ user: user,
128
+ **resource
129
+ )
130
+ end
131
+
132
+ # # Retrieve paged PixClaims
133
+ #
134
+ # Receive a list of up to 100 PixClaim objects previously created in the Stark infra API and the cursor to the next page.
135
+ # Use this function instead of query if you want to manually page your claims.
136
+ #
137
+ # ## Parameters (optional):
138
+ # - cursor [string, default nil]: cursor returned on the previous page function call
139
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
140
+ # - after [Date or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
141
+ # - before [Date or string, default nil]: date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
142
+ # - status [string, default nil]: filter for status of retrieved objects. Options: 'created', 'failed', 'delivered', 'confirmed', 'success', 'canceled'
143
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
144
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
145
+ # - type [string, default nil]: filter for the type of retrieved PixClaims. Options: 'ownership' or 'portability'
146
+ # - agent [string, default nil]: filter for the agent of retrieved PixClaims. Options: 'claimer' or 'claimed'.
147
+ # - key_type [string, default nil]: filter for the PixKey type of retrieved PixClaims. Options: 'cpf', 'cnpj', 'phone', 'email' and 'evp',
148
+ # - key_id [string, default nil]: filter PixClaims linked to a specific PixKey id. Example: '+5511989898989'.
149
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
150
+ #
151
+ # ## Return:
152
+ # - list of PixClaim objects with updated attributes
153
+ # - cursor to retrieve the next page of PixClaim objects
154
+ def self.page(
155
+ cursor: nil, limit: nil, after: nil, before: nil, status: nil, ids: nil,
156
+ type: nil, agent: nil, key_type: nil, key_id: nil, user: nil
157
+ )
158
+ after = StarkInfra::Utils::Checks.check_date(after)
159
+ before = StarkInfra::Utils::Checks.check_date(before)
160
+ StarkInfra::Utils::Rest.get_page(
161
+ cursor: cursor,
162
+ limit: limit,
163
+ after: after,
164
+ before: before,
165
+ status: status,
166
+ ids: ids,
167
+ type: type,
168
+ agent: agent,
169
+ key_type: key_type,
170
+ key_id: key_id,
171
+ user: user,
172
+ **resource
173
+ )
174
+ end
175
+
176
+ # # Update a PixClaim entity
177
+ #
178
+ # Respond to a received PixClaim.
179
+ #
180
+ # ## Parameters (required):
181
+ # - id [string]: PixClaim unique id. ex: '5656565656565656'
182
+ # - status [string]: patched status for Pix Claim. Options: 'confirmed' and 'canceled'
183
+ #
184
+ # ## Parameters (optional):
185
+ # - reason [string, default 'userRequested']: reason why the PixClaim is being patched. Options: 'fraud', 'userRequested', 'accountClosure'.
186
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
187
+ #
188
+ # ## Return:
189
+ # - updated PixClaim object
190
+ def self.update(id, status:, reason: nil, user: nil)
191
+ StarkInfra::Utils::Rest.patch_id(
192
+ id: id,
193
+ status: status,
194
+ reason: reason,
195
+ user: user,
196
+ **resource
197
+ )
198
+ end
199
+
200
+ def self.resource
201
+ {
202
+ resource_name: 'PixClaim',
203
+ resource_maker: proc { |json|
204
+ PixClaim.new(
205
+ account_created: json['account_created'],
206
+ account_number: json['account_number'],
207
+ account_type: json['account_type'],
208
+ branch_code: json['branch_code'],
209
+ name: json['name'],
210
+ tax_id: json['tax_id'],
211
+ key_id: json['key_id'],
212
+ id: json['id'],
213
+ status: json['status'],
214
+ type: json['type'],
215
+ key_type: json['key_type'],
216
+ agent: json['agent'],
217
+ bank_code: json['bank_code'],
218
+ claimed_bank_code: json['claimed_bank_code'],
219
+ created: json['created'],
220
+ updated: json['updated']
221
+ )
222
+ }
223
+ }
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+
6
+ module StarkInfra
7
+ # # PixDirector object
8
+ #
9
+ # Mandatory data that must be registered within the Central Bank for
10
+ # emergency contact purposes. When you initialize a PixDirector,
11
+ # the entity will not be automatically created in the Stark Infra API.
12
+ # The 'create' function sends the objects to the Stark Infra API and
13
+ # returns the list of created objects.
14
+ #
15
+ # ## Parameters (required):
16
+ # - name [string]: name of the PixDirector. ex: 'Edward Stark'.
17
+ # - tax_id [string]: tax ID (CPF) of the PixDirector. ex: '012.345.678-90'
18
+ # - phone [string]: phone of the PixDirector. ex: '+551198989898'
19
+ # - email [string]: email of the PixDirector. ex: 'ned.stark@starkbank.com'
20
+ # - password [string]: password of the PixDirector. ex: '12345678'
21
+ # - team_email [string]: team email. ex: 'pix.team@company.com'
22
+ # - team_phones [list of strings]: list of phones of the team. ex: ['+5511988889999', '+5511988889998']
23
+ #
24
+ # ## Attributes (return-only):
25
+ # - id [string]: unique id returned when the PixDirector is created. ex: '5656565656565656'
26
+ # - status [string]: current PixDirector status. ex: 'success'
27
+ class PixDirector < StarkInfra::Utils::Resource
28
+ attr_reader :name, :tax_id, :phone, :email, :password, :team_email, :team_phones, :id, :status
29
+ def initialize(name:, tax_id:, phone:, email:, password:, team_email:, team_phones:, id: nil, status: nil)
30
+ super(id)
31
+ @name = name
32
+ @tax_id = tax_id
33
+ @phone = phone
34
+ @email = email
35
+ @password = password
36
+ @team_email = team_email
37
+ @team_phones = team_phones
38
+ @status = status
39
+ end
40
+
41
+ # # Create a PixDirector
42
+ #
43
+ # Send a PixDirector object for creation in the Stark Infra API
44
+ #
45
+ # ## Parameters (required):
46
+ # - director [PixDirector object]: PixDirector object to be created in the API. ex: PixDirector.new()
47
+ #
48
+ # ## Parameters (optional):
49
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
50
+ #
51
+ # ## Return:
52
+ # - PixDirector object with updated attributes.
53
+ def self.create(director, user: nil)
54
+ StarkInfra::Utils::Rest.post_single(entity: director, user: user, **resource)
55
+ end
56
+
57
+ def self.resource
58
+ {
59
+ resource_name: 'PixDirector',
60
+ resource_maker: proc { |json|
61
+ PixDirector.new(
62
+ id: json['id'],
63
+ name: json['name'],
64
+ tax_id: json['tax_id'],
65
+ phone: json['phone'],
66
+ email: json['email'],
67
+ password: json['password'],
68
+ team_email: json['team_email'],
69
+ team_phones: json['team_phones'],
70
+ status: json['status']
71
+ )
72
+ }
73
+ }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+
6
+ module StarkInfra
7
+ # # PixDomain::Certificate object
8
+ #
9
+ # The Certificate object displays the certificate information from a specific domain.
10
+ #
11
+ # ## Attributes (return-only):
12
+ # - content [string]: certificate of the Pix participant in PEM format.
13
+ class Certificate < StarkInfra::Utils::SubResource
14
+ attr_reader :content
15
+ def initialize(content: nil)
16
+ @content = content
17
+ end
18
+
19
+ def self.resource
20
+ {
21
+ resource_name: 'Certificate',
22
+ resource_maker: proc { |json|
23
+ Certificate.new(
24
+ content: json['content']
25
+ )
26
+ }
27
+ }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('certificate')
6
+
7
+ module StarkInfra
8
+ # # PixDomain object
9
+ #
10
+ # The PixDomain object displays the domain name and the QR Code
11
+ # domain certificate of Pix participants.
12
+ # All certificates must be registered with the Central Bank.
13
+ #
14
+ # ## Attributes (return-only):
15
+ # - certificates [list of PixDomain::Certificate objects]: certificate information of the Pix participant.
16
+ # - name [string]: current active domain (URL) of the Pix participant.
17
+ class PixDomain < StarkInfra::Utils::SubResource
18
+ attr_reader :certificates, :name
19
+ def initialize(certificates: nil, name: nil)
20
+ @certificates = certificates
21
+ @name = name
22
+ end
23
+
24
+ # # Retrieve PixDomains
25
+ #
26
+ # Receive a generator of PixDomain objects registered at the Central Bank.
27
+ #
28
+ # ## Parameters (optional):
29
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
30
+ #
31
+ # ## Return:
32
+ # - generator of PixDomain objects with updated attributes
33
+ def self.query(user: nil)
34
+ StarkInfra::Utils::Rest.get_stream(user: user, **resource)
35
+ end
36
+
37
+ def self._parse_certificates(certificates)
38
+ certificate_maker = StarkInfra::Certificate.resource[:resource_maker]
39
+ parsed_certificates = []
40
+ certificates.each do |certificate|
41
+ parsed_certificates << StarkInfra::Utils::API.from_api_json(certificate_maker, certificate)
42
+ end
43
+ parsed_certificates
44
+ end
45
+
46
+ def self.resource
47
+ {
48
+ resource_name: 'PixDomain',
49
+ resource_maker: proc { |json|
50
+ PixDomain.new(
51
+ name: json['name'],
52
+ certificates: _parse_certificates(json['certificates'])
53
+ )
54
+ }
55
+ }
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('pixinfraction')
7
+
8
+ module StarkInfra
9
+ class PixInfraction
10
+ # # PixInfraction::Log object
11
+ #
12
+ # Every time a PixInfraction entity is modified, a corresponding PixInfraction::Log
13
+ # is generated for the entity. This log is never generated by the
14
+ # user.
15
+ #
16
+ # ## Attributes:
17
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
18
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
19
+ # - type [string]: type of the PixInfraction event which triggered the log creation. Options: 'created', 'failed', 'delivering', 'delivered', 'closed', 'canceled'
20
+ # - errors [list of strings]: list of errors linked to this PixInfraction event.
21
+ # - infraction [PixInfraction]: PixInfraction entity to which the log refers to.
22
+ class Log < StarkInfra::Utils::Resource
23
+ attr_reader :id, :created, :type, :errors, :infraction
24
+ def initialize(id:, created:, type:, errors:, infraction:)
25
+ super(id)
26
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
27
+ @type = type
28
+ @errors = errors
29
+ @infraction = infraction
30
+ end
31
+
32
+ # # Retrieve a specific Log
33
+ #
34
+ # Receive a single Log object previously created by the Stark Infra API by passing its id
35
+ #
36
+ # ## Parameters (required):
37
+ # - id [string]: object unique id. ex: '5656565656565656'
38
+ #
39
+ # ## Parameters (optional):
40
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
41
+ #
42
+ # ## Return:
43
+ # - Log object with updated attributes
44
+ def self.get(id, user: nil)
45
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
46
+ end
47
+
48
+ # # Retrieve Logs
49
+ #
50
+ # Receive a generator of Log objects previously created in the Stark Infra API
51
+ #
52
+ # ## Parameters (optional):
53
+ # - ids [list of strings, default nil]: Log ids to filter PixInfraction Logs. ex: ['5656565656565656']
54
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
55
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
56
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
57
+ # - types [list of strings, default nil]: filter retrieved objects by their types. Options: 'created', 'failed', 'delivering', 'delivered', 'closed', 'canceled'
58
+ # - infraction_ids [list of strings, default nil]: list of PixInfraction ids to filter retrieved objects. ex: %w[5656565656565656 4545454545454545]
59
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
60
+ #
61
+ # ## Return:
62
+ # - list of Log objects with updated attributes
63
+ def self.query(ids: nil, limit: nil, after: nil, before: nil, types: nil, infraction_ids: nil, user: nil)
64
+ after = StarkInfra::Utils::Checks.check_date(after)
65
+ before = StarkInfra::Utils::Checks.check_date(before)
66
+ StarkInfra::Utils::Rest.get_stream(
67
+ ids: ids,
68
+ limit: limit,
69
+ after: after,
70
+ before: before,
71
+ types: types,
72
+ infraction_ids: infraction_ids,
73
+ user: user,
74
+ **resource
75
+ )
76
+ end
77
+
78
+ # # Retrieve paged Logs
79
+ #
80
+ # Receive a list of up to 100 Log objects previously created in the Stark Infra API and the cursor to the next page.
81
+ # Use this function instead of query if you want to manually page your infractions.
82
+ #
83
+ # ## Parameters (optional):
84
+ # - cursor [string, default nil]: cursor returned on the previous page function call
85
+ # - ids [list of strings, default nil]: Log ids to filter PixInfraction Logs. ex: ['5656565656565656']
86
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
87
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
88
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
89
+ # - types [list of strings, default nil]: filter retrieved objects by their types. Options: 'created', 'failed', 'delivering', 'delivered', 'closed', 'canceled'
90
+ # - infraction_ids [list of strings, default nil]: list of PixInfraction ids to filter retrieved objects. ex: %w[5656565656565656 4545454545454545]
91
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
92
+ #
93
+ # ## Return:
94
+ # - list of Log objects with updated attributes
95
+ # - Cursor to retrieve the next page of Log objects
96
+ def self.page(cursor: nil, ids: nil, limit: nil, after: nil, before: nil, types: nil, infraction_ids: nil, user: nil)
97
+ after = StarkInfra::Utils::Checks.check_date(after)
98
+ before = StarkInfra::Utils::Checks.check_date(before)
99
+ StarkInfra::Utils::Rest.get_page(
100
+ cursor: cursor,
101
+ ids: ids,
102
+ limit: limit,
103
+ after: after,
104
+ before: before,
105
+ types: types,
106
+ infraction_ids: infraction_ids,
107
+ user: user,
108
+ **resource
109
+ )
110
+ end
111
+
112
+ def self.resource
113
+ infraction_maker = StarkInfra::PixInfraction.resource[:resource_maker]
114
+ {
115
+ resource_name: 'PixInfractionLog',
116
+ resource_maker: proc { |json|
117
+ Log.new(
118
+ id: json['id'],
119
+ created: json['created'],
120
+ type: json['type'],
121
+ errors: json['errors'],
122
+ infraction: StarkInfra::Utils::API.from_api_json(infraction_maker, json['infraction'])
123
+ )
124
+ }
125
+ }
126
+ end
127
+ end
128
+ end
129
+ end