102 lines
3.7 KiB
Dart
102 lines
3.7 KiB
Dart
//
|
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
|
//
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:built_value/serializer.dart';
|
|
import 'package:piped_api/src/serializers.dart';
|
|
import 'package:piped_api/src/auth/api_key_auth.dart';
|
|
import 'package:piped_api/src/auth/basic_auth.dart';
|
|
import 'package:piped_api/src/auth/bearer_auth.dart';
|
|
import 'package:piped_api/src/auth/oauth.dart';
|
|
import 'package:piped_api/src/api/channel_api.dart';
|
|
import 'package:piped_api/src/api/feed_api.dart';
|
|
import 'package:piped_api/src/api/search_api.dart';
|
|
import 'package:piped_api/src/api/unauthenticated_api.dart';
|
|
import 'package:piped_api/src/api/video_api.dart';
|
|
|
|
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: const Duration(milliseconds: 5000),
|
|
receiveTimeout: const Duration(milliseconds: 3000),
|
|
)) {
|
|
if (interceptors == null) {
|
|
this.dio.interceptors.addAll([
|
|
OAuthInterceptor(),
|
|
BasicAuthInterceptor(),
|
|
BearerAuthInterceptor(),
|
|
ApiKeyAuthInterceptor(),
|
|
]);
|
|
} else {
|
|
this.dio.interceptors.addAll(interceptors);
|
|
}
|
|
}
|
|
|
|
void setOAuthToken(String name, String token) {
|
|
if (this.dio.interceptors.any((i) => i is OAuthInterceptor)) {
|
|
(this.dio.interceptors.firstWhere((i) => i is OAuthInterceptor) as OAuthInterceptor).tokens[name] = token;
|
|
}
|
|
}
|
|
|
|
void setBearerAuth(String name, String token) {
|
|
if (this.dio.interceptors.any((i) => i is BearerAuthInterceptor)) {
|
|
(this.dio.interceptors.firstWhere((i) => i is BearerAuthInterceptor) as BearerAuthInterceptor).tokens[name] = token;
|
|
}
|
|
}
|
|
|
|
void setBasicAuth(String name, String username, String password) {
|
|
if (this.dio.interceptors.any((i) => i is BasicAuthInterceptor)) {
|
|
(this.dio.interceptors.firstWhere((i) => i is BasicAuthInterceptor) as BasicAuthInterceptor).authInfo[name] = BasicAuthInfo(username, password);
|
|
}
|
|
}
|
|
|
|
void setApiKey(String name, String apiKey) {
|
|
if (this.dio.interceptors.any((i) => i is ApiKeyAuthInterceptor)) {
|
|
(this.dio.interceptors.firstWhere((element) => element is ApiKeyAuthInterceptor) as ApiKeyAuthInterceptor).apiKeys[name] = apiKey;
|
|
}
|
|
}
|
|
|
|
/// Get ChannelApi instance, base route and serializer can be overridden by a given but be careful,
|
|
/// by doing that all interceptors will not be executed
|
|
ChannelApi getChannelApi() {
|
|
return ChannelApi(dio, serializers);
|
|
}
|
|
|
|
/// Get FeedApi instance, base route and serializer can be overridden by a given but be careful,
|
|
/// by doing that all interceptors will not be executed
|
|
FeedApi getFeedApi() {
|
|
return FeedApi(dio, serializers);
|
|
}
|
|
|
|
/// Get SearchApi instance, base route and serializer can be overridden by a given but be careful,
|
|
/// by doing that all interceptors will not be executed
|
|
SearchApi getSearchApi() {
|
|
return SearchApi(dio, serializers);
|
|
}
|
|
|
|
/// 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);
|
|
}
|
|
|
|
/// Get VideoApi instance, base route and serializer can be overridden by a given but be careful,
|
|
/// by doing that all interceptors will not be executed
|
|
VideoApi getVideoApi() {
|
|
return VideoApi(dio, serializers);
|
|
}
|
|
}
|