starkinfra 0.0.2 → 0.0.3

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 (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,89 @@
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
+ # # IssuingBin object
9
+ #
10
+ # The IssuingBin object displays information of registered BINs to your Workspace.
11
+ # They represent a group of cards that begin with the same numbers (BIN) and offer the same product to end customers.
12
+ #
13
+ # ## Attributes (return-only):
14
+ # - id [string]: unique BIN number registered within the card network. ex: '53810200'
15
+ # - network [string]: card network flag. ex: 'mastercard'
16
+ # - settlement [string]: settlement type. ex: 'credit'
17
+ # - category [string]: purchase category. ex: 'prepaid'
18
+ # - client [string]: client type. ex: 'business'
19
+ # - created [DateTime]: creation datetime for the IssuingBin. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
20
+ # - updated [DateTime]: latest update datetime for the IssuingBin. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
21
+ class IssuingBin < StarkInfra::Utils::Resource
22
+ attr_reader :id, :network, :settlement, :category, :client, :updated, :created
23
+ def initialize(id: nil, network: nil, settlement: nil, category: nil, client: nil, updated: nil, created: nil)
24
+ super(id)
25
+ @network = network
26
+ @settlement = settlement
27
+ @category = category
28
+ @client = client
29
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
30
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
31
+ end
32
+
33
+ # # Retrieve the IssuingBin object
34
+ #
35
+ # Receive a generator of IssuingBin objects previously registered in the Stark Infra API
36
+ #
37
+ # ## Parameters (optional):
38
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
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
+ # - generator of IssuingBin objects with updated attributes
43
+ def self.query(limit: nil, user: nil)
44
+ StarkInfra::Utils::Rest.get_stream(
45
+ limit: limit,
46
+ user: user,
47
+ **resource
48
+ )
49
+ end
50
+
51
+ # # Retrieve paged IssuingBins
52
+ #
53
+ # Receive a list of up to 100 IssuingBin objects previously registered in the Stark Infra API and the cursor to the next page.
54
+ #
55
+ # ## Parameters (optional):
56
+ # - cursor [string, default nil]: cursor returned on the previous page function call.
57
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Max = 100. ex: 35
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
+ # - list of IssuingBin objects with updated attributes
62
+ # - cursor to retrieve the next page of IssuingBin objects
63
+ def self.page(cursor: nil, limit: nil, user: nil)
64
+ StarkInfra::Utils::Rest.get_page(
65
+ cursor: cursor,
66
+ limit: limit,
67
+ user: user,
68
+ **resource
69
+ )
70
+ end
71
+
72
+ def self.resource
73
+ {
74
+ resource_name: 'IssuingBin',
75
+ resource_maker: proc { |json|
76
+ IssuingBin.new(
77
+ id: json['id'],
78
+ network: json['network'],
79
+ settlement: json['settlement'],
80
+ category: json['category'],
81
+ client: json['client'],
82
+ updated: json['updated'],
83
+ created: json['created']
84
+ )
85
+ }
86
+ }
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,260 @@
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
+ # # IssuingCard object
9
+ #
10
+ # The IssuingCard object displays the information of the cards created in your Workspace.
11
+ # Sensitive information will only be returned when the 'expand' parameter is used, to avoid security concerns.
12
+ #
13
+ # ## Parameters (required):
14
+ # - holder_name [string]: card holder name. ex: 'Tony Stark'
15
+ # - holder_tax_id [string]: card holder tax ID. ex: '012.345.678-90'
16
+ # - holder_external_id [string] card holder unique id, generated by the user to avoid duplicated holders. ex: 'my-entity/123'
17
+ #
18
+ # ## Parameters (optional):
19
+ # - display_name [string, default nil]: card displayed name. ex: 'ANTHONY STARK'
20
+ # - rules [list of IssuingRule objects, default nil]: [EXPANDABLE] list of card spending rules.
21
+ # - bin_id [string, default nil]: BIN ID to which the card is bound. ex: '53810200'
22
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
23
+ # - street_line_1 [string, default nil]: card holder main address. ex: 'Av. Paulista, 200'
24
+ # - street_line_2 [string, default nil]: card holder address complement. ex: 'Apto. 123'
25
+ # - district [string, default nil]: card holder address district / neighbourhood. ex: 'Bela Vista'
26
+ # - city [string, default nil]: card holder address city. ex: 'Rio de Janeiro'
27
+ # - state_code [string, default nil]: card holder address state. ex: 'GO'
28
+ # - zip_code [string, default nil]: card holder address zip code. ex: '01311-200'
29
+ #
30
+ # ## Attributes (return-only):
31
+ # - id [string]: unique id returned when IssuingCard is created. ex: '5656565656565656'
32
+ # - holder_id [string]: card holder unique id. ex: '5656565656565656'
33
+ # - type [string]: card type. ex: 'virtual'
34
+ # - status [string]: current IssuingCard status. ex: 'active', 'blocked', 'canceled', 'expired'.
35
+ # - number [string]: [EXPANDABLE] masked card number. Expand to unmask the value. ex: '123'.
36
+ # - security_code [string]: [EXPANDABLE] masked card verification value (cvv). Expand to unmask the value. ex: '123'.
37
+ # - expiration [string]: [EXPANDABLE] masked card expiration datetime. Expand to unmask the value. ex: '2032-02-29T23:59:59.999999+00:00'.
38
+ # - created [DateTime]: creation datetime for the IssuingCard. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
39
+ # - updated [DateTime]: latest update datetime for the IssuingCard. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
40
+ class IssuingCard < StarkInfra::Utils::Resource
41
+ attr_reader :id, :holder_id, :holder_name, :holder_tax_id, :holder_external_id, :type, :display_name, :status,
42
+ :rules, :bin_id, :street_line_1, :street_line_2, :district, :city, :state_code, :zip_code, :tags, :number,
43
+ :security_code, :expiration, :created, :updated
44
+ def initialize(
45
+ holder_name:, holder_tax_id:, holder_external_id:, id: nil, holder_id: nil, type: nil,
46
+ display_name: nil, status: nil, rules: nil, bin_id: nil, street_line_1: nil, street_line_2: nil, district: nil,
47
+ city: nil, state_code: nil, zip_code: nil, tags: nil, number: nil, security_code: nil, expiration: nil,
48
+ created: nil, updated: nil
49
+ )
50
+ super(id)
51
+ @holder_name = holder_name
52
+ @holder_tax_id = holder_tax_id
53
+ @holder_external_id = holder_external_id
54
+ @holder_id = holder_id
55
+ @type = type
56
+ @display_name = display_name
57
+ @status = status
58
+ @rules = StarkInfra::IssuingRule.parse_rules(rules)
59
+ @bin_id = bin_id
60
+ @street_line_1 = street_line_1
61
+ @street_line_2 = street_line_2
62
+ @district = district
63
+ @city = city
64
+ @state_code = state_code
65
+ @zip_code = zip_code
66
+ @tags = tags
67
+ @number = number
68
+ @security_code = security_code
69
+ @expiration = expiration
70
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
71
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
72
+ end
73
+
74
+ # # Create IssuingCards
75
+ #
76
+ # Send a list of IssuingCard objects for creation in the Stark Infra API
77
+ #
78
+ # ## Parameters (required):
79
+ # - cards [list of IssuingCard objects]: list of IssuingCard objects to be created in the API
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
+ # - list of IssuingCard objects with updated attributes
86
+ def self.create(cards:, expand: nil, user: nil)
87
+ StarkInfra::Utils::Rest.post(entities: cards, expand: expand, user: user, **resource)
88
+ end
89
+
90
+ # # Retrieve a specific IssuingCard
91
+ #
92
+ # Receive a single IssuingCard object previously created in the Stark Infra API by its id
93
+ #
94
+ # ## Parameters (required):
95
+ # - id [string]: object unique id. ex: '5656565656565656'
96
+ #
97
+ # ## Parameters (optional):
98
+ # - expand [list of strings, default nil]: fields to expand information. ex: ['rules', 'securityCode', 'number', 'expiration']
99
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
100
+ #
101
+ # ## Return:
102
+ # - IssuingCard object with updated attributes
103
+ def self.get(id, expand: nil, user: nil)
104
+ StarkInfra::Utils::Rest.get_id(id: id, expand: expand, user: user, **resource)
105
+ end
106
+
107
+ # # Retrieve IssuingCards
108
+ #
109
+ # Receive a generator of IssuingCards objects previously created in the Stark Infra API
110
+ #
111
+ # ## Parameters (optional):
112
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
113
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
114
+ # - after [DateTime or string, default nil] date filter for objects created only after specified date. ex: DateTime.new(2020, 3, 10)
115
+ # - before [DateTime or string, default nil] date filter for objects created only before specified date. ex: DateTime.new(2020, 3, 10)
116
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'blocked', 'canceled', 'expired']
117
+ # - types [list of strings, default nil]: card type. ex: ['virtual']
118
+ # - holder_ids [list of strings]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
119
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
120
+ # - expand [list of strings, default []]: fields to expand information. ex: ['rules', 'security_code', 'number', 'expiration']
121
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
122
+ #
123
+ # ## Return:
124
+ # - generator of IssuingCards objects with updated attributes
125
+ def self.query(limit: nil, ids: nil, after: nil, before: nil, status: nil, types: nil, holder_ids: nil, tags: nil,
126
+ expand: nil, user: nil)
127
+ after = StarkInfra::Utils::Checks.check_date(after)
128
+ before = StarkInfra::Utils::Checks.check_date(before)
129
+ StarkInfra::Utils::Rest.get_stream(
130
+ limit: limit,
131
+ ids: ids,
132
+ after: after,
133
+ before: before,
134
+ status: status,
135
+ types: types,
136
+ holder_ids: holder_ids,
137
+ tags: tags,
138
+ expand: expand,
139
+ user: user,
140
+ **resource
141
+ )
142
+ end
143
+
144
+ # # Retrieve paged IssuingCards
145
+ #
146
+ # Receive a list of IssuingCards objects previously created in the Stark Infra API and the cursor to the next page.
147
+ #
148
+ # ## Parameters (optional):
149
+ # - cursor [string, default nil]: cursor returned on the previous page function call.
150
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
151
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
152
+ # - after [DateTime or string, default nil] date filter for objects created only after specified date. ex: DateTime.new(2020, 3, 10)
153
+ # - before [DateTime or string, default nil] date filter for objects created only before specified date. ex: DateTime.new(2020, 3, 10)
154
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'blocked', 'canceled', 'expired']
155
+ # - types [list of strings, default nil]: card type. ex: ['virtual']
156
+ # - holder_ids [list of strings]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
157
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
158
+ # - expand [list of strings, default []]: fields to expand information. ex: ['rules', 'security_code', 'number', 'expiration']
159
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
160
+ #
161
+ # ## Return:
162
+ # - list of IssuingCards objects with updated attributes
163
+ # - cursor to retrieve the next page of IssuingCards objects
164
+ def self.page(cursor: nil, limit: nil, ids: nil, after: nil, before: nil, status: nil, types: nil, holder_ids: nil,
165
+ tags: nil, expand: nil, user: nil)
166
+ after = StarkInfra::Utils::Checks.check_date(after)
167
+ before = StarkInfra::Utils::Checks.check_date(before)
168
+ StarkInfra::Utils::Rest.get_page(
169
+ cursor: cursor,
170
+ limit: limit,
171
+ ids: ids,
172
+ after: after,
173
+ before: before,
174
+ status: status,
175
+ types: types,
176
+ holder_ids: holder_ids,
177
+ tags: tags,
178
+ expand: expand,
179
+ user: user,
180
+ **resource
181
+ )
182
+ end
183
+
184
+ # # Update IssuingCard entity
185
+ #
186
+ # Update an IssuingCard by passing id.
187
+ #
188
+ # ## Parameters (required):
189
+ # - id [string]: IssuingCard unique id. ex: '5656565656565656'
190
+ #
191
+ # ## Parameters (optional):
192
+ # - status [string, default nil]: You may block the IssuingCard by passing 'blocked' or activate by passing 'active' in the status
193
+ # - display_name [string, default nil]: card displayed name
194
+ # - rules [list of IssuingRule objects, default nil]: [EXPANDABLE] list of card spending rules.
195
+ # - tags [list of strings, default nil]: list of strings for tagging
196
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
197
+ #
198
+ # ## Return:
199
+ # - target IssuingCard with updated attributes
200
+ def self.update(id, status: nil, display_name: nil, rules: nil, tags: nil, user: nil)
201
+ StarkInfra::Utils::Rest.patch_id(
202
+ id: id,
203
+ status: status,
204
+ display_name: display_name,
205
+ rules: rules,
206
+ tags: tags,
207
+ user: user,
208
+ **resource
209
+ )
210
+ end
211
+
212
+ # # Cancel an IssuingCard entity
213
+ #
214
+ # Cancel an IssuingCard entity previously created in the Stark Infra API
215
+ #
216
+ # ## Parameters (required):
217
+ # - id [string]: IssuingCard unique id. ex: '5656565656565656'
218
+ #
219
+ # ## Parameters (optional):
220
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
221
+ #
222
+ # ## Return:
223
+ # - canceled IssuingCard object
224
+ def self.cancel(id, user: nil)
225
+ StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
226
+ end
227
+
228
+ def self.resource
229
+ {
230
+ resource_name: 'IssuingCard',
231
+ resource_maker: proc { |json|
232
+ IssuingCard.new(
233
+ id: json['id'],
234
+ holder_id: json['holder_id'],
235
+ holder_name: json['holder_name'],
236
+ holder_tax_id: json['holder_tax_id'],
237
+ holder_external_id: json['holder_external_id'],
238
+ type: json['type'],
239
+ display_name: json['display_name'],
240
+ status: json['status'],
241
+ rules: json['rules'],
242
+ bin_id: json['bin_id'],
243
+ street_line_1: json['street_line_1'],
244
+ street_line_2: json['street_line_2'],
245
+ district: json['district'],
246
+ city: json['city'],
247
+ state_code: json['state_code'],
248
+ zip_code: json['zip_code'],
249
+ tags: json['tags'],
250
+ number: json['number'],
251
+ security_code: json['security_code'],
252
+ expiration: json['expiration'],
253
+ created: json['created'],
254
+ updated: json['updated']
255
+ )
256
+ }
257
+ }
258
+ end
259
+ end
260
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('issuingcard')
7
+
8
+ module StarkInfra
9
+ class IssuingCard
10
+ # # IssuingCard::Log object
11
+ #
12
+ # Every time an IssuingCard entity is updated, a corresponding issuing card.Log is generated for the entity. This log
13
+ # is never generated by the user, but it can be retrieved to check additional information on the IssuingCard.
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 IssuingCard event which triggered the log creation. ex: 'processing' or 'success'
19
+ # - card [IssuingCard]: IssuingCard entity to which the log refers to.
20
+ class Log < StarkInfra::Utils::Resource
21
+ attr_reader :id, :created, :type, :card
22
+ def initialize(id:, created:, type:, card:)
23
+ super(id)
24
+ @type = type
25
+ @card = card
26
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
27
+ end
28
+
29
+ # # Retrieve a specific Log
30
+ #
31
+ # Receive a single Log object previously created by the Stark Infra API by passing its id
32
+ #
33
+ # ## Parameters (required):
34
+ # - id [string]: object unique id. ex: '5656565656565656'
35
+ #
36
+ # ## Parameters (optional):
37
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
38
+ #
39
+ # ## Return:
40
+ # - Log object with updated attributes
41
+ def self.get(id, user: nil)
42
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
43
+ end
44
+
45
+ # # Retrieve Logs
46
+ #
47
+ # Receive a generator of Log objects previously created in the Stark Infra API
48
+ #
49
+ # ## Parameters (optional):
50
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
51
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
52
+ # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
53
+ # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
54
+ # - types [list of strings, default nil]: filter for log event types. ex: ['blocked', 'canceled', 'created', 'expired', 'unblocked', 'updated']
55
+ # - card_ids [list of strings, default nil]: list of IssuingCard ids to filter logs. ex: ['5656565656565656', '4545454545454545']
56
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
57
+ #
58
+ # ## Return:
59
+ # - generator of Log objects with updated attributes
60
+ def self.query(limit: nil, after: nil, before: nil, types: nil, card_ids: nil, user: nil)
61
+ after = StarkInfra::Utils::Checks.check_date(after)
62
+ before = StarkInfra::Utils::Checks.check_date(before)
63
+ StarkInfra::Utils::Rest.get_stream(
64
+ limit: limit,
65
+ after: after,
66
+ before: before,
67
+ types: types,
68
+ card_ids: card_ids,
69
+ user: user,
70
+ **resource
71
+ )
72
+ end
73
+
74
+ # # Retrieve paged Logs
75
+ #
76
+ # Receive a list of up to 100 Log objects previously created in the Stark Infra API and the cursor to the next page.
77
+ # Use this function instead of query if you want to manually page your logs.
78
+ #
79
+ # ## Parameters (optional):
80
+ # - cursor [string, default nil]: cursor returned on the previous page function call
81
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
82
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Max = 100. ex: 35
83
+ # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
84
+ # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
85
+ # - types [list of strings, default nil]: filter for log event types. ex: ['blocked', 'canceled', 'created', 'expired', 'unblocked', 'updated']
86
+ # - card_ids [list of strings, default nil]: list of IssuingCard ids to filter logs. ex: ['5656565656565656', '4545454545454545']
87
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
88
+ #
89
+ # ## Return:
90
+ # - list of Log objects with updated attributes
91
+ # - Cursor to retrieve the next page of Log objects
92
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, card_ids: nil, user: nil)
93
+ after = StarkInfra::Utils::Checks.check_date(after)
94
+ before = StarkInfra::Utils::Checks.check_date(before)
95
+ StarkInfra::Utils::Rest.get_page(
96
+ cursor: cursor,
97
+ limit: limit,
98
+ after: after,
99
+ before: before,
100
+ types: types,
101
+ card_ids: card_ids,
102
+ user: user,
103
+ **resource
104
+ )
105
+ end
106
+
107
+ def self.resource
108
+ request_maker = StarkInfra::IssuingCard.resource[:resource_maker]
109
+ {
110
+ resource_name: 'IssuingCardLog',
111
+ resource_maker: proc { |json|
112
+ Log.new(
113
+ id: json['id'],
114
+ created: json['created'],
115
+ type: json['type'],
116
+ card: StarkInfra::Utils::API.from_api_json(request_maker, json['card'])
117
+ )
118
+ }
119
+ }
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,206 @@
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
+ # # IssuingHolder object
9
+ #
10
+ # The IssuingHolder describes a card holder that may group several cards.
11
+ #
12
+ # ## Parameters (required):
13
+ # - name [string]: card holder name.
14
+ # - tax_id [string]: card holder tax ID
15
+ # - external_id [string] card holder external ID
16
+ #
17
+ # ## Parameters (optional):
18
+ # - rules [list of IssuingRule objects, default nil]: [EXPANDABLE] list of holder spending rules.
19
+ # - tags [list of strings, default []]: list of strings for tagging. ex: ['travel', 'food']
20
+ #
21
+ # ## Attributes (return-only):
22
+ # - id [string]: unique id returned when IssuingHolder is created. ex: '5656565656565656'
23
+ # - status [string]: current IssuingHolder status. ex: 'active', 'blocked', 'canceled'
24
+ # - updated [DateTime]: latest update datetime for the IssuingHolder. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
25
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
26
+ class IssuingHolder < StarkInfra::Utils::Resource
27
+ attr_reader :id, :name, :tax_id, :external_id, :status, :rules, :tags, :updated, :created
28
+ def initialize(
29
+ name:, tax_id:, external_id:, id: nil, status: nil, rules: nil, tags: nil, updated: nil, created: nil
30
+ )
31
+ super(id)
32
+ @name = name
33
+ @tax_id = tax_id
34
+ @external_id = external_id
35
+ @status = status
36
+ @rules = StarkInfra::IssuingRule.parse_rules(rules)
37
+ @tags = tags
38
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
39
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
40
+ end
41
+
42
+ # # Create IssuingHolders
43
+ #
44
+ # Send a list of IssuingHolder objects for creation in the Stark Infra API
45
+ #
46
+ # ## Parameters (required):
47
+ # - holders [list of IssuingHolder objects]: list of IssuingHolder objects to be created in the API
48
+ #
49
+ # ## Parameters (optional):
50
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
51
+ #
52
+ # ## Return:
53
+ # - list of IssuingHolder objects with updated attributes
54
+ def self.create(holders:, user: nil)
55
+ StarkInfra::Utils::Rest.post(entities: holders, user: user, **resource)
56
+ end
57
+
58
+ # # Retrieve a specific IssuingHolder
59
+ #
60
+ # Receive a single IssuingHolder object previously created in the Stark Infra API by its id
61
+ #
62
+ # ## Parameters (required):
63
+ # - id [string]: object unique id. ex: '5656565656565656'
64
+ #
65
+ # ## Parameters (optional):
66
+ # - expand [list of strings, default nil]: fields to expand information. ex: ['rules']
67
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
68
+ #
69
+ # ## Return:
70
+ # - IssuingHolder object with updated attributes
71
+ def self.get(id, expand: nil, user: nil)
72
+ StarkInfra::Utils::Rest.get_id(id: id, expand: expand, user: user, **resource)
73
+ end
74
+
75
+ # # Retrieve IssuingHolders
76
+ #
77
+ # Receive a generator of IssuingHolder objects previously created in the Stark Infra API
78
+ #
79
+ # ## Parameters (optional):
80
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
81
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
82
+ # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
83
+ # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
84
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'blocked', 'canceled']
85
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
86
+ # - expand [string, default nil]: fields to expand information. ex: ['rules']
87
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
88
+ #
89
+ # ## Return:
90
+ # - generator of IssuingHolders objects with updated attributes
91
+ def self.query(limit: nil, ids: nil, after: nil, before: nil, status: nil, tags: nil, expand: nil, user: nil)
92
+ after = StarkInfra::Utils::Checks.check_date(after)
93
+ before = StarkInfra::Utils::Checks.check_date(before)
94
+ StarkInfra::Utils::Rest.get_stream(
95
+ limit: limit,
96
+ ids: ids,
97
+ after: after,
98
+ before: before,
99
+ status: status,
100
+ tags: tags,
101
+ expand: expand,
102
+ user: user,
103
+ **resource
104
+ )
105
+ end
106
+
107
+ # # Retrieve paged IssuingHolders
108
+ #
109
+ # Receive a list of IssuingHolder objects previously created in the Stark Infra API and the cursor to the next page.
110
+ #
111
+ # ## Parameters (optional):
112
+ # - cursor [string, default nil]: cursor returned on the previous page function call.
113
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
114
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
115
+ # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
116
+ # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
117
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'blocked', 'canceled']
118
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
119
+ # - expand [string, default nil]: fields to expand information. ex: ['rules']
120
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
121
+ #
122
+ # ## Return:
123
+ # - list of IssuingHolders objects with updated attributes
124
+ # - cursor to retrieve the next page of IssuingHolders objects
125
+ def self.page(cursor: nil, limit: nil, ids: nil, after: nil, before: nil, status: nil, tags: nil, expand: nil,
126
+ user: nil)
127
+ after = StarkInfra::Utils::Checks.check_date(after)
128
+ before = StarkInfra::Utils::Checks.check_date(before)
129
+ StarkInfra::Utils::Rest.get_page(
130
+ cursor: cursor,
131
+ limit: limit,
132
+ ids: ids,
133
+ after: after,
134
+ before: before,
135
+ status: status,
136
+ tags: tags,
137
+ expand: expand,
138
+ user: user,
139
+ **resource
140
+ )
141
+ end
142
+
143
+ # # Update IssuingHolder entity
144
+ #
145
+ # Update an IssuingHolder by passing id, if it hasn't been paid yet.
146
+ #
147
+ # ## Parameters (required):
148
+ # - id [string]: IssuingHolder id. ex: '5656565656565656'
149
+ #
150
+ # ## Parameters (optional):
151
+ # - status [string, default nil]: You may block the IssuingHolder by passing 'blocked' in the status
152
+ # - name [string, default nil]: card holder name.
153
+ # - tags [list of strings, default nil]: list of strings for tagging
154
+ # - rules [list of IssuingRule objects, default nil]: list of objects that represent the holder's spending rules.
155
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
156
+ #
157
+ # ## Return:
158
+ # - target IssuingHolder with updated attributes
159
+ def self.update(id, status: nil, name: nil, tags: nil, rules: nil, user: nil)
160
+ StarkInfra::Utils::Rest.patch_id(
161
+ id: id,
162
+ status: status,
163
+ name: name,
164
+ tags: tags,
165
+ rules: rules,
166
+ user: user,
167
+ **resource
168
+ )
169
+ end
170
+
171
+ # # Cancel an IssuingHolder entity
172
+ #
173
+ # Cancel an IssuingHolder entity previously created in the Stark Infra API
174
+ #
175
+ # ## Parameters (required):
176
+ # - id [string]: IssuingHolder unique id. ex: '5656565656565656'
177
+ #
178
+ # ## Parameters (optional):
179
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
180
+ #
181
+ # ## Return:
182
+ # - canceled IssuingHolder object
183
+ def self.cancel(id, user: nil)
184
+ StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
185
+ end
186
+
187
+ def self.resource
188
+ {
189
+ resource_name: 'IssuingHolder',
190
+ resource_maker: proc { |json|
191
+ IssuingHolder.new(
192
+ id: json['id'],
193
+ name: json['name'],
194
+ tax_id: json['tax_id'],
195
+ external_id: json['external_id'],
196
+ status: json['status'],
197
+ rules: json['rules'],
198
+ tags: json['tags'],
199
+ updated: json['updated'],
200
+ created: json['created']
201
+ )
202
+ }
203
+ }
204
+ end
205
+ end
206
+ end