Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 22495dc

Browse files
authored
Merge pull request #3 from devsdocs/dev
Dev
2 parents dbdcb42 + 001cfeb commit 22495dc

File tree

16 files changed

+551
-521
lines changed

16 files changed

+551
-521
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.dev/**
22
test/**
3-
thunder-tests/**
3+
thunder-tests/**
4+
doc/**

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ print(result?.toJson());
7777
}
7878
```
7979

80+
### Get raw JSON String as result instead of prebuild model
81+
82+
```dart
83+
void main()async{
84+
ApiConfig.printLog = true;
85+
final key = Platform.environment['DOODSTREAM_API_KEY']!;
86+
final doodstreamClient = DoodstreamApi(key);
87+
final getAccount = await doodstreamClient.rawApi.accountInfo(); // Using rawApi directive
88+
print(getAccount); // Print a JSON string
89+
}
90+
```
91+
8092
### - TODO List:
8193

8294
- [x] [Doodstream](https://doodstream.com)

example/doodstream.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import 'dart:io';
33
import 'package:dart_api_collection/dart_api_collection.dart';
44

55
void main() async {
6-
ApiConfig.printLog = true;
6+
ApiConfig.logConfig
7+
..enableLog = true
8+
..showResponseHeader = false;
79
final key = Platform.environment['DOODSTREAM_API_KEY']!;
810
final doodstreamClient = DoodstreamApi(key);
911
final getAccount = await doodstreamClient.accountInfo();

example/gofile.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import 'dart:io';
33
import 'package:dart_api_collection/dart_api_collection.dart';
44

55
void main() async {
6-
ApiConfig.printLog = true;
6+
ApiConfig.logConfig
7+
..enableLog = true
8+
..showResponseHeader = false;
79
final token = Platform.environment['GOFILE_TOKEN']!;
810
final gofileClient = GofileApi(token);
911
final getAccount = await gofileClient.accountInfo();

example/mixdrop.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import 'dart:io';
33
import 'package:dart_api_collection/dart_api_collection.dart';
44

55
void main() async {
6-
ApiConfig.printLog = true;
6+
ApiConfig.logConfig
7+
..enableLog = true
8+
..showResponseHeader = false;
79
final user = Platform.environment['MIXDROP_EMAIL']!;
810
final key = Platform.environment['MIXDROP_KEY']!;
911
final mixdropClient = MixdropApi(user, key);

example/streamtape.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import 'dart:io';
33
import 'package:dart_api_collection/dart_api_collection.dart';
44

55
void main() async {
6-
ApiConfig.printLog = true;
6+
ApiConfig.logConfig
7+
..enableLog = true
8+
..showResponseHeader = false;
79
final user = Platform.environment['STREAMTAPE_USER']!;
810
final key = Platform.environment['STREAMTAPE_KEY']!;
911
final streamtapeClient = StreamtapeApi(user, key);

lib/src/common/extension.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ extension PrivateFileExt on File {
1111
String get fileExt => uri.fileExt;
1212

1313
Future<MultipartFile> get toMultipart async => MultipartFile.fromFile(path);
14-
Future<MultipartFile> get toMultipartWithName async =>
15-
MultipartFile.fromFile(path, filename: fileNameAndExt);
1614
}
1715

1816
extension DirectoryExt on Directory {
@@ -55,6 +53,8 @@ extension StringExt on String {
5553
List<String> get splitDot => split('.');
5654
dynamic get toJsonObject => json.decode(this);
5755
bool get containsDot => contains('.');
56+
String get capitalizeWord =>
57+
this[0].toUpperCase() + substring(1).toLowerCase();
5858
}
5959

6060
extension UriExt on Uri {
@@ -104,4 +104,6 @@ extension BoolExt on bool? {
104104

105105
/// either null or '1' or '0'
106106
String? get toStringFlagOrNull => this != null ? toStringFlag : null;
107+
108+
String get capitalize => '$this'.capitalizeWord;
107109
}

lib/src/common/progress.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ StreamController<FileTransferProgress> transferProgress =
66
class FileTransferProgress {
77
FileTransferProgress(
88
this.id, {
9-
this.name,
109
this.type,
10+
this.name,
1111
this.current,
1212
this.total,
1313
this.isUpload,
1414
});
15-
16-
/// File ID in encoded [sha256]
1715
final String? id;
1816
final ServiceType? type;
1917
final String? name;
@@ -31,8 +29,8 @@ class FileTransferProgress {
3129
}) =>
3230
FileTransferProgress(
3331
id ?? this.id,
34-
name: name ?? this.name,
3532
type: type ?? this.type,
33+
name: name ?? this.name,
3634
current: current ?? this.current,
3735
total: total ?? this.total,
3836
isUpload: isUpload ?? this.isUpload,

lib/src/common/raw_http.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
part of '../common.dart';
22

33
class RawHttp {
4-
final _dio = Dio();
4+
factory RawHttp() {
5+
_instance ??= RawHttp._internal();
6+
return _instance!;
7+
}
8+
9+
RawHttp._internal();
10+
final Dio _dio = Dio();
11+
12+
static RawHttp? _instance;
513

614
Interceptors get interceptors => _dio.interceptors;
715

@@ -105,7 +113,7 @@ class RawHttp {
105113
options: options,
106114
onSendProgress: fileTransferProgress != null
107115
? (current, total) => transferProgress.add(
108-
fileTransferProgress.copyWith(current: current, total: total),
116+
fileTransferProgress.copyWith(current: current, total: total),
109117
)
110118
: null,
111119
))

lib/src/common/settings.dart

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,56 @@
11
part of '../common.dart';
22

33
class ApiConfig {
4-
static bool get printLog => _printLog ??= false;
4+
static _LogConfig get logConfig => _logConfig ??= _LogConfig();
55

6-
static set printLog(bool value) => _printLog = value;
6+
static set logConfig(_LogConfig value) => _logConfig = value;
77

8-
static bool? _printLog;
8+
static _LogConfig? _logConfig;
9+
}
10+
11+
class _LogConfig {
12+
factory _LogConfig({
13+
bool enableLog = false,
14+
bool request = true,
15+
bool requestHeader = true,
16+
bool requestBody = true,
17+
bool responseHeader = true,
18+
bool responseBody = true,
19+
bool error = true,
20+
}) {
21+
_instance ??= _LogConfig._internal(
22+
enableLog: enableLog,
23+
showRequest: request,
24+
showRequestHeader: requestHeader,
25+
showRequestBody: requestBody,
26+
showResponseHeader: responseHeader,
27+
showResponseBody: responseBody,
28+
showError: error,
29+
);
30+
return _instance!;
31+
}
32+
33+
_LogConfig._internal({
34+
required this.enableLog,
35+
required this.showRequest,
36+
required this.showRequestHeader,
37+
required this.showRequestBody,
38+
required this.showResponseHeader,
39+
required this.showResponseBody,
40+
required this.showError,
41+
});
42+
43+
bool enableLog;
44+
bool showRequest;
45+
bool showRequestHeader;
46+
bool showRequestBody;
47+
bool showResponseHeader;
48+
bool showResponseBody;
49+
bool showError;
50+
51+
static _LogConfig? _instance;
52+
53+
@override
54+
String toString() =>
55+
'Log Enabled: ${enableLog.capitalize}\nShow Request: ${showRequest.capitalize}\nShow Request Header: ${showRequestHeader.capitalize}\nShow Request Body: ${showRequestBody.capitalize}\nShow Response Header: ${showResponseHeader.capitalize}\nShow Response Body: ${showResponseBody.capitalize}\nShow Error: ${showError.capitalize}';
956
}

0 commit comments

Comments
 (0)