starkinfra 0.2.0 → 0.3.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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/brcodepreview/brcodepreview.rb +12 -8
  3. data/lib/cardmethod/cardmethod.rb +1 -1
  4. data/lib/creditholmes/creditholmes.rb +160 -0
  5. data/lib/creditnote/creditnote.rb +19 -18
  6. data/lib/creditnote/invoice/discount.rb +1 -1
  7. data/lib/creditnote/invoice/invoice.rb +4 -3
  8. data/lib/creditnote/log.rb +16 -17
  9. data/lib/creditpreview/creditpreview.rb +2 -8
  10. data/lib/dynamicbrcode/dynamicbrcode.rb +3 -3
  11. data/lib/event/attempt.rb +1 -1
  12. data/lib/event/event.rb +1 -1
  13. data/lib/individualdocument/individualdocument.rb +165 -0
  14. data/lib/individualdocument/log.rb +125 -0
  15. data/lib/individualidentity/individualidentity.rb +193 -0
  16. data/lib/individualidentity/log.rb +124 -0
  17. data/lib/issuingcard/issuingcard.rb +11 -12
  18. data/lib/issuingcard/log.rb +19 -19
  19. data/lib/issuingdesign/issuingdesign.rb +138 -0
  20. data/lib/issuingembossingkit/issuingembossingkit.rb +121 -0
  21. data/lib/issuingembossingrequest/issuingembossingrequest.rb +210 -0
  22. data/lib/issuingembossingrequest/log.rb +128 -0
  23. data/lib/issuingholder/issuingholder.rb +8 -7
  24. data/lib/issuingholder/log.rb +17 -17
  25. data/lib/issuinginvoice/issuinginvoice.rb +6 -5
  26. data/lib/issuinginvoice/log.rb +16 -16
  27. data/lib/issuingproduct/issuingproduct.rb +2 -2
  28. data/lib/issuingpurchase/issuingpurchase.rb +15 -11
  29. data/lib/issuingpurchase/log.rb +15 -15
  30. data/lib/issuingrestock/issuingrestock.rb +162 -0
  31. data/lib/issuingrestock/log.rb +127 -0
  32. data/lib/issuingstock/issuingstock.rb +138 -0
  33. data/lib/issuingstock/log.rb +130 -0
  34. data/lib/issuingtransaction/issuingtransaction.rb +7 -6
  35. data/lib/issuingwithdrawal/issuingwithdrawal.rb +8 -11
  36. data/lib/pixchargeback/log.rb +12 -12
  37. data/lib/pixclaim/log.rb +13 -13
  38. data/lib/pixclaim/pixclaim.rb +4 -4
  39. data/lib/pixdomain/pixdomain.rb +1 -1
  40. data/lib/pixinfraction/log.rb +18 -18
  41. data/lib/pixinfraction/pixinfraction.rb +3 -3
  42. data/lib/pixkey/log.rb +18 -18
  43. data/lib/pixkey/pixkey.rb +4 -3
  44. data/lib/pixrequest/log.rb +22 -18
  45. data/lib/pixrequest/pixrequest.rb +3 -0
  46. data/lib/pixreversal/log.rb +1 -1
  47. data/lib/pixstatement/pixstatement.rb +1 -1
  48. data/lib/starkinfra.rb +13 -0
  49. data/lib/staticbrcode/staticbrcode.rb +8 -2
  50. data/lib/utils/bacenid.rb +1 -1
  51. data/lib/utils/request.rb +1 -1
  52. data/lib/webhook/webhook.rb +9 -9
  53. metadata +15 -2
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+ require_relative('../utils/parse')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/resource')
7
+
8
+ module StarkInfra
9
+ # # IndividualDocument object
10
+ #
11
+ # Individual documents are images containing either side of a document or a selfie
12
+ # to be used in a matching validation. When created, they must be attached to an individual
13
+ # identity to be used for its validation.
14
+ #
15
+ # When you initialize a IndividualDocument, the entity will not be automatically
16
+ # created in the Stark Infra API. The 'create' function sends the objects
17
+ # to the Stark Infra API and returns the list of created objects.
18
+ #
19
+ # ## Parameters (required):
20
+ # - type [string]: type of the IndividualDocument. Options: "drivers-license-front", "drivers-license-back", "identity-front", "identity-back" or "selfie"
21
+ # - content [string]: Base64 data url of the picture. ex: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...
22
+ # - content_type [string]: content MIME type. This parameter is required as input only. ex: "image/png" or "image/jpeg"
23
+ # - identity_id [string]: Unique id of IndividualIdentity. ex: "5656565656565656"
24
+ #
25
+ # ## Parameters (optional):
26
+ # - tags [list of strings, default nil]: list of strings for reference when searching for IndividualDocuments. ex: ["employees", "monthly"]
27
+ #
28
+ # ## Attributes (return-only):
29
+ # - id [string]: unique id returned when the IndividualDocument is created. ex: "5656565656565656"
30
+ # - status [string]: current status of the IndividualDocument. Options: "created", "canceled", "processing", "failed", "success"
31
+ # - created [DateTime]: creation datetime for the IndividualDocument. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
32
+ class IndividualDocument < StarkInfra::Utils::Resource
33
+ attr_reader :type, :content, :content_type, :identity_id, :tags, :id, :status, :created
34
+ def initialize(type:, content:, content_type:, identity_id:, tags: nil, id: nil, status: nil, created: nil)
35
+ super(id)
36
+ @type = type
37
+ @identity_id = identity_id
38
+ @tags = tags
39
+ @status = status
40
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
41
+ @content = content
42
+ @content_type = content_type
43
+
44
+ if @content_type
45
+ @content = "data:#{content_type};base64,#{Base64.encode64(content)}"
46
+ @content_type = nil
47
+ end
48
+ end
49
+
50
+ # # Create IndividualDocuments
51
+ #
52
+ # Send a list of IndividualDocument objects for creation at the Stark Infra API
53
+ #
54
+ # ## Parameters (required):
55
+ # - documents [list of IndividualDocument objects]: list of IndividualDocument objects to be created in the API.
56
+ #
57
+ # ## Parameters (optional):
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 IndividualDocument object with updated attributes
62
+ def self.create(documents, user: nil)
63
+ StarkInfra::Utils::Rest.post(entities: documents, user: user, **resource)
64
+ end
65
+
66
+ # # Retrieve a specific IndividualDocument
67
+ #
68
+ # Receive a single IndividualDocument object previously created in the Stark Infra API by its id
69
+ #
70
+ # ## Parameters (required):
71
+ # - id [string]: object unique id. ex: "5656565656565656"
72
+ #
73
+ # ## Parameters (optional):
74
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
75
+ #
76
+ # ## Return:
77
+ # - IndividualDocument object with updated attributes
78
+ def self.get(id, user: nil)
79
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
80
+ end
81
+
82
+ # # Retrieve IndividualDocuments
83
+ #
84
+ # Receive a generator of IndividualDocument objects previously created in the Stark Infra API
85
+ #
86
+ # ## Parameters (optional):
87
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
88
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
89
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
90
+ # - status [list of strings, default nil]: filter for status of retrieved objects. Options: ["created", "canceled", "processing", "failed", "success"]
91
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
92
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
93
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
94
+ #
95
+ # ## Return:
96
+ # - generator of IndividualDocument objects with updated attributes
97
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
98
+ after = StarkInfra::Utils::Checks.check_date(after)
99
+ before = StarkInfra::Utils::Checks.check_date(before)
100
+ StarkInfra::Utils::Rest.get_stream(
101
+ limit: limit,
102
+ after: after,
103
+ before: before,
104
+ status: status,
105
+ tags: tags,
106
+ ids: ids,
107
+ user: user,
108
+ **resource
109
+ )
110
+ end
111
+
112
+ # # Retrieve paged IndividualDocuments
113
+ #
114
+ # Receive a list of up to 100 IndividualDocument objects previously created in the Stark Infra API and the cursor to the next page.
115
+ # Use this function instead of query if you want to manually page your requests.
116
+ #
117
+ # ## Parameters (optional):
118
+ # - cursor [string, default nil]: cursor returned on the previous page function call
119
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex 35
120
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
121
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
122
+ # - status [list of strings, default nil]: filter for status of retrieved objects. Options: ["created", "canceled", "processing", "failed", "success"]
123
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
124
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
125
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
126
+ #
127
+ # ## Return:
128
+ # - list of IndividualDocument objects with updated attributes
129
+ # - cursor to retrieve the next page of IndividualDocument objects
130
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
131
+ after = StarkInfra::Utils::Checks.check_date(after)
132
+ before = StarkInfra::Utils::Checks.check_date(before)
133
+ StarkInfra::Utils::Rest.get_page(
134
+ cursor: cursor,
135
+ limit: limit,
136
+ after: after,
137
+ before: before,
138
+ status: status,
139
+ tags: tags,
140
+ ids: ids,
141
+ user: user,
142
+ **resource
143
+ )
144
+ end
145
+
146
+
147
+ def self.resource
148
+ {
149
+ resource_name: 'IndividualDocument',
150
+ resource_maker: proc { |json|
151
+ IndividualDocument.new(
152
+ type: json['type'],
153
+ content: json['content'],
154
+ content_type: json['content_type'],
155
+ identity_id: json['identity_id'],
156
+ tags: json['tags'],
157
+ id: json['id'],
158
+ status: json['status'],
159
+ created: json['created']
160
+ )
161
+ }
162
+ }
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+ require_relative('../utils/checks')
5
+ require_relative('IndividualDocument')
6
+ require_relative('../utils/resource')
7
+
8
+ module StarkInfra
9
+ class IndividualDocument
10
+ # # IndividualDocument::Log object
11
+ #
12
+ # Every time an IndividualDocument entity is updated, a corresponding IndividualDocument::Log is generated for the entity.
13
+ # This Log is never generated by the user, but it can be retrieved to check additional information on the IndividualDocument.
14
+ #
15
+ # ## Attributes (return-only):
16
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
17
+ # - document [IndividualDocument]: IndividualDocument entity to which the log refers to.
18
+ # - errors [list of strings]: list of errors linked to this IndividualDocument event
19
+ # - type [string]: type of the IndividualDocument event which triggered the log creation. ex: 'approved', 'canceled', 'confirmed', 'denied', 'reversed', 'voided'.
20
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
21
+ class Log < StarkInfra::Utils::Resource
22
+ attr_reader :id, :document, :errors, :type, :created
23
+ def initialize(id: nil, document: nil, errors: nil, type: nil, created: nil)
24
+ super(id)
25
+ @document = document
26
+ @errors = errors
27
+ @type = type
28
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
29
+ end
30
+
31
+ # # Retrieve a specific IndividualDocument::Log
32
+ #
33
+ # Receive a single IndividualDocument::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
+ # - IndividualDocument::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 IndividualDocument::Logs
48
+ #
49
+ # Receive a generator of IndividualDocument::Log objects previously created in the Stark Infra API
50
+ #
51
+ # ## Parameters (optional):
52
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
53
+ # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
54
+ # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
55
+ # - types [list of strings, default nil]: filter for log event types. ex: ['created', 'canceled', 'processing', 'failed', 'success']
56
+ # - document_ids [list of strings, default nil]: list of IndividualDocument ids to filter logs. ex: ['5656565656565656', '4545454545454545']
57
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
58
+ #
59
+ # ## Return:
60
+ # - generator of IndividualDocument::Log objects with updated attributes
61
+ def self.query(ids: nil, limit: nil, after: nil, before: nil, types: nil, document_ids: nil, user: nil)
62
+ after = StarkInfra::Utils::Checks.check_date(after)
63
+ before = StarkInfra::Utils::Checks.check_date(before)
64
+ StarkInfra::Utils::Rest.get_stream(
65
+ ids: ids,
66
+ limit: limit,
67
+ after: after,
68
+ before: before,
69
+ types: types,
70
+ document_ids: document_ids,
71
+ user: user,
72
+ **resource
73
+ )
74
+ end
75
+
76
+ # # Retrieve paged IndividualDocument::Logs
77
+ #
78
+ # Receive a list of up to 100 IndividualDocument::Log objects previously created in the Stark Infra API and the cursor to the next page.
79
+ # Use this function instead of query if you want to manually page your documents.
80
+ #
81
+ # ## Parameters (optional):
82
+ # - cursor [string, default nil]: cursor returned on the previous page function call
83
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
84
+ # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
85
+ # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
86
+ # - types [list of strings, default nil]: filter for log event types. ex: ['created', 'canceled', 'processing', 'failed', 'success']
87
+ # - document_ids [list of strings, default nil]: list of document ids to filter logs. ex: ['5656565656565656', '4545454545454545']
88
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
89
+ #
90
+ # ## Return:
91
+ # - list of IndividualDocument::Log objects with updated attributes
92
+ # - cursor to retrieve the next page of Log objects
93
+ def self.page(cursor: nil, ids: nil, limit: nil, after: nil, before: nil, types: nil, document_ids: nil, user: nil)
94
+ after = StarkInfra::Utils::Checks.check_date(after)
95
+ before = StarkInfra::Utils::Checks.check_date(before)
96
+ StarkInfra::Utils::Rest.get_page(
97
+ cursor: cursor,
98
+ limit: limit,
99
+ after: after,
100
+ before: before,
101
+ types: types,
102
+ document_ids: document_ids,
103
+ user: user,
104
+ **resource
105
+ )
106
+ end
107
+
108
+ def self.resource
109
+ request_maker = StarkInfra::IndividualDocument.resource[:resource_maker]
110
+ {
111
+ resource_name: 'IndividualDocumentLog',
112
+ resource_maker: proc { |json|
113
+ Log.new(
114
+ id: json['id'],
115
+ document: StarkInfra::Utils::API.from_api_json(request_maker, json['document']),
116
+ errors: json['errors'],
117
+ type: json['type'],
118
+ created: json['created']
119
+ )
120
+ }
121
+ }
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,193 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+ require_relative('../utils/parse')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/resource')
7
+
8
+ module StarkInfra
9
+ # # IndividualIdentity object
10
+ #
11
+ # An IndividualDocument represents an individual to be validated. It can have several individual documents attached
12
+ # to it, which are used to validate the identity of the individual. Once an individual identity is created, individual
13
+ # documents must be attached to it using the created method of the individual document resource. When all the required
14
+ # individual documents are attached to an individual identity it can be sent to validation by patching its status to
15
+ # processing.
16
+ #
17
+ # When you initialize a IndividualIdentity, the entity will not be automatically
18
+ # created in the Stark Infra API. The 'create' function sends the objects
19
+ # to the Stark Infra API and returns the list of created objects.
20
+ #
21
+ # ## Parameters (required):
22
+ # - name [string]: individual's full name. ex: "Edward Stark".
23
+ # - tax_id [string]: individual's tax ID (CPF). ex: "594.739.480-42"
24
+ #
25
+ # ## Parameters (optional):
26
+ # - tags [list of strings, default nil]: list of strings for reference when searching for IndividualIdentities. ex: ["employees", "monthly"]
27
+ #
28
+ # ## Attributes (return-only):
29
+ # - id [string]: unique id returned when the IndividualIdentity is created. ex: "5656565656565656"
30
+ # - status [string]: current status of the IndividualIdentity. Options: "created", "canceled", "processing", "failed", "success"
31
+ # - created [DateTime]: creation datetime for the IndividualIdentity. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
32
+ class IndividualIdentity < StarkInfra::Utils::Resource
33
+ attr_reader :name, :tax_id, :tags, :id, :status, :created
34
+ def initialize(name:, tax_id:, tags: nil, id: nil, status: nil, created: nil)
35
+ super(id)
36
+ @name = name
37
+ @tax_id = tax_id
38
+ @tags = tags
39
+ @status = status
40
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
41
+ end
42
+
43
+ # # Create IndividualIdentities
44
+ #
45
+ # Send a list of IndividualIdentity objects for creation at the Stark Infra API
46
+ #
47
+ # ## Parameters (required):
48
+ # - identities [list of IndividualIdentity objects]: list of IndividualIdentity objects to be created in the API.
49
+ #
50
+ # ## Parameters (optional):
51
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
52
+ #
53
+ # ## Return:
54
+ # - list of IndividualIdentity objects with updated attributes
55
+ def self.create(identities, user: nil)
56
+ StarkInfra::Utils::Rest.post(entities: identities, user: user, **resource)
57
+ end
58
+
59
+ # # Retrieve a specific IndividualIdentity
60
+ #
61
+ # Receive a single IndividualIdentity object previously created in the Stark Infra API by its id
62
+ #
63
+ # ## Parameters (required):
64
+ # - id [string]: object unique id. ex: "5656565656565656"
65
+ #
66
+ # ## Parameters (optional):
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
+ # - IndividualIdentity object with updated attributes
71
+ def self.get(uuid, user: nil)
72
+ StarkInfra::Utils::Rest.get_id(id: uuid, user: user, **resource)
73
+ end
74
+
75
+ # # Retrieve IndividualIdentities
76
+ #
77
+ # Receive a generator of IndividualIdentity 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
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
82
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
83
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ["created", "canceled", "processing", "failed", "success"]
84
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
85
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
86
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
87
+ #
88
+ # ## Return:
89
+ # - generator of IndividualIdentity objects with updated attributes
90
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
91
+ after = StarkInfra::Utils::Checks.check_date(after)
92
+ before = StarkInfra::Utils::Checks.check_date(before)
93
+ StarkInfra::Utils::Rest.get_stream(
94
+ limit: limit,
95
+ after: after,
96
+ before: before,
97
+ status: status,
98
+ tags: tags,
99
+ ids: ids,
100
+ user: user,
101
+ **resource
102
+ )
103
+ end
104
+
105
+ # # Retrieve paged IndividualIdentities
106
+ #
107
+ # Receive a list of up to 100 IndividualIdentity objects previously created in the Stark Infra API and the cursor to the next page.
108
+ # Use this function instead of query if you want to manually page your requests.
109
+ #
110
+ # ## Parameters (optional):
111
+ # - cursor [string, default nil]: cursor returned on the previous page function call
112
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex 35
113
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
114
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
115
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ["created", "canceled", "processing", "failed", "success"]
116
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
117
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
118
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
119
+ #
120
+ # ## Return:
121
+ # - list of IndividualIdentity objects with updated attributes
122
+ # - cursor to retrieve the next page of IndividualIdentity objects
123
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
124
+ after = StarkInfra::Utils::Checks.check_date(after)
125
+ before = StarkInfra::Utils::Checks.check_date(before)
126
+ StarkInfra::Utils::Rest.get_page(
127
+ cursor: cursor,
128
+ limit: limit,
129
+ after: after,
130
+ before: before,
131
+ status: status,
132
+ tags: tags,
133
+ ids: ids,
134
+ user: user,
135
+ **resource
136
+ )
137
+ end
138
+
139
+ # # Update IndividualIdentity entity
140
+ #
141
+ # Update an IndividualIdentity by passing id.
142
+ #
143
+ # ## Parameters (required):
144
+ # - id [string]: IndividualIdentity unique id. ex: '5656565656565656'
145
+ # - status [string]: You may send IndividualDocuments to validation by passing 'processing' in the status
146
+ #
147
+ # ## Parameters (optional):
148
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
149
+ #
150
+ # ## Return:
151
+ # - target IndividualIdentity with updated attributes
152
+ def self.update(id, status:, user: nil)
153
+ StarkInfra::Utils::Rest.patch_id(
154
+ id: id,
155
+ status: status,
156
+ user: user,
157
+ **resource
158
+ )
159
+ end
160
+
161
+ # # Cancel an IndividualIdentity entity
162
+ #
163
+ # Cancel an IndividualIdentity entity previously created in the Stark Infra API
164
+ #
165
+ # ## Parameters (required):
166
+ # - id [string]: IndividualIdentity unique id. ex: '5656565656565656'
167
+ #
168
+ # ## Parameters (optional):
169
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
170
+ #
171
+ # ## Return:
172
+ # - canceled IndividualIdentity object
173
+ def self.cancel(id, user: nil)
174
+ StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
175
+ end
176
+
177
+ def self.resource
178
+ {
179
+ resource_name: 'IndividualIdentity',
180
+ resource_maker: proc { |json|
181
+ IndividualIdentity.new(
182
+ name: json['name'],
183
+ tax_id: json['tax_id'],
184
+ tags: json['tags'],
185
+ id: json['id'],
186
+ status: json['status'],
187
+ created: json['created']
188
+ )
189
+ }
190
+ }
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+ require_relative('../utils/checks')
5
+ require_relative('IndividualIdentity')
6
+ require_relative('../utils/resource')
7
+
8
+ module StarkInfra
9
+ class IndividualIdentity
10
+ # # IndividualIdentity::Log object
11
+ #
12
+ # Every time an IndividualIdentity entity is updated, a corresponding IndividualIdentity::Log is generated for the entity.
13
+ # This Log is never generated by the user, but it can be retrieved to check additional information on the IndividualIdentity.
14
+ #
15
+ # ## Attributes (return-only):
16
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
17
+ # - identity [IndividualIdentity]: IndividualIdentity entity to which the log refers to.
18
+ # - errors [list of strings]: list of errors linked to this IndividualIdentity event
19
+ # - type [string]: type of the IndividualIdentity event which triggered the log creation. ex: "created", "canceled", "processing", "failed", "success"
20
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
21
+ class Log < StarkInfra::Utils::Resource
22
+ attr_reader :id, :identity, :errors, :type, :created
23
+ def initialize(id: nil, identity: nil, errors: nil, type: nil, created: nil)
24
+ super(id)
25
+ @identity = identity
26
+ @errors = errors
27
+ @type = type
28
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
29
+ end
30
+
31
+ # # Retrieve a specific IndividualIdentity::Log
32
+ #
33
+ # Receive a single IndividualIdentity::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
+ # - IndividualIdentity::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 IndividualIdentity::Logs
48
+ #
49
+ # Receive a generator of IndividualIdentity::Log objects previously created in the Stark Infra API
50
+ #
51
+ # ## Parameters (optional):
52
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
53
+ # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
54
+ # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
55
+ # - types [list of strings, default nil]: filter for log event types. ex: "created", "canceled", "processing", "failed", "success"
56
+ # - identity_ids [list of strings, default nil]: list of identity ids to filter logs. ex: ['5656565656565656', '4545454545454545']
57
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
58
+ #
59
+ # ## Return:
60
+ # - generator of IndividualIdentity::Log objects with updated attributes
61
+ def self.query(limit: nil, after: nil, before: nil, types: nil, identity_ids: nil, user: nil)
62
+ after = StarkInfra::Utils::Checks.check_date(after)
63
+ before = StarkInfra::Utils::Checks.check_date(before)
64
+ StarkInfra::Utils::Rest.get_stream(
65
+ limit: limit,
66
+ after: after,
67
+ before: before,
68
+ types: types,
69
+ identity_ids: identity_ids,
70
+ user: user,
71
+ **resource
72
+ )
73
+ end
74
+
75
+ # # Retrieve paged IndividualIdentity::Logs
76
+ #
77
+ # Receive a list of up to 100 IndividualIdentity::Log objects previously created in the Stark Infra API and the cursor to the next page.
78
+ # Use this function instead of query if you want to manually page your identities.
79
+ #
80
+ # ## Parameters (optional):
81
+ # - cursor [string, default nil]: cursor returned on the previous page function call
82
+ # - limit [integer, default 100]: 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: "created", "canceled", "processing", "failed", "success"
86
+ # - identity_ids [list of strings, default nil]: list of identity 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 IndividualIdentity::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, identity_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
+ identity_ids: identity_ids,
102
+ user: user,
103
+ **resource
104
+ )
105
+ end
106
+
107
+ def self.resource
108
+ request_maker = StarkInfra::IndividualIdentity.resource[:resource_maker]
109
+ {
110
+ resource_name: 'IndividualIdentityLog',
111
+ resource_maker: proc { |json|
112
+ Log.new(
113
+ id: json['id'],
114
+ identity: StarkInfra::Utils::API.from_api_json(request_maker, json['identity']),
115
+ errors: json['errors'],
116
+ type: json['type'],
117
+ created: json['created']
118
+ )
119
+ }
120
+ }
121
+ end
122
+ end
123
+ end
124
+ end