Skip to content

Commit 6857cc3

Browse files
authored
Merge pull request #60 from starkbank/feature/raw-methods
Add raw methods
2 parents 83ec085 + 4b913b6 commit 6857cc3

File tree

8 files changed

+487
-18
lines changed

8 files changed

+487
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ Given a version number MAJOR.MINOR.PATCH, increment:
1313

1414

1515
## [Unreleased]
16-
## Added
16+
### Added
1717
- update function to Deposit resource
18+
- raw methods
1819

1920
## [2.11.0] - 2023-09-18
2021
### Removed

Gemfile.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PATH
22
remote: .
33
specs:
44
starkbank (2.11.0)
5-
starkcore (~> 0.0.1)
5+
starkcore (~> 0.2.2)
66

77
GEM
88
remote: https://rubygems.org/
@@ -29,13 +29,14 @@ GEM
2929
parser (>= 3.2.1.0)
3030
ruby-progressbar (1.13.0)
3131
starkbank-ecdsa (2.0.0)
32-
starkcore (0.0.1)
32+
starkcore (0.2.2)
3333
starkbank-ecdsa (~> 2.0.0)
3434
unicode-display_width (1.8.0)
3535

3636
PLATFORMS
3737
arm64-darwin-21
3838
arm64-darwin-22
39+
ruby
3940

4041
DEPENDENCIES
4142
minitest (~> 5.14.1)

README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ is as easy as sending a text message to your client!
5353
- [WebhookEvents](#process-webhook-events): Manage webhook events
5454
- [WebhookEventAttempts](#query-failed-webhook-event-delivery-attempts-information): Query failed webhook event deliveries
5555
- [Workspaces](#create-a-new-workspace): Manage your accounts
56+
- [Request](#request): Send a custom request to Stark Bank. This can be used to access features that haven't been mapped yet.
5657
- [Handling errors](#handling-errors)
5758
- [Help and Feedback](#help-and-feedback)
5859

@@ -2463,6 +2464,163 @@ updatedWorkspace = StarkBank::Workspace.update(
24632464
puts updatedWorkspace
24642465
```
24652466

2467+
# Request
2468+
2469+
This resource allows you to send HTTP requests to StarkBank routes.
2470+
2471+
## GET
2472+
2473+
You can perform a GET request to any StarkBank route.
2474+
2475+
It's possible to get a single resource using its id in the path.
2476+
2477+
```ruby
2478+
require('starkbank')
2479+
2480+
example_id = "5155165527080960"
2481+
request = StarkBank::Request.get(
2482+
path:"/invoice/#{example_id}"
2483+
).json
2484+
2485+
puts request
2486+
```
2487+
2488+
You can also get the specific resource log,
2489+
2490+
```ruby
2491+
require('starkbank')
2492+
2493+
example_id = "5699165527090460"
2494+
request = StarkBank::Request.get(
2495+
path:"/invoice/log/#{example_id}",
2496+
).json
2497+
2498+
puts request
2499+
```
2500+
2501+
This same method will be used to list all created items for the requested resource.
2502+
2503+
```ruby
2504+
require('starkbank')
2505+
2506+
request = StarkBank::Request.get(
2507+
path:"/invoice",
2508+
query:{"limit": 10, "status": "paid"},
2509+
).json
2510+
2511+
puts request
2512+
```
2513+
2514+
To list logs, you will use the same logic as for getting a single log.
2515+
2516+
```ruby
2517+
require('starkbank')
2518+
2519+
request = StarkBank::Request.get(
2520+
path:"/invoice/log",
2521+
query:{"limit": 10, "status": "paid"},
2522+
).json
2523+
2524+
puts request
2525+
```
2526+
2527+
You can get a resource file using this method.
2528+
2529+
```ruby
2530+
require('starkbank')
2531+
2532+
example_id = "5155165527080960"
2533+
pdf = StarkBank::Request.get(
2534+
path:"/invoice/#{example_id}/pdf",
2535+
).content
2536+
File.binwrite('invoice.pdf', pdf)
2537+
```
2538+
2539+
## POST
2540+
2541+
You can perform a POST request to any StarkBank route.
2542+
2543+
This will create an object for each item sent in your request
2544+
2545+
**Note**: It's not possible to create multiple resources simultaneously. You need to send separate requests if you want to create multiple resources, such as invoices and boletos.
2546+
2547+
```ruby
2548+
require('starkbank')
2549+
2550+
data={
2551+
"invoices": [
2552+
{
2553+
"amount": 100,
2554+
"name": "Iron Bank S.A.",
2555+
"taxId": "20.018.183/0001-80"
2556+
},
2557+
{
2558+
"amount": 450000,
2559+
"name": "Arya Stark.",
2560+
"taxId": "012.345.678-90"
2561+
}
2562+
]
2563+
}
2564+
request = StarkBank::Request.get(
2565+
path:"/invoice",
2566+
body:data
2567+
).json
2568+
puts request
2569+
```
2570+
2571+
## PATCH
2572+
2573+
You can perform a PATCH request to any StarkBank route.
2574+
2575+
It's possible to update a single item of a StarkBank resource.
2576+
```ruby
2577+
require('starkbank')
2578+
2579+
example_id = "5155165527080960"
2580+
request = StarkBank::Request.patch(
2581+
path:"/invoice/#{example_id}",
2582+
body:{"amount": 0},
2583+
).json
2584+
puts request
2585+
```
2586+
2587+
## PUT
2588+
2589+
You can perform a PUT request to any StarkBank route.
2590+
2591+
It's possible to put a single item of a StarkBank resource.
2592+
```ruby
2593+
require('starkbank')
2594+
2595+
data = {
2596+
"profiles": [
2597+
{
2598+
"interval": "day",
2599+
"delay": 0
2600+
}
2601+
]
2602+
}
2603+
request = StarkBank::Request.put(
2604+
path:"/split-profile",
2605+
body:data,
2606+
).json
2607+
puts request
2608+
```
2609+
## DELETE
2610+
2611+
You can perform a DELETE request to any StarkBank route.
2612+
2613+
It's possible to delete items of StarkBank resource.
2614+
```ruby
2615+
require('starkbank')
2616+
2617+
example_id = "5155165527080960"
2618+
request = StarkBank::Request.delete(
2619+
path:"/transfer/#{example_id}",
2620+
).json
2621+
puts request
2622+
```
2623+
24662624
# Handling errors
24672625

24682626
The SDK may raise one of four types of errors: __InputErrors__, __InternalServerError__, __UnknownError__, __InvalidSignatureError__

lib/request/request.rb

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# frozen_string_literal: true
2+
3+
require('starkcore')
4+
require_relative('../utils/rest')
5+
require_relative('../utils/parse')
6+
7+
module StarkBank
8+
9+
class Request
10+
11+
# # Retrieve any StarkBank resource
12+
#
13+
# Receive a json of resources previously created in StarkBank's API
14+
#
15+
# Parameters (required):
16+
#
17+
# - path [string]: StarkBank resource's route. ex: "/invoice/"
18+
# - query [json, default None]: Query parameters. ex: {"limit": 1, "status": paid}
19+
#
20+
# Parameters (optional):
21+
#
22+
# - user [Organization/Project object, default None]: Organization or Project object. Not necessary if StarkBank.user
23+
# was set before function call
24+
#
25+
# Return:
26+
# - json of StarkBank objects with updated attributes
27+
28+
def self.get(path:, query: nil, user: nil)
29+
content = StarkBank::Utils::Rest.get_raw(
30+
path: path,
31+
query: query,
32+
user: user,
33+
prefix: "Joker",
34+
raiseException: false
35+
)
36+
end
37+
38+
# # Create any StarkBank resource
39+
#
40+
# Send a json to create StarkBank resources
41+
#
42+
# Parameters (required):
43+
#
44+
# - path [string]: StarkBank resource's route. ex: "/invoice/"
45+
# - body [json]: request parameters. ex: {"invoices": [{"amount": 100, "name": "Iron Bank S.A.", "taxId": "20.018.183/0001-80"}]}
46+
#
47+
# Parameters (optional):
48+
#
49+
# - user [Organization/Project object, default None]: Organization or Project object. Not necessary if StarkBank.user
50+
# was set before function call
51+
# - query [json, default None]: Query parameters. ex: {"limit": 1, "status": paid}
52+
#
53+
# Return:
54+
#
55+
# - list of resources jsons with updated attributes
56+
57+
def self.post(path:, payload:, query: nil, user: nil)
58+
content = StarkBank::Utils::Rest.post_raw(
59+
path: path,
60+
query: query,
61+
payload: payload,
62+
user: user,
63+
prefix: "Joker",
64+
raiseException: false
65+
)
66+
end
67+
68+
# # Update any StarkBank resource
69+
#
70+
# Send a json with parameters of StarkBank resources to update them
71+
#
72+
# Parameters (required):
73+
#
74+
# - path [string]: StarkBank resource's route. ex: "/invoice/5699165527090460"
75+
# - body [json]: request parameters. ex: {"amount": 100}
76+
#
77+
# Parameters (optional):
78+
#
79+
# - user [Organization/Project object, default None]: Organization or Project object. Not necessary if StarkBank.user
80+
# was set before function call
81+
#
82+
# Return:
83+
# - json of the resource with updated attributes
84+
85+
def self.patch(path:, payload:, query: nil, user: nil)
86+
content = StarkBank::Utils::Rest.patch_raw(
87+
path: path,
88+
query: query,
89+
payload: payload,
90+
user: user,
91+
prefix: "Joker",
92+
raiseException: false
93+
)
94+
end
95+
96+
# # Put any StarkBank resource
97+
#
98+
# Send a json with parameters of a StarkBank resources to create them.
99+
# If the resource already exists, you will update it.
100+
#
101+
# Parameters (required):
102+
#
103+
# - path [string]: StarkBank resource's route. ex: "/split-profile"
104+
# - body [json]: request parameters. ex: {"profiles": [{"interval": day, "delay": "1"}]}
105+
#
106+
# Parameters (optional):
107+
#
108+
# - user [Organization/Project object, default None]: Organization or Project object. Not necessary if StarkBank.user
109+
# was set before function call
110+
#
111+
# Return:
112+
# - json of the resource with updated attributes
113+
114+
def self.put(path:, payload:, query: nil, user: nil)
115+
content = StarkBank::Utils::Rest.put_raw(
116+
path: path,
117+
query: query,
118+
payload: payload,
119+
user: user,
120+
prefix: "Joker",
121+
raiseException: false
122+
)
123+
end
124+
125+
# # Delete any StarkBank resource
126+
#
127+
# Send parameters of StarkBank resources and delete them
128+
#
129+
# Parameters (required):
130+
#
131+
# - path [string]: StarkBank resource's route. ex: "/transfer/5699165527090460"
132+
#
133+
# Parameters (optional):
134+
#
135+
# - user [Organization/Project object, default None]: Organization or Project object. Not necessary if StarkBank.user
136+
# was set before function call
137+
#
138+
# Return:
139+
# - json of the resource with updated attributes
140+
141+
def self.delete(path:, query: nil, user: nil)
142+
content = StarkBank::Utils::Rest.delete_raw(
143+
path: path,
144+
query: query,
145+
user: user,
146+
prefix: "Joker",
147+
raiseException: false
148+
)
149+
end
150+
end
151+
end

lib/starkbank.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
require_relative('payment_preview/tax_preview')
5555
require_relative('payment_preview/utility_preview')
5656
require_relative('institution/institution')
57+
require_relative('request/request')
5758

5859
# SDK to facilitate Ruby integrations with Stark Bank
5960
module StarkBank

0 commit comments

Comments
 (0)