Skip to content

Commit 5fc806f

Browse files
committed
chore: package rename
1 parent 3c50cd0 commit 5fc806f

File tree

9 files changed

+73
-65
lines changed

9 files changed

+73
-65
lines changed

.github/dependabot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ updates:
1010
schedule:
1111
interval: "daily"
1212
ignore:
13-
- dependency-name: "ht_*"
13+
- dependency-name: "core"

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ht_http_client
1+
# http_client
22

33
![coverage: percentage](https://img.shields.io/badge/coverage-XX-green)
44
[![style: very good analysis](https://img.shields.io/badge/style-very_good_analysis-B22C89.svg)](https://pub.dev/packages/very_good_analysis)
@@ -8,14 +8,14 @@ A robust and reusable Dart HTTP client built on top of the `dio` package. It sim
88

99
## Description
1010

11-
This package provides an `HtHttpClient` class designed to be used as a foundational data access component in Dart or Flutter applications. It abstracts away the complexities of setting up `dio`, handling authentication tokens, and interpreting various HTTP error conditions, offering a cleaner interface for making API calls.
11+
This package provides an `HttpClient` class designed to be used as a foundational data access component in Dart or Flutter applications. It abstracts away the complexities of setting up `dio`, handling authentication tokens, and interpreting various HTTP error conditions, offering a cleaner interface for making API calls.
1212

1313
Key features include:
1414
* Base URL configuration.
1515
* Simplified `get`, `post`, `put`, `delete` methods.
1616
* Automatic injection of `Authorization: Bearer <token>` headers via an interceptor.
1717
* Token retrieval via a flexible `TokenProvider` function.
18-
* Mapping of `DioException` types and non-2xx HTTP status codes to specific `HtHttpException` subtypes (`NetworkException`, `BadRequestException`, `UnauthorizedException`, etc.) defined in the `ht_shared` package.
18+
* Mapping of `DioException` types and non-2xx HTTP status codes to specific `HttpException` subtypes (`NetworkException`, `BadRequestException`, `UnauthorizedException`, etc.) defined in the `core` package.
1919
* Support for request cancellation using `dio`'s `CancelToken`.
2020

2121
## Getting Started
@@ -24,27 +24,27 @@ Add the package to your `pubspec.yaml`:
2424

2525
```yaml
2626
dependencies:
27-
ht_http_client:
27+
http_client:
2828
git:
29-
url: https://github.com/headlines-toolkit/ht-http-client.git
30-
dio: ^5.8.0+1 # ht_http_client relies on dio
29+
url: https://github.com/flutter-news-app-full-source-code/http-client.git
30+
dio: ^5.8.0+1 # http_client relies on dio
3131
```
3232
3333
Then run `dart pub get` or `flutter pub get`.
3434

3535
## Features
3636

37-
* **`HtHttpClient` Class:** The main entry point for making requests.
37+
* **`HttpClient` Class:** The main entry point for making requests.
3838
* **HTTP Methods:** `get<T>()`, `post<T>()`, `put<T>()`, `delete<T>()`.
3939
* **Authentication:** Automatic Bearer token injection using a provided `TokenProvider`.
40-
* **Error Handling:** Throws specific `HtHttpException` subtypes (defined in `ht_shared`) for easier error management.
40+
* **Error Handling:** Throws specific `HttpException` subtypes (defined in `core`) for easier error management.
4141
* **Cancellation:** Supports request cancellation via `CancelToken`.
4242

4343
## Usage
4444

4545
```dart
46-
import 'package:ht_http_client/ht_http_client.dart';
47-
import 'package:ht_shared/ht_shared.dart'; // Import for HtHttpException types
46+
import 'package:http_client/http_client.dart';
47+
import 'package:core/core.dart'; // Import for HttpException types
4848
import 'package:dio/dio.dart'; // For CancelToken
4949
5050
// 1. Define your token provider function
@@ -57,7 +57,7 @@ Future<String?> myTokenProvider() async {
5757
5858
void main() async {
5959
// 2. Create an instance of the client
60-
final client = HtHttpClient(
60+
final client = HttpClient(
6161
baseUrl: 'https://api.example.com/v1',
6262
tokenProvider: myTokenProvider,
6363
);
@@ -91,7 +91,7 @@ void main() async {
9191
// Handle offline state or retry logic
9292
} on NotFoundException catch (e) {
9393
print('Resource not found: ${e.message}');
94-
} on HtHttpException catch (e) { // Catch other specific or general client errors
94+
} on HttpException catch (e) { // Catch other specific or general client errors
9595
print('HTTP Client Error: ${e.message}');
9696
} catch (e) { // Catch any other unexpected errors
9797
print('An unexpected error occurred: $e');
@@ -104,13 +104,15 @@ void main() async {
104104
data: {'name': 'New Item', 'value': 123},
105105
);
106106
print('Created item: $newItem');
107-
} on HtHttpException catch (e) {
107+
} on HttpException catch (e) {
108108
print('Error creating item: ${e.message}');
109109
}
110110
}
111111
112112
```
113113

114-
## License
114+
## 🔑 Licensing
115115

116-
This package is licensed under the [PolyForm Free Trial](https://polyformproject.org/licenses/free-trial/1.0.0). Please review the terms before use.
116+
This package is source-available and licensed under the [PolyForm Free Trial 1.0.0](LICENSE). Please review the terms before use.
117+
118+
For commercial licensing options that grant the right to build and distribute unlimited applications, please visit the main [**Flutter News App - Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code) organization.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
library;
44

55
// Export the main client class
6-
export 'src/ht_http_client.dart';
6+
export 'src/http_client.dart';
77
// Export the TokenProvider typedef for convenience
88
export 'src/interceptors/auth_interceptor.dart' show TokenProvider;
Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
//
22
// ignore_for_file: only_throw_errors
33

4+
import 'package:core/core.dart';
45
import 'package:dio/dio.dart';
5-
import 'package:ht_http_client/src/adapters/http_adapter.dart';
6-
import 'package:ht_http_client/src/interceptors/auth_interceptor.dart';
7-
import 'package:ht_http_client/src/interceptors/error_interceptor.dart';
8-
import 'package:ht_shared/ht_shared.dart';
6+
import 'package:http_client/src/adapters/http_adapter.dart';
7+
import 'package:http_client/src/interceptors/auth_interceptor.dart';
8+
import 'package:http_client/src/interceptors/error_interceptor.dart';
99
import 'package:logging/logging.dart';
1010

11-
/// {@template ht_http_client}
11+
/// {@template http_client}
1212
/// A robust HTTP client built on top of Dio, providing simplified API calls,
1313
/// automatic authentication header injection, and custom exception mapping.
1414
///
1515
/// This client handles common HTTP methods (GET, POST, PUT, DELETE) and maps
16-
/// Dio errors and non-2xx status codes to specific [HtHttpException] subtypes
16+
/// Dio errors and non-2xx status codes to specific [HttpException] subtypes
1717
/// defined in `exceptions.dart`.
1818
/// {@endtemplate}
19-
class HtHttpClient {
20-
/// {@macro ht_http_client}
19+
class HttpClient {
20+
/// {@macro http_client}
2121
///
22-
/// Creates an instance of [HtHttpClient].
22+
/// Creates an instance of [HttpClient].
2323
///
2424
/// Requires a "baseUrl" for the API endpoint and a [tokenProvider] function
2525
/// to asynchronously retrieve the authentication token.
@@ -30,14 +30,14 @@ class HtHttpClient {
3030
/// - list of additional [interceptors] to be added alongside
3131
/// the default Auth and Error interceptors.
3232
/// - [logger]: Optional [Logger] instance for logging HTTP requests and responses.
33-
HtHttpClient({
33+
HttpClient({
3434
required String baseUrl,
3535
required TokenProvider tokenProvider,
3636
Dio? dioInstance,
3737
List<Interceptor>? interceptors,
3838
Logger? logger,
39-
}) : _dio = dioInstance ?? Dio(),
40-
_logger = logger ?? Logger('HtHttpClient') {
39+
}) : _dio = dioInstance ?? Dio(),
40+
_logger = logger ?? Logger('HttpClient') {
4141
// Configure base options
4242
_dio.options = BaseOptions(
4343
baseUrl: baseUrl,
@@ -77,30 +77,30 @@ class HtHttpClient {
7777
/// - [cancelToken]: Optional [CancelToken] for request cancellation.
7878
///
7979
/// Returns the response data decoded as type [T].
80-
/// Throws an [HtHttpException] on network errors or non-2xx status codes.
80+
/// Throws an [HttpException] on network errors or non-2xx status codes.
8181
Future<T> get<T>(
8282
String path, {
8383
Map<String, dynamic>? queryParameters,
8484
Options? options,
8585
CancelToken? cancelToken,
8686
}) async {
87-
_logger.info(
88-
'GET request to: $path, Query Parameters: $queryParameters',
89-
);
87+
_logger.info('GET request to: $path, Query Parameters: $queryParameters');
9088
try {
9189
final response = await _dio.get<T>(
9290
path,
9391
queryParameters: queryParameters,
9492
options: options,
9593
cancelToken: cancelToken,
9694
);
97-
_logger.info('GET request to $path successful. Status: ${response.statusCode}');
95+
_logger.info(
96+
'GET request to $path successful. Status: ${response.statusCode}',
97+
);
9898
// Dio automatically throws for non-2xx, ErrorInterceptor maps it
9999
return response.data as T;
100100
} on DioException catch (e) {
101-
if (e.error is HtHttpException) {
101+
if (e.error is HttpException) {
102102
_logger.severe(
103-
'GET request to $path failed with HtHttpException: ${e.error}',
103+
'GET request to $path failed with HttpException: ${e.error}',
104104
);
105105
throw e.error!;
106106
}
@@ -118,7 +118,7 @@ class HtHttpClient {
118118
/// - [cancelToken]: Optional [CancelToken] for request cancellation.
119119
///
120120
/// Returns the response data decoded as type [T].
121-
/// Throws an [HtHttpException] on network errors or non-2xx status codes.
121+
/// Throws an [HttpException] on network errors or non-2xx status codes.
122122
Future<T> post<T>(
123123
String path, {
124124
dynamic data,
@@ -137,12 +137,14 @@ class HtHttpClient {
137137
options: options,
138138
cancelToken: cancelToken,
139139
);
140-
_logger.info('POST request to $path successful. Status: ${response.statusCode}');
140+
_logger.info(
141+
'POST request to $path successful. Status: ${response.statusCode}',
142+
);
141143
return response.data as T;
142144
} on DioException catch (e) {
143-
if (e.error is HtHttpException) {
145+
if (e.error is HttpException) {
144146
_logger.severe(
145-
'POST request to $path failed with HtHttpException: ${e.error}',
147+
'POST request to $path failed with HttpException: ${e.error}',
146148
);
147149
throw e.error!;
148150
}
@@ -160,7 +162,7 @@ class HtHttpClient {
160162
/// - [cancelToken]: Optional [CancelToken] for request cancellation.
161163
///
162164
/// Returns the response data decoded as type [T].
163-
/// Throws an [HtHttpException] on network errors or non-2xx status codes.
165+
/// Throws an [HttpException] on network errors or non-2xx status codes.
164166
Future<T> put<T>(
165167
String path, {
166168
dynamic data,
@@ -179,12 +181,14 @@ class HtHttpClient {
179181
options: options,
180182
cancelToken: cancelToken,
181183
);
182-
_logger.info('PUT request to $path successful. Status: ${response.statusCode}');
184+
_logger.info(
185+
'PUT request to $path successful. Status: ${response.statusCode}',
186+
);
183187
return response.data as T;
184188
} on DioException catch (e) {
185-
if (e.error is HtHttpException) {
189+
if (e.error is HttpException) {
186190
_logger.severe(
187-
'PUT request to $path failed with HtHttpException: ${e.error}',
191+
'PUT request to $path failed with HttpException: ${e.error}',
188192
);
189193
throw e.error!;
190194
}
@@ -202,7 +206,7 @@ class HtHttpClient {
202206
/// - [cancelToken]: Optional [CancelToken] for request cancellation.
203207
///
204208
/// Returns the response data decoded as type [T].
205-
/// Throws an [HtHttpException] on network errors or non-2xx status codes.
209+
/// Throws an [HttpException] on network errors or non-2xx status codes.
206210
Future<T> delete<T>(
207211
String path, {
208212
dynamic data,
@@ -221,12 +225,14 @@ class HtHttpClient {
221225
options: options,
222226
cancelToken: cancelToken,
223227
);
224-
_logger.info('DELETE request to $path successful. Status: ${response.statusCode}');
228+
_logger.info(
229+
'DELETE request to $path successful. Status: ${response.statusCode}',
230+
);
225231
return response.data as T;
226232
} on DioException catch (e) {
227-
if (e.error is HtHttpException) {
233+
if (e.error is HttpException) {
228234
_logger.severe(
229-
'DELETE request to $path failed with HtHttpException: ${e.error}',
235+
'DELETE request to $path failed with HttpException: ${e.error}',
230236
);
231237
throw e.error!;
232238
}

lib/src/interceptors/error_interceptor.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import 'dart:io';
22

33
import 'package:dio/dio.dart';
4-
import 'package:ht_shared/ht_shared.dart';
4+
import 'package:core/core.dart';
55

66
/// Dio interceptor that catches [DioException]s and maps them to specific
7-
/// [HtHttpException] subtypes for clearer error handling downstream.
7+
/// [HttpException] subtypes for clearer error handling downstream.
88
class ErrorInterceptor extends Interceptor {
99
@override
1010
void onError(DioException err, ErrorInterceptorHandler handler) {
11-
final HtHttpException mappedException;
11+
final HttpException mappedException;
1212

1313
switch (err.type) {
1414
case DioExceptionType.connectionTimeout:
@@ -90,7 +90,6 @@ class ErrorInterceptor extends Interceptor {
9090

9191
if (responseData is Map) {
9292
// New Pattern: Check for the nested {"error": {"message": "..."}}
93-
// This is the standard format for ht_api.
9493
if (responseData.containsKey('error') && responseData['error'] is Map) {
9594
final errorMap = responseData['error'] as Map;
9695
if (errorMap.containsKey('message') && errorMap['message'] is String) {
@@ -103,7 +102,8 @@ class ErrorInterceptor extends Interceptor {
103102
responseData['message'] is String) {
104103
return responseData['message'] as String;
105104
}
106-
if (responseData.containsKey('error') && responseData['error'] is String) {
105+
if (responseData.containsKey('error') &&
106+
responseData['error'] is String) {
107107
return responseData['error'] as String;
108108
}
109109
if (responseData.containsKey('detail') &&

pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
name: ht_http_client
1+
name: http_client
22
description: Robust and reusable Dart HTTP client built on top of the `dio` package. It simplifies API interactions by providing common HTTP methods, automatic authentication header injection, and mapping network/status code errors to specific custom exceptions.
3-
repository: https://github.com/headlines-toolkit/ht_http_client
3+
repository: https://github.com/flutter-news-app-full-source-code/http_client
44
publish_to: none
55

66
environment:
77
sdk: ^3.8.0
88

99
dependencies:
10-
dio: ^5.8.0+1
11-
ht_shared:
10+
core:
1211
git:
13-
url: https://github.com/headlines-toolkit/ht-shared.git
12+
url: https://github.com/flutter-news-app-full-source-code/core.git
13+
dio: ^5.8.0+1
1414
logging: ^1.3.0
1515

1616
dev_dependencies:
1717
mocktail: ^1.0.4
1818
test: ^1.25.8
19-
very_good_analysis: ^7.0.0
19+
very_good_analysis: ^9.0.0

test/src/interceptors/auth_interceptor_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:dio/dio.dart';
2-
import 'package:ht_http_client/src/interceptors/auth_interceptor.dart';
2+
import 'package:http_client/src/interceptors/auth_interceptor.dart';
33
import 'package:mocktail/mocktail.dart';
44
import 'package:test/test.dart';
55

test/src/interceptors/error_interceptor_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import 'dart:io';
22

3+
import 'package:core/core.dart'; // Updated import
34
import 'package:dio/dio.dart';
4-
import 'package:ht_http_client/src/interceptors/error_interceptor.dart';
5-
import 'package:ht_shared/ht_shared.dart'; // Updated import
5+
import 'package:http_client/src/interceptors/error_interceptor.dart';
66
import 'package:mocktail/mocktail.dart';
77
import 'package:test/test.dart';
88

@@ -42,7 +42,7 @@ void main() {
4242
});
4343

4444
// Helper function to verify the rejection
45-
void verifyRejection<T extends HtHttpException>({
45+
void verifyRejection<T extends HttpException>({
4646
required DioException originalDioErr,
4747
String? expectedMessage, // Optional: for specific message checks
4848
}) {
@@ -54,13 +54,13 @@ void main() {
5454

5555
expect(captured.error, isA<T>());
5656
expect(captured.error, isNotNull);
57-
// Removed check for dioException as it's no longer part of HtHttpException
57+
// Removed check for dioException as it's no longer part of HttpException
5858
expect(captured.requestOptions, originalDioErr.requestOptions);
5959
expect(captured.response, originalDioErr.response);
6060
expect(captured.type, originalDioErr.type);
6161
// Check message if provided
6262
if (expectedMessage != null) {
63-
expect((captured.error! as HtHttpException).message, expectedMessage);
63+
expect((captured.error! as HttpException).message, expectedMessage);
6464
}
6565
}
6666

0 commit comments

Comments
 (0)