starkinfra 0.0.2 → 0.0.3

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 +561 -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 +260 -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 +81 -0
  18. data/lib/issuingtransaction/issuingtransaction.rb +136 -0
  19. data/lib/issuingwithdrawal/issuingwithdrawal.rb +153 -0
  20. data/lib/pixbalance/pixbalance.rb +13 -13
  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 +225 -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 +239 -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 +72 -71
  36. data/lib/pixstatement/pixstatement.rb +22 -23
  37. data/lib/starkinfra.rb +32 -2
  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 +1 -1
  47. data/lib/utils/rest.rb +7 -5
  48. data/lib/utils/returnid.rb +11 -0
  49. data/lib/webhook/webhook.rb +124 -0
  50. metadata +45 -24
@@ -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
@@ -0,0 +1,212 @@
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
+ # # PixInfraction object
9
+ #
10
+ # PixInfractions are used to report transactions that are suspected of
11
+ # fraud, to request a refund or to reverse a refund.
12
+ # When you initialize a PixInfraction, the entity will not be automatically
13
+ # created in the Stark Infra API. The 'create' function sends the objects
14
+ # to the Stark Infra API and returns the created object.
15
+ #
16
+ # ## Parameters (required):
17
+ # - reference_id [string]: end_to_end_id or return_id of the transaction being reported. ex: 'E20018183202201201450u34sDGd19lz'
18
+ # - type [string]: type of infraction report. Options: 'fraud', 'reversal', 'reversalChargeback'
19
+ #
20
+ # ## Parameters (optional):
21
+ # - description [string, default nil]: description for any details that can help with the infraction investigation.
22
+ #
23
+ # ## Attributes (return-only):
24
+ # - id [string]: unique id returned when the PixInfraction is created. ex: '5656565656565656'
25
+ # - credited_bank_code [string]: bank_code of the credited Pix participant in the reported transaction. ex: '20018183'
26
+ # - debited_bank_code [string]: bank_code of the debited Pix participant in the reported transaction. ex: '20018183'
27
+ # - agent [string]: Options: 'reporter' if you created the PixInfraction, 'reported' if you received the PixInfraction.
28
+ # - analysis [string]: analysis that led to the result.
29
+ # - bacen_id [string]: central bank's unique UUID that identifies the infraction report.
30
+ # - reported_by [string]: agent that reported the PixInfraction. Options: 'debited', 'credited'.
31
+ # - result [string]: result after the analysis of the PixInfraction by the receiving party. Options: 'agreed', 'disagreed'
32
+ # - status [string]: current PixInfraction status. Options: 'created', 'failed', 'delivered', 'closed', 'canceled'.
33
+ # - created [DateTime]: creation datetime for the PixInfraction. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
+ # - updated [DateTime]: latest update datetime for the PixInfraction. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
35
+ class PixInfraction < StarkInfra::Utils::Resource
36
+ attr_reader :reference_id, :type, :description, :id, :credited_bank_code, :agent, :analysis, :bacen_id,
37
+ :debited_bank_code, :reported_by, :result, :status, :created, :updated
38
+ def initialize(
39
+ reference_id:, type:, description:, id: nil, credited_bank_code: nil, agent: nil, analysis: nil, bacen_id: nil,
40
+ debited_bank_code: nil, reported_by: nil, result: nil, status: nil, created: nil, updated: nil
41
+ )
42
+ super(id)
43
+ @reference_id = reference_id
44
+ @type = type
45
+ @description = description
46
+ @credited_bank_code = credited_bank_code
47
+ @agent = agent
48
+ @analysis = analysis
49
+ @bacen_id = bacen_id
50
+ @debited_bank_code = debited_bank_code
51
+ @reported_by = reported_by
52
+ @result = result
53
+ @status = status
54
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
55
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
56
+ end
57
+
58
+ # # Create PixInfractions
59
+ #
60
+ # Send a list of PixInfraction objects for creation in the Stark Infra API
61
+ #
62
+ # ## Parameters (required):
63
+ # - infractions [list of PixInfraction objects]: list of PixInfraction objects to be created in the API. ex: [PixInfraction.new()]
64
+ #
65
+ # ## Parameters (optional):
66
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
67
+ #
68
+ # ## Return:
69
+ # - list of PixInfraction objects with updated attributes
70
+ def self.create(infractions, user: nil)
71
+ StarkInfra::Utils::Rest.post(entities: infractions, user: user, **resource)
72
+ end
73
+
74
+ # # Retrieve a specific PixInfraction
75
+ #
76
+ # Receive a single PixInfraction object previously created in the Stark Infra API by passing its id
77
+ #
78
+ # ## Parameters (required):
79
+ # - id [string]: object unique id. ex: '5656565656565656'
80
+ #
81
+ # ## Parameters (optional):
82
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
83
+ #
84
+ # ## Return:
85
+ # - PixInfraction object with updated attributes
86
+ def self.get(id, user: nil)
87
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
88
+ end
89
+
90
+ # # Retrieve PixInfractions
91
+ #
92
+ # Receive a generator of PixInfraction objects previously created in the Stark Infra API
93
+ #
94
+ # ## Parameters (optional):
95
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
96
+ # - after [Date or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
97
+ # - before [Date or string, default nil]: date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
98
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
99
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
100
+ # - type [string]: filter for the type of retrieved PixInfractions. Options: 'fraud', 'reversal', 'reversalChargeback'
101
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
102
+ #
103
+ # ## Return:
104
+ # - generator of PixInfraction objects with updated attributes
105
+ def self.query(limit: nil, after: nil, before: nil, status: nil, ids: nil, type: nil, user: nil)
106
+ after = StarkInfra::Utils::Checks.check_date(after)
107
+ before = StarkInfra::Utils::Checks.check_date(before)
108
+ StarkInfra::Utils::Rest.get_stream(
109
+ limit: limit,
110
+ after: after,
111
+ before: before,
112
+ status: status,
113
+ ids: ids,
114
+ type: type,
115
+ user: user,
116
+ **resource
117
+ )
118
+ end
119
+
120
+ # # Retrieve paged PixInfractions
121
+ #
122
+ # Receive a list of up to 100 PixInfraction objects previously created in the Stark infra API and the cursor to the next page.
123
+ # Use this function instead of query if you want to manually page your infractions.
124
+ #
125
+ # ## Parameters (optional):
126
+ # - cursor [string, default nil]: cursor returned on the previous page function call
127
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
128
+ # - after [Date or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
129
+ # - before [Date or string, default nil]: date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
130
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
131
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
132
+ # - type [string, default nil]: filter for the type of retrieved PixInfractions. Options: 'fraud', 'reversal', 'reversalChargeback'
133
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
134
+ #
135
+ # ## Return:
136
+ # - list of PixInfraction objects with updated attributes
137
+ # - cursor to retrieve the next page of PixInfraction objects
138
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, ids: nil, type: nil, user: nil)
139
+ after = StarkInfra::Utils::Checks.check_date(after)
140
+ before = StarkInfra::Utils::Checks.check_date(before)
141
+ StarkInfra::Utils::Rest.get_page(
142
+ cursor: cursor,
143
+ limit: limit,
144
+ after: after,
145
+ before: before,
146
+ status: status,
147
+ ids: ids,
148
+ type: type,
149
+ user: user,
150
+ **resource
151
+ )
152
+ end
153
+
154
+ # # Update a PixInfraction entity
155
+ #
156
+ # Respond to a received PixInfraction.
157
+ #
158
+ # ## Parameters (required):
159
+ # - id [string]: PixInfraction unique id. ex: '5656565656565656'
160
+ # - result [string]: result after the analysis of the PixInfraction. Options: 'agreed', 'disagreed'
161
+ #
162
+ # ## Parameters (optional):
163
+ # - analysis [string, nil]: analysis that led to the result.
164
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
165
+ #
166
+ # ## Return:
167
+ # - updated PixInfraction object
168
+ def self.update(id, result:, analysis: nil, user: nil)
169
+ StarkInfra::Utils::Rest.patch_id(id: id, result: result, analysis: analysis, user: user, **resource)
170
+ end
171
+
172
+ # # Cancel a PixInfraction entity
173
+ #
174
+ # Cancel a PixInfraction entity previously created in the Stark Infra API
175
+ #
176
+ # ## Parameters (required):
177
+ # - id [string]: PixInfraction unique id. ex: '5656565656565656'
178
+ #
179
+ # ## Parameters (optional):
180
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
181
+ #
182
+ # ## Return:
183
+ # - canceled PixInfraction object
184
+ def self.cancel(id, user: nil)
185
+ StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
186
+ end
187
+
188
+ def self.resource
189
+ {
190
+ resource_name: 'PixInfraction',
191
+ resource_maker: proc { |json|
192
+ PixInfraction.new(
193
+ id: json['id'],
194
+ reference_id: json['reference_id'],
195
+ type: json['type'],
196
+ description: json['description'],
197
+ credited_bank_code: json['credited_bank_code'],
198
+ agent: json['agent'],
199
+ analysis: json['analysis'],
200
+ bacen_id: json['bacen_id'],
201
+ debited_bank_code: json['debited_bank_code'],
202
+ reported_by: json['reported_by'],
203
+ result: json['result'],
204
+ status: json['status'],
205
+ created: json['created'],
206
+ updated: json['updated']
207
+ )
208
+ }
209
+ }
210
+ end
211
+ end
212
+ end
data/lib/pixkey/log.rb ADDED
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('pixkey')
7
+
8
+ module StarkInfra
9
+ class PixKey
10
+ # # PixKey::Log object
11
+ #
12
+ # Every time a PixKey entity is modified, a corresponding PixKey::Log is generated for the entity.
13
+ # This log is never generated by the user.
14
+ #
15
+ # ## Attributes:
16
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
17
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
18
+ # - type [string]: type of the PixKey event which triggered the log creation. Options: 'created', 'registered', 'updated', 'failed', 'canceling', 'canceled'.
19
+ # - errors [list of strings]: list of errors linked to this PixKey event.
20
+ # - key [PixKey]: PixKey entity to which the log refers to.
21
+ class Log < StarkInfra::Utils::Resource
22
+ attr_reader :id, :created, :type, :errors, :key
23
+ def initialize(id:, created:, type:, errors:, key:)
24
+ super(id)
25
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
26
+ @type = type
27
+ @errors = errors
28
+ @key = key
29
+ end
30
+
31
+ # # Retrieve a specific Log
32
+ #
33
+ # Receive a single Log object previously created by the Stark Infra API by passing its id
34
+ #
35
+ # ## Parameters (required):
36
+ # - id [string]: object unique id. ex: '5656565656565656'
37
+ #
38
+ # ## Parameters (optional):
39
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
40
+ #
41
+ # ## Return:
42
+ # - Log object with updated attributes
43
+ def self.get(id, user: nil)
44
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
45
+ end
46
+
47
+ # # Retrieve Logs
48
+ #
49
+ # Receive a generator of Log objects previously created in the Stark Infra API
50
+ #
51
+ # ## Parameters (optional):
52
+ # - ids [list of strings, default nil]: Log ids to filter PixKey Logs. ex: ['5656565656565656']
53
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
54
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
55
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
56
+ # - types [list of strings, default nil]: filter PixKey Logs by their types. Options: 'created', 'registered', 'updated', 'failed', 'canceling', 'canceled'.
57
+ # - key_ids [list of strings, default nil]: list of PixKey ids to filter retrieved objects. ex: %w[5656565656565656 4545454545454545]
58
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
59
+ #
60
+ # ## Return:
61
+ # - generator of Log objects with updated attributes
62
+ def self.query(ids: nil, limit: nil, after: nil, before: nil, types: nil, key_ids: nil, user: nil)
63
+ after = StarkInfra::Utils::Checks.check_date(after)
64
+ before = StarkInfra::Utils::Checks.check_date(before)
65
+ StarkInfra::Utils::Rest.get_stream(
66
+ ids: ids,
67
+ limit: limit,
68
+ after: after,
69
+ before: before,
70
+ types: types,
71
+ key_ids: key_ids,
72
+ user: user,
73
+ **resource
74
+ )
75
+ end
76
+
77
+ # # Retrieve paged Logs
78
+ #
79
+ # Receive a list of up to 100 Log objects previously created in the Stark Infra API and the cursor to the next page.
80
+ # Use this function instead of query if you want to manually page your keys.
81
+ #
82
+ # ## Parameters (optional):
83
+ # - ids [list of strings, default nil]: Log ids to filter PixKey Logs. ex: ['5656565656565656']
84
+ # - cursor [string, default nil]: cursor returned on the previous page function call
85
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
86
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
87
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
88
+ # - types [list of strings]: filter PixKey Logs by their types. Options: 'created', 'registered', 'updated', 'failed', 'canceling', 'canceled'.
89
+ # - key_ids [list of strings, default nil]: list of PixKey ids to filter retrieved objects. ex: %w[5656565656565656 4545454545454545]
90
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
91
+ #
92
+ # ## Return:
93
+ # - list of Log objects with updated attributes
94
+ # - cursor to retrieve the next page of Log objects
95
+ def self.page(cursor: nil, ids: nil, limit: nil, after: nil, before: nil, types: nil, key_ids: nil, user: nil)
96
+ after = StarkInfra::Utils::Checks.check_date(after)
97
+ before = StarkInfra::Utils::Checks.check_date(before)
98
+ StarkInfra::Utils::Rest.get_page(
99
+ cursor: cursor,
100
+ ids: ids,
101
+ limit: limit,
102
+ after: after,
103
+ before: before,
104
+ types: types,
105
+ key_ids: key_ids,
106
+ user: user,
107
+ **resource
108
+ )
109
+ end
110
+
111
+ def self.resource
112
+ key_maker = StarkInfra::PixKey.resource[:resource_maker]
113
+ {
114
+ resource_name: 'PixKeyLog',
115
+ resource_maker: proc { |json|
116
+ Log.new(
117
+ id: json['id'],
118
+ created: json['created'],
119
+ type: json['type'],
120
+ errors: json['errors'],
121
+ key: StarkInfra::Utils::API.from_api_json(key_maker, json['key'])
122
+ )
123
+ }
124
+ }
125
+ end
126
+ end
127
+ end
128
+ end