Skip to content

Commit a22fda1

Browse files
committed
feat: refactor HTTP request handling in instabug CLI
- Removed `http` dependency from `pubspec.yaml`. - Added a new `makeHttpPostRequest` function in `bin/instabug.dart` for handling HTTP POST requests. - Updated `upload_so_files.dart` to utilize the new HTTP request function for uploading .so files.
1 parent 3ea25fa commit a22fda1

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

bin/commands/upload_so_files.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import 'dart:developer';
2-
import 'dart:io';
3-
import 'package:args/args.dart';
4-
import 'package:http/http.dart' as http;
1+
part of '../instabug.dart';
52

63
/**
74
* This script uploads .so files to the specified endpoint used in NDK crash reporting.
8-
* Usage: dart instabug.dart upload-so-files --arch <arch> --file <path> --api_key <key> --token <token> --name <name>
5+
* Usage: dart run instabug_flutter:instabug upload-so-files --arch <arch> --file <path> --api_key <key> --token <token> --name <name>
96
*/
107

118
class UploadSoFilesOptions {
@@ -126,8 +123,8 @@ class UploadSoFilesCommand {
126123

127124
const endPoint = 'https://api.instabug.com/api/web/public/so_files';
128125

129-
final response = await http.post(
130-
Uri.parse(endPoint),
126+
final response = await makeHttpPostRequest(
127+
url: endPoint,
131128
body: body,
132129
);
133130

bin/instabug.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env dart
22

3-
import 'dart:developer';
3+
import 'dart:convert';
44
import 'dart:io';
55

66
import 'package:args/args.dart';
77

8-
import 'commands/upload_so_files.dart';
8+
part 'commands/upload_so_files.dart';
99

1010
// Command registry for easy management
1111
class CommandRegistry {
@@ -27,6 +27,36 @@ class CommandHandler {
2727
CommandHandler({required this.parser, required this.execute});
2828
}
2929

30+
Future<bool> makeHttpPostRequest({
31+
required String url,
32+
required Map<String, String> body,
33+
Map<String, String>? headers,
34+
}) async {
35+
try {
36+
final client = HttpClient();
37+
38+
final request = await client.postUrl(Uri.parse(url));
39+
40+
request.headers.contentType = ContentType.json;
41+
42+
request.write(jsonEncode(body));
43+
44+
final response = await request.close();
45+
46+
if (response.statusCode >= 200 && response.statusCode < 300) {
47+
final responseBody = await response.transform(utf8.decoder).join();
48+
return true;
49+
} else {
50+
print('Error: ${response.statusCode}');
51+
return false;
52+
}
53+
54+
} catch (e) {
55+
print('[Instabug-CLI] Error while making HTTP POST request: $e');
56+
exit(1);
57+
}
58+
}
59+
3060
void main(List<String> args) async {
3161
final parser = ArgParser()..addFlag('help', abbr: 'h');
3262

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ dependencies:
1111
args: ^2.4.0
1212
flutter:
1313
sdk: flutter
14-
http: ^0.13.6
1514
meta: ^1.3.0
1615
stack_trace: ^1.10.0
1716

0 commit comments

Comments
 (0)