6 Commits
dev ... native

Author SHA1 Message Date
373b800a3d Update README.md 2025-06-11 12:49:02 -03:00
d2ec71e7ae Add native instance and runtime statics 2025-06-04 18:35:14 -03:00
6ab490ce07 Generate native bindings from rust crate 2025-06-04 17:09:39 -03:00
738f9c947b Add utils crates 2025-06-04 11:30:22 -03:00
f5d3e86eb2 Update README.md 2025-06-03 19:49:03 -03:00
Guilherme Werner
23af141e2d Generate api client with openapi-generator (#3)
* Generate api client with openapi-generator

* Add wrapper struct

* Add basic example
2025-06-03 19:47:49 -03:00
124 changed files with 8490 additions and 1120 deletions

14
.cargo/config.toml Normal file
View File

@@ -0,0 +1,14 @@
[build]
rustflags = ["--cfg", "uuid_unstable"]
[profile.dev]
lto = "off"
[profile.release]
lto = "thin"
[target.'cfg(target_os = "windows")']
rustflags = ["-C", "target-feature=+crt-static"]
[target.'cfg(target_family = "wasm")']
rustflags = ["--cfg", "web_sys_unstable_apis"]

221
.clang-format Normal file
View File

@@ -0,0 +1,221 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterExternBlock: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAfterAttributes: Never
BreakAfterJavaFieldAnnotations: false
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Custom
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: ".*"
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: "(Test)?$"
IncludeIsMainSourceRegex: ""
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
Decimal: 0
Hex: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Right
PPIndentWidth: -1
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseTab: Never
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
---

View File

@@ -1,3 +1,2 @@
CLIENT_ID=
CLIENT_SECRET=
TRIBUFU_API_URL=https://api.tribufu.com
TRIBUFU_API_KEY=""
TRIBUFU_API_URL="https://api.tribufu.com"

23
.gitignore vendored
View File

@@ -1,40 +1,17 @@
__pycache__/
.gradle/
.idea/
.metals/
.next/
.parcel-cache/
.vs/
.vscode/
bin/
binaries/
build/
node_modules/
obj/
saved/
target/
.DS_Store
.env
*.crt
*.csproj
*.filters
*.fsproj
*.key
*.log
*.make
*.mwb.bak
*.pem
*.sln
*.user
*.vcxproj
*.vpp.*
*.wasm
*.xcodeproj
*.xcworkspace
Cargo.lock
desktop.ini
keystore.jks
local.properties
Makefile
next-env.d.ts

View File

@@ -0,0 +1,8 @@
docs/
.gitignore
.travis.yml
Cargo.toml
git_push.sh
README.md
src/lib.rs

46
.openapi-generator/FILES Normal file
View File

@@ -0,0 +1,46 @@
src/apis/configuration.rs
src/apis/mod.rs
src/apis/tribufu_generated_api.rs
src/models/account.rs
src/models/application.rs
src/models/application_type.rs
src/models/authorize_request.rs
src/models/code_challenge_method.rs
src/models/crypto_view_model.rs
src/models/game.rs
src/models/game_server.rs
src/models/game_server_cluster.rs
src/models/grant_type.rs
src/models/group.rs
src/models/group_game.rs
src/models/group_member.rs
src/models/group_rank.rs
src/models/hash_view_model.rs
src/models/introspect_request.rs
src/models/ip_address.rs
src/models/leaderboard_item.rs
src/models/leaderboard_order.rs
src/models/login_provider.rs
src/models/login_request.rs
src/models/login_response.rs
src/models/mod.rs
src/models/package.rs
src/models/profile.rs
src/models/profile_game.rs
src/models/profile_group.rs
src/models/refresh_request.rs
src/models/register_request.rs
src/models/response_type.rs
src/models/revoke_request.rs
src/models/search_request.rs
src/models/search_type.rs
src/models/server_metrics.rs
src/models/server_status.rs
src/models/subscription.rs
src/models/token_hint_type.rs
src/models/token_request.rs
src/models/token_response.rs
src/models/token_type.rs
src/models/update_profile.rs
src/models/user_info.rs
src/models/user_type.rs

View File

@@ -0,0 +1 @@
7.12.0

View File

@@ -1,8 +1,8 @@
[package]
name = "tribufu"
version = "0.1.0"
description = "Tribufu SDK"
repository = "https://github.com/Tribufu/TribufuRust"
version = "1.1.0"
description = "REST API to access Tribufu services."
repository = "https://github.com/tribufu/tribufu-rust"
authors = ["Tribufu <contact@tribufu.com>"]
license = "MIT"
readme = "README.md"
@@ -11,40 +11,42 @@ publish = true
exclude = [
".editorconfig",
".env*",
".gitattributes",
".github/",
".openapi-generator-ignore",
".openapi-generator/",
".vscode/",
"examples/",
"scripts/",
"scripts/",
]
[workspace]
resolver = "2"
members = ["src/*"]
exclude = ["src/apis", "src/models"]
[lib]
name = "tribufu"
crate-type = ["rlib"]
path = "src/lib.rs"
[features]
#actix = ["tribufu-actix"]
[dependencies]
#tribufu-actix = { version = "0.1.0", path = "./src/actix", optional = true }
alnilam-consts = { version = "0.0.4" }
anyhow = "1.0.75"
base64 = "0.21.5"
chrono = { version = "0.4.22", features = ["serde", "rustc-serialize"] }
derive_more = "0.99.17"
mintaka-error = { version = "0.0.1" }
reqwest = { version = "0.11.18", features = ["json", "stream"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
serde_with = "3.4.0"
tribufu-constants = { version = "0.1.0", path = "./src/constants" }
tribufu-types = { version = "0.1.0", path = "./src/types" }
tribufu-constants = { version = "0.0.5", path = "./src/constants" }
async-trait = "^0.1"
reqwest = { version = "^0.12", features = ["json", "multipart"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
serde_repr = "^0.1"
serde_with = { version = "^3.8", default-features = false, features = [
"base64",
"std",
"macros",
] }
url = "^2.5"
uuid = { version = "^1.8", features = ["serde", "v4"] }
[dev-dependencies]
dotenv = "0.15.0"
tokio = { version = "1", features = ["full"] }
tokio = { version = "1.45.1", features = ["full"] }

View File

@@ -1,6 +1,6 @@
# Tribufu Rust
Rust SDK to access Tribufu APIs and services.
Native SDK to access Tribufu APIs and services.
[![Crates.io][crates-badge]][crates-url]
[![MIT License][mit-badge]][mit-url]
@@ -9,7 +9,7 @@ Rust SDK to access Tribufu APIs and services.
[crates-badge]: https://img.shields.io/crates/v/tribufu.svg
[crates-url]: https://crates.io/crates/tribufu
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
[mit-url]: https://github.com/Tribufu/TribufuRust/blob/main/LICENSE.txt
[mit-url]: https://github.com/tribufu/tribufu-rust/blob/main/LICENSE.txt
[discord-badge]: https://img.shields.io/discord/276504514616623104.svg?logo=discord&style=flat-square
[discord-url]: https://www.tribufu.com/discord
@@ -20,4 +20,4 @@ Rust SDK to access Tribufu APIs and services.
This project is licensed under the [MIT License].
[MIT License]: https://github.com/Tribufu/TribufuRust/blob/main/LICENSE.txt
[MIT License]: https://github.com/tribufu/tribufu-rust/blob/main/LICENSE.txt

157
config/cbindgen.toml Normal file
View File

@@ -0,0 +1,157 @@
language = "C"
header = "// Copyright (c) Tribufu. All Rights Reserved.\n// SPDX-License-Identifier: MIT"
pragma_once = true
include_version = false
namespaces = []
using_namespaces = []
sys_includes = ["tribufu/prelude.h"]
includes = []
no_includes = true
cpp_compat = false
braces = "NextLine"
line_length = 100
tab_width = 4
documentation = true
documentation_style = "doxy"
style = "tag"
[defines]
"debug_assertions" = "TRIBUFU_DEBUG"
"not(debug_assertions)" = "TRIBUFU_RELEASE"
"panic = abort" = "TRIBUFU_PANIC_ABORT"
"panic = unwind" = "TRIBUFU_PANIC_UNWIND"
"proc_macro" = "TRIBUFU_PROC_MACRO"
"target_arch = aarch64" = "TRIBUFU_AARCH64"
"target_arch = arm" = "TRIBUFU_ARM"
"target_arch = armV7" = "TRIBUFU_ARMV7"
"target_arch = armv4t" = "TRIBUFU_ARMV4T"
"target_arch = armv6" = "TRIBUFU_ARMV6"
"target_arch = armv7a" = "TRIBUFU_ARMV7A"
"target_arch = armv7s" = "TRIBUFU_ARMV7S"
"target_arch = avr" = "TRIBUFU_AVR"
"target_arch = bpfeb" = "TRIBUFU_BPFEB"
"target_arch = bpfel" = "TRIBUFU_BPFEL"
"target_arch = hexagon" = "TRIBUFU_HEXAGON"
"target_arch = i386" = "TRIBUFU_I386"
"target_arch = i586" = "TRIBUFU_I586"
"target_arch = i686" = "TRIBUFU_I686"
"target_arch = m68k" = "TRIBUFU_M68K"
"target_arch = mips" = "TRIBUFU_MIPS"
"target_arch = mipsel" = "TRIBUFU_MIPSEL"
"target_arch = msp430" = "TRIBUFU_MSP430"
"target_arch = powerpc" = "TRIBUFU_POWERPC"
"target_arch = powerpc64" = "TRIBUFU_POWERPC64"
"target_arch = powerpc64l" = "TRIBUFU_POWERPC64L"
"target_arch = riscv32gc" = "TRIBUFU_RISCV32GC"
"target_arch = s390x" = "TRIBUFU_S390X"
"target_arch = sparc" = "TRIBUFU_SPARC"
"target_arch = sparc64" = "TRIBUFU_SPARC64"
"target_arch = thumbv4t" = "TRIBUFU_THUMBV4T"
"target_arch = thumbv7a" = "TRIBUFU_THUMBV7A"
"target_arch = thumbv7neon" = "TRIBUFU_THUMBV7NEON"
"target_arch = wasm32" = "TRIBUFU_WASM32"
"target_arch = wasm64" = "TRIBUFU_WASM64"
"target_arch = x86" = "TRIBUFU_X86"
"target_arch = x86_64" = "TRIBUFU_X86_64"
"target_endian = big" = "TRIBUFU_BIG_ENDIAN"
"target_endian = little" = "TRIBUFU_LITTLE_ENDIAN"
"target_env = gnu" = "TRIBUFU_GNU"
"target_env = msvc" = "TRIBUFU_MSVC"
"target_env = musl" = "TRIBUFU_MUSL"
"target_env = sgx" = "TRIBUFU_SGX"
"target_family = unix" = "TRIBUFU_UNIX"
"target_family = wasm" = "TRIBUFU_WASM"
"target_family = windows" = "TRIBUFU_MICROSOFT"
"target_feature = avx" = "TRIBUFU_AVX"
"target_feature = avx2" = "TRIBUFU_AVX2"
"target_feature = crt-static" = "TRIBUFU_CRTSTATIC"
"target_feature = rdrand" = "TRIBUFU_RDRAND"
"target_feature = sse" = "TRIBUFU_SSE"
"target_feature = sse2" = "TRIBUFU_SSE2"
"target_feature = sse4.1" = "TRIBUFU_SSE41"
"target_has_atomic = 128" = "TRIBUFU_ATOMIC_128"
"target_has_atomic = 16" = "TRIBUFU_ATOMIC_16"
"target_has_atomic = 32" = "TRIBUFU_ATOMIC_32"
"target_has_atomic = 64" = "TRIBUFU_ATOMIC_64"
"target_has_atomic = 8" = "TRIBUFU_ATOMIC_8"
"target_has_atomic = ptr" = "TRIBUFU_ATOMIC_PTR"
"target_os = android" = "TRIBUFU_ANDROID"
"target_os = dragonfly" = "TRIBUFU_DRAGONFLY"
"target_os = freebsd" = "TRIBUFU_FREEBSD"
"target_os = ios" = "TRIBUFU_IOS"
"target_os = linux" = "TRIBUFU_LINUX"
"target_os = macos" = "TRIBUFU_MACOS"
"target_os = netbsd" = "TRIBUFU_NETBSD"
"target_os = openbsd" = "TRIBUFU_OPENBSD"
"target_os = windows" = "TRIBUFU_WINDOWS"
"target_pointer_width = 16" = "TRIBUFU_POINTER_16"
"target_pointer_width = 32" = "TRIBUFU_POINTER_32"
"target_pointer_width = 64" = "TRIBUFU_POINTER_64"
"target_vendor = apple" = "TRIBUFU_APPLE"
"target_vendor = fortanix" = "TRIBUFU_FORTANIX"
"target_vendor = pc" = "TRIBUFU_MICROSOFT"
"target_vendor = unknown" = "TRIBUFU_UNKNOWN"
[export]
include = []
exclude = []
item_types = ["enums", "structs", "typedefs", "functions"]
renaming_overrides_prefixing = false
[layout]
packed = "PACKED"
aligned_n = "ALIGNED"
[fn]
prefix = "TRIBUFU_API"
args = "horizontal"
must_use = "MUST_USE_FUNC"
no_return = "NO_RETURN"
rename_args = "None"
sort_by = "Name"
[struct]
rename_fields = "None"
must_use = "MUST_USE_STRUCT"
derive_constructor = true
derive_eq = false
derive_neq = false
derive_lt = false
derive_lte = false
derive_gt = false
derive_gte = false
[enum]
rename_variants = "None"
add_sentinel = false
prefix_with_name = false
enum_class = false
derive_helper_methods = false
derive_const_casts = false
derive_mut_casts = false
must_use = "MUST_USE_ENUM"
derive_tagged_enum_destructor = false
derive_tagged_enum_copy_constructor = false
derive_tagged_enum_copy_assignment = false
private_default_tagged_enum_constructor = false
[const]
allow_static_const = true
allow_constexpr = false
sort_by = "Name"
[macro_expansion]
bitflags = true
[parse]
parse_deps = true
include = []
exclude = []
clean = false
extra_bindings = []
[parse.expand]
crates = []
all_features = true
default_features = true
features = []

10
examples/agent.rs Normal file
View File

@@ -0,0 +1,10 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
use tribufu::TribufuApi;
#[tokio::main]
async fn main() {
let user_agent = TribufuApi::get_user_agent();
println!("{}", user_agent);
}

View File

@@ -1,10 +1,14 @@
// Copyright (c) Tribufu. All Rights Reserved
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
use tribufu::*;
use dotenv::dotenv;
use tribufu::apis::tribufu_generated_api::TribufuGeneratedApi;
use tribufu::TribufuApi;
#[tokio::main]
async fn main() {
let api = TribufuApi::default();
let games = api.get_games(Some(1)).await.unwrap();
println!("{:?}", games);
dotenv().unwrap();
let tribufu = TribufuApi::from_env_or_default(None);
let user_info = tribufu.get_user_info().await.unwrap();
println!("{:?}", user_info);
}

14
examples/c/main.c Normal file
View File

@@ -0,0 +1,14 @@
// Copyright (c) Tribufu. All Rights Reserved.
#include <stdio.h>
#include <tribufu/api.h>
int main(int argc, char **argv)
{
tribufu_api_initialize();
char *version = tribufu_api_get_user_agent();
printf("%s\n", version);
tribufu_free_string(version);
tribufu_api_shutdown();
return 0;
}

212
examples/c/premake5.lua Normal file
View File

@@ -0,0 +1,212 @@
--- @diagnostic disable: undefined-global
project "example_c"
location "."
kind "ConsoleApp"
language "C"
targetdir("../../bin/%{cfg.platform}")
objdir("../../target/%{cfg.buildcfg}/obj/%{prj.name}/%{cfg.platform}")
files
{
"./**.c",
"./**.h",
"../../include/**.h",
}
vpaths
{
["Sources"] = { "./**.c" },
["Headers"] = { "./**.h", "../../include/**.h" },
}
includedirs
{
"../../include",
}
libdirs
{
"../../bin/%{cfg.platform}",
}
-- Profile
filter { "configurations:debug" }
runtime "Debug"
symbols "On"
defines
{
"DEBUG",
"TRACE",
"TRIBUFU_DEBUG",
"TRIBUFU_TRACE",
}
filter { "configurations:release" }
runtime "Release"
optimize "On"
defines
{
"RELEASE",
"TRIBUFU_RELEASE",
}
-- Platform
filter { "platforms:win-*" }
system "windows"
systemversion "latest"
staticruntime "On"
toolset "msc"
defines
{
"TRIBUFU_DESKTOP",
"TRIBUFU_DYNAMIC",
"TRIBUFU_LIBRARY",
"TRIBUFU_WINDOWS",
}
links
{
"tribufu_sdk.lib",
}
prelinkcommands
{
}
postbuildcommands
{
}
filter { "platforms:osx-*" }
system "macosx"
systemversion "10.15"
toolset "clang"
defines
{
"TRIBUFU_APPLE",
"TRIBUFU_DESKTOP",
"TRIBUFU_DYNAMIC",
"TRIBUFU_LIBRARY",
"TRIBUFU_MAC",
}
links
{
"tribufu_sdk",
}
prelinkcommands
{
}
postbuildcommands
{
}
filter { "platforms:linux-*" }
system "linux"
toolset "gcc"
defines
{
"TRIBUFU_DESKTOP",
"TRIBUFU_DYNAMIC",
"TRIBUFU_LIBRARY",
"TRIBUFU_LINUX",
"TRIBUFU_UNIX",
}
links
{
"tribufu_sdk",
}
prelinkcommands
{
}
postbuildcommands
{
}
filter { "platforms:android-*" }
system "android"
toolset "clang"
defines
{
"TRIBUFU_ANDROID",
"TRIBUFU_DYNAMIC",
"TRIBUFU_LIBRARY",
"TRIBUFU_MOBILE",
"TRIBUFU_UNIX",
}
links
{
"tribufu_sdk",
}
prelinkcommands
{
}
postbuildcommands
{
}
filter { "platforms:ios-*" }
system "ios"
systemversion "13.0"
toolset "clang"
defines
{
"TRIBUFU_APPLE",
"TRIBUFU_IOS",
"TRIBUFU_LIBRARY",
"TRIBUFU_MOBILE",
"TRIBUFU_MONOLITHIC",
}
links
{
"tribufu_sdk",
}
-- Architecture
filter { "platforms:*-x86" }
architecture "x86"
defines
{
"TRIBUFU_32BITS",
"TRIBUFU_X86",
}
filter { "platforms:*-x64" }
architecture "x64"
defines
{
"TRIBUFU_64BITS",
"TRIBUFU_X64",
}
filter { "platforms:*-arm64" }
architecture "ARM64"
defines
{
"TRIBUFU_64BITS",
"TRIBUFU_ARM64",
}

14
examples/cpp/main.cpp Normal file
View File

@@ -0,0 +1,14 @@
// Copyright (c) Tribufu. All Rights Reserved.
#include <iostream>
#include <tribufu/api.h>
int main(int argc, char **argv)
{
tribufu_api_initialize();
const char *version = tribufu_api_get_user_agent();
std::cout << version << std::endl;
tribufu_free_string((char *)version);
tribufu_api_shutdown();
return 0;
}

213
examples/cpp/premake5.lua Normal file
View File

@@ -0,0 +1,213 @@
--- @diagnostic disable: undefined-global
project "example_cpp"
location "."
kind "ConsoleApp"
language "C++"
cppdialect "C++20"
targetdir("../../bin/%{cfg.platform}")
objdir("../../target/%{cfg.buildcfg}/obj/%{prj.name}/%{cfg.platform}")
files
{
"./**.cpp",
"./**.h",
"../../include/**.h",
}
vpaths
{
["Sources"] = { "./**.cpp" },
["Headers"] = { "./**.h", "../../include/**.h" },
}
includedirs
{
"../../include",
}
libdirs
{
"../../bin/%{cfg.platform}",
}
-- Profile
filter { "configurations:debug" }
runtime "Debug"
symbols "On"
defines
{
"DEBUG",
"TRACE",
"TRIBUFU_DEBUG",
"TRIBUFU_TRACE",
}
filter { "configurations:release" }
runtime "Release"
optimize "On"
defines
{
"RELEASE",
"TRIBUFU_RELEASE",
}
-- Platform
filter { "platforms:win-*" }
system "windows"
systemversion "latest"
staticruntime "On"
toolset "msc"
defines
{
"TRIBUFU_DESKTOP",
"TRIBUFU_DYNAMIC",
"TRIBUFU_LIBRARY",
"TRIBUFU_WINDOWS",
}
links
{
"tribufu_sdk.lib",
}
prelinkcommands
{
}
postbuildcommands
{
}
filter { "platforms:osx-*" }
system "macosx"
systemversion "10.15"
toolset "clang"
defines
{
"TRIBUFU_APPLE",
"TRIBUFU_DESKTOP",
"TRIBUFU_DYNAMIC",
"TRIBUFU_LIBRARY",
"TRIBUFU_MAC",
}
links
{
"tribufu_sdk",
}
prelinkcommands
{
}
postbuildcommands
{
}
filter { "platforms:linux-*" }
system "linux"
toolset "gcc"
defines
{
"TRIBUFU_DESKTOP",
"TRIBUFU_DYNAMIC",
"TRIBUFU_LIBRARY",
"TRIBUFU_LINUX",
"TRIBUFU_UNIX",
}
links
{
"tribufu_sdk",
}
prelinkcommands
{
}
postbuildcommands
{
}
filter { "platforms:android-*" }
system "android"
toolset "clang"
defines
{
"TRIBUFU_ANDROID",
"TRIBUFU_DYNAMIC",
"TRIBUFU_LIBRARY",
"TRIBUFU_MOBILE",
"TRIBUFU_UNIX",
}
links
{
"tribufu_sdk",
}
prelinkcommands
{
}
postbuildcommands
{
}
filter { "platforms:ios-*" }
system "ios"
systemversion "13.0"
toolset "clang"
defines
{
"TRIBUFU_APPLE",
"TRIBUFU_IOS",
"TRIBUFU_LIBRARY",
"TRIBUFU_MOBILE",
"TRIBUFU_MONOLITHIC",
}
links
{
"tribufu_sdk",
}
-- Architecture
filter { "platforms:*-x86" }
architecture "x86"
defines
{
"TRIBUFU_32BITS",
"TRIBUFU_X86",
}
filter { "platforms:*-x64" }
architecture "x64"
defines
{
"TRIBUFU_64BITS",
"TRIBUFU_X64",
}
filter { "platforms:*-arm64" }
architecture "ARM64"
defines
{
"TRIBUFU_64BITS",
"TRIBUFU_ARM64",
}

View File

@@ -1,10 +0,0 @@
// Copyright (c) Tribufu. All Rights Reserved
use tribufu::*;
#[tokio::main]
async fn main() {
let api = TribufuApi::with_client_from_env().unwrap_or_default();
let games = api.get_games(Some(1)).await.unwrap();
println!("{:?}", games);
}

6
include/tribufu.h Normal file
View File

@@ -0,0 +1,6 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
#pragma once
#include <tribufu/api.h>

6
include/tribufu/api.h Normal file
View File

@@ -0,0 +1,6 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
#pragma once
#include <tribufu/native.h>

25
include/tribufu/macros.h Normal file
View File

@@ -0,0 +1,25 @@
// Copyright (c) Tribufu. All Rights Reserved.
#pragma once
#ifdef __cplusplus
#define TRIBUFU_CPP
#endif
#ifndef EXTERN_C
#ifdef TRIBUFU_CPP
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif
#endif
#define TRIBUFU_API EXTERN_C
/*
#ifdef TRIBUFU_LIBRARY
#define TRIBUFU_API DLLEXPORT
#else
#define TRIBUFU_API DLLIMPORT
#endif
*/

38
include/tribufu/native.h Normal file
View File

@@ -0,0 +1,38 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
#pragma once
#include <tribufu/prelude.h>
typedef void TribufuApiGetUserInfoCallbackData;
typedef void (*TribufuApiGetUserInfoCallback)(void*, const TribufuApiGetUserInfoCallbackData*);
/**
* Gets the user agent string for the Tribufu API.
*/
TRIBUFU_API const char *tribufu_api_get_user_agent(void);
TRIBUFU_API void tribufu_api_get_user_info(void *context, TribufuApiGetUserInfoCallback callback);
/**
* Gets the version of the Tribufu API.
*/
TRIBUFU_API const char *tribufu_api_get_version(void);
/**
* Initialize the Tribufu API instance.
*
* This must be called before any other API functions.
*/
TRIBUFU_API bool tribufu_api_initialize(void);
/**
* Shutdown the Tribufu API instance.
*
* This must be called when the API is no longer needed.
*/
TRIBUFU_API void tribufu_api_shutdown(void);
TRIBUFU_API void tribufu_free_string(char *ptr);

View File

@@ -0,0 +1,21 @@
// Copyright (c) Tribufu. All Rights Reserved.
#pragma once
#ifdef _WIN32
#ifndef DLLEXPORT
#define DLLEXPORT __declspec(dllexport)
#endif
#ifndef DLLIMPORT
#define DLLIMPORT __declspec(dllimport)
#endif
#endif
#ifdef __MACH__ || __APPLE__ || __linux__ || __FreeBSD__ || __ANDROID__
#ifndef DLLEXPORT
#define DLLEXPORT __attribute__((visibility("default")))
#endif
#ifndef DLLIMPORT
#define DLLIMPORT __attribute__((visibility("default")))
#endif
#endif

View File

@@ -0,0 +1,7 @@
// Copyright (c) Tribufu. All Rights Reserved.
#pragma once
#include <tribufu/macros.h>
#include <tribufu/platform.h>
#include <tribufu/std.h>

26
include/tribufu/std.h Normal file
View File

@@ -0,0 +1,26 @@
// Copyright (c) Tribufu. All Rights Reserved.
#pragma once
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef TRIBUFU_CPP
#include <algorithm>
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <future>
#include <iostream>
#include <memory>
#include <new>
#include <ostream>
#include <sstream>
#include <string>
#include <thread>
#include <utility>
#endif

31
premake5.lua Normal file
View File

@@ -0,0 +1,31 @@
--- @diagnostic disable: undefined-global
workspace "tribufu"
location "."
configurations { "debug", "release" }
if _ACTION == "vs2022" then
platforms {
"win-arm64",
"win-x64",
"win-x86",
}
end
if _ACTION == "gmake2" then
platforms {
"linux-arm64",
"linux-x64",
"linux-x86",
}
end
if _ACTION == "xcode4" then
platforms {
"osx-arm64",
"osx-x64",
}
end
include "examples/c"
include "examples/cpp"

3
scripts/cbindgen.ps1 Normal file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env sh
cbindgen --config ./config/cbindgen.toml --crate tribufu-sdk --output ./include/tribufu/native.h

10
scripts/unix/premake.sh Normal file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env sh
if [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]
then
./vendor/premake-core/linux/premake5 gmake2
elif [ "$(uname)" = "Darwin" ]
then
./vendor/premake-core/mac/premake5 xcode4
fi

12
scripts/windows/build.ps1 Normal file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env pwsh
echo "Building for win-x64"
cargo build --workspace
New-Item "bin/win-x64" -ItemType Directory -Force
Remove-Item -Path "bin/win-x64/*" -Force -Recurse
Copy-Item -Path "target/debug/tribufu_sdk.dll.lib" -Destination "bin/win-x64/tribufu_sdk.lib"
Copy-Item -Path "target/debug/tribufu_sdk.dll" -Destination "bin/win-x64/tribufu_sdk.dll"
msbuild /p:Configuration="debug" /p:Platform="win-x64"

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env pwsh
java -jar ./vendor/openapi-generator/openapi-generator-cli.jar generate `
-i https://api.tribufu.com/openapi.json `
-g rust `
-o . `
--global-property apis,models,supportingFiles,apiDocs=false,modelDocs=false,apiTests=false,modelTests=false `
--additional-properties=packageName=tribufu,library=reqwest-trait,supportAsync=true,preferUnsignedInt=true `
--openapi-normalizer SET_TAGS_FOR_ALL_OPERATIONS=TribufuGenerated `
--skip-validate-spec

View File

@@ -0,0 +1,3 @@
@echo off
call .\vendor\premake-core\windows\premake5.exe vs2022

View File

@@ -1,19 +0,0 @@
[package]
name = "tribufu-actix"
version = "0.1.0"
description = "Tribufu Actix Extension"
repository = "https://github.com/Tribufu/TribufuRust"
authors = ["Tribufu <contact@tribufu.com>"]
license = "MIT"
edition = "2021"
publish = true
[lib]
name = "tribufu_actix"
crate-type = ["rlib"]
path = "lib.rs"
[dependencies]
#tribufu-api = { path = "../api" }
actix-web = { version = "4", features = ["rustls"] }
mintaka-error = { version = "0.0.1" }

View File

@@ -1,25 +0,0 @@
// Copyright (c) Tribufu. All Rights Reserved.
use actix_web::HttpRequest;
pub trait TribufuApiActixExtension {
fn from_actix(req: &HttpRequest) -> Self;
}
/*
impl TribufuApiActixExtension for TribufuApi {
fn from_actix(req: &HttpRequest) -> Self {
let mut api = Self::with_client_from_env().unwrap_or_default();
if let Some(authorization) = req.headers().get("Authorization") {
let authorization = authorization.to_str().unwrap();
if authorization.starts_with("Bearer ") {
api = Self::with_user(authorization[7..].to_string());
}
}
return api;
}
}
*/

View File

@@ -1,118 +0,0 @@
// Copyright (c) Tribufu. All Rights Reserved.
use std::env;
use reqwest::{
header::{HeaderMap, HeaderValue, AUTHORIZATION},
Client as HttpClient,
};
use tribufu_constants::{TRIBUFU_API_URL, TRIBUFU_VERSION};
#[derive(Debug, Default)]
pub enum TribufuApiOptions {
#[default]
Anonymous,
ApiKey {
api_key: String,
},
Token {
access_token: String,
refresh_token: Option<String>,
expires_in: Option<u64>,
},
}
/// **Tribufu API**
///
/// Use this class to interact with the Tribufu API.
///
/// *There are three ways to use the Tribufu API:*
/// - A api key give you public read only access to the Tribufu API.
/// - A bot give you read and write access to the Tribufu API as a bot account.
/// - A client give you read and write access to the Tribufu API as a client application.
pub struct TribufuApi {
pub(crate) http: HttpClient,
pub(crate) options: TribufuApiOptions,
}
impl Default for TribufuApi {
fn default() -> Self {
Self::new(TribufuApiOptions::Anonymous)
}
}
impl TribufuApi {
pub fn new(options: TribufuApiOptions) -> Self {
let http = HttpClient::builder()
.default_headers(Self::default_headers())
.build()
.unwrap();
TribufuApi { http, options }
}
pub fn with_api_key(api_key: String) -> Self {
Self::new(TribufuApiOptions::ApiKey { api_key })
}
pub fn from_env(prefix: Option<&str>) -> Option<Self> {
let prefix = if let Some(prefix) = prefix {
format!("{}_", prefix)
} else {
"".to_string()
};
if let Ok(api_key) = env::var(format!("{prefix}API_KEY")) {
Some(Self::with_api_key(api_key))
} else {
None
}
}
pub fn from_env_or_default(prefix: Option<&str>) -> Self {
Self::from_env(prefix).unwrap_or_default()
}
pub(crate) fn debug_enabled() -> bool {
return cfg!(debug_assertions);
}
#[inline]
pub(crate) fn get_base_url() -> String {
if Self::debug_enabled() {
return env::var("TRIBUFU_API_URL").unwrap_or(TRIBUFU_API_URL.to_string());
}
TRIBUFU_API_URL.to_string()
}
#[inline]
fn default_headers() -> HeaderMap {
let mut headers = HeaderMap::new();
headers.insert("X-Tribufu-Language", "rust".parse().unwrap());
headers.insert("X-Tribufu-Version", TRIBUFU_VERSION.parse().unwrap());
headers
}
pub(crate) fn headers(&self) -> HeaderMap {
let mut headers = TribufuApi::default_headers();
match &self.options {
TribufuApiOptions::ApiKey { api_key } => {
headers.insert(
"Authorization",
HeaderValue::from_str(&format!("ApiKey {}", api_key)).unwrap(),
);
}
TribufuApiOptions::Token { access_token, .. } => {
headers.insert(
"Authorization",
HeaderValue::from_str(&format!("Bearer {}", access_token)).unwrap(),
);
}
_ => {}
}
headers
}
}

View File

@@ -1,386 +0,0 @@
// Copyright (c) Tribufu. All Rights Reserved.
use alnilam_consts::TARGET_TRIPLE;
use mintaka_error::{Error, Result};
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};
use reqwest::Client;
use std::env;
use tribufu_constants::TRIBUFU_VERSION;
use tribufu_types::games::Game;
use tribufu_types::oauth2::{OAuth2GrantType, OAuth2TokenRequest, OAuth2TokenResponse};
use tribufu_types::users::*;
pub enum Credentials {
Anonymous,
ApiKey {
api_key: String,
},
Client {
client_id: u64,
client_secret: String,
},
}
pub enum Token {
ApiKey {
api_key: String,
},
Basic {
basic_token: String,
},
Bearer {
access_token: String,
refresh_token: Option<String>,
},
}
pub struct TribufuApi {
}
impl TribufuApi {
const TRIBUFU_API_URL: &'static str = "https://api.tribufu.com";
pub fn new(credentials: Credentials) -> Self {
let http = Client::builder()
.user_agent(Self::user_agent())
.default_headers(Self::default_headers())
.build()
.unwrap();
Self {
base_url: Self::get_base_url(),
credentials,
token: None,
http,
}
}
pub fn debug_enabled(&self) -> bool {
return cfg!(debug_assertions);
}
#[inline]
fn user_agent() -> String {
format!(
"Tribufu/{} (+https://api.tribufu.com; {})",
TRIBUFU_VERSION, TARGET_TRIPLE
)
}
#[inline]
fn default_headers() -> HeaderMap {
let mut headers = HeaderMap::new();
headers.insert("X-Tribufu-Language", HeaderValue::from_static("rust"));
headers.insert(
"X-Tribufu-Version",
HeaderValue::from_static(TRIBUFU_VERSION),
);
headers
}
fn get_base_url() -> String {
if cfg!(debug_assertions) {
return env::var("TRIBUFU_API_URL")
.unwrap_or_else(|_| Self::TRIBUFU_API_URL.to_string());
}
Self::TRIBUFU_API_URL.to_string()
}
pub fn with_api_key(api_key: String) -> Self {
Self::new(Credentials::ApiKey { api_key })
}
pub fn with_client(client_id: u64, client_secret: String) -> Self {
Self::new(Credentials::Client {
client_id,
client_secret,
})
}
pub fn with_api_key_from_env() -> Option<Self> {
if let Ok(api_key) = env::var("TRIBUFU_API_KEY") {
Some(Self::with_api_key(api_key))
} else {
None
}
}
pub fn with_client_from_env() -> Option<Self> {
let client_id = env::var("TRIBUFU_CLIENT_ID");
let client_secret = env::var("TRIBUFU_CLIENT_SECRET");
if let (Ok(client_id), Ok(client_secret)) = (client_id, client_secret) {
Some(Self::with_client(client_id.parse().unwrap(), client_secret))
} else {
None
}
}
pub fn set_anonymous(&mut self) {
self.credentials = Credentials::Anonymous;
}
pub fn set_api_key(&mut self, api_key: String) {
self.credentials = Credentials::ApiKey { api_key };
}
pub fn set_clients(&mut self, client_id: u64, client_secret: String) {
self.credentials = Credentials::Client {
client_id,
client_secret,
};
}
pub fn set_basic_token(&mut self, basic_token: String) {
self.token = Some(Token::Basic { basic_token });
}
pub fn set_bearer_token(&mut self, access_token: String, refresh_token: Option<String>) {
self.token = Some(Token::Bearer {
access_token,
refresh_token,
});
}
#[inline]
fn headers(&self) -> HeaderMap {
let mut headers = Self::default_headers();
match &self.token {
Some(token) => match token {
Token::ApiKey { api_key } => {
headers.insert(
AUTHORIZATION,
HeaderValue::from_str(&format!("ApiKey {}", api_key)).unwrap(),
);
}
Token::Basic { basic_token } => {
headers.insert(
AUTHORIZATION,
HeaderValue::from_str(&format!("Basic {}", basic_token)).unwrap(),
);
}
Token::Bearer { access_token, .. } => {
headers.insert(
AUTHORIZATION,
HeaderValue::from_str(&format!("Bearer {}", access_token)).unwrap(),
);
}
},
None => {}
}
headers
}
pub async fn get_token_with_code(
&mut self,
code: String,
client_id: u64,
client_secret: String,
) -> Result<OAuth2TokenResponse> {
self.get_oauth_token(
OAuth2GrantType::AuthorizationCode,
Some(code),
client_id,
client_secret,
None,
None,
)
.await
}
pub async fn get_token_from_password(
&mut self,
username: String,
password: String,
client_id: u64,
client_secret: String,
) -> Result<OAuth2TokenResponse> {
self.get_oauth_token(
OAuth2GrantType::Password,
Some(password),
client_id,
client_secret,
None,
Some(username),
)
.await
}
pub async fn get_token_from_passkey(
&mut self,
username: String,
passkey: String,
client_id: u64,
client_secret: String,
) -> Result<OAuth2TokenResponse> {
self.get_oauth_token(
OAuth2GrantType::Passkey,
Some(passkey),
client_id,
client_secret,
None,
Some(username),
)
.await
}
pub async fn refresh_token(
&mut self,
refresh_token: String,
client_id: u64,
client_secret: String,
) -> Result<OAuth2TokenResponse> {
self.get_oauth_token(
OAuth2GrantType::RefreshToken,
Some(refresh_token),
client_id,
client_secret,
None,
None,
)
.await
}
pub async fn get_client_token(
&mut self,
client_id: u64,
client_secret: String,
) -> Result<OAuth2TokenResponse> {
self.get_oauth_token(
OAuth2GrantType::ClientCredentials,
None,
client_id,
client_secret,
None,
None,
)
.await
}
pub async fn get_server_token(
&mut self,
server_id: u64,
client_id: u64,
client_secret: String,
) -> Result<OAuth2TokenResponse> {
self.get_oauth_token(
OAuth2GrantType::ClientCredentials,
None,
client_id,
client_secret,
Some("server_id".to_string()),
Some(server_id.to_string()),
)
.await
}
async fn get_oauth_token(
&self,
grant_type: OAuth2GrantType,
grant_value: Option<String>,
client_id: u64,
client_secret: String,
subject_key: Option<String>,
subject_value: Option<String>,
) -> Result<OAuth2TokenResponse> {
let code = if grant_type == OAuth2GrantType::AuthorizationCode {
grant_value.clone()
} else {
None
};
let refresh_token = if grant_type == OAuth2GrantType::RefreshToken {
grant_value.clone()
} else {
None
};
let mut require_username = false;
let password = if grant_type == OAuth2GrantType::Password {
require_username = true;
grant_value.clone()
} else {
None
};
let passkey = if grant_type == OAuth2GrantType::Passkey {
require_username = true;
grant_value.clone()
} else {
None
};
let username = if require_username && subject_value.is_some() {
subject_value.clone()
} else {
None
};
let request_body = OAuth2TokenRequest {
grant_type,
code,
refresh_token,
username,
password,
passkey,
client_id: Some(client_id.to_string()),
client_secret: Some(client_secret.clone()),
redirect_uri: None,
};
let params = if subject_key.is_some() && subject_value.is_some() {
format!("?{}={}", subject_key.unwrap(), subject_value.unwrap())
} else {
"".to_string()
};
let url = format!("{}/v1/oauth2/token{}", self.base_url, params);
let headers = self.headers();
let response = self
.http
.post(url)
.headers(headers)
.form(&request_body)
.send()
.await?;
if response.status() != 200 {
return Err(Error::msg(format!(
"Failed to get token: {}",
response.status()
)));
}
Ok(response.json().await?)
}
pub async fn get_user_info(&self) -> Result<Profile> {
let url = format!("{}/v1/oauth2/userinfo", self.base_url);
let headers = self.headers();
let response = self.http.get(url).headers(headers).send().await?;
Ok(response.json().await?)
}
pub async fn get_games(&self, page: Option<u32>) -> Result<Vec<Game>> {
let page = page.unwrap_or(1);
let url = format!("{}/v1/packages?page={}", self.base_url, page);
let headers = self.headers();
let response = self.http.get(url).headers(headers).send().await?;
Ok(response.json().await?)
}
pub async fn get_game(&self, id: u64) -> Result<Game> {
let url = format!("{}/v1/packages/{}", self.base_url, id);
let headers = self.headers();
let response = self.http.get(url).headers(headers).send().await?;
Ok(response.json().await?)
}
}

51
src/apis/configuration.rs Normal file
View File

@@ -0,0 +1,51 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
#[derive(Debug, Clone)]
pub struct Configuration {
pub base_path: String,
pub user_agent: Option<String>,
pub client: reqwest::Client,
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub bearer_access_token: Option<String>,
pub api_key: Option<ApiKey>,
}
pub type BasicAuth = (String, Option<String>);
#[derive(Debug, Clone)]
pub struct ApiKey {
pub prefix: Option<String>,
pub key: String,
}
impl Configuration {
pub fn new() -> Configuration {
Configuration::default()
}
}
impl Default for Configuration {
fn default() -> Self {
Configuration {
base_path: "http://localhost".to_owned(),
user_agent: Some("OpenAPI-Generator/1.1.0/rust".to_owned()),
client: reqwest::Client::new(),
basic_auth: None,
oauth_access_token: None,
bearer_access_token: None,
api_key: None,
}
}
}

117
src/apis/mod.rs Normal file
View File

@@ -0,0 +1,117 @@
use std::error;
use std::fmt;
#[derive(Debug, Clone)]
pub struct ResponseContent<T> {
pub status: reqwest::StatusCode,
pub content: String,
pub entity: Option<T>,
}
#[derive(Debug)]
pub enum Error<T> {
Reqwest(reqwest::Error),
Serde(serde_json::Error),
Io(std::io::Error),
ResponseError(ResponseContent<T>),
}
impl <T> fmt::Display for Error<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (module, e) = match self {
Error::Reqwest(e) => ("reqwest", e.to_string()),
Error::Serde(e) => ("serde", e.to_string()),
Error::Io(e) => ("IO", e.to_string()),
Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
};
write!(f, "error in {}: {}", module, e)
}
}
impl <T: fmt::Debug> error::Error for Error<T> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
Some(match self {
Error::Reqwest(e) => e,
Error::Serde(e) => e,
Error::Io(e) => e,
Error::ResponseError(_) => return None,
})
}
}
impl <T> From<reqwest::Error> for Error<T> {
fn from(e: reqwest::Error) -> Self {
Error::Reqwest(e)
}
}
impl <T> From<serde_json::Error> for Error<T> {
fn from(e: serde_json::Error) -> Self {
Error::Serde(e)
}
}
impl <T> From<std::io::Error> for Error<T> {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}
pub fn urlencode<T: AsRef<str>>(s: T) -> String {
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
}
pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
if let serde_json::Value::Object(object) = value {
let mut params = vec![];
for (key, value) in object {
match value {
serde_json::Value::Object(_) => params.append(&mut parse_deep_object(
&format!("{}[{}]", prefix, key),
value,
)),
serde_json::Value::Array(array) => {
for (i, value) in array.iter().enumerate() {
params.append(&mut parse_deep_object(
&format!("{}[{}][{}]", prefix, key, i),
value,
));
}
},
serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())),
_ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
}
}
return params;
}
unimplemented!("Only objects are supported with style=deepObject")
}
/// Internal use only
/// A content type supported by this client.
#[allow(dead_code)]
enum ContentType {
Json,
Text,
Unsupported(String)
}
impl From<&str> for ContentType {
fn from(content_type: &str) -> Self {
if content_type.starts_with("application") && content_type.contains("json") {
return Self::Json;
} else if content_type.starts_with("text/plain") {
return Self::Text;
} else {
return Self::Unsupported(content_type.to_string());
}
}
}
pub mod tribufu_generated_api;
pub mod configuration;

File diff suppressed because it is too large Load Diff

View File

@@ -1 +0,0 @@
// Copyright (c) Tribufu. All Rights Reserved.

View File

@@ -1,83 +0,0 @@
// Copyright (c) Tribufu. All Rights Reserved.
use std::env;
use reqwest::header::{HeaderMap, HeaderValue};
use crate::{TribufuApi, TribufuApiOptions};
pub struct TribufuClient {
client_id: u64,
client_secret: String,
api: TribufuApi,
}
impl TribufuClient {
pub fn new(client_id: u64, client_secret: impl Into<String>) -> Self {
Self {
client_id,
client_secret: client_secret.into(),
api: TribufuApi::default(),
}
}
pub fn from_env(prefix: Option<&str>) -> Option<Self> {
let prefix = if let Some(prefix) = prefix {
format!("{}_", prefix)
} else {
"".to_string()
};
let client_id = env::var(format!("{prefix}CLIENT_ID"));
let client_secret = env::var(format!("{prefix}CLIENT_SECRET"));
if let (Ok(client_id), Ok(client_secret)) = (client_id, client_secret) {
Some(Self::new(client_id.parse().unwrap(), client_secret))
} else {
None
}
}
pub(crate) fn set_tokens(
&mut self,
access_token: String,
refresh_token: Option<String>,
expires_in: Option<u64>,
) {
self.api.options = TribufuApiOptions::Token {
access_token,
refresh_token,
expires_in,
};
}
pub(crate) fn clear_tokens(&mut self) {
self.api.options = TribufuApiOptions::Anonymous;
}
#[inline]
fn oauth_headers(&self) -> HeaderMap {
let mut headers = self.api.headers();
headers.insert("Authorization", HeaderValue::from_str("Basic").unwrap());
headers.insert(
"Content-Type",
HeaderValue::from_str("application/x-www-form-urlencoded").unwrap(),
);
headers
}
pub fn api(&self) -> &TribufuApi {
&self.api
}
pub fn api_mut(&mut self) -> &mut TribufuApi {
&mut self.api
}
pub fn client_id(&self) -> u64 {
self.client_id
}
}

View File

@@ -1,16 +1,20 @@
[package]
name = "tribufu-constants"
version = "0.1.0"
version = "0.0.5"
description = "Tribufu Constants"
repository = "https://github.com/Tribufu/TribufuRust"
repository = "https://github.com/tribufu/tribufu-rust"
authors = ["Tribufu <contact@tribufu.com>"]
license = "MIT"
edition = "2021"
publish = true
publish = false
[lib]
name = "tribufu_constants"
crate-type = ["rlib"]
path = "lib.rs"
[dependencies]
[build-dependencies]
vergen = { version = "=5.1.5", default-features = false, features = [
"build",
"cargo",
"rustc",
] }

8
src/constants/build.rs Normal file
View File

@@ -0,0 +1,8 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
use vergen::{vergen, Config};
fn main() {
vergen(Config::default()).unwrap();
}

View File

@@ -1,13 +1,19 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
/// The version of the Tribufu SDK.
pub const TRIBUFU_VERSION: &'static str = env!("CARGO_PKG_VERSION");
use std::env::consts;
/// The default Tribufu API URL.
pub const TRIBUFU_API_URL: &'static str = "https://api.tribufu.com";
/// The default Tribufu WEB URL.
pub const TRIBUFU_WEB_URL: &'static str = "https://www.tribufu.com";
/// The default Tribufu CDN URL.
pub const TRIBUFU_CDN_URL: &'static str = "https://cdn.tribufu.com";
pub const BUILD_TIMESTAMP: &'static str = env!("VERGEN_BUILD_TIMESTAMP");
pub const CARGO_PROFILE: &'static str = env!("VERGEN_CARGO_PROFILE");
pub const LLVM_VERSION: &'static str = env!("VERGEN_RUSTC_LLVM_VERSION");
pub const RUSTC_CHANNEL: &'static str = env!("VERGEN_RUSTC_CHANNEL");
pub const RUSTC_COMMIT: &'static str = env!("VERGEN_RUSTC_COMMIT_HASH");
pub const RUSTC_VERSION: &'static str = env!("VERGEN_RUSTC_SEMVER");
pub const TARGET_ARCH: &'static str = consts::ARCH;
pub const TARGET_DLL_EXTENSION: &'static str = consts::DLL_EXTENSION;
pub const TARGET_DLL_SUFFIX: &'static str = consts::DLL_SUFFIX;
pub const TARGET_EXE_EXTENSION: &'static str = consts::EXE_EXTENSION;
pub const TARGET_EXE_SUFFIX: &'static str = consts::EXE_SUFFIX;
pub const TARGET_FAMILY: &'static str = consts::FAMILY;
pub const TARGET_OS: &'static str = consts::OS;
pub const TARGET_TRIPLE: &'static str = env!("VERGEN_CARGO_TARGET_TRIPLE");

17
src/error/Cargo.toml Normal file
View File

@@ -0,0 +1,17 @@
[package]
name = "tribufu-error"
version = "0.0.5"
description = "Tribufu Error"
repository = "https://github.com/tribufu/tribufu-rust"
authors = ["Tribufu <contact@tribufu.com>"]
edition = "2021"
publish = false
[lib]
name = "tribufu_error"
crate-type = ["rlib"]
path = "lib.rs"
[dependencies]
anyhow = "1.0.44"
thiserror = "2.0.12"

7
src/error/lib.rs Normal file
View File

@@ -0,0 +1,7 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
pub use anyhow::Error;
pub use thiserror::Error;
pub type Result<T> = core::result::Result<T, Error>;

18
src/json/Cargo.toml Normal file
View File

@@ -0,0 +1,18 @@
[package]
name = "tribufu-json"
version = "0.0.5"
description = "Tribufu Json"
repository = "https://github.com/tribufu/tribufu-rust"
authors = ["Tribufu <contact@tribufu.com>"]
edition = "2021"
publish = false
[lib]
name = "tribufu_json"
crate-type = ["rlib"]
path = "lib.rs"
[dependencies]
tribufu-error = { version = "0.0.5", path = "../error" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

49
src/json/lib.rs Normal file
View File

@@ -0,0 +1,49 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
use serde::Serialize;
use serde_json::ser::PrettyFormatter;
use serde_json::Serializer;
use tribufu_error::Result;
#[macro_export]
macro_rules! include_json {
($path:expr) => {
$crate::from_str(include_str!($path)).expect("Failed to load JSON")
};
}
pub use serde_json::from_slice;
pub use serde_json::from_str;
pub use serde_json::to_string;
pub use serde_json::to_value;
pub use serde_json::to_vec_pretty;
pub fn to_string_pretty<T>(value: &T) -> Result<String>
where
T: Serialize,
{
let obj = to_value(value).expect("Failed to serialize JSON");
let mut buf = Vec::new();
let fmt = PrettyFormatter::with_indent(b" ");
let mut ser = Serializer::with_formatter(&mut buf, fmt);
obj.serialize(&mut ser)?;
Ok(String::from_utf8(buf)?)
}
#[cfg(test)]
mod tests {
use super::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct JsonTest {
version: String,
}
#[test]
fn test_include_json() {
let data: JsonTest = include_json!("test.json");
assert!(data.version == "0.0.0".to_owned())
}
}

3
src/json/test.json Normal file
View File

@@ -0,0 +1,3 @@
{
"version": "0.0.0"
}

View File

@@ -1,17 +1,112 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(clippy::too_many_arguments)]
pub use tribufu_constants::TRIBUFU_VERSION;
pub use tribufu_types as types;
use crate::apis::configuration::{ApiKey, Configuration};
use crate::apis::tribufu_generated_api::TribufuGeneratedApiClient;
use reqwest::Client;
use tribufu_constants::{RUSTC_VERSION, TARGET_TRIPLE};
use std::env::{self, consts};
use std::sync::Arc;
mod api;
mod bot;
mod client;
mod server;
pub mod apis;
pub mod models;
pub use api::*;
pub use bot::*;
pub use client::*;
pub use server::*;
/// Use this to interact with the Tribufu API.
pub struct TribufuApi;
impl TribufuApi {
/// The default base URL for the Tribufu API.
pub const DEFAULT_BASE_URL: &'static str = "https://api.tribufu.com";
/// Create a TribufuApi instance.
pub fn new(api_key: Option<String>) -> TribufuGeneratedApiClient {
let configuration = Self::create_configuration(api_key);
let configuration_arc = Arc::new(configuration);
TribufuGeneratedApiClient::new(configuration_arc)
}
/// Create a TribufuApi with the default options.
pub fn default() -> TribufuGeneratedApiClient {
Self::new(None)
}
/// Create a TribufuApi with the given API key.
///
/// An API key gives you public read only access to the Tribufu API.
pub fn with_api_key(api_key: String) -> TribufuGeneratedApiClient {
Self::new(Some(api_key))
}
/// Try to create a TribufuApi from environment variables.
///
/// This will only work if the environment variables are set.
pub fn from_env(prefix: Option<&str>) -> Option<TribufuGeneratedApiClient> {
let prefix = prefix.unwrap_or("TRIBUFU");
let api_key_var = format!("{}_API_KEY", prefix);
if let Ok(api_key) = env::var(api_key_var) {
if !api_key.trim().is_empty() {
return Some(Self::with_api_key(api_key));
}
}
None
}
/// Create a TribufuApi from environment variables or the default API.
///
/// This will fallback to the default API if the environment variables are not set.
pub fn from_env_or_default(prefix: Option<&str>) -> TribufuGeneratedApiClient {
Self::from_env(prefix).unwrap_or_else(Self::default)
}
/// Gets the version of the Tribufu API client.
pub fn get_version() -> String {
env!("CARGO_PKG_VERSION").to_owned()
}
/// Gets the user agent string for the Tribufu API client.
pub fn get_user_agent() -> String {
let version = Self::get_version();
format!("Tribufu/{} (Rust {}; {})", version, RUSTC_VERSION, TARGET_TRIPLE)
}
/// Checks if debug mode is enabled.
pub fn debug_enabled() -> bool {
cfg!(debug_assertions)
}
/// Get the base URL for the Tribufu API.
fn get_base_url() -> String {
if let Ok(base_url) = env::var("TRIBUFU_API_URL") {
if Self::debug_enabled() && !base_url.trim().is_empty() {
return base_url;
}
}
Self::DEFAULT_BASE_URL.to_string()
}
/// Creates a configuration for the Tribufu API client.
fn create_configuration(api_key: Option<String>) -> Configuration {
let base_path = Self::get_base_url();
let user_agent = Some(Self::get_user_agent());
let api_key_obj = if let Some(api_key) = api_key {
Some(ApiKey {
prefix: Some("ApiKey".to_owned()),
key: api_key,
})
} else {
None
};
Configuration {
base_path,
user_agent,
api_key: api_key_obj,
..Default::default()
}
}
}

20
src/log/Cargo.toml Normal file
View File

@@ -0,0 +1,20 @@
[package]
name = "tribufu-log"
version = "0.0.5"
description = "Tribufu Log"
repository = "https://github.com/tribufu/tribufu-rust"
authors = ["Tribufu <contact@tribufu.com>"]
edition = "2021"
publish = false
[lib]
name = "tribufu_log"
crate-type = ["rlib"]
path = "lib.rs"
[dependencies]
tribufu-error = { version = "0.0.5", path = "../error" }
chrono = "0.4.23"
env_logger = "0.10.1"
log = "0.4"
serde = { version = "1.0", features = ["derive"] }

19
src/log/colors.rs Normal file
View File

@@ -0,0 +1,19 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
pub const BLACK: u8 = 0;
pub const RED: u8 = 1;
pub const GREEN: u8 = 2;
pub const YELLOW: u8 = 3;
pub const BLUE: u8 = 4;
pub const MAGENTA: u8 = 5;
pub const CYAN: u8 = 6;
pub const WHITE: u8 = 7;
pub const BRIGHT_BLACK: u8 = 8;
pub const BRIGHT_RED: u8 = 9;
pub const BRIGHT_GREEN: u8 = 10;
pub const BRIGHT_YELLOW: u8 = 11;
pub const BRIGHT_BLUE: u8 = 12;
pub const BRIGHT_MAGENTA: u8 = 13;
pub const BRIGHT_CYAN: u8 = 14;
pub const BRIGHT_WHITE: u8 = 15;

118
src/log/lib.rs Normal file
View File

@@ -0,0 +1,118 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
use chrono::prelude::*;
pub use env_logger::fmt::Color;
use env_logger::{Builder, Target};
pub use log::debug;
pub use log::error;
pub use log::info;
pub use log::trace;
pub use log::warn;
use log::Level;
use log::LevelFilter;
use serde::{Deserialize, Serialize};
use std::io::Write;
pub mod colors;
mod log_config;
pub use log_config::*;
pub fn init() {
let logger = Logger::from_env(None);
logger.init();
}
pub fn init_level(level: LogLevel) {
let logger = Logger::new(level.into());
logger.init();
}
#[derive(Default, Debug, Copy, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum LogLevel {
#[default]
Off,
Error,
Warn,
Info,
Debug,
Trace,
}
impl LogLevel {
pub fn from_str(s: &str) -> Option<Self> {
match s {
"off" => Some(Self::Off),
"error" => Some(Self::Error),
"warn" => Some(Self::Warn),
"info" => Some(Self::Info),
"debug" => Some(Self::Debug),
"trace" => Some(Self::Trace),
_ => None,
}
}
}
impl From<LogLevel> for LevelFilter {
fn from(level: LogLevel) -> Self {
match level {
LogLevel::Off => LevelFilter::Off,
LogLevel::Error => LevelFilter::Error,
LogLevel::Warn => LevelFilter::Warn,
LogLevel::Info => LevelFilter::Info,
LogLevel::Debug => LevelFilter::Debug,
LogLevel::Trace => LevelFilter::Trace,
}
}
}
pub struct Logger {
builder: Builder,
}
impl Logger {
pub fn new(level: LevelFilter) -> Self {
let mut builder = Builder::new();
builder.filter_level(level);
Self { builder }
}
pub fn with_config(config: LogConfig) -> Self {
let mut builder = Builder::new();
builder.filter_level(config.level.into());
Self { builder }
}
pub fn from_env(var: Option<String>) -> Self {
let builder = Builder::from_env(var.unwrap_or("LOG_LEVEL".to_string()));
Self { builder }
}
pub fn init(mut self) {
self.builder
.target(Target::Stdout)
.format(|fmt, record| {
let mut style = fmt.style();
match record.level() {
Level::Error => style.set_color(Color::Ansi256(colors::RED)),
Level::Warn => style.set_color(Color::Ansi256(colors::YELLOW)),
Level::Info => style.set_color(Color::Ansi256(colors::GREEN)),
Level::Debug => style.set_color(Color::Ansi256(colors::WHITE)),
Level::Trace => style.set_color(Color::Ansi256(colors::BRIGHT_BLACK)),
};
let line = format!(
"[{}] [{}]: {}",
Local::now().format("%Y-%m-%dT%H:%M:%S"),
record.level(),
record.args()
);
writeln!(fmt, "{}", style.value(line))
})
.init();
}
}

22
src/log/log_config.rs Normal file
View File

@@ -0,0 +1,22 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
use crate::LogLevel;
use serde::{Deserialize, Serialize};
use std::env;
use tribufu_error::Result;
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct LogConfig {
pub level: LogLevel,
pub file: Option<String>,
}
impl LogConfig {
pub fn from_env() -> Result<Self> {
Ok(Self {
level: LogLevel::from_str(&env::var("LOG_LEVEL")?).unwrap_or_default(),
file: env::var("LOG_FILE").ok(),
})
}
}

48
src/models/account.rs Normal file
View File

@@ -0,0 +1,48 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Account {
#[serde(rename = "id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub id: Option<Option<String>>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "provider", skip_serializing_if = "Option::is_none")]
pub provider: Option<models::LoginProvider>,
#[serde(rename = "user_id", skip_serializing_if = "Option::is_none")]
pub user_id: Option<String>,
#[serde(rename = "authorized", skip_serializing_if = "Option::is_none")]
pub authorized: Option<bool>,
#[serde(rename = "fields", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub fields: Option<Option<serde_json::Value>>,
#[serde(rename = "created", skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
#[serde(rename = "updated", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub updated: Option<Option<String>>,
}
impl Account {
pub fn new() -> Account {
Account {
id: None,
name: None,
provider: None,
user_id: None,
authorized: None,
fields: None,
created: None,
updated: None,
}
}
}

84
src/models/application.rs Normal file
View File

@@ -0,0 +1,84 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Application {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub description: Option<Option<String>>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub r#type: Option<models::ApplicationType>,
#[serde(rename = "organization_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub organization_id: Option<Option<String>>,
#[serde(rename = "icon_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub icon_url: Option<Option<String>>,
#[serde(rename = "banner_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub banner_url: Option<Option<String>>,
#[serde(rename = "capsule_image_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub capsule_image_url: Option<Option<String>>,
#[serde(rename = "library_image_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub library_image_url: Option<Option<String>>,
#[serde(rename = "parent_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub parent_id: Option<Option<String>>,
#[serde(rename = "slug", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub slug: Option<Option<String>>,
#[serde(rename = "visibility", skip_serializing_if = "Option::is_none")]
pub visibility: Option<i32>,
#[serde(rename = "password", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub password: Option<Option<String>>,
#[serde(rename = "primary", skip_serializing_if = "Option::is_none")]
pub primary: Option<i32>,
#[serde(rename = "user_count", skip_serializing_if = "Option::is_none")]
pub user_count: Option<i32>,
#[serde(rename = "achievement_count", skip_serializing_if = "Option::is_none")]
pub achievement_count: Option<i32>,
#[serde(rename = "badge_count", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub badge_count: Option<Option<i32>>,
#[serde(rename = "download_count", skip_serializing_if = "Option::is_none")]
pub download_count: Option<i32>,
#[serde(rename = "created", skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
#[serde(rename = "updated", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub updated: Option<Option<String>>,
}
impl Application {
pub fn new() -> Application {
Application {
id: None,
name: None,
description: None,
r#type: None,
organization_id: None,
icon_url: None,
banner_url: None,
capsule_image_url: None,
library_image_url: None,
parent_id: None,
slug: None,
visibility: None,
password: None,
primary: None,
user_count: None,
achievement_count: None,
badge_count: None,
download_count: None,
created: None,
updated: None,
}
}
}

View File

@@ -0,0 +1,38 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum ApplicationType {
#[serde(rename = "application")]
Application,
#[serde(rename = "game")]
Game,
}
impl std::fmt::Display for ApplicationType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Application => write!(f, "application"),
Self::Game => write!(f, "game"),
}
}
}
impl Default for ApplicationType {
fn default() -> ApplicationType {
Self::Application
}
}

View File

@@ -0,0 +1,45 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct AuthorizeRequest {
#[serde(rename = "response_type", skip_serializing_if = "Option::is_none")]
pub response_type: Option<models::ResponseType>,
#[serde(rename = "client_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub client_id: Option<Option<String>>,
#[serde(rename = "code_challenge", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub code_challenge: Option<Option<String>>,
#[serde(rename = "code_challenge_method", skip_serializing_if = "Option::is_none")]
pub code_challenge_method: Option<models::CodeChallengeMethod>,
#[serde(rename = "redirect_uri", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub redirect_uri: Option<Option<String>>,
#[serde(rename = "scope", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub scope: Option<Option<String>>,
#[serde(rename = "state", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub state: Option<Option<String>>,
}
impl AuthorizeRequest {
pub fn new() -> AuthorizeRequest {
AuthorizeRequest {
response_type: None,
client_id: None,
code_challenge: None,
code_challenge_method: None,
redirect_uri: None,
scope: None,
state: None,
}
}
}

View File

@@ -0,0 +1,38 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum CodeChallengeMethod {
#[serde(rename = "plain")]
Plain,
#[serde(rename = "S256")]
S256,
}
impl std::fmt::Display for CodeChallengeMethod {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Plain => write!(f, "plain"),
Self::S256 => write!(f, "S256"),
}
}
}
impl Default for CodeChallengeMethod {
fn default() -> CodeChallengeMethod {
Self::Plain
}
}

View File

@@ -0,0 +1,30 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct CryptoViewModel {
#[serde(rename = "encoded", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub encoded: Option<Option<String>>,
#[serde(rename = "decoded", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub decoded: Option<Option<String>>,
}
impl CryptoViewModel {
pub fn new() -> CryptoViewModel {
CryptoViewModel {
encoded: None,
decoded: None,
}
}
}

117
src/models/game.rs Normal file
View File

@@ -0,0 +1,117 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Game {
#[serde(rename = "game_port", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub game_port: Option<Option<i32>>,
#[serde(rename = "query_port", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub query_port: Option<Option<i32>>,
#[serde(rename = "rcon_port", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub rcon_port: Option<Option<i32>>,
#[serde(rename = "server_count", skip_serializing_if = "Option::is_none")]
pub server_count: Option<i32>,
#[serde(rename = "steam_app_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub steam_app_id: Option<Option<i32>>,
#[serde(rename = "steam_server_app_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub steam_server_app_id: Option<Option<i32>>,
#[serde(rename = "enable_servers", skip_serializing_if = "Option::is_none")]
pub enable_servers: Option<bool>,
#[serde(rename = "rust_gamedig_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub rust_gamedig_id: Option<Option<String>>,
#[serde(rename = "node_gamedig_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub node_gamedig_id: Option<Option<String>>,
#[serde(rename = "server_connect_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub server_connect_url: Option<Option<String>>,
#[serde(rename = "server_tags", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub server_tags: Option<Option<String>>,
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub description: Option<Option<String>>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub r#type: Option<models::ApplicationType>,
#[serde(rename = "organization_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub organization_id: Option<Option<String>>,
#[serde(rename = "icon_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub icon_url: Option<Option<String>>,
#[serde(rename = "banner_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub banner_url: Option<Option<String>>,
#[serde(rename = "capsule_image_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub capsule_image_url: Option<Option<String>>,
#[serde(rename = "library_image_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub library_image_url: Option<Option<String>>,
#[serde(rename = "parent_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub parent_id: Option<Option<String>>,
#[serde(rename = "slug", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub slug: Option<Option<String>>,
#[serde(rename = "visibility", skip_serializing_if = "Option::is_none")]
pub visibility: Option<i32>,
#[serde(rename = "password", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub password: Option<Option<String>>,
#[serde(rename = "primary", skip_serializing_if = "Option::is_none")]
pub primary: Option<i32>,
#[serde(rename = "user_count", skip_serializing_if = "Option::is_none")]
pub user_count: Option<i32>,
#[serde(rename = "achievement_count", skip_serializing_if = "Option::is_none")]
pub achievement_count: Option<i32>,
#[serde(rename = "badge_count", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub badge_count: Option<Option<i32>>,
#[serde(rename = "download_count", skip_serializing_if = "Option::is_none")]
pub download_count: Option<i32>,
#[serde(rename = "created", skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
#[serde(rename = "updated", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub updated: Option<Option<String>>,
}
impl Game {
pub fn new() -> Game {
Game {
game_port: None,
query_port: None,
rcon_port: None,
server_count: None,
steam_app_id: None,
steam_server_app_id: None,
enable_servers: None,
rust_gamedig_id: None,
node_gamedig_id: None,
server_connect_url: None,
server_tags: None,
id: None,
name: None,
description: None,
r#type: None,
organization_id: None,
icon_url: None,
banner_url: None,
capsule_image_url: None,
library_image_url: None,
parent_id: None,
slug: None,
visibility: None,
password: None,
primary: None,
user_count: None,
achievement_count: None,
badge_count: None,
download_count: None,
created: None,
updated: None,
}
}
}

117
src/models/game_server.rs Normal file
View File

@@ -0,0 +1,117 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct GameServer {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub description: Option<Option<String>>,
#[serde(rename = "address", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub address: Option<Option<String>>,
#[serde(rename = "game_port", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub game_port: Option<Option<i32>>,
#[serde(rename = "query_port", skip_serializing_if = "Option::is_none")]
pub query_port: Option<i32>,
#[serde(rename = "game_id", skip_serializing_if = "Option::is_none")]
pub game_id: Option<String>,
#[serde(rename = "game_icon_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub game_icon_url: Option<Option<String>>,
#[serde(rename = "version", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub version: Option<Option<String>>,
#[serde(rename = "featured", skip_serializing_if = "Option::is_none")]
pub featured: Option<bool>,
#[serde(rename = "cluster_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub cluster_id: Option<Option<String>>,
#[serde(rename = "website_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub website_url: Option<Option<String>>,
#[serde(rename = "banner_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub banner_url: Option<Option<String>>,
#[serde(rename = "owner_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub owner_id: Option<Option<String>>,
#[serde(rename = "uptime", skip_serializing_if = "Option::is_none")]
pub uptime: Option<f64>,
#[serde(rename = "status", skip_serializing_if = "Option::is_none")]
pub status: Option<models::ServerStatus>,
#[serde(rename = "ping", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub ping: Option<Option<i32>>,
#[serde(rename = "map", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub map: Option<Option<String>>,
#[serde(rename = "used_slots", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub used_slots: Option<Option<i32>>,
#[serde(rename = "max_slots", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub max_slots: Option<Option<i32>>,
#[serde(rename = "motd", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub motd: Option<Option<String>>,
#[serde(rename = "players", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub players: Option<Option<String>>,
#[serde(rename = "last_online", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub last_online: Option<Option<String>>,
#[serde(rename = "country", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub country: Option<Option<String>>,
#[serde(rename = "steam", skip_serializing_if = "Option::is_none")]
pub steam: Option<bool>,
#[serde(rename = "discord_server_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub discord_server_id: Option<Option<String>>,
#[serde(rename = "youtube_video_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub youtube_video_url: Option<Option<String>>,
#[serde(rename = "tags", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub tags: Option<Option<String>>,
#[serde(rename = "comment_count", skip_serializing_if = "Option::is_none")]
pub comment_count: Option<i32>,
#[serde(rename = "created", skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
#[serde(rename = "updated", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub updated: Option<Option<String>>,
}
impl GameServer {
pub fn new() -> GameServer {
GameServer {
id: None,
name: None,
description: None,
address: None,
game_port: None,
query_port: None,
game_id: None,
game_icon_url: None,
version: None,
featured: None,
cluster_id: None,
website_url: None,
banner_url: None,
owner_id: None,
uptime: None,
status: None,
ping: None,
map: None,
used_slots: None,
max_slots: None,
motd: None,
players: None,
last_online: None,
country: None,
steam: None,
discord_server_id: None,
youtube_video_url: None,
tags: None,
comment_count: None,
created: None,
updated: None,
}
}
}

View File

@@ -0,0 +1,66 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct GameServerCluster {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub description: Option<Option<String>>,
#[serde(rename = "game_id", skip_serializing_if = "Option::is_none")]
pub game_id: Option<String>,
#[serde(rename = "website_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub website_url: Option<Option<String>>,
#[serde(rename = "banner_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub banner_url: Option<Option<String>>,
#[serde(rename = "owner_id", skip_serializing_if = "Option::is_none")]
pub owner_id: Option<String>,
#[serde(rename = "discord_server_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub discord_server_id: Option<Option<String>>,
#[serde(rename = "youtube_video_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub youtube_video_url: Option<Option<String>>,
#[serde(rename = "tags", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub tags: Option<Option<String>>,
#[serde(rename = "comment_count", skip_serializing_if = "Option::is_none")]
pub comment_count: Option<i32>,
#[serde(rename = "server_count", skip_serializing_if = "Option::is_none")]
pub server_count: Option<i32>,
#[serde(rename = "created", skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
#[serde(rename = "updated", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub updated: Option<Option<String>>,
}
impl GameServerCluster {
pub fn new() -> GameServerCluster {
GameServerCluster {
id: None,
name: None,
description: None,
game_id: None,
website_url: None,
banner_url: None,
owner_id: None,
discord_server_id: None,
youtube_video_url: None,
tags: None,
comment_count: None,
server_count: None,
created: None,
updated: None,
}
}
}

44
src/models/grant_type.rs Normal file
View File

@@ -0,0 +1,44 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum GrantType {
#[serde(rename = "authorization_code")]
AuthorizationCode,
#[serde(rename = "client_credentials")]
ClientCredentials,
#[serde(rename = "password")]
Password,
#[serde(rename = "refresh_token")]
RefreshToken,
}
impl std::fmt::Display for GrantType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::AuthorizationCode => write!(f, "authorization_code"),
Self::ClientCredentials => write!(f, "client_credentials"),
Self::Password => write!(f, "password"),
Self::RefreshToken => write!(f, "refresh_token"),
}
}
}
impl Default for GrantType {
fn default() -> GrantType {
Self::AuthorizationCode
}
}

72
src/models/group.rs Normal file
View File

@@ -0,0 +1,72 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Group {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "uuid", skip_serializing_if = "Option::is_none")]
pub uuid: Option<uuid::Uuid>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "tag", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub tag: Option<Option<String>>,
#[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub description: Option<Option<String>>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub r#type: Option<i32>,
#[serde(rename = "privacy", skip_serializing_if = "Option::is_none")]
pub privacy: Option<i32>,
#[serde(rename = "owner_id", skip_serializing_if = "Option::is_none")]
pub owner_id: Option<String>,
#[serde(rename = "verified", skip_serializing_if = "Option::is_none")]
pub verified: Option<bool>,
#[serde(rename = "photo_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub photo_url: Option<Option<String>>,
#[serde(rename = "banner_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub banner_url: Option<Option<String>>,
#[serde(rename = "member_count", skip_serializing_if = "Option::is_none")]
pub member_count: Option<i32>,
#[serde(rename = "follower_count", skip_serializing_if = "Option::is_none")]
pub follower_count: Option<i32>,
#[serde(rename = "view_count", skip_serializing_if = "Option::is_none")]
pub view_count: Option<i32>,
#[serde(rename = "created", skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
#[serde(rename = "updated", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub updated: Option<Option<String>>,
}
impl Group {
pub fn new() -> Group {
Group {
id: None,
uuid: None,
name: None,
tag: None,
description: None,
r#type: None,
privacy: None,
owner_id: None,
verified: None,
photo_url: None,
banner_url: None,
member_count: None,
follower_count: None,
view_count: None,
created: None,
updated: None,
}
}
}

45
src/models/group_game.rs Normal file
View File

@@ -0,0 +1,45 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct GroupGame {
#[serde(rename = "group_id", skip_serializing_if = "Option::is_none")]
pub group_id: Option<String>,
#[serde(rename = "group", skip_serializing_if = "Option::is_none")]
pub group: Option<Box<models::Group>>,
#[serde(rename = "application_id", skip_serializing_if = "Option::is_none")]
pub application_id: Option<String>,
#[serde(rename = "application", skip_serializing_if = "Option::is_none")]
pub application: Option<Box<models::Application>>,
#[serde(rename = "stats", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub stats: Option<Option<serde_json::Value>>,
#[serde(rename = "acquired", skip_serializing_if = "Option::is_none")]
pub acquired: Option<String>,
#[serde(rename = "last_used", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub last_used: Option<Option<String>>,
}
impl GroupGame {
pub fn new() -> GroupGame {
GroupGame {
group_id: None,
group: None,
application_id: None,
application: None,
stats: None,
acquired: None,
last_used: None,
}
}
}

View File

@@ -0,0 +1,51 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct GroupMember {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "uuid", skip_serializing_if = "Option::is_none")]
pub uuid: Option<uuid::Uuid>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "display_name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub display_name: Option<Option<String>>,
#[serde(rename = "verified", skip_serializing_if = "Option::is_none")]
pub verified: Option<bool>,
#[serde(rename = "photo_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub photo_url: Option<Option<String>>,
#[serde(rename = "last_online", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub last_online: Option<Option<String>>,
#[serde(rename = "rank", skip_serializing_if = "Option::is_none")]
pub rank: Option<models::GroupRank>,
#[serde(rename = "since", skip_serializing_if = "Option::is_none")]
pub since: Option<String>,
}
impl GroupMember {
pub fn new() -> GroupMember {
GroupMember {
id: None,
uuid: None,
name: None,
display_name: None,
verified: None,
photo_url: None,
last_online: None,
rank: None,
since: None,
}
}
}

41
src/models/group_rank.rs Normal file
View File

@@ -0,0 +1,41 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum GroupRank {
#[serde(rename = "member")]
Member,
#[serde(rename = "leader")]
Leader,
#[serde(rename = "owner")]
Owner,
}
impl std::fmt::Display for GroupRank {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Member => write!(f, "member"),
Self::Leader => write!(f, "leader"),
Self::Owner => write!(f, "owner"),
}
}
}
impl Default for GroupRank {
fn default() -> GroupRank {
Self::Member
}
}

View File

@@ -0,0 +1,27 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct HashViewModel {
#[serde(rename = "value", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub value: Option<Option<String>>,
}
impl HashViewModel {
pub fn new() -> HashViewModel {
HashViewModel {
value: None,
}
}
}

View File

@@ -0,0 +1,30 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct IntrospectRequest {
#[serde(rename = "token", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub token: Option<Option<String>>,
#[serde(rename = "token_type_hint", skip_serializing_if = "Option::is_none")]
pub token_type_hint: Option<models::TokenHintType>,
}
impl IntrospectRequest {
pub fn new() -> IntrospectRequest {
IntrospectRequest {
token: None,
token_type_hint: None,
}
}
}

78
src/models/ip_address.rs Normal file
View File

@@ -0,0 +1,78 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct IpAddress {
#[serde(rename = "address", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub address: Option<Option<String>>,
#[serde(rename = "version", skip_serializing_if = "Option::is_none")]
pub version: Option<i32>,
#[serde(rename = "network", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub network: Option<Option<String>>,
#[serde(rename = "reserved", skip_serializing_if = "Option::is_none")]
pub reserved: Option<bool>,
#[serde(rename = "asn", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub asn: Option<Option<String>>,
#[serde(rename = "isp", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub isp: Option<Option<String>>,
#[serde(rename = "continent", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub continent: Option<Option<String>>,
#[serde(rename = "country", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub country: Option<Option<String>>,
#[serde(rename = "region", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub region: Option<Option<String>>,
#[serde(rename = "city", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub city: Option<Option<String>>,
#[serde(rename = "postal_code", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub postal_code: Option<Option<String>>,
#[serde(rename = "calling_code", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub calling_code: Option<Option<String>>,
#[serde(rename = "tld", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub tld: Option<Option<String>>,
#[serde(rename = "language", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub language: Option<Option<String>>,
#[serde(rename = "timezone", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub timezone: Option<Option<String>>,
#[serde(rename = "currency", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub currency: Option<Option<String>>,
#[serde(rename = "latitude", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub latitude: Option<Option<f32>>,
#[serde(rename = "longitude", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub longitude: Option<Option<f32>>,
}
impl IpAddress {
pub fn new() -> IpAddress {
IpAddress {
address: None,
version: None,
network: None,
reserved: None,
asn: None,
isp: None,
continent: None,
country: None,
region: None,
city: None,
postal_code: None,
calling_code: None,
tld: None,
language: None,
timezone: None,
currency: None,
latitude: None,
longitude: None,
}
}
}

View File

@@ -0,0 +1,42 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct LeaderboardItem {
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "display_name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub display_name: Option<Option<String>>,
#[serde(rename = "photo_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub photo_url: Option<Option<String>>,
#[serde(rename = "level", skip_serializing_if = "Option::is_none")]
pub level: Option<i32>,
#[serde(rename = "experience", skip_serializing_if = "Option::is_none")]
pub experience: Option<f64>,
#[serde(rename = "points", skip_serializing_if = "Option::is_none")]
pub points: Option<f64>,
}
impl LeaderboardItem {
pub fn new() -> LeaderboardItem {
LeaderboardItem {
name: None,
display_name: None,
photo_url: None,
level: None,
experience: None,
points: None,
}
}
}

View File

@@ -0,0 +1,38 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum LeaderboardOrder {
#[serde(rename = "level")]
Level,
#[serde(rename = "points")]
Points,
}
impl std::fmt::Display for LeaderboardOrder {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Level => write!(f, "level"),
Self::Points => write!(f, "points"),
}
}
}
impl Default for LeaderboardOrder {
fn default() -> LeaderboardOrder {
Self::Level
}
}

View File

@@ -0,0 +1,53 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum LoginProvider {
#[serde(rename = "steam")]
Steam,
#[serde(rename = "epic")]
Epic,
#[serde(rename = "discord")]
Discord,
#[serde(rename = "microsoft")]
Microsoft,
#[serde(rename = "playstation")]
Playstation,
#[serde(rename = "google")]
Google,
#[serde(rename = "apple")]
Apple,
}
impl std::fmt::Display for LoginProvider {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Steam => write!(f, "steam"),
Self::Epic => write!(f, "epic"),
Self::Discord => write!(f, "discord"),
Self::Microsoft => write!(f, "microsoft"),
Self::Playstation => write!(f, "playstation"),
Self::Google => write!(f, "google"),
Self::Apple => write!(f, "apple"),
}
}
}
impl Default for LoginProvider {
fn default() -> LoginProvider {
Self::Steam
}
}

View File

@@ -0,0 +1,30 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct LoginRequest {
#[serde(rename = "login", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub login: Option<Option<String>>,
#[serde(rename = "password", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub password: Option<Option<String>>,
}
impl LoginRequest {
pub fn new() -> LoginRequest {
LoginRequest {
login: None,
password: None,
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct LoginResponse {
#[serde(rename = "user", skip_serializing_if = "Option::is_none")]
pub user: Option<Box<models::UserInfo>>,
#[serde(rename = "access_token", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub access_token: Option<Option<String>>,
#[serde(rename = "refresh_token", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub refresh_token: Option<Option<String>>,
#[serde(rename = "expires_in", skip_serializing_if = "Option::is_none")]
pub expires_in: Option<i64>,
}
impl LoginResponse {
pub fn new() -> LoginResponse {
LoginResponse {
user: None,
access_token: None,
refresh_token: None,
expires_in: None,
}
}
}

84
src/models/mod.rs Normal file
View File

@@ -0,0 +1,84 @@
pub mod account;
pub use self::account::Account;
pub mod application;
pub use self::application::Application;
pub mod application_type;
pub use self::application_type::ApplicationType;
pub mod authorize_request;
pub use self::authorize_request::AuthorizeRequest;
pub mod code_challenge_method;
pub use self::code_challenge_method::CodeChallengeMethod;
pub mod crypto_view_model;
pub use self::crypto_view_model::CryptoViewModel;
pub mod game;
pub use self::game::Game;
pub mod game_server;
pub use self::game_server::GameServer;
pub mod game_server_cluster;
pub use self::game_server_cluster::GameServerCluster;
pub mod grant_type;
pub use self::grant_type::GrantType;
pub mod group;
pub use self::group::Group;
pub mod group_game;
pub use self::group_game::GroupGame;
pub mod group_member;
pub use self::group_member::GroupMember;
pub mod group_rank;
pub use self::group_rank::GroupRank;
pub mod hash_view_model;
pub use self::hash_view_model::HashViewModel;
pub mod introspect_request;
pub use self::introspect_request::IntrospectRequest;
pub mod ip_address;
pub use self::ip_address::IpAddress;
pub mod leaderboard_item;
pub use self::leaderboard_item::LeaderboardItem;
pub mod leaderboard_order;
pub use self::leaderboard_order::LeaderboardOrder;
pub mod login_provider;
pub use self::login_provider::LoginProvider;
pub mod login_request;
pub use self::login_request::LoginRequest;
pub mod login_response;
pub use self::login_response::LoginResponse;
pub mod package;
pub use self::package::Package;
pub mod profile;
pub use self::profile::Profile;
pub mod profile_game;
pub use self::profile_game::ProfileGame;
pub mod profile_group;
pub use self::profile_group::ProfileGroup;
pub mod refresh_request;
pub use self::refresh_request::RefreshRequest;
pub mod register_request;
pub use self::register_request::RegisterRequest;
pub mod response_type;
pub use self::response_type::ResponseType;
pub mod revoke_request;
pub use self::revoke_request::RevokeRequest;
pub mod search_request;
pub use self::search_request::SearchRequest;
pub mod search_type;
pub use self::search_type::SearchType;
pub mod server_metrics;
pub use self::server_metrics::ServerMetrics;
pub mod server_status;
pub use self::server_status::ServerStatus;
pub mod subscription;
pub use self::subscription::Subscription;
pub mod token_hint_type;
pub use self::token_hint_type::TokenHintType;
pub mod token_request;
pub use self::token_request::TokenRequest;
pub mod token_response;
pub use self::token_response::TokenResponse;
pub mod token_type;
pub use self::token_type::TokenType;
pub mod update_profile;
pub use self::update_profile::UpdateProfile;
pub mod user_info;
pub use self::user_info::UserInfo;
pub mod user_type;
pub use self::user_type::UserType;

60
src/models/package.rs Normal file
View File

@@ -0,0 +1,60 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Package {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub description: Option<Option<String>>,
#[serde(rename = "image_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub image_url: Option<Option<String>>,
#[serde(rename = "author_id", skip_serializing_if = "Option::is_none")]
pub author_id: Option<String>,
#[serde(rename = "version", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub version: Option<Option<String>>,
#[serde(rename = "file_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub file_url: Option<Option<String>>,
#[serde(rename = "raw_size", skip_serializing_if = "Option::is_none")]
pub raw_size: Option<f64>,
#[serde(rename = "download_count", skip_serializing_if = "Option::is_none")]
pub download_count: Option<i32>,
#[serde(rename = "last_download", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub last_download: Option<Option<String>>,
#[serde(rename = "created", skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
#[serde(rename = "updated", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub updated: Option<Option<String>>,
}
impl Package {
pub fn new() -> Package {
Package {
id: None,
name: None,
description: None,
image_url: None,
author_id: None,
version: None,
file_url: None,
raw_size: None,
download_count: None,
last_download: None,
created: None,
updated: None,
}
}
}

78
src/models/profile.rs Normal file
View File

@@ -0,0 +1,78 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Profile {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "uuid", skip_serializing_if = "Option::is_none")]
pub uuid: Option<uuid::Uuid>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "display_name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub display_name: Option<Option<String>>,
#[serde(rename = "verified", skip_serializing_if = "Option::is_none")]
pub verified: Option<bool>,
#[serde(rename = "level", skip_serializing_if = "Option::is_none")]
pub level: Option<i32>,
#[serde(rename = "experience", skip_serializing_if = "Option::is_none")]
pub experience: Option<f64>,
#[serde(rename = "public_birthday", skip_serializing_if = "Option::is_none")]
pub public_birthday: Option<bool>,
#[serde(rename = "birthday", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub birthday: Option<Option<String>>,
#[serde(rename = "points", skip_serializing_if = "Option::is_none")]
pub points: Option<f64>,
#[serde(rename = "location", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub location: Option<Option<String>>,
#[serde(rename = "photo_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub photo_url: Option<Option<String>>,
#[serde(rename = "banner_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub banner_url: Option<Option<String>>,
#[serde(rename = "last_online", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub last_online: Option<Option<String>>,
#[serde(rename = "biography", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub biography: Option<Option<String>>,
#[serde(rename = "view_count", skip_serializing_if = "Option::is_none")]
pub view_count: Option<i32>,
#[serde(rename = "created", skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
#[serde(rename = "updated", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub updated: Option<Option<String>>,
}
impl Profile {
pub fn new() -> Profile {
Profile {
id: None,
uuid: None,
name: None,
display_name: None,
verified: None,
level: None,
experience: None,
public_birthday: None,
birthday: None,
points: None,
location: None,
photo_url: None,
banner_url: None,
last_online: None,
biography: None,
view_count: None,
created: None,
updated: None,
}
}
}

View File

@@ -0,0 +1,57 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct ProfileGame {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "capsule_image_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub capsule_image_url: Option<Option<String>>,
#[serde(rename = "library_image_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub library_image_url: Option<Option<String>>,
#[serde(rename = "slug", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub slug: Option<Option<String>>,
#[serde(rename = "time_used", skip_serializing_if = "Option::is_none")]
pub time_used: Option<f64>,
#[serde(rename = "unlocked_achievements", skip_serializing_if = "Option::is_none")]
pub unlocked_achievements: Option<i32>,
#[serde(rename = "total_achievements", skip_serializing_if = "Option::is_none")]
pub total_achievements: Option<i32>,
#[serde(rename = "stats", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub stats: Option<Option<serde_json::Value>>,
#[serde(rename = "acquired", skip_serializing_if = "Option::is_none")]
pub acquired: Option<String>,
#[serde(rename = "last_used", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub last_used: Option<Option<String>>,
}
impl ProfileGame {
pub fn new() -> ProfileGame {
ProfileGame {
id: None,
name: None,
capsule_image_url: None,
library_image_url: None,
slug: None,
time_used: None,
unlocked_achievements: None,
total_achievements: None,
stats: None,
acquired: None,
last_used: None,
}
}
}

View File

@@ -0,0 +1,54 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct ProfileGroup {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "uuid", skip_serializing_if = "Option::is_none")]
pub uuid: Option<uuid::Uuid>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "tag", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub tag: Option<Option<String>>,
#[serde(rename = "privacy", skip_serializing_if = "Option::is_none")]
pub privacy: Option<i32>,
#[serde(rename = "verified", skip_serializing_if = "Option::is_none")]
pub verified: Option<bool>,
#[serde(rename = "photo_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub photo_url: Option<Option<String>>,
#[serde(rename = "member_count", skip_serializing_if = "Option::is_none")]
pub member_count: Option<i32>,
#[serde(rename = "rank", skip_serializing_if = "Option::is_none")]
pub rank: Option<models::GroupRank>,
#[serde(rename = "since", skip_serializing_if = "Option::is_none")]
pub since: Option<String>,
}
impl ProfileGroup {
pub fn new() -> ProfileGroup {
ProfileGroup {
id: None,
uuid: None,
name: None,
tag: None,
privacy: None,
verified: None,
photo_url: None,
member_count: None,
rank: None,
since: None,
}
}
}

View File

@@ -0,0 +1,27 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct RefreshRequest {
#[serde(rename = "refresh_token", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub refresh_token: Option<Option<String>>,
}
impl RefreshRequest {
pub fn new() -> RefreshRequest {
RefreshRequest {
refresh_token: None,
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct RegisterRequest {
#[serde(rename = "uuid", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub uuid: Option<Option<uuid::Uuid>>,
#[serde(rename = "name")]
pub name: String,
#[serde(rename = "email", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub email: Option<Option<String>>,
#[serde(rename = "password")]
pub password: String,
}
impl RegisterRequest {
pub fn new(name: String, password: String) -> RegisterRequest {
RegisterRequest {
uuid: None,
name,
email: None,
password,
}
}
}

View File

@@ -0,0 +1,38 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum ResponseType {
#[serde(rename = "code")]
Code,
#[serde(rename = "token")]
Token,
}
impl std::fmt::Display for ResponseType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Code => write!(f, "code"),
Self::Token => write!(f, "token"),
}
}
}
impl Default for ResponseType {
fn default() -> ResponseType {
Self::Code
}
}

View File

@@ -0,0 +1,30 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct RevokeRequest {
#[serde(rename = "token", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub token: Option<Option<String>>,
#[serde(rename = "token_type_hint", skip_serializing_if = "Option::is_none")]
pub token_type_hint: Option<models::TokenHintType>,
}
impl RevokeRequest {
pub fn new() -> RevokeRequest {
RevokeRequest {
token: None,
token_type_hint: None,
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct SearchRequest {
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub r#type: Option<models::SearchType>,
#[serde(rename = "query", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub query: Option<Option<String>>,
#[serde(rename = "page", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub page: Option<Option<i32>>,
#[serde(rename = "game_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub game_id: Option<Option<String>>,
}
impl SearchRequest {
pub fn new() -> SearchRequest {
SearchRequest {
r#type: None,
query: None,
page: None,
game_id: None,
}
}
}

44
src/models/search_type.rs Normal file
View File

@@ -0,0 +1,44 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum SearchType {
#[serde(rename = "user")]
User,
#[serde(rename = "group")]
Group,
#[serde(rename = "server")]
Server,
#[serde(rename = "cluster")]
Cluster,
}
impl std::fmt::Display for SearchType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::User => write!(f, "user"),
Self::Group => write!(f, "group"),
Self::Server => write!(f, "server"),
Self::Cluster => write!(f, "cluster"),
}
}
}
impl Default for SearchType {
fn default() -> SearchType {
Self::User
}
}

View File

@@ -0,0 +1,33 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct ServerMetrics {
#[serde(rename = "server_count", skip_serializing_if = "Option::is_none")]
pub server_count: Option<i32>,
#[serde(rename = "package_count", skip_serializing_if = "Option::is_none")]
pub package_count: Option<i32>,
#[serde(rename = "country_count", skip_serializing_if = "Option::is_none")]
pub country_count: Option<i32>,
}
impl ServerMetrics {
pub fn new() -> ServerMetrics {
ServerMetrics {
server_count: None,
package_count: None,
country_count: None,
}
}
}

View File

@@ -0,0 +1,41 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum ServerStatus {
#[serde(rename = "unknown")]
Unknown,
#[serde(rename = "offline")]
Offline,
#[serde(rename = "online")]
Online,
}
impl std::fmt::Display for ServerStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Unknown => write!(f, "unknown"),
Self::Offline => write!(f, "offline"),
Self::Online => write!(f, "online"),
}
}
}
impl Default for ServerStatus {
fn default() -> ServerStatus {
Self::Unknown
}
}

View File

@@ -0,0 +1,45 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Subscription {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub description: Option<Option<String>>,
#[serde(rename = "image_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub image_url: Option<Option<String>>,
#[serde(rename = "prices", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub prices: Option<Option<std::collections::HashMap<String, f64>>>,
#[serde(rename = "created", skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
#[serde(rename = "updated", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub updated: Option<Option<String>>,
}
impl Subscription {
pub fn new() -> Subscription {
Subscription {
id: None,
name: None,
description: None,
image_url: None,
prices: None,
created: None,
updated: None,
}
}
}

View File

@@ -0,0 +1,38 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum TokenHintType {
#[serde(rename = "access_token")]
AccessToken,
#[serde(rename = "refresh_token")]
RefreshToken,
}
impl std::fmt::Display for TokenHintType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::AccessToken => write!(f, "access_token"),
Self::RefreshToken => write!(f, "refresh_token"),
}
}
}
impl Default for TokenHintType {
fn default() -> TokenHintType {
Self::AccessToken
}
}

View File

@@ -0,0 +1,48 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct TokenRequest {
#[serde(rename = "grant_type", skip_serializing_if = "Option::is_none")]
pub grant_type: Option<models::GrantType>,
#[serde(rename = "code", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub code: Option<Option<String>>,
#[serde(rename = "username", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub username: Option<Option<String>>,
#[serde(rename = "password", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub password: Option<Option<String>>,
#[serde(rename = "refresh_token", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub refresh_token: Option<Option<String>>,
#[serde(rename = "client_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub client_id: Option<Option<String>>,
#[serde(rename = "redirect_uri", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub redirect_uri: Option<Option<String>>,
#[serde(rename = "code_verifier", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub code_verifier: Option<Option<String>>,
}
impl TokenRequest {
pub fn new() -> TokenRequest {
TokenRequest {
grant_type: None,
code: None,
username: None,
password: None,
refresh_token: None,
client_id: None,
redirect_uri: None,
code_verifier: None,
}
}
}

View File

@@ -0,0 +1,42 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct TokenResponse {
#[serde(rename = "token_type", skip_serializing_if = "Option::is_none")]
pub token_type: Option<models::TokenType>,
#[serde(rename = "access_token", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub access_token: Option<Option<String>>,
#[serde(rename = "refresh_token", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub refresh_token: Option<Option<String>>,
#[serde(rename = "scope", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub scope: Option<Option<String>>,
#[serde(rename = "state", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub state: Option<Option<String>>,
#[serde(rename = "expires_in", skip_serializing_if = "Option::is_none")]
pub expires_in: Option<i64>,
}
impl TokenResponse {
pub fn new() -> TokenResponse {
TokenResponse {
token_type: None,
access_token: None,
refresh_token: None,
scope: None,
state: None,
expires_in: None,
}
}
}

35
src/models/token_type.rs Normal file
View File

@@ -0,0 +1,35 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum TokenType {
#[serde(rename = "bearer")]
Bearer,
}
impl std::fmt::Display for TokenType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Bearer => write!(f, "bearer"),
}
}
}
impl Default for TokenType {
fn default() -> TokenType {
Self::Bearer
}
}

View File

@@ -0,0 +1,30 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct UpdateProfile {
#[serde(rename = "display_name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub display_name: Option<Option<String>>,
#[serde(rename = "biography", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub biography: Option<Option<String>>,
}
impl UpdateProfile {
pub fn new() -> UpdateProfile {
UpdateProfile {
display_name: None,
biography: None,
}
}
}

99
src/models/user_info.rs Normal file
View File

@@ -0,0 +1,99 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct UserInfo {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "uuid", skip_serializing_if = "Option::is_none")]
pub uuid: Option<uuid::Uuid>,
#[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub name: Option<Option<String>>,
#[serde(rename = "display_name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub display_name: Option<Option<String>>,
#[serde(rename = "email", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub email: Option<Option<String>>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub r#type: Option<models::UserType>,
#[serde(rename = "flags", skip_serializing_if = "Option::is_none")]
pub flags: Option<String>,
#[serde(rename = "permissions", skip_serializing_if = "Option::is_none")]
pub permissions: Option<String>,
#[serde(rename = "verified", skip_serializing_if = "Option::is_none")]
pub verified: Option<bool>,
#[serde(rename = "level", skip_serializing_if = "Option::is_none")]
pub level: Option<i32>,
#[serde(rename = "experience", skip_serializing_if = "Option::is_none")]
pub experience: Option<f64>,
#[serde(rename = "public_birthday", skip_serializing_if = "Option::is_none")]
pub public_birthday: Option<bool>,
#[serde(rename = "birthday", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub birthday: Option<Option<String>>,
#[serde(rename = "points", skip_serializing_if = "Option::is_none")]
pub points: Option<f64>,
#[serde(rename = "location", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub location: Option<Option<String>>,
#[serde(rename = "language", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub language: Option<Option<String>>,
#[serde(rename = "timezone", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub timezone: Option<Option<String>>,
#[serde(rename = "currency", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub currency: Option<Option<String>>,
#[serde(rename = "photo_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub photo_url: Option<Option<String>>,
#[serde(rename = "banner_url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub banner_url: Option<Option<String>>,
#[serde(rename = "last_online", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub last_online: Option<Option<String>>,
#[serde(rename = "biography", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub biography: Option<Option<String>>,
#[serde(rename = "view_count", skip_serializing_if = "Option::is_none")]
pub view_count: Option<i32>,
#[serde(rename = "created", skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
#[serde(rename = "updated", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub updated: Option<Option<String>>,
}
impl UserInfo {
pub fn new() -> UserInfo {
UserInfo {
id: None,
uuid: None,
name: None,
display_name: None,
email: None,
r#type: None,
flags: None,
permissions: None,
verified: None,
level: None,
experience: None,
public_birthday: None,
birthday: None,
points: None,
location: None,
language: None,
timezone: None,
currency: None,
photo_url: None,
banner_url: None,
last_online: None,
biography: None,
view_count: None,
created: None,
updated: None,
}
}
}

38
src/models/user_type.rs Normal file
View File

@@ -0,0 +1,38 @@
/*
* Tribufu API
*
* REST API to access Tribufu services.
*
* The version of the OpenAPI document: 1.1.0
* Contact: contact@tribufu.com
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UserType {
#[serde(rename = "user")]
User,
#[serde(rename = "bot")]
Bot,
}
impl std::fmt::Display for UserType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::User => write!(f, "user"),
Self::Bot => write!(f, "bot"),
}
}
}
impl Default for UserType {
fn default() -> UserType {
Self::User
}
}

21
src/native/Cargo.toml Normal file
View File

@@ -0,0 +1,21 @@
[package]
name = "tribufu-sdk"
version = "0.0.0"
description = "Tribufu Native"
repository = "https://github.com/tribufu/tribufu-rust"
authors = ["Tribufu <contact@tribufu.com>"]
license = "UNLICENSED"
edition = "2021"
publish = false
[lib]
name = "tribufu_sdk"
crate-type = ["rlib", "cdylib", "staticlib"]
path = "lib.rs"
[dependencies]
tribufu = { path = "../../" }
futures = "0.3.31"
libc = "0.2.172"
once_cell = "1.19.0"
tokio = { version = "1.45.1", features = ["full"] }

88
src/native/api.rs Normal file
View File

@@ -0,0 +1,88 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: UNLICENSED
use crate::models::{TribufuApiCallbackContext, TribufuApiGetUserInfoCallback};
use futures::lock::Mutex;
use libc::{c_char, c_void};
use once_cell::sync::Lazy;
use std::ffi::CString;
use std::ptr;
use tokio::runtime::Runtime;
use tribufu::apis::tribufu_generated_api::TribufuGeneratedApiClient;
use tribufu::TribufuApi;
static INSTANCE: Lazy<Mutex<Option<TribufuGeneratedApiClient>>> = Lazy::new(|| Mutex::new(None));
static RUNTIME: Lazy<Runtime> = Lazy::new(|| Runtime::new().unwrap());
/// Gets the version of the Tribufu API.
#[no_mangle]
pub extern "C" fn tribufu_api_get_version() -> *const c_char {
CString::new(TribufuApi::get_version()).unwrap().into_raw()
}
/// Gets the user agent string for the Tribufu API.
#[no_mangle]
pub extern "C" fn tribufu_api_get_user_agent() -> *const c_char {
CString::new(TribufuApi::get_user_agent())
.unwrap()
.into_raw()
}
/// Initialize the Tribufu API instance.
///
/// This must be called before any other API functions.
#[no_mangle]
pub extern "C" fn tribufu_api_initialize() -> bool {
let api = TribufuApi::from_env_or_default(None);
if INSTANCE.try_lock().is_none() {
return false;
}
let mut instance = INSTANCE.try_lock().unwrap();
*instance = Some(api);
true
}
/// Shutdown the Tribufu API instance.
///
/// This must be called when the API is no longer needed.
#[no_mangle]
pub extern "C" fn tribufu_api_shutdown() {
if INSTANCE.try_lock().is_none() {
return;
}
let mut instance = INSTANCE.try_lock().unwrap();
*instance = None;
}
#[no_mangle]
#[allow(unused_variables)]
pub extern "C" fn tribufu_api_get_user_info(
context: *mut c_void,
callback: TribufuApiGetUserInfoCallback,
) {
let context = TribufuApiCallbackContext(context);
RUNTIME.spawn(async move {
let mut instance = INSTANCE.lock().await;
if instance.is_none() {
callback(context.as_ptr(), ptr::null());
return;
}
let api = instance.as_mut();
if api.is_none() {
callback(context.as_ptr(), ptr::null());
return;
}
let api = api.unwrap();
// TODO: Implement logic here
callback(context.as_ptr(), ptr::null());
});
}

8
src/native/lib.rs Normal file
View File

@@ -0,0 +1,8 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: UNLICENSED
#![allow(dead_code)]
pub mod api;
pub mod mem;
pub mod models;

16
src/native/mem.rs Normal file
View File

@@ -0,0 +1,16 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: UNLICENSED
use std::ffi::CString;
use std::os::raw::c_char;
#[no_mangle]
pub extern "C" fn tribufu_free_string(ptr: *mut c_char) {
if ptr.is_null() {
return;
}
unsafe {
let _ = CString::from_raw(ptr);
}
}

Some files were not shown because too many files have changed in this diff Show More