mirror of
https://github.com/tribufu/sdk-rust
synced 2025-06-16 11:14:17 +00:00
Add wrapper struct
This commit is contained in:
@ -5,3 +5,4 @@ docs/
|
|||||||
Cargo.toml
|
Cargo.toml
|
||||||
git_push.sh
|
git_push.sh
|
||||||
README.md
|
README.md
|
||||||
|
src/lib.rs
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
src/apis/configuration.rs
|
src/apis/configuration.rs
|
||||||
src/apis/mod.rs
|
src/apis/mod.rs
|
||||||
src/apis/tribufu_api.rs
|
src/apis/tribufu_generated_api.rs
|
||||||
src/lib.rs
|
|
||||||
src/models/account.rs
|
src/models/account.rs
|
||||||
src/models/application.rs
|
src/models/application.rs
|
||||||
src/models/application_type.rs
|
src/models/application_type.rs
|
||||||
|
@ -6,5 +6,5 @@ java -jar ./vendor/openapi-generator/openapi-generator-cli.jar generate `
|
|||||||
-o . `
|
-o . `
|
||||||
--global-property apis,models,supportingFiles,apiDocs=false,modelDocs=false,apiTests=false,modelTests=false `
|
--global-property apis,models,supportingFiles,apiDocs=false,modelDocs=false,apiTests=false,modelTests=false `
|
||||||
--additional-properties=packageName=tribufu,library=reqwest-trait,supportAsync=true,preferUnsignedInt=true `
|
--additional-properties=packageName=tribufu,library=reqwest-trait,supportAsync=true,preferUnsignedInt=true `
|
||||||
--openapi-normalizer SET_TAGS_FOR_ALL_OPERATIONS=Tribufu `
|
--openapi-normalizer SET_TAGS_FOR_ALL_OPERATIONS=TribufuGenerated `
|
||||||
--skip-validate-spec
|
--skip-validate-spec
|
||||||
|
@ -111,7 +111,7 @@ impl From<&str> for ContentType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod tribufu_api;
|
pub mod tribufu_generated_api;
|
||||||
|
|
||||||
pub mod configuration;
|
pub mod configuration;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ use super::{Error, configuration};
|
|||||||
use crate::apis::ContentType;
|
use crate::apis::ContentType;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait TribufuApi: Send + Sync {
|
pub trait TribufuGeneratedApi: Send + Sync {
|
||||||
|
|
||||||
/// POST /v1/oauth2/authorize
|
/// POST /v1/oauth2/authorize
|
||||||
///
|
///
|
||||||
@ -381,11 +381,11 @@ pub trait TribufuApi: Send + Sync {
|
|||||||
async fn update_user_profile<'id, 'update_profile>(&self, id: &'id str, update_profile: Option<models::UpdateProfile>) -> Result<models::Profile, Error<UpdateUserProfileError>>;
|
async fn update_user_profile<'id, 'update_profile>(&self, id: &'id str, update_profile: Option<models::UpdateProfile>) -> Result<models::Profile, Error<UpdateUserProfileError>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TribufuApiClient {
|
pub struct TribufuGeneratedApiClient {
|
||||||
configuration: Arc<configuration::Configuration>
|
configuration: Arc<configuration::Configuration>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TribufuApiClient {
|
impl TribufuGeneratedApiClient {
|
||||||
pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
|
pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
|
||||||
Self { configuration }
|
Self { configuration }
|
||||||
}
|
}
|
||||||
@ -394,7 +394,7 @@ impl TribufuApiClient {
|
|||||||
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl TribufuApi for TribufuApiClient {
|
impl TribufuGeneratedApi for TribufuGeneratedApiClient {
|
||||||
/// <b>🔒 Required permissions:</b> <code>tribufu.identity.oauth2.authorize</code>
|
/// <b>🔒 Required permissions:</b> <code>tribufu.identity.oauth2.authorize</code>
|
||||||
async fn authorize<'authorize_request>(&self, authorize_request: Option<models::AuthorizeRequest>) -> Result<(), Error<AuthorizeError>> {
|
async fn authorize<'authorize_request>(&self, authorize_request: Option<models::AuthorizeRequest>) -> Result<(), Error<AuthorizeError>> {
|
||||||
let local_var_configuration = &self.configuration;
|
let local_var_configuration = &self.configuration;
|
109
src/lib.rs
109
src/lib.rs
@ -1,10 +1,111 @@
|
|||||||
|
// Copyright (c) Tribufu. All Rights Reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
#![allow(clippy::too_many_arguments)]
|
#![allow(clippy::too_many_arguments)]
|
||||||
|
|
||||||
extern crate serde_repr;
|
use crate::apis::configuration::{ApiKey, Configuration};
|
||||||
extern crate serde;
|
use crate::apis::tribufu_generated_api::TribufuGeneratedApiClient;
|
||||||
extern crate serde_json;
|
use reqwest::Client;
|
||||||
extern crate url;
|
use std::env::{self, consts};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub mod apis;
|
pub mod apis;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
|
|
||||||
|
/// 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/{} ({}; {})", version, consts::OS, consts::ARCH)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user