-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.lua
85 lines (75 loc) · 2.27 KB
/
example.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
_0rbit = require("src.main")
local json = require("json")
-- The URL to send the GET request to
GET_URL = "https://0rbit.co"
-- The URL to send the POST request to
POST_URL = "https://g8way.0rbit.co/graphql"
-- The data body to be sent in the POST request
POST_BODY = json.encode({
query = [[
query {
transactions(
owners: ["vh-NTHVvlKZqRxc8LyyTNok65yQ55a_PJ1zWLb9G2JI"]
) {
edges {
node {
id
}
}
}
}
]]
});
--[[
Example function to be called when the response is received.
@msg: The response message
]]
function onResponse(msg)
print("Response: " .. json.encode(msg))
end
--[[
Example Handler for sending a GET request.
@GET_URL: The URL to send the GET request to
]]
Handlers.add(
"TestGetRequest",
Handlers.utils.hasMatchingTag("Action", "Test-Get-Request"),
function()
_0rbit.sendGetRequest(GET_URL)
end
)
--[[
Example Handler for sending a POST request.
@BASE_URL: The URL to send the POST request to
@BODY: The data body to be sent in the POST request
]]
Handlers.add(
"Test-Post-Request",
Handlers.utils.hasMatchingTag("Action", "Test-Post-Request"),
function()
_0rbit.sendPostRequest(POST_URL, POST_BODY)
end
)
--[[
Example Handler for receiving a response.
@msg: The response message
@onResponse (optional): The function to be called when the response is received
]]
Handlers.add(
"Receive-Response",
Handlers.utils.hasMatchingTag("Action", "Receive-Response"),
function(msg)
_0rbit.receiveResponse(msg, onResponse)
end
)
--[[
Example Handler for getting the balance of the current processId.
@recepient (optional): The processId to get the balance of. If not passed, then the balance of the current processId is returned.
]]
Handlers.add(
"Get-Balance",
Handlers.utils.hasMatchingTag("Action", "Get-Balance"),
function()
_0rbit.getBalance()
end
)