piped_dart/lib/api.dart

75 lines
2.2 KiB
Dart
Raw Normal View History

2022-06-05 08:34:50 +00:00
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.7
// ignore_for_file: unused_import
library piped_api.api;
import 'package:dio/dio.dart';
import 'package:built_value/serializer.dart';
import 'package:piped_api/serializers.dart';
import 'package:piped_api/auth/api_key_auth.dart';
import 'package:piped_api/auth/basic_auth.dart';
import 'package:piped_api/auth/oauth.dart';
import 'package:piped_api/api/unauthenticated_api.dart';
final _defaultInterceptors = [
OAuthInterceptor(),
BasicAuthInterceptor(),
ApiKeyAuthInterceptor(),
];
class PipedApi {
static const String basePath = r'https://pipedapi.kavin.rocks';
final Dio dio;
final Serializers serializers;
PipedApi({
Dio dio,
Serializers serializers,
String basePathOverride,
List<Interceptor> interceptors,
}) : this.serializers = serializers ?? standardSerializers,
this.dio = dio ??
Dio(BaseOptions(
baseUrl: basePathOverride ?? basePath,
connectTimeout: 5000,
receiveTimeout: 3000,
)) {
if (interceptors == null) {
this.dio.interceptors.addAll(_defaultInterceptors);
} else {
this.dio.interceptors.addAll(interceptors);
}
}
void setOAuthToken(String name, String token) {
(this.dio.interceptors.firstWhere((element) => element is OAuthInterceptor, orElse: null) as OAuthInterceptor)?.tokens[name] = token;
}
void setBasicAuth(String name, String username, String password) {
(this.dio.interceptors.firstWhere((element) => element is BasicAuthInterceptor, orElse: null) as BasicAuthInterceptor)?.authInfo[name] = BasicAuthInfo(username, password);
}
void setApiKey(String name, String apiKey) {
(this.dio.interceptors.firstWhere((element) => element is ApiKeyAuthInterceptor, orElse: null) as ApiKeyAuthInterceptor)?.apiKeys[name] = apiKey;
}
/**
* Get UnauthenticatedApi instance, base route and serializer can be overridden by a given but be careful,
* by doing that all interceptors will not be executed
*/
UnauthenticatedApi getUnauthenticatedApi() {
return UnauthenticatedApi(dio, serializers);
}
}