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.
- checksums.yaml +4 -4
- data/lib/creditnote/creditnote.rb +561 -0
- data/lib/creditnote/log.rb +126 -0
- data/lib/event/attempt.rb +126 -0
- data/lib/event/event.rb +125 -7
- data/lib/issuingauthorization/issuingauthorization.rb +141 -0
- data/lib/issuingbalance/issuingbalance.rb +55 -0
- data/lib/issuingbin/issuingbin.rb +89 -0
- data/lib/issuingcard/issuingcard.rb +260 -0
- data/lib/issuingcard/log.rb +123 -0
- data/lib/issuingholder/issuingholder.rb +206 -0
- data/lib/issuingholder/log.rb +123 -0
- data/lib/issuinginvoice/issuinginvoice.rb +152 -0
- data/lib/issuinginvoice/log.rb +120 -0
- data/lib/issuingpurchase/issuingpurchase.rb +209 -0
- data/lib/issuingpurchase/log.rb +131 -0
- data/lib/issuingrule/issuingrule.rb +81 -0
- data/lib/issuingtransaction/issuingtransaction.rb +136 -0
- data/lib/issuingwithdrawal/issuingwithdrawal.rb +153 -0
- data/lib/pixbalance/pixbalance.rb +13 -13
- data/lib/pixchargeback/log.rb +129 -0
- data/lib/pixchargeback/pixchargeback.rb +225 -0
- data/lib/pixclaim/log.rb +135 -0
- data/lib/pixclaim/pixclaim.rb +225 -0
- data/lib/pixdirector/pixdirector.rb +76 -0
- data/lib/pixdomain/certificate.rb +30 -0
- data/lib/pixdomain/pixdomain.rb +58 -0
- data/lib/pixinfraction/log.rb +129 -0
- data/lib/pixinfraction/pixinfraction.rb +212 -0
- data/lib/pixkey/log.rb +128 -0
- data/lib/pixkey/pixkey.rb +239 -0
- data/lib/pixrequest/log.rb +16 -16
- data/lib/pixrequest/pixrequest.rb +66 -67
- data/lib/pixreversal/log.rb +13 -12
- data/lib/pixreversal/pixreversal.rb +72 -71
- data/lib/pixstatement/pixstatement.rb +22 -23
- data/lib/starkinfra.rb +32 -2
- data/lib/user/organization.rb +54 -0
- data/lib/user/project.rb +37 -0
- data/lib/user/user.rb +20 -0
- data/lib/utils/api.rb +10 -2
- data/lib/utils/bacenid.rb +19 -0
- data/lib/utils/checks.rb +2 -3
- data/lib/utils/endtoendid.rb +11 -0
- data/lib/utils/parse.rb +13 -13
- data/lib/utils/request.rb +1 -1
- data/lib/utils/rest.rb +7 -5
- data/lib/utils/returnid.rb +11 -0
- data/lib/webhook/webhook.rb +124 -0
- metadata +45 -24
data/lib/utils/parse.rb
CHANGED
@@ -5,28 +5,30 @@ require('starkbank-ecdsa')
|
|
5
5
|
require_relative('api')
|
6
6
|
require_relative('cache')
|
7
7
|
require_relative('request')
|
8
|
-
require_relative('../error')
|
9
|
-
|
8
|
+
require_relative('../error')
|
10
9
|
|
11
10
|
module StarkInfra
|
12
11
|
module Utils
|
13
12
|
module Parse
|
14
13
|
def self.parse_and_verify(content:, signature:, user: nil, resource:, key: nil)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
json = JSON.parse(content)
|
15
|
+
json = JSON.parse(content)[key] unless key.nil?
|
16
|
+
event = StarkInfra::Utils::API.from_api_json(resource[:resource_maker], json)
|
19
17
|
|
20
18
|
begin
|
21
19
|
signature = EllipticCurve::Signature.fromBase64(signature)
|
22
20
|
rescue
|
23
21
|
raise(StarkInfra::Error::InvalidSignatureError, 'The provided signature is not valid')
|
24
22
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
|
24
|
+
if verify_signature(content: content, signature: signature, user: user)
|
25
|
+
return event
|
26
|
+
end
|
27
|
+
|
28
|
+
if verify_signature(content: content, signature: signature, user: user, refresh: true)
|
29
|
+
return event
|
30
|
+
end
|
31
|
+
|
30
32
|
raise(StarkInfra::Error::InvalidSignatureError, 'The provided signature and content do not match the Stark Infra public key')
|
31
33
|
end
|
32
34
|
|
@@ -46,5 +48,3 @@ module StarkInfra
|
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
49
|
-
|
50
|
-
|
data/lib/utils/request.rb
CHANGED
@@ -61,7 +61,7 @@ module StarkInfra
|
|
61
61
|
req['Access-Time'] = access_time
|
62
62
|
req['Access-Signature'] = signature
|
63
63
|
req['Content-Type'] = 'application/json'
|
64
|
-
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-
|
64
|
+
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-Infra-0.0.3"
|
65
65
|
req['Accept-Language'] = language
|
66
66
|
|
67
67
|
request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }
|
data/lib/utils/rest.rb
CHANGED
@@ -50,26 +50,27 @@ module StarkInfra
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def self.get_id(resource_name:, resource_maker:, id:, user: nil)
|
53
|
+
def self.get_id(resource_name:, resource_maker:, id:, user: nil, **query)
|
54
54
|
json = StarkInfra::Utils::Request.fetch(
|
55
55
|
method: 'GET',
|
56
56
|
path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}",
|
57
|
+
query: query,
|
57
58
|
user: user
|
58
59
|
).json
|
59
60
|
entity = json[StarkInfra::Utils::API.last_name(resource_name)]
|
60
61
|
StarkInfra::Utils::API.from_api_json(resource_maker, entity)
|
61
62
|
end
|
62
63
|
|
63
|
-
def self.get_content(resource_name:,
|
64
|
+
def self.get_content(resource_name:, sub_resource_name:, id:, user: nil, **query)
|
64
65
|
StarkInfra::Utils::Request.fetch(
|
65
66
|
method: 'GET',
|
66
67
|
path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}/#{sub_resource_name}",
|
67
|
-
query:
|
68
|
+
query: query,
|
68
69
|
user: user
|
69
70
|
).content
|
70
71
|
end
|
71
72
|
|
72
|
-
def self.post(resource_name:, resource_maker:, entities:, user: nil)
|
73
|
+
def self.post(resource_name:, resource_maker:, entities:, user: nil, **query)
|
73
74
|
jsons = []
|
74
75
|
entities.each do |entity|
|
75
76
|
jsons << StarkInfra::Utils::API.api_json(entity)
|
@@ -79,6 +80,7 @@ module StarkInfra
|
|
79
80
|
method: 'POST',
|
80
81
|
path: StarkInfra::Utils::API.endpoint(resource_name),
|
81
82
|
payload: payload,
|
83
|
+
query: query,
|
82
84
|
user: user
|
83
85
|
).json
|
84
86
|
returned_jsons = json[StarkInfra::Utils::API.last_name_plural(resource_name)]
|
@@ -126,7 +128,7 @@ module StarkInfra
|
|
126
128
|
method: 'GET',
|
127
129
|
path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}/#{StarkInfra::Utils::API.endpoint(sub_resource_name)}",
|
128
130
|
user: user,
|
129
|
-
query:
|
131
|
+
query: query
|
130
132
|
).json
|
131
133
|
entity = json[StarkInfra::Utils::API.last_name(sub_resource_name)]
|
132
134
|
StarkInfra::Utils::API.from_api_json(sub_resource_maker, entity)
|
@@ -0,0 +1,124 @@
|
|
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
|
+
# # Webhook subscription object
|
9
|
+
#
|
10
|
+
# A Webhook is used to subscribe to notification events on a user-selected endpoint.
|
11
|
+
# Currently available services for subscription are contract, credit-note, signer, issuing-card, issuing-invoice, issuing-purchase, pix-request.in, pix-request.out, pix-reversal.in, pix-reversal.out, pix-claim, pix-key, pix-chargeback, pix-infraction.
|
12
|
+
#
|
13
|
+
# ## Parameters (required):
|
14
|
+
# - url [string]: URL that will be notified when an event occurs.
|
15
|
+
# - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['contract', 'credit-note', 'signer', 'issuing-card', 'issuing-invoice', 'issuing-purchase', 'pix-request.in', 'pix-request.out', 'pix-reversal.in', 'pix-reversal.out', 'pix-claim', 'pix-key', 'pix-chargeback', 'pix-infraction']
|
16
|
+
#
|
17
|
+
# ## Attributes:
|
18
|
+
# - id [string]: unique id returned when the webhook is created. ex: '5656565656565656'
|
19
|
+
class Webhook < StarkInfra::Utils::Resource
|
20
|
+
attr_reader :url, :subscriptions, :id
|
21
|
+
def initialize(url:, subscriptions:, id: nil)
|
22
|
+
super(id)
|
23
|
+
@url = url
|
24
|
+
@subscriptions = subscriptions
|
25
|
+
end
|
26
|
+
|
27
|
+
# # Create Webhook subscription
|
28
|
+
#
|
29
|
+
# Send a single Webhook subscription for creation in the Stark Infra API
|
30
|
+
#
|
31
|
+
# ## Parameters (required):
|
32
|
+
# - webhook [Webhook object or hash]: Webhook subscription to be created to receive Events. ex: Webhook.new()
|
33
|
+
#
|
34
|
+
# ## Parameters (optional):
|
35
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
36
|
+
#
|
37
|
+
# ## Return:
|
38
|
+
# - Webhook object with updated attributes
|
39
|
+
def self.create(webhook, user: nil)
|
40
|
+
StarkInfra::Utils::Rest.post_single(entity: webhook, user: user, **resource)
|
41
|
+
end
|
42
|
+
|
43
|
+
# # Retrieve a specific Webhook subscription
|
44
|
+
#
|
45
|
+
# Receive a single Webhook subscription object previously created in the Stark Infra API by passing its id
|
46
|
+
#
|
47
|
+
# ## Parameters (required):
|
48
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
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
|
+
# - Webhook object with updated attributes
|
55
|
+
def self.get(id, user: nil)
|
56
|
+
StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
|
57
|
+
end
|
58
|
+
|
59
|
+
# # Retrieve Webhook subscriptions
|
60
|
+
#
|
61
|
+
# Receive a generator of Webhook subscription objects previously created in the Stark Infra API
|
62
|
+
#
|
63
|
+
# ## Parameters (optional):
|
64
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
65
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
66
|
+
#
|
67
|
+
# ## Return:
|
68
|
+
# - generator of Webhook objects with updated attributes
|
69
|
+
def self.query(limit: nil, user: nil)
|
70
|
+
StarkInfra::Utils::Rest.get_stream(user: user, limit: limit, **resource)
|
71
|
+
end
|
72
|
+
|
73
|
+
# # Retrieve paged Webhooks
|
74
|
+
#
|
75
|
+
# Receive a list of up to 100 Webhook objects previously created in the Stark Infra API and the cursor to the next page.
|
76
|
+
# Use this function instead of query if you want to manually page your requests.
|
77
|
+
#
|
78
|
+
# ## Parameters (optional):
|
79
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
80
|
+
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
|
81
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
82
|
+
#
|
83
|
+
# ## Return:
|
84
|
+
# - list of Webhook objects with updated attributes
|
85
|
+
# - cursor to retrieve the next page of Webhook objects
|
86
|
+
def self.page(cursor: nil, limit: nil, user: nil)
|
87
|
+
return StarkInfra::Utils::Rest.get_page(
|
88
|
+
cursor: cursor,
|
89
|
+
limit: limit,
|
90
|
+
user: user,
|
91
|
+
**resource
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
# # Delete a Webhook entity
|
96
|
+
#
|
97
|
+
# Delete a Webhook entity previously created in the Stark Infra API
|
98
|
+
#
|
99
|
+
# ## Parameters (required):
|
100
|
+
# - id [string]: Webhook unique id. ex: '5656565656565656'
|
101
|
+
#
|
102
|
+
# ## Parameters (optional):
|
103
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
104
|
+
#
|
105
|
+
# ## Return:
|
106
|
+
# - deleted Webhook object
|
107
|
+
def self.delete(id, user: nil)
|
108
|
+
StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.resource
|
112
|
+
{
|
113
|
+
resource_name: 'Webhook',
|
114
|
+
resource_maker: proc { |json|
|
115
|
+
Webhook.new(
|
116
|
+
id: json['id'],
|
117
|
+
url: json['url'],
|
118
|
+
subscriptions: json['subscriptions']
|
119
|
+
)
|
120
|
+
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: starkinfra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- starkinfra
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: starkbank
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2.6.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 2.6.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: starkbank-ecdsa
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +30,14 @@ dependencies:
|
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: 5.14.
|
33
|
+
version: 5.14.4
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: 5.14.
|
40
|
+
version: 5.14.4
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,38 +66,73 @@ dependencies:
|
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0.81'
|
83
|
-
description:
|
84
|
-
email:
|
69
|
+
description:
|
70
|
+
email:
|
85
71
|
executables: []
|
86
72
|
extensions: []
|
87
73
|
extra_rdoc_files: []
|
88
74
|
files:
|
75
|
+
- lib/creditnote/creditnote.rb
|
76
|
+
- lib/creditnote/log.rb
|
89
77
|
- lib/error.rb
|
78
|
+
- lib/event/attempt.rb
|
90
79
|
- lib/event/event.rb
|
80
|
+
- lib/issuingauthorization/issuingauthorization.rb
|
81
|
+
- lib/issuingbalance/issuingbalance.rb
|
82
|
+
- lib/issuingbin/issuingbin.rb
|
83
|
+
- lib/issuingcard/issuingcard.rb
|
84
|
+
- lib/issuingcard/log.rb
|
85
|
+
- lib/issuingholder/issuingholder.rb
|
86
|
+
- lib/issuingholder/log.rb
|
87
|
+
- lib/issuinginvoice/issuinginvoice.rb
|
88
|
+
- lib/issuinginvoice/log.rb
|
89
|
+
- lib/issuingpurchase/issuingpurchase.rb
|
90
|
+
- lib/issuingpurchase/log.rb
|
91
|
+
- lib/issuingrule/issuingrule.rb
|
92
|
+
- lib/issuingtransaction/issuingtransaction.rb
|
93
|
+
- lib/issuingwithdrawal/issuingwithdrawal.rb
|
91
94
|
- lib/key.rb
|
92
95
|
- lib/pixbalance/pixbalance.rb
|
96
|
+
- lib/pixchargeback/log.rb
|
97
|
+
- lib/pixchargeback/pixchargeback.rb
|
98
|
+
- lib/pixclaim/log.rb
|
99
|
+
- lib/pixclaim/pixclaim.rb
|
100
|
+
- lib/pixdirector/pixdirector.rb
|
101
|
+
- lib/pixdomain/certificate.rb
|
102
|
+
- lib/pixdomain/pixdomain.rb
|
103
|
+
- lib/pixinfraction/log.rb
|
104
|
+
- lib/pixinfraction/pixinfraction.rb
|
105
|
+
- lib/pixkey/log.rb
|
106
|
+
- lib/pixkey/pixkey.rb
|
93
107
|
- lib/pixrequest/log.rb
|
94
108
|
- lib/pixrequest/pixrequest.rb
|
95
109
|
- lib/pixreversal/log.rb
|
96
110
|
- lib/pixreversal/pixreversal.rb
|
97
111
|
- lib/pixstatement/pixstatement.rb
|
98
112
|
- lib/starkinfra.rb
|
113
|
+
- lib/user/organization.rb
|
114
|
+
- lib/user/project.rb
|
115
|
+
- lib/user/user.rb
|
99
116
|
- lib/utils/api.rb
|
117
|
+
- lib/utils/bacenid.rb
|
100
118
|
- lib/utils/cache.rb
|
101
119
|
- lib/utils/case.rb
|
102
120
|
- lib/utils/checks.rb
|
121
|
+
- lib/utils/endtoendid.rb
|
103
122
|
- lib/utils/environment.rb
|
104
123
|
- lib/utils/parse.rb
|
105
124
|
- lib/utils/request.rb
|
106
125
|
- lib/utils/resource.rb
|
107
126
|
- lib/utils/rest.rb
|
127
|
+
- lib/utils/returnid.rb
|
108
128
|
- lib/utils/sub_resource.rb
|
109
129
|
- lib/utils/url.rb
|
130
|
+
- lib/webhook/webhook.rb
|
110
131
|
homepage: https://github.com/starkinfra/sdk-ruby
|
111
132
|
licenses:
|
112
133
|
- MIT
|
113
134
|
metadata: {}
|
114
|
-
post_install_message:
|
135
|
+
post_install_message:
|
115
136
|
rdoc_options: []
|
116
137
|
require_paths:
|
117
138
|
- lib
|
@@ -126,8 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
147
|
- !ruby/object:Gem::Version
|
127
148
|
version: '0'
|
128
149
|
requirements: []
|
129
|
-
rubygems_version: 3.1
|
130
|
-
signing_key:
|
150
|
+
rubygems_version: 3.0.3.1
|
151
|
+
signing_key:
|
131
152
|
specification_version: 4
|
132
153
|
summary: SDK to facilitate Ruby integrations with Stark Infra
|
133
154
|
test_files: []
|