fix plugin http types & docs (#5494)
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
- Minor: Added drop indicator line while dragging in tables. (#5256)
|
- Minor: Added drop indicator line while dragging in tables. (#5256)
|
||||||
- Minor: Add channel points indication for new bits power-up redemptions. (#5471)
|
- Minor: Add channel points indication for new bits power-up redemptions. (#5471)
|
||||||
- Minor: Added `/warn <username> <reason>` command for mods. This prevents the user from chatting until they acknowledge the warning. (#5474)
|
- Minor: Added `/warn <username> <reason>` command for mods. This prevents the user from chatting until they acknowledge the warning. (#5474)
|
||||||
- Minor: Introduce HTTP API for plugins. (#5383, #5492)
|
- Minor: Introduce HTTP API for plugins. (#5383, #5492, #5494)
|
||||||
- Bugfix: Fixed tab move animation occasionally failing to start after closing a tab. (#5426)
|
- Bugfix: Fixed tab move animation occasionally failing to start after closing a tab. (#5426)
|
||||||
- Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378)
|
- Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378)
|
||||||
- Bugfix: Fixed restricted users usernames not being clickable. (#5405)
|
- Bugfix: Fixed restricted users usernames not being clickable. (#5405)
|
||||||
|
|||||||
+19
-24
@@ -158,12 +158,27 @@ function c2.Channel.by_twitch_id(id) end
|
|||||||
|
|
||||||
-- End src/controllers/plugins/api/ChannelRef.hpp
|
-- End src/controllers/plugins/api/ChannelRef.hpp
|
||||||
|
|
||||||
-- Begin src/controllers/plugins/api/HTTPRequest.hpp
|
-- Begin src/controllers/plugins/api/HTTPResponse.hpp
|
||||||
|
|
||||||
---@class HTTPResponse
|
---@class HTTPResponse
|
||||||
---@field data string Data received from the server
|
HTTPResponse = {}
|
||||||
---@field status integer? HTTP Status code returned by the server
|
|
||||||
---@field error string A somewhat human readable description of an error if such happened
|
--- Returns the data. This is not guaranteed to be encoded using any
|
||||||
|
--- particular encoding scheme. It's just the bytes the server returned.
|
||||||
|
---
|
||||||
|
function HTTPResponse:data() end
|
||||||
|
|
||||||
|
--- Returns the status code.
|
||||||
|
---
|
||||||
|
function HTTPResponse:status() end
|
||||||
|
|
||||||
|
--- A somewhat human readable description of an error if such happened
|
||||||
|
---
|
||||||
|
function HTTPResponse:error() end
|
||||||
|
|
||||||
|
-- End src/controllers/plugins/api/HTTPResponse.hpp
|
||||||
|
|
||||||
|
-- Begin src/controllers/plugins/api/HTTPRequest.hpp
|
||||||
|
|
||||||
---@alias HTTPCallback fun(result: HTTPResponse): nil
|
---@alias HTTPCallback fun(result: HTTPResponse): nil
|
||||||
---@class HTTPRequest
|
---@class HTTPRequest
|
||||||
@@ -213,26 +228,6 @@ function HTTPRequest.create(method, url) end
|
|||||||
|
|
||||||
-- End src/controllers/plugins/api/HTTPRequest.hpp
|
-- End src/controllers/plugins/api/HTTPRequest.hpp
|
||||||
|
|
||||||
-- Begin src/controllers/plugins/api/HTTPResponse.hpp
|
|
||||||
|
|
||||||
---@class HTTPResponse
|
|
||||||
HTTPResponse = {}
|
|
||||||
|
|
||||||
--- Returns the data. This is not guaranteed to be encoded using any
|
|
||||||
--- particular encoding scheme. It's just the bytes the server returned.
|
|
||||||
---
|
|
||||||
function HTTPResponse:data() end
|
|
||||||
|
|
||||||
--- Returns the status code.
|
|
||||||
---
|
|
||||||
function HTTPResponse:status() end
|
|
||||||
|
|
||||||
--- A somewhat human readable description of an error if such happened
|
|
||||||
---
|
|
||||||
function HTTPResponse:error() end
|
|
||||||
|
|
||||||
-- End src/controllers/plugins/api/HTTPResponse.hpp
|
|
||||||
|
|
||||||
-- Begin src/common/network/NetworkCommon.hpp
|
-- Begin src/common/network/NetworkCommon.hpp
|
||||||
|
|
||||||
---@alias HTTPMethod integer
|
---@alias HTTPMethod integer
|
||||||
|
|||||||
+4
-12
@@ -420,14 +420,6 @@ It returns something like: `"ConnectionRefusedError"`, `"401"`.
|
|||||||
This function returns the HTTP status code of the request or `nil` if there was
|
This function returns the HTTP status code of the request or `nil` if there was
|
||||||
an error before a status code could be received.
|
an error before a status code could be received.
|
||||||
|
|
||||||
```lua
|
|
||||||
{
|
|
||||||
data = "This is the data received from the server as a string",
|
|
||||||
status = 200, -- HTTP status code returned by the server or nil if no response was received because of an error
|
|
||||||
error = "A somewhat human readable description of an error if such happened"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `HTTPRequest`
|
#### `HTTPRequest`
|
||||||
|
|
||||||
Allows you to send an HTTP request to a URL. Do not create requests that you
|
Allows you to send an HTTP request to a URL. Do not create requests that you
|
||||||
@@ -443,7 +435,7 @@ containing a valid URL (ex. `https://example.com/path/to/api`).
|
|||||||
```lua
|
```lua
|
||||||
local req = c2.HTTPRequest.create(c2.HTTPMethod.Get, "https://example.com")
|
local req = c2.HTTPRequest.create(c2.HTTPMethod.Get, "https://example.com")
|
||||||
req:on_success(function (res)
|
req:on_success(function (res)
|
||||||
print(res.data)
|
print(res:data())
|
||||||
end)
|
end)
|
||||||
req:execute()
|
req:execute()
|
||||||
```
|
```
|
||||||
@@ -496,12 +488,12 @@ request:set_header("Content-Type", "text/plain")
|
|||||||
request:on_success(function (res)
|
request:on_success(function (res)
|
||||||
print('Success!')
|
print('Success!')
|
||||||
-- Data is in res.data
|
-- Data is in res.data
|
||||||
print(res.status)
|
print(res:status())
|
||||||
end)
|
end)
|
||||||
request:on_error(function (res)
|
request:on_error(function (res)
|
||||||
print('Error!')
|
print('Error!')
|
||||||
print(res.status)
|
print(res:status())
|
||||||
print(res.error)
|
print(res:error())
|
||||||
end)
|
end)
|
||||||
request:finally(function ()
|
request:finally(function ()
|
||||||
print('Finally')
|
print('Finally')
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ struct CompletionEvent {
|
|||||||
/**
|
/**
|
||||||
* @includefile common/Channel.hpp
|
* @includefile common/Channel.hpp
|
||||||
* @includefile controllers/plugins/api/ChannelRef.hpp
|
* @includefile controllers/plugins/api/ChannelRef.hpp
|
||||||
* @includefile controllers/plugins/api/HTTPRequest.hpp
|
|
||||||
* @includefile controllers/plugins/api/HTTPResponse.hpp
|
* @includefile controllers/plugins/api/HTTPResponse.hpp
|
||||||
|
* @includefile controllers/plugins/api/HTTPRequest.hpp
|
||||||
* @includefile common/network/NetworkCommon.hpp
|
* @includefile common/network/NetworkCommon.hpp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,6 @@
|
|||||||
namespace chatterino::lua::api {
|
namespace chatterino::lua::api {
|
||||||
// NOLINTBEGIN(readability-identifier-naming)
|
// NOLINTBEGIN(readability-identifier-naming)
|
||||||
|
|
||||||
/**
|
|
||||||
* @lua@class HTTPResponse
|
|
||||||
* @lua@field data string Data received from the server
|
|
||||||
* @lua@field status integer? HTTP Status code returned by the server
|
|
||||||
* @lua@field error string A somewhat human readable description of an error if such happened
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @lua@alias HTTPCallback fun(result: HTTPResponse): nil
|
* @lua@alias HTTPCallback fun(result: HTTPResponse): nil
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user