Skip to content

Commit

Permalink
fix: use http.get when client is not provided (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Sep 13, 2021
1 parent 8f31383 commit 67ec60c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/src/pub_updater.dart
Expand Up @@ -16,20 +16,22 @@ class PackageInfoNotFoundFailue implements Exception {}
/// {@endtemplate}
class PubUpdater {
/// {@macro pub_update}
PubUpdater([http.Client? client]) : _client = client ?? http.Client();
PubUpdater([http.Client? client]) : _client = client;

/// The pub.dev base url for querying package versions
static const _baseUrl = 'https://pub.dev/packages/';
final http.Client _client;
final http.Client? _client;

Future<http.Response> _get(Uri uri) => _client?.get(uri) ?? http.get(uri);

/// Checks whether or not [currentVersion] is the latest version
/// for the package associated with [packageName]
Future<bool> isUpToDate({
required String packageName,
required String currentVersion,
}) async {
final url = Uri.parse('$_baseUrl$packageName.json');
final response = await _client.get(url);
final uri = Uri.parse('$_baseUrl$packageName.json');
final response = await _get(uri);

if (response.statusCode != HttpStatus.ok) throw PackageInfoRequestFailure();

Expand Down

0 comments on commit 67ec60c

Please sign in to comment.