From 32dbfe9c37d4265207d18d563d6f9f2c20944875 Mon Sep 17 00:00:00 2001 From: leoafarias Date: Tue, 20 Oct 2020 08:14:30 -0400 Subject: [PATCH] Updates --- .gitignore | 33 + CHANGELOG.md | 15 + README.md | 81 +- analysis_options.yaml | 15 + assets/logo.png | Bin 0 -> 11789 bytes coverage_badge.svg | 20 + example/example.md | 10 + lib/pub_api_client.dart | 6 + lib/src/models/package_score_model.dart | 18 + .../models/package_score_model.freezed.dart | 242 +++++ lib/src/models/package_score_model.g.dart | 28 + lib/src/models/pub_package_model.dart | 38 + lib/src/models/pub_package_model.freezed.dart | 418 ++++++++ lib/src/models/pub_package_model.g.dart | 49 + lib/src/models/pubspec_model.dart | 60 ++ lib/src/models/pubspec_model.freezed.dart | 936 ++++++++++++++++++ lib/src/models/pubspec_model.g.dart | 92 ++ lib/src/models/search_results_model.dart | 33 + .../models/search_results_model.freezed.dart | 314 ++++++ lib/src/models/search_results_model.g.dart | 35 + lib/src/pub_api_client_base.dart | 56 ++ lib/src/version.dart | 2 + pubspec.yaml | 23 + test/pubdev_api_test.dart | 48 + 24 files changed, 2570 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 analysis_options.yaml create mode 100644 assets/logo.png create mode 100644 coverage_badge.svg create mode 100644 example/example.md create mode 100644 lib/pub_api_client.dart create mode 100644 lib/src/models/package_score_model.dart create mode 100644 lib/src/models/package_score_model.freezed.dart create mode 100644 lib/src/models/package_score_model.g.dart create mode 100644 lib/src/models/pub_package_model.dart create mode 100644 lib/src/models/pub_package_model.freezed.dart create mode 100644 lib/src/models/pub_package_model.g.dart create mode 100644 lib/src/models/pubspec_model.dart create mode 100644 lib/src/models/pubspec_model.freezed.dart create mode 100644 lib/src/models/pubspec_model.g.dart create mode 100644 lib/src/models/search_results_model.dart create mode 100644 lib/src/models/search_results_model.freezed.dart create mode 100644 lib/src/models/search_results_model.g.dart create mode 100644 lib/src/pub_api_client_base.dart create mode 100644 lib/src/version.dart create mode 100644 pubspec.yaml create mode 100644 test/pubdev_api_test.dart diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73cdba8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# Files and directories created by pub +.dart_tool/ +.packages +# Remove the following pattern if you wish to check in your lock file +pubspec.lock +# Do not version the sdk versions +.DS_Store + +# Conventional directory for build outputs +build/ + +# Directory created by dartdoc +doc/api/ + +# Test Coverage +test/.test_coverage.dart + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# Visual Studio Code related +.classpath +.project +.settings/ +.vscode/ +coverage/lcov.info + +# FVM during tests +.fvm +.vscode/settings.json \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..fc2b271 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +## 1.0.3 + +- Added user-agent to requests + +## 1.0.2 + +- Further improvements + +## 1.0.1 + +- Test improvements and API clean up + +## 1.0.0 + +- Initial version diff --git a/README.md b/README.md index 9ee9002..950b353 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,79 @@ -# pubdev_api -API Client for Pub.dev +drawing + +[![Pub Version](https://img.shields.io/pub/v/pub_api_client?label=version&style=flat-square)](https://pub.dev/packages/pub_api_client/changelog) [![Health](https://img.shields.io/badge/dynamic/json?color=blue&label=health&query=pub_points&url=http://www.pubscore.gq/pub-points?package=pub_api_client&style=flat-square&cacheSeconds=90000)](https://pub.dev/packages/pub_api_client/score) [![Coverage Status](https://coveralls.io/repos/github/leoafarias/pub_api_client/badge.svg?branch=main)](https://coveralls.io/github/leoafarias/pub_api_client?branch=main) [![MIT Licence](https://img.shields.io/github/license/leoafarias/pub_api_client?style=flat-square&longCache=true)](https://opensource.org/licenses/mit-license.php) + +## An unofficial API client for [Pub.dev](https://www.pub.dev) + +Implements all `known` endpoints available on pub.dev. If any particular endpoint is missing please [open an issue][tracker]. + +## Usage + +A simple usage example: + +```dart +import 'package:pub_api_client/pub_api_client.dart'; + +main() { + final client = PubClient(); +} +``` + +## Get Package Info + +Retrieves all available information about an specific package. + +```dart + final package = await client.getPackage('pkg_name'); +``` + +## Get Package Score + +Returns the following score information about a package. + +- Pub Points +- Popularity +- Likes + +```dart + final score = await client.getScore('pkg_name'); +``` + +## Get Package Versions + +The method `getPackage` also returns the versions. However if all you need is versions use this method since it's lighter. + +```dart + final package = await client.getVersions('pkg_name'); +``` + +## Search Packages + +Allows you to search for packages on pub.dev. Will return the packages that match the query. + +```dart +final results = await client.search('query'); +// Returns the packages that match the query +print(results.packages) +``` + +### Paging Search Results + +You are able to page search results. + +```dart +final results = await client.search('query'); +final nextResults = await results.nextPage(); + +print(nextResults.packages) +``` + +If you want to retrieve a specific result page you can call the `page` parameter directly. + +```dart +final results = await client.search('query',page:2); +print(results.packages) +``` + +Please file feature requests and bugs at the [issue tracker][tracker]. + +[tracker]: https://github.com/leoafarias/pub_api_client/issues diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..a94129b --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,15 @@ +# Defines a default set of lint rules enforced for +# projects at Google. For details and rationale, +# see https://github.com/dart-lang/pedantic#enabled-lints. +include: package:pedantic/analysis_options.yaml + +# For lint rules and documentation, see http://dart-lang.github.io/linter/lints. +# Uncomment to specify additional rules. +# linter: +# rules: +# - camel_case_types + +analyzer: + exclude: + - "**/*.g.dart" + - "**/*.freezed.dart" diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..83c671f634e50769cbee0358c361220862386c8b GIT binary patch literal 11789 zcma)iWmuds({5>@xLa{8wu?hc(c%S)7hR;tLUDI1?$F{a?(P&Xvbf9QF2&s)&bIIS zUEewX&X4EWWRhnxnN6-t=DtIf6r?fHNYP%rc!4SNNkZkt3j_yv*$3q{{7r#Ps|)`@ zG!>N>eet3y8vVfl30~&|Ys#3&%fDcOmr-6I1e?7;gqIND4=Mb4@#1CX%m0xeIAp&1 zpYjWzz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&$=F|xMGlW49aT+5!P_M$B;GY`Wst+T*djyEw@^^o&Jx$$AJM4 zL4!p5BmR*`QOM!p>8oI&>;JIz4E{1p|L+gMlzaz`f5~}Y5i!KS$2S@%anb#&y$pT< zIBz!?6@rJ_a8BzRxEf6V7!o*t^93CaAEIV5GM2|t^1n#F6Xz?~`c2$W$lsc8J5Bq5 zpzW-~=)ai$O%R;C+L>uA^{ROTke0XS87`n2|QC8Aq<`C z#lOM(-&?~d3W^YAC={6JY0`!9Z$4iUUj~04+b}ettb1pRXZxQ)I9>|VQC~C!`o(PL z5*tV(a@S?tM=){!CDuw&FXFn&E3?x4-0km7A)vEX8Tab2CH56C{@eH+_XHCm9E|bk z;kB1C=L(TX3k8ySZSmo5w?M#!ose3U29+P&Et)`>vf66@%_aVO<{^xzT zZxj&q@J;@h;qzu~^k#@lluZO-K7uvT*EUrYfKmBy+OyF}Rppm|4rq}^X^$jd4z|?} g{V(U4>hT#NTpal_qSU7DFDF|@QbD3z?5p4Z0p)!44gdfE literal 0 HcmV?d00001 diff --git a/coverage_badge.svg b/coverage_badge.svg new file mode 100644 index 0000000..4a135f6 --- /dev/null +++ b/coverage_badge.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + coverage + coverage + 16% + 16% + + diff --git a/example/example.md b/example/example.md new file mode 100644 index 0000000..0461367 --- /dev/null +++ b/example/example.md @@ -0,0 +1,10 @@ +```dart +import 'package:pub_api_client/pub_api_client.dart'; + +void main() async { + final client = PubClient(); + final packageInfo = await client.getPackage('fvm'); + print('Package Info: $packageInfo'); +} + +``` diff --git a/lib/pub_api_client.dart b/lib/pub_api_client.dart new file mode 100644 index 0000000..521ca6b --- /dev/null +++ b/lib/pub_api_client.dart @@ -0,0 +1,6 @@ +/// Support for doing something awesome. +/// +/// More dartdocs go here. +library pubdev_api; + +export 'src/pub_api_client_base.dart'; diff --git a/lib/src/models/package_score_model.dart b/lib/src/models/package_score_model.dart new file mode 100644 index 0000000..62abdec --- /dev/null +++ b/lib/src/models/package_score_model.dart @@ -0,0 +1,18 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'package_score_model.freezed.dart'; +part 'package_score_model.g.dart'; + +@freezed +abstract class PackageScore with _$PackageScore { + factory PackageScore({ + final int grantedPoints, + final int maxPoints, + final int likeCount, + final double popularityScore, + final DateTime lastUpdated, + }) = _PackageScore; + + factory PackageScore.fromJson(Map json) => + _$PackageScoreFromJson(json); +} diff --git a/lib/src/models/package_score_model.freezed.dart b/lib/src/models/package_score_model.freezed.dart new file mode 100644 index 0000000..f78d348 --- /dev/null +++ b/lib/src/models/package_score_model.freezed.dart @@ -0,0 +1,242 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies + +part of 'package_score_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; +PackageScore _$PackageScoreFromJson(Map json) { + return _PackageScore.fromJson(json); +} + +/// @nodoc +class _$PackageScoreTearOff { + const _$PackageScoreTearOff(); + +// ignore: unused_element + _PackageScore call( + {int grantedPoints, + int maxPoints, + int likeCount, + double popularityScore, + DateTime lastUpdated}) { + return _PackageScore( + grantedPoints: grantedPoints, + maxPoints: maxPoints, + likeCount: likeCount, + popularityScore: popularityScore, + lastUpdated: lastUpdated, + ); + } + +// ignore: unused_element + PackageScore fromJson(Map json) { + return PackageScore.fromJson(json); + } +} + +/// @nodoc +// ignore: unused_element +const $PackageScore = _$PackageScoreTearOff(); + +/// @nodoc +mixin _$PackageScore { + int get grantedPoints; + int get maxPoints; + int get likeCount; + double get popularityScore; + DateTime get lastUpdated; + + Map toJson(); + $PackageScoreCopyWith get copyWith; +} + +/// @nodoc +abstract class $PackageScoreCopyWith<$Res> { + factory $PackageScoreCopyWith( + PackageScore value, $Res Function(PackageScore) then) = + _$PackageScoreCopyWithImpl<$Res>; + $Res call( + {int grantedPoints, + int maxPoints, + int likeCount, + double popularityScore, + DateTime lastUpdated}); +} + +/// @nodoc +class _$PackageScoreCopyWithImpl<$Res> implements $PackageScoreCopyWith<$Res> { + _$PackageScoreCopyWithImpl(this._value, this._then); + + final PackageScore _value; + // ignore: unused_field + final $Res Function(PackageScore) _then; + + @override + $Res call({ + Object grantedPoints = freezed, + Object maxPoints = freezed, + Object likeCount = freezed, + Object popularityScore = freezed, + Object lastUpdated = freezed, + }) { + return _then(_value.copyWith( + grantedPoints: grantedPoints == freezed + ? _value.grantedPoints + : grantedPoints as int, + maxPoints: maxPoints == freezed ? _value.maxPoints : maxPoints as int, + likeCount: likeCount == freezed ? _value.likeCount : likeCount as int, + popularityScore: popularityScore == freezed + ? _value.popularityScore + : popularityScore as double, + lastUpdated: + lastUpdated == freezed ? _value.lastUpdated : lastUpdated as DateTime, + )); + } +} + +/// @nodoc +abstract class _$PackageScoreCopyWith<$Res> + implements $PackageScoreCopyWith<$Res> { + factory _$PackageScoreCopyWith( + _PackageScore value, $Res Function(_PackageScore) then) = + __$PackageScoreCopyWithImpl<$Res>; + @override + $Res call( + {int grantedPoints, + int maxPoints, + int likeCount, + double popularityScore, + DateTime lastUpdated}); +} + +/// @nodoc +class __$PackageScoreCopyWithImpl<$Res> extends _$PackageScoreCopyWithImpl<$Res> + implements _$PackageScoreCopyWith<$Res> { + __$PackageScoreCopyWithImpl( + _PackageScore _value, $Res Function(_PackageScore) _then) + : super(_value, (v) => _then(v as _PackageScore)); + + @override + _PackageScore get _value => super._value as _PackageScore; + + @override + $Res call({ + Object grantedPoints = freezed, + Object maxPoints = freezed, + Object likeCount = freezed, + Object popularityScore = freezed, + Object lastUpdated = freezed, + }) { + return _then(_PackageScore( + grantedPoints: grantedPoints == freezed + ? _value.grantedPoints + : grantedPoints as int, + maxPoints: maxPoints == freezed ? _value.maxPoints : maxPoints as int, + likeCount: likeCount == freezed ? _value.likeCount : likeCount as int, + popularityScore: popularityScore == freezed + ? _value.popularityScore + : popularityScore as double, + lastUpdated: + lastUpdated == freezed ? _value.lastUpdated : lastUpdated as DateTime, + )); + } +} + +@JsonSerializable() + +/// @nodoc +class _$_PackageScore implements _PackageScore { + _$_PackageScore( + {this.grantedPoints, + this.maxPoints, + this.likeCount, + this.popularityScore, + this.lastUpdated}); + + factory _$_PackageScore.fromJson(Map json) => + _$_$_PackageScoreFromJson(json); + + @override + final int grantedPoints; + @override + final int maxPoints; + @override + final int likeCount; + @override + final double popularityScore; + @override + final DateTime lastUpdated; + + @override + String toString() { + return 'PackageScore(grantedPoints: $grantedPoints, maxPoints: $maxPoints, likeCount: $likeCount, popularityScore: $popularityScore, lastUpdated: $lastUpdated)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _PackageScore && + (identical(other.grantedPoints, grantedPoints) || + const DeepCollectionEquality() + .equals(other.grantedPoints, grantedPoints)) && + (identical(other.maxPoints, maxPoints) || + const DeepCollectionEquality() + .equals(other.maxPoints, maxPoints)) && + (identical(other.likeCount, likeCount) || + const DeepCollectionEquality() + .equals(other.likeCount, likeCount)) && + (identical(other.popularityScore, popularityScore) || + const DeepCollectionEquality() + .equals(other.popularityScore, popularityScore)) && + (identical(other.lastUpdated, lastUpdated) || + const DeepCollectionEquality() + .equals(other.lastUpdated, lastUpdated))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(grantedPoints) ^ + const DeepCollectionEquality().hash(maxPoints) ^ + const DeepCollectionEquality().hash(likeCount) ^ + const DeepCollectionEquality().hash(popularityScore) ^ + const DeepCollectionEquality().hash(lastUpdated); + + @override + _$PackageScoreCopyWith<_PackageScore> get copyWith => + __$PackageScoreCopyWithImpl<_PackageScore>(this, _$identity); + + @override + Map toJson() { + return _$_$_PackageScoreToJson(this); + } +} + +abstract class _PackageScore implements PackageScore { + factory _PackageScore( + {int grantedPoints, + int maxPoints, + int likeCount, + double popularityScore, + DateTime lastUpdated}) = _$_PackageScore; + + factory _PackageScore.fromJson(Map json) = + _$_PackageScore.fromJson; + + @override + int get grantedPoints; + @override + int get maxPoints; + @override + int get likeCount; + @override + double get popularityScore; + @override + DateTime get lastUpdated; + @override + _$PackageScoreCopyWith<_PackageScore> get copyWith; +} diff --git a/lib/src/models/package_score_model.g.dart b/lib/src/models/package_score_model.g.dart new file mode 100644 index 0000000..3b843c7 --- /dev/null +++ b/lib/src/models/package_score_model.g.dart @@ -0,0 +1,28 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'package_score_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_PackageScore _$_$_PackageScoreFromJson(Map json) { + return _$_PackageScore( + grantedPoints: json['grantedPoints'] as int, + maxPoints: json['maxPoints'] as int, + likeCount: json['likeCount'] as int, + popularityScore: (json['popularityScore'] as num)?.toDouble(), + lastUpdated: json['lastUpdated'] == null + ? null + : DateTime.parse(json['lastUpdated'] as String), + ); +} + +Map _$_$_PackageScoreToJson(_$_PackageScore instance) => + { + 'grantedPoints': instance.grantedPoints, + 'maxPoints': instance.maxPoints, + 'likeCount': instance.likeCount, + 'popularityScore': instance.popularityScore, + 'lastUpdated': instance.lastUpdated?.toIso8601String(), + }; diff --git a/lib/src/models/pub_package_model.dart b/lib/src/models/pub_package_model.dart new file mode 100644 index 0000000..0397526 --- /dev/null +++ b/lib/src/models/pub_package_model.dart @@ -0,0 +1,38 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:pub_api_client/src/models/pubspec_model.dart'; + +part 'pub_package_model.freezed.dart'; +part 'pub_package_model.g.dart'; + +@freezed +abstract class PubPackage implements _$PubPackage { + const PubPackage._(); + + factory PubPackage({ + String name, + PackageVersion latest, + List versions, + }) = _PubPackage; + + factory PubPackage.fromJson(Map json) => + _$PubPackageFromJson(json); + + String get version => _latestPubspec.version; + String get description => _latestPubspec.description; + String get url => 'https://pub.dev/packages/$name'; + PubSpec get _latestPubspec => versions.last.pubspec; +} + +@freezed +abstract class PackageVersion with _$PackageVersion { + @JsonSerializable(fieldRename: FieldRename.snake) + factory PackageVersion({ + String version, + PubSpec pubspec, + String archiveUrl, + DateTime published, + }) = _PackageVersion; + + factory PackageVersion.fromJson(Map json) => + _$PackageVersionFromJson(json); +} diff --git a/lib/src/models/pub_package_model.freezed.dart b/lib/src/models/pub_package_model.freezed.dart new file mode 100644 index 0000000..6373217 --- /dev/null +++ b/lib/src/models/pub_package_model.freezed.dart @@ -0,0 +1,418 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies + +part of 'pub_package_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; +PubPackage _$PubPackageFromJson(Map json) { + return _PubPackage.fromJson(json); +} + +/// @nodoc +class _$PubPackageTearOff { + const _$PubPackageTearOff(); + +// ignore: unused_element + _PubPackage call( + {String name, PackageVersion latest, List versions}) { + return _PubPackage( + name: name, + latest: latest, + versions: versions, + ); + } + +// ignore: unused_element + PubPackage fromJson(Map json) { + return PubPackage.fromJson(json); + } +} + +/// @nodoc +// ignore: unused_element +const $PubPackage = _$PubPackageTearOff(); + +/// @nodoc +mixin _$PubPackage { + String get name; + PackageVersion get latest; + List get versions; + + Map toJson(); + $PubPackageCopyWith get copyWith; +} + +/// @nodoc +abstract class $PubPackageCopyWith<$Res> { + factory $PubPackageCopyWith( + PubPackage value, $Res Function(PubPackage) then) = + _$PubPackageCopyWithImpl<$Res>; + $Res call( + {String name, PackageVersion latest, List versions}); + + $PackageVersionCopyWith<$Res> get latest; +} + +/// @nodoc +class _$PubPackageCopyWithImpl<$Res> implements $PubPackageCopyWith<$Res> { + _$PubPackageCopyWithImpl(this._value, this._then); + + final PubPackage _value; + // ignore: unused_field + final $Res Function(PubPackage) _then; + + @override + $Res call({ + Object name = freezed, + Object latest = freezed, + Object versions = freezed, + }) { + return _then(_value.copyWith( + name: name == freezed ? _value.name : name as String, + latest: latest == freezed ? _value.latest : latest as PackageVersion, + versions: versions == freezed + ? _value.versions + : versions as List, + )); + } + + @override + $PackageVersionCopyWith<$Res> get latest { + if (_value.latest == null) { + return null; + } + return $PackageVersionCopyWith<$Res>(_value.latest, (value) { + return _then(_value.copyWith(latest: value)); + }); + } +} + +/// @nodoc +abstract class _$PubPackageCopyWith<$Res> implements $PubPackageCopyWith<$Res> { + factory _$PubPackageCopyWith( + _PubPackage value, $Res Function(_PubPackage) then) = + __$PubPackageCopyWithImpl<$Res>; + @override + $Res call( + {String name, PackageVersion latest, List versions}); + + @override + $PackageVersionCopyWith<$Res> get latest; +} + +/// @nodoc +class __$PubPackageCopyWithImpl<$Res> extends _$PubPackageCopyWithImpl<$Res> + implements _$PubPackageCopyWith<$Res> { + __$PubPackageCopyWithImpl( + _PubPackage _value, $Res Function(_PubPackage) _then) + : super(_value, (v) => _then(v as _PubPackage)); + + @override + _PubPackage get _value => super._value as _PubPackage; + + @override + $Res call({ + Object name = freezed, + Object latest = freezed, + Object versions = freezed, + }) { + return _then(_PubPackage( + name: name == freezed ? _value.name : name as String, + latest: latest == freezed ? _value.latest : latest as PackageVersion, + versions: versions == freezed + ? _value.versions + : versions as List, + )); + } +} + +@JsonSerializable() + +/// @nodoc +class _$_PubPackage extends _PubPackage { + _$_PubPackage({this.name, this.latest, this.versions}) : super._(); + + factory _$_PubPackage.fromJson(Map json) => + _$_$_PubPackageFromJson(json); + + @override + final String name; + @override + final PackageVersion latest; + @override + final List versions; + + @override + String toString() { + return 'PubPackage(name: $name, latest: $latest, versions: $versions)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _PubPackage && + (identical(other.name, name) || + const DeepCollectionEquality().equals(other.name, name)) && + (identical(other.latest, latest) || + const DeepCollectionEquality().equals(other.latest, latest)) && + (identical(other.versions, versions) || + const DeepCollectionEquality() + .equals(other.versions, versions))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(name) ^ + const DeepCollectionEquality().hash(latest) ^ + const DeepCollectionEquality().hash(versions); + + @override + _$PubPackageCopyWith<_PubPackage> get copyWith => + __$PubPackageCopyWithImpl<_PubPackage>(this, _$identity); + + @override + Map toJson() { + return _$_$_PubPackageToJson(this); + } +} + +abstract class _PubPackage extends PubPackage { + _PubPackage._() : super._(); + factory _PubPackage( + {String name, + PackageVersion latest, + List versions}) = _$_PubPackage; + + factory _PubPackage.fromJson(Map json) = + _$_PubPackage.fromJson; + + @override + String get name; + @override + PackageVersion get latest; + @override + List get versions; + @override + _$PubPackageCopyWith<_PubPackage> get copyWith; +} + +PackageVersion _$PackageVersionFromJson(Map json) { + return _PackageVersion.fromJson(json); +} + +/// @nodoc +class _$PackageVersionTearOff { + const _$PackageVersionTearOff(); + +// ignore: unused_element + _PackageVersion call( + {String version, + PubSpec pubspec, + String archiveUrl, + DateTime published}) { + return _PackageVersion( + version: version, + pubspec: pubspec, + archiveUrl: archiveUrl, + published: published, + ); + } + +// ignore: unused_element + PackageVersion fromJson(Map json) { + return PackageVersion.fromJson(json); + } +} + +/// @nodoc +// ignore: unused_element +const $PackageVersion = _$PackageVersionTearOff(); + +/// @nodoc +mixin _$PackageVersion { + String get version; + PubSpec get pubspec; + String get archiveUrl; + DateTime get published; + + Map toJson(); + $PackageVersionCopyWith get copyWith; +} + +/// @nodoc +abstract class $PackageVersionCopyWith<$Res> { + factory $PackageVersionCopyWith( + PackageVersion value, $Res Function(PackageVersion) then) = + _$PackageVersionCopyWithImpl<$Res>; + $Res call( + {String version, PubSpec pubspec, String archiveUrl, DateTime published}); + + $PubSpecCopyWith<$Res> get pubspec; +} + +/// @nodoc +class _$PackageVersionCopyWithImpl<$Res> + implements $PackageVersionCopyWith<$Res> { + _$PackageVersionCopyWithImpl(this._value, this._then); + + final PackageVersion _value; + // ignore: unused_field + final $Res Function(PackageVersion) _then; + + @override + $Res call({ + Object version = freezed, + Object pubspec = freezed, + Object archiveUrl = freezed, + Object published = freezed, + }) { + return _then(_value.copyWith( + version: version == freezed ? _value.version : version as String, + pubspec: pubspec == freezed ? _value.pubspec : pubspec as PubSpec, + archiveUrl: + archiveUrl == freezed ? _value.archiveUrl : archiveUrl as String, + published: + published == freezed ? _value.published : published as DateTime, + )); + } + + @override + $PubSpecCopyWith<$Res> get pubspec { + if (_value.pubspec == null) { + return null; + } + return $PubSpecCopyWith<$Res>(_value.pubspec, (value) { + return _then(_value.copyWith(pubspec: value)); + }); + } +} + +/// @nodoc +abstract class _$PackageVersionCopyWith<$Res> + implements $PackageVersionCopyWith<$Res> { + factory _$PackageVersionCopyWith( + _PackageVersion value, $Res Function(_PackageVersion) then) = + __$PackageVersionCopyWithImpl<$Res>; + @override + $Res call( + {String version, PubSpec pubspec, String archiveUrl, DateTime published}); + + @override + $PubSpecCopyWith<$Res> get pubspec; +} + +/// @nodoc +class __$PackageVersionCopyWithImpl<$Res> + extends _$PackageVersionCopyWithImpl<$Res> + implements _$PackageVersionCopyWith<$Res> { + __$PackageVersionCopyWithImpl( + _PackageVersion _value, $Res Function(_PackageVersion) _then) + : super(_value, (v) => _then(v as _PackageVersion)); + + @override + _PackageVersion get _value => super._value as _PackageVersion; + + @override + $Res call({ + Object version = freezed, + Object pubspec = freezed, + Object archiveUrl = freezed, + Object published = freezed, + }) { + return _then(_PackageVersion( + version: version == freezed ? _value.version : version as String, + pubspec: pubspec == freezed ? _value.pubspec : pubspec as PubSpec, + archiveUrl: + archiveUrl == freezed ? _value.archiveUrl : archiveUrl as String, + published: + published == freezed ? _value.published : published as DateTime, + )); + } +} + +@JsonSerializable(fieldRename: FieldRename.snake) + +/// @nodoc +class _$_PackageVersion implements _PackageVersion { + _$_PackageVersion( + {this.version, this.pubspec, this.archiveUrl, this.published}); + + factory _$_PackageVersion.fromJson(Map json) => + _$_$_PackageVersionFromJson(json); + + @override + final String version; + @override + final PubSpec pubspec; + @override + final String archiveUrl; + @override + final DateTime published; + + @override + String toString() { + return 'PackageVersion(version: $version, pubspec: $pubspec, archiveUrl: $archiveUrl, published: $published)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _PackageVersion && + (identical(other.version, version) || + const DeepCollectionEquality() + .equals(other.version, version)) && + (identical(other.pubspec, pubspec) || + const DeepCollectionEquality() + .equals(other.pubspec, pubspec)) && + (identical(other.archiveUrl, archiveUrl) || + const DeepCollectionEquality() + .equals(other.archiveUrl, archiveUrl)) && + (identical(other.published, published) || + const DeepCollectionEquality() + .equals(other.published, published))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(version) ^ + const DeepCollectionEquality().hash(pubspec) ^ + const DeepCollectionEquality().hash(archiveUrl) ^ + const DeepCollectionEquality().hash(published); + + @override + _$PackageVersionCopyWith<_PackageVersion> get copyWith => + __$PackageVersionCopyWithImpl<_PackageVersion>(this, _$identity); + + @override + Map toJson() { + return _$_$_PackageVersionToJson(this); + } +} + +abstract class _PackageVersion implements PackageVersion { + factory _PackageVersion( + {String version, + PubSpec pubspec, + String archiveUrl, + DateTime published}) = _$_PackageVersion; + + factory _PackageVersion.fromJson(Map json) = + _$_PackageVersion.fromJson; + + @override + String get version; + @override + PubSpec get pubspec; + @override + String get archiveUrl; + @override + DateTime get published; + @override + _$PackageVersionCopyWith<_PackageVersion> get copyWith; +} diff --git a/lib/src/models/pub_package_model.g.dart b/lib/src/models/pub_package_model.g.dart new file mode 100644 index 0000000..d669ca7 --- /dev/null +++ b/lib/src/models/pub_package_model.g.dart @@ -0,0 +1,49 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pub_package_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_PubPackage _$_$_PubPackageFromJson(Map json) { + return _$_PubPackage( + name: json['name'] as String, + latest: json['latest'] == null + ? null + : PackageVersion.fromJson(json['latest'] as Map), + versions: (json['versions'] as List) + ?.map((e) => e == null + ? null + : PackageVersion.fromJson(e as Map)) + ?.toList(), + ); +} + +Map _$_$_PubPackageToJson(_$_PubPackage instance) => + { + 'name': instance.name, + 'latest': instance.latest, + 'versions': instance.versions, + }; + +_$_PackageVersion _$_$_PackageVersionFromJson(Map json) { + return _$_PackageVersion( + version: json['version'] as String, + pubspec: json['pubspec'] == null + ? null + : PubSpec.fromJson(json['pubspec'] as Map), + archiveUrl: json['archive_url'] as String, + published: json['published'] == null + ? null + : DateTime.parse(json['published'] as String), + ); +} + +Map _$_$_PackageVersionToJson(_$_PackageVersion instance) => + { + 'version': instance.version, + 'pubspec': instance.pubspec, + 'archive_url': instance.archiveUrl, + 'published': instance.published?.toIso8601String(), + }; diff --git a/lib/src/models/pubspec_model.dart b/lib/src/models/pubspec_model.dart new file mode 100644 index 0000000..4c30030 --- /dev/null +++ b/lib/src/models/pubspec_model.dart @@ -0,0 +1,60 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'pubspec_model.freezed.dart'; +part 'pubspec_model.g.dart'; + +@freezed +abstract class PubSpec with _$PubSpec { + @JsonSerializable(fieldRename: FieldRename.snake) + factory PubSpec({ + Map dependencies, + Map dependencyOverrides, + String description, + Map devDependencies, + String documentation, + Map environment, + Map executables, + String homepage, + String issueTracker, + String name, + String publishTo, + String repository, + String version, + }) = _Pubspec; + factory PubSpec.fromJson(Map json) => + _$PubSpecFromJson(json); +} + +@freezed +abstract class Dependency with _$Dependency { + factory Dependency({ + String sdk, + String version, + Hosted hosted, + dynamic git, + String path, + }) = _Dependency; + factory Dependency.fromJson(Map json) => + _$DependencyFromJson(json); +} + +@freezed +abstract class GitClass with _$GitClass { + factory GitClass({ + String path, + String ref, + String url, + }) = _GitClass; + factory GitClass.fromJson(Map json) => + _$GitClassFromJson(json); +} + +@freezed +abstract class Hosted with _$Hosted { + factory Hosted({ + String name, + String url, + }) = _Hosted; + + factory Hosted.fromJson(Map json) => _$HostedFromJson(json); +} diff --git a/lib/src/models/pubspec_model.freezed.dart b/lib/src/models/pubspec_model.freezed.dart new file mode 100644 index 0000000..3d188c5 --- /dev/null +++ b/lib/src/models/pubspec_model.freezed.dart @@ -0,0 +1,936 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies + +part of 'pubspec_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; +PubSpec _$PubSpecFromJson(Map json) { + return _Pubspec.fromJson(json); +} + +/// @nodoc +class _$PubSpecTearOff { + const _$PubSpecTearOff(); + +// ignore: unused_element + _Pubspec call( + {Map dependencies, + Map dependencyOverrides, + String description, + Map devDependencies, + String documentation, + Map environment, + Map executables, + String homepage, + String issueTracker, + String name, + String publishTo, + String repository, + String version}) { + return _Pubspec( + dependencies: dependencies, + dependencyOverrides: dependencyOverrides, + description: description, + devDependencies: devDependencies, + documentation: documentation, + environment: environment, + executables: executables, + homepage: homepage, + issueTracker: issueTracker, + name: name, + publishTo: publishTo, + repository: repository, + version: version, + ); + } + +// ignore: unused_element + PubSpec fromJson(Map json) { + return PubSpec.fromJson(json); + } +} + +/// @nodoc +// ignore: unused_element +const $PubSpec = _$PubSpecTearOff(); + +/// @nodoc +mixin _$PubSpec { + Map get dependencies; + Map get dependencyOverrides; + String get description; + Map get devDependencies; + String get documentation; + Map get environment; + Map get executables; + String get homepage; + String get issueTracker; + String get name; + String get publishTo; + String get repository; + String get version; + + Map toJson(); + $PubSpecCopyWith get copyWith; +} + +/// @nodoc +abstract class $PubSpecCopyWith<$Res> { + factory $PubSpecCopyWith(PubSpec value, $Res Function(PubSpec) then) = + _$PubSpecCopyWithImpl<$Res>; + $Res call( + {Map dependencies, + Map dependencyOverrides, + String description, + Map devDependencies, + String documentation, + Map environment, + Map executables, + String homepage, + String issueTracker, + String name, + String publishTo, + String repository, + String version}); +} + +/// @nodoc +class _$PubSpecCopyWithImpl<$Res> implements $PubSpecCopyWith<$Res> { + _$PubSpecCopyWithImpl(this._value, this._then); + + final PubSpec _value; + // ignore: unused_field + final $Res Function(PubSpec) _then; + + @override + $Res call({ + Object dependencies = freezed, + Object dependencyOverrides = freezed, + Object description = freezed, + Object devDependencies = freezed, + Object documentation = freezed, + Object environment = freezed, + Object executables = freezed, + Object homepage = freezed, + Object issueTracker = freezed, + Object name = freezed, + Object publishTo = freezed, + Object repository = freezed, + Object version = freezed, + }) { + return _then(_value.copyWith( + dependencies: dependencies == freezed + ? _value.dependencies + : dependencies as Map, + dependencyOverrides: dependencyOverrides == freezed + ? _value.dependencyOverrides + : dependencyOverrides as Map, + description: + description == freezed ? _value.description : description as String, + devDependencies: devDependencies == freezed + ? _value.devDependencies + : devDependencies as Map, + documentation: documentation == freezed + ? _value.documentation + : documentation as String, + environment: environment == freezed + ? _value.environment + : environment as Map, + executables: executables == freezed + ? _value.executables + : executables as Map, + homepage: homepage == freezed ? _value.homepage : homepage as String, + issueTracker: issueTracker == freezed + ? _value.issueTracker + : issueTracker as String, + name: name == freezed ? _value.name : name as String, + publishTo: publishTo == freezed ? _value.publishTo : publishTo as String, + repository: + repository == freezed ? _value.repository : repository as String, + version: version == freezed ? _value.version : version as String, + )); + } +} + +/// @nodoc +abstract class _$PubspecCopyWith<$Res> implements $PubSpecCopyWith<$Res> { + factory _$PubspecCopyWith(_Pubspec value, $Res Function(_Pubspec) then) = + __$PubspecCopyWithImpl<$Res>; + @override + $Res call( + {Map dependencies, + Map dependencyOverrides, + String description, + Map devDependencies, + String documentation, + Map environment, + Map executables, + String homepage, + String issueTracker, + String name, + String publishTo, + String repository, + String version}); +} + +/// @nodoc +class __$PubspecCopyWithImpl<$Res> extends _$PubSpecCopyWithImpl<$Res> + implements _$PubspecCopyWith<$Res> { + __$PubspecCopyWithImpl(_Pubspec _value, $Res Function(_Pubspec) _then) + : super(_value, (v) => _then(v as _Pubspec)); + + @override + _Pubspec get _value => super._value as _Pubspec; + + @override + $Res call({ + Object dependencies = freezed, + Object dependencyOverrides = freezed, + Object description = freezed, + Object devDependencies = freezed, + Object documentation = freezed, + Object environment = freezed, + Object executables = freezed, + Object homepage = freezed, + Object issueTracker = freezed, + Object name = freezed, + Object publishTo = freezed, + Object repository = freezed, + Object version = freezed, + }) { + return _then(_Pubspec( + dependencies: dependencies == freezed + ? _value.dependencies + : dependencies as Map, + dependencyOverrides: dependencyOverrides == freezed + ? _value.dependencyOverrides + : dependencyOverrides as Map, + description: + description == freezed ? _value.description : description as String, + devDependencies: devDependencies == freezed + ? _value.devDependencies + : devDependencies as Map, + documentation: documentation == freezed + ? _value.documentation + : documentation as String, + environment: environment == freezed + ? _value.environment + : environment as Map, + executables: executables == freezed + ? _value.executables + : executables as Map, + homepage: homepage == freezed ? _value.homepage : homepage as String, + issueTracker: issueTracker == freezed + ? _value.issueTracker + : issueTracker as String, + name: name == freezed ? _value.name : name as String, + publishTo: publishTo == freezed ? _value.publishTo : publishTo as String, + repository: + repository == freezed ? _value.repository : repository as String, + version: version == freezed ? _value.version : version as String, + )); + } +} + +@JsonSerializable(fieldRename: FieldRename.snake) + +/// @nodoc +class _$_Pubspec implements _Pubspec { + _$_Pubspec( + {this.dependencies, + this.dependencyOverrides, + this.description, + this.devDependencies, + this.documentation, + this.environment, + this.executables, + this.homepage, + this.issueTracker, + this.name, + this.publishTo, + this.repository, + this.version}); + + factory _$_Pubspec.fromJson(Map json) => + _$_$_PubspecFromJson(json); + + @override + final Map dependencies; + @override + final Map dependencyOverrides; + @override + final String description; + @override + final Map devDependencies; + @override + final String documentation; + @override + final Map environment; + @override + final Map executables; + @override + final String homepage; + @override + final String issueTracker; + @override + final String name; + @override + final String publishTo; + @override + final String repository; + @override + final String version; + + @override + String toString() { + return 'PubSpec(dependencies: $dependencies, dependencyOverrides: $dependencyOverrides, description: $description, devDependencies: $devDependencies, documentation: $documentation, environment: $environment, executables: $executables, homepage: $homepage, issueTracker: $issueTracker, name: $name, publishTo: $publishTo, repository: $repository, version: $version)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _Pubspec && + (identical(other.dependencies, dependencies) || + const DeepCollectionEquality() + .equals(other.dependencies, dependencies)) && + (identical(other.dependencyOverrides, dependencyOverrides) || + const DeepCollectionEquality() + .equals(other.dependencyOverrides, dependencyOverrides)) && + (identical(other.description, description) || + const DeepCollectionEquality() + .equals(other.description, description)) && + (identical(other.devDependencies, devDependencies) || + const DeepCollectionEquality() + .equals(other.devDependencies, devDependencies)) && + (identical(other.documentation, documentation) || + const DeepCollectionEquality() + .equals(other.documentation, documentation)) && + (identical(other.environment, environment) || + const DeepCollectionEquality() + .equals(other.environment, environment)) && + (identical(other.executables, executables) || + const DeepCollectionEquality() + .equals(other.executables, executables)) && + (identical(other.homepage, homepage) || + const DeepCollectionEquality() + .equals(other.homepage, homepage)) && + (identical(other.issueTracker, issueTracker) || + const DeepCollectionEquality() + .equals(other.issueTracker, issueTracker)) && + (identical(other.name, name) || + const DeepCollectionEquality().equals(other.name, name)) && + (identical(other.publishTo, publishTo) || + const DeepCollectionEquality() + .equals(other.publishTo, publishTo)) && + (identical(other.repository, repository) || + const DeepCollectionEquality() + .equals(other.repository, repository)) && + (identical(other.version, version) || + const DeepCollectionEquality().equals(other.version, version))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(dependencies) ^ + const DeepCollectionEquality().hash(dependencyOverrides) ^ + const DeepCollectionEquality().hash(description) ^ + const DeepCollectionEquality().hash(devDependencies) ^ + const DeepCollectionEquality().hash(documentation) ^ + const DeepCollectionEquality().hash(environment) ^ + const DeepCollectionEquality().hash(executables) ^ + const DeepCollectionEquality().hash(homepage) ^ + const DeepCollectionEquality().hash(issueTracker) ^ + const DeepCollectionEquality().hash(name) ^ + const DeepCollectionEquality().hash(publishTo) ^ + const DeepCollectionEquality().hash(repository) ^ + const DeepCollectionEquality().hash(version); + + @override + _$PubspecCopyWith<_Pubspec> get copyWith => + __$PubspecCopyWithImpl<_Pubspec>(this, _$identity); + + @override + Map toJson() { + return _$_$_PubspecToJson(this); + } +} + +abstract class _Pubspec implements PubSpec { + factory _Pubspec( + {Map dependencies, + Map dependencyOverrides, + String description, + Map devDependencies, + String documentation, + Map environment, + Map executables, + String homepage, + String issueTracker, + String name, + String publishTo, + String repository, + String version}) = _$_Pubspec; + + factory _Pubspec.fromJson(Map json) = _$_Pubspec.fromJson; + + @override + Map get dependencies; + @override + Map get dependencyOverrides; + @override + String get description; + @override + Map get devDependencies; + @override + String get documentation; + @override + Map get environment; + @override + Map get executables; + @override + String get homepage; + @override + String get issueTracker; + @override + String get name; + @override + String get publishTo; + @override + String get repository; + @override + String get version; + @override + _$PubspecCopyWith<_Pubspec> get copyWith; +} + +Dependency _$DependencyFromJson(Map json) { + return _Dependency.fromJson(json); +} + +/// @nodoc +class _$DependencyTearOff { + const _$DependencyTearOff(); + +// ignore: unused_element + _Dependency call( + {String sdk, String version, Hosted hosted, dynamic git, String path}) { + return _Dependency( + sdk: sdk, + version: version, + hosted: hosted, + git: git, + path: path, + ); + } + +// ignore: unused_element + Dependency fromJson(Map json) { + return Dependency.fromJson(json); + } +} + +/// @nodoc +// ignore: unused_element +const $Dependency = _$DependencyTearOff(); + +/// @nodoc +mixin _$Dependency { + String get sdk; + String get version; + Hosted get hosted; + dynamic get git; + String get path; + + Map toJson(); + $DependencyCopyWith get copyWith; +} + +/// @nodoc +abstract class $DependencyCopyWith<$Res> { + factory $DependencyCopyWith( + Dependency value, $Res Function(Dependency) then) = + _$DependencyCopyWithImpl<$Res>; + $Res call( + {String sdk, String version, Hosted hosted, dynamic git, String path}); + + $HostedCopyWith<$Res> get hosted; +} + +/// @nodoc +class _$DependencyCopyWithImpl<$Res> implements $DependencyCopyWith<$Res> { + _$DependencyCopyWithImpl(this._value, this._then); + + final Dependency _value; + // ignore: unused_field + final $Res Function(Dependency) _then; + + @override + $Res call({ + Object sdk = freezed, + Object version = freezed, + Object hosted = freezed, + Object git = freezed, + Object path = freezed, + }) { + return _then(_value.copyWith( + sdk: sdk == freezed ? _value.sdk : sdk as String, + version: version == freezed ? _value.version : version as String, + hosted: hosted == freezed ? _value.hosted : hosted as Hosted, + git: git == freezed ? _value.git : git as dynamic, + path: path == freezed ? _value.path : path as String, + )); + } + + @override + $HostedCopyWith<$Res> get hosted { + if (_value.hosted == null) { + return null; + } + return $HostedCopyWith<$Res>(_value.hosted, (value) { + return _then(_value.copyWith(hosted: value)); + }); + } +} + +/// @nodoc +abstract class _$DependencyCopyWith<$Res> implements $DependencyCopyWith<$Res> { + factory _$DependencyCopyWith( + _Dependency value, $Res Function(_Dependency) then) = + __$DependencyCopyWithImpl<$Res>; + @override + $Res call( + {String sdk, String version, Hosted hosted, dynamic git, String path}); + + @override + $HostedCopyWith<$Res> get hosted; +} + +/// @nodoc +class __$DependencyCopyWithImpl<$Res> extends _$DependencyCopyWithImpl<$Res> + implements _$DependencyCopyWith<$Res> { + __$DependencyCopyWithImpl( + _Dependency _value, $Res Function(_Dependency) _then) + : super(_value, (v) => _then(v as _Dependency)); + + @override + _Dependency get _value => super._value as _Dependency; + + @override + $Res call({ + Object sdk = freezed, + Object version = freezed, + Object hosted = freezed, + Object git = freezed, + Object path = freezed, + }) { + return _then(_Dependency( + sdk: sdk == freezed ? _value.sdk : sdk as String, + version: version == freezed ? _value.version : version as String, + hosted: hosted == freezed ? _value.hosted : hosted as Hosted, + git: git == freezed ? _value.git : git as dynamic, + path: path == freezed ? _value.path : path as String, + )); + } +} + +@JsonSerializable() + +/// @nodoc +class _$_Dependency implements _Dependency { + _$_Dependency({this.sdk, this.version, this.hosted, this.git, this.path}); + + factory _$_Dependency.fromJson(Map json) => + _$_$_DependencyFromJson(json); + + @override + final String sdk; + @override + final String version; + @override + final Hosted hosted; + @override + final dynamic git; + @override + final String path; + + @override + String toString() { + return 'Dependency(sdk: $sdk, version: $version, hosted: $hosted, git: $git, path: $path)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _Dependency && + (identical(other.sdk, sdk) || + const DeepCollectionEquality().equals(other.sdk, sdk)) && + (identical(other.version, version) || + const DeepCollectionEquality() + .equals(other.version, version)) && + (identical(other.hosted, hosted) || + const DeepCollectionEquality().equals(other.hosted, hosted)) && + (identical(other.git, git) || + const DeepCollectionEquality().equals(other.git, git)) && + (identical(other.path, path) || + const DeepCollectionEquality().equals(other.path, path))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(sdk) ^ + const DeepCollectionEquality().hash(version) ^ + const DeepCollectionEquality().hash(hosted) ^ + const DeepCollectionEquality().hash(git) ^ + const DeepCollectionEquality().hash(path); + + @override + _$DependencyCopyWith<_Dependency> get copyWith => + __$DependencyCopyWithImpl<_Dependency>(this, _$identity); + + @override + Map toJson() { + return _$_$_DependencyToJson(this); + } +} + +abstract class _Dependency implements Dependency { + factory _Dependency( + {String sdk, + String version, + Hosted hosted, + dynamic git, + String path}) = _$_Dependency; + + factory _Dependency.fromJson(Map json) = + _$_Dependency.fromJson; + + @override + String get sdk; + @override + String get version; + @override + Hosted get hosted; + @override + dynamic get git; + @override + String get path; + @override + _$DependencyCopyWith<_Dependency> get copyWith; +} + +GitClass _$GitClassFromJson(Map json) { + return _GitClass.fromJson(json); +} + +/// @nodoc +class _$GitClassTearOff { + const _$GitClassTearOff(); + +// ignore: unused_element + _GitClass call({String path, String ref, String url}) { + return _GitClass( + path: path, + ref: ref, + url: url, + ); + } + +// ignore: unused_element + GitClass fromJson(Map json) { + return GitClass.fromJson(json); + } +} + +/// @nodoc +// ignore: unused_element +const $GitClass = _$GitClassTearOff(); + +/// @nodoc +mixin _$GitClass { + String get path; + String get ref; + String get url; + + Map toJson(); + $GitClassCopyWith get copyWith; +} + +/// @nodoc +abstract class $GitClassCopyWith<$Res> { + factory $GitClassCopyWith(GitClass value, $Res Function(GitClass) then) = + _$GitClassCopyWithImpl<$Res>; + $Res call({String path, String ref, String url}); +} + +/// @nodoc +class _$GitClassCopyWithImpl<$Res> implements $GitClassCopyWith<$Res> { + _$GitClassCopyWithImpl(this._value, this._then); + + final GitClass _value; + // ignore: unused_field + final $Res Function(GitClass) _then; + + @override + $Res call({ + Object path = freezed, + Object ref = freezed, + Object url = freezed, + }) { + return _then(_value.copyWith( + path: path == freezed ? _value.path : path as String, + ref: ref == freezed ? _value.ref : ref as String, + url: url == freezed ? _value.url : url as String, + )); + } +} + +/// @nodoc +abstract class _$GitClassCopyWith<$Res> implements $GitClassCopyWith<$Res> { + factory _$GitClassCopyWith(_GitClass value, $Res Function(_GitClass) then) = + __$GitClassCopyWithImpl<$Res>; + @override + $Res call({String path, String ref, String url}); +} + +/// @nodoc +class __$GitClassCopyWithImpl<$Res> extends _$GitClassCopyWithImpl<$Res> + implements _$GitClassCopyWith<$Res> { + __$GitClassCopyWithImpl(_GitClass _value, $Res Function(_GitClass) _then) + : super(_value, (v) => _then(v as _GitClass)); + + @override + _GitClass get _value => super._value as _GitClass; + + @override + $Res call({ + Object path = freezed, + Object ref = freezed, + Object url = freezed, + }) { + return _then(_GitClass( + path: path == freezed ? _value.path : path as String, + ref: ref == freezed ? _value.ref : ref as String, + url: url == freezed ? _value.url : url as String, + )); + } +} + +@JsonSerializable() + +/// @nodoc +class _$_GitClass implements _GitClass { + _$_GitClass({this.path, this.ref, this.url}); + + factory _$_GitClass.fromJson(Map json) => + _$_$_GitClassFromJson(json); + + @override + final String path; + @override + final String ref; + @override + final String url; + + @override + String toString() { + return 'GitClass(path: $path, ref: $ref, url: $url)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _GitClass && + (identical(other.path, path) || + const DeepCollectionEquality().equals(other.path, path)) && + (identical(other.ref, ref) || + const DeepCollectionEquality().equals(other.ref, ref)) && + (identical(other.url, url) || + const DeepCollectionEquality().equals(other.url, url))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(path) ^ + const DeepCollectionEquality().hash(ref) ^ + const DeepCollectionEquality().hash(url); + + @override + _$GitClassCopyWith<_GitClass> get copyWith => + __$GitClassCopyWithImpl<_GitClass>(this, _$identity); + + @override + Map toJson() { + return _$_$_GitClassToJson(this); + } +} + +abstract class _GitClass implements GitClass { + factory _GitClass({String path, String ref, String url}) = _$_GitClass; + + factory _GitClass.fromJson(Map json) = _$_GitClass.fromJson; + + @override + String get path; + @override + String get ref; + @override + String get url; + @override + _$GitClassCopyWith<_GitClass> get copyWith; +} + +Hosted _$HostedFromJson(Map json) { + return _Hosted.fromJson(json); +} + +/// @nodoc +class _$HostedTearOff { + const _$HostedTearOff(); + +// ignore: unused_element + _Hosted call({String name, String url}) { + return _Hosted( + name: name, + url: url, + ); + } + +// ignore: unused_element + Hosted fromJson(Map json) { + return Hosted.fromJson(json); + } +} + +/// @nodoc +// ignore: unused_element +const $Hosted = _$HostedTearOff(); + +/// @nodoc +mixin _$Hosted { + String get name; + String get url; + + Map toJson(); + $HostedCopyWith get copyWith; +} + +/// @nodoc +abstract class $HostedCopyWith<$Res> { + factory $HostedCopyWith(Hosted value, $Res Function(Hosted) then) = + _$HostedCopyWithImpl<$Res>; + $Res call({String name, String url}); +} + +/// @nodoc +class _$HostedCopyWithImpl<$Res> implements $HostedCopyWith<$Res> { + _$HostedCopyWithImpl(this._value, this._then); + + final Hosted _value; + // ignore: unused_field + final $Res Function(Hosted) _then; + + @override + $Res call({ + Object name = freezed, + Object url = freezed, + }) { + return _then(_value.copyWith( + name: name == freezed ? _value.name : name as String, + url: url == freezed ? _value.url : url as String, + )); + } +} + +/// @nodoc +abstract class _$HostedCopyWith<$Res> implements $HostedCopyWith<$Res> { + factory _$HostedCopyWith(_Hosted value, $Res Function(_Hosted) then) = + __$HostedCopyWithImpl<$Res>; + @override + $Res call({String name, String url}); +} + +/// @nodoc +class __$HostedCopyWithImpl<$Res> extends _$HostedCopyWithImpl<$Res> + implements _$HostedCopyWith<$Res> { + __$HostedCopyWithImpl(_Hosted _value, $Res Function(_Hosted) _then) + : super(_value, (v) => _then(v as _Hosted)); + + @override + _Hosted get _value => super._value as _Hosted; + + @override + $Res call({ + Object name = freezed, + Object url = freezed, + }) { + return _then(_Hosted( + name: name == freezed ? _value.name : name as String, + url: url == freezed ? _value.url : url as String, + )); + } +} + +@JsonSerializable() + +/// @nodoc +class _$_Hosted implements _Hosted { + _$_Hosted({this.name, this.url}); + + factory _$_Hosted.fromJson(Map json) => + _$_$_HostedFromJson(json); + + @override + final String name; + @override + final String url; + + @override + String toString() { + return 'Hosted(name: $name, url: $url)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _Hosted && + (identical(other.name, name) || + const DeepCollectionEquality().equals(other.name, name)) && + (identical(other.url, url) || + const DeepCollectionEquality().equals(other.url, url))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(name) ^ + const DeepCollectionEquality().hash(url); + + @override + _$HostedCopyWith<_Hosted> get copyWith => + __$HostedCopyWithImpl<_Hosted>(this, _$identity); + + @override + Map toJson() { + return _$_$_HostedToJson(this); + } +} + +abstract class _Hosted implements Hosted { + factory _Hosted({String name, String url}) = _$_Hosted; + + factory _Hosted.fromJson(Map json) = _$_Hosted.fromJson; + + @override + String get name; + @override + String get url; + @override + _$HostedCopyWith<_Hosted> get copyWith; +} diff --git a/lib/src/models/pubspec_model.g.dart b/lib/src/models/pubspec_model.g.dart new file mode 100644 index 0000000..da0639d --- /dev/null +++ b/lib/src/models/pubspec_model.g.dart @@ -0,0 +1,92 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pubspec_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_Pubspec _$_$_PubspecFromJson(Map json) { + return _$_Pubspec( + dependencies: json['dependencies'] as Map, + dependencyOverrides: json['dependency_overrides'] as Map, + description: json['description'] as String, + devDependencies: json['dev_dependencies'] as Map, + documentation: json['documentation'] as String, + environment: (json['environment'] as Map)?.map( + (k, e) => MapEntry(k, e as String), + ), + executables: json['executables'] as Map, + homepage: json['homepage'] as String, + issueTracker: json['issue_tracker'] as String, + name: json['name'] as String, + publishTo: json['publish_to'] as String, + repository: json['repository'] as String, + version: json['version'] as String, + ); +} + +Map _$_$_PubspecToJson(_$_Pubspec instance) => + { + 'dependencies': instance.dependencies, + 'dependency_overrides': instance.dependencyOverrides, + 'description': instance.description, + 'dev_dependencies': instance.devDependencies, + 'documentation': instance.documentation, + 'environment': instance.environment, + 'executables': instance.executables, + 'homepage': instance.homepage, + 'issue_tracker': instance.issueTracker, + 'name': instance.name, + 'publish_to': instance.publishTo, + 'repository': instance.repository, + 'version': instance.version, + }; + +_$_Dependency _$_$_DependencyFromJson(Map json) { + return _$_Dependency( + sdk: json['sdk'] as String, + version: json['version'] as String, + hosted: json['hosted'] == null + ? null + : Hosted.fromJson(json['hosted'] as Map), + git: json['git'], + path: json['path'] as String, + ); +} + +Map _$_$_DependencyToJson(_$_Dependency instance) => + { + 'sdk': instance.sdk, + 'version': instance.version, + 'hosted': instance.hosted, + 'git': instance.git, + 'path': instance.path, + }; + +_$_GitClass _$_$_GitClassFromJson(Map json) { + return _$_GitClass( + path: json['path'] as String, + ref: json['ref'] as String, + url: json['url'] as String, + ); +} + +Map _$_$_GitClassToJson(_$_GitClass instance) => + { + 'path': instance.path, + 'ref': instance.ref, + 'url': instance.url, + }; + +_$_Hosted _$_$_HostedFromJson(Map json) { + return _$_Hosted( + name: json['name'] as String, + url: json['url'] as String, + ); +} + +Map _$_$_HostedToJson(_$_Hosted instance) => { + 'name': instance.name, + 'url': instance.url, + }; diff --git a/lib/src/models/search_results_model.dart b/lib/src/models/search_results_model.dart new file mode 100644 index 0000000..b9eeaa3 --- /dev/null +++ b/lib/src/models/search_results_model.dart @@ -0,0 +1,33 @@ +import 'dart:convert'; + +import 'package:http/http.dart' as http; + +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'search_results_model.freezed.dart'; +part 'search_results_model.g.dart'; + +@freezed +abstract class SearchResults implements _$SearchResults { + const SearchResults._(); + factory SearchResults({ + final List packages, + String next, + }) = _SearchResults; + + factory SearchResults.fromJson(Map json) => + _$SearchResultsFromJson(json); + + Future nextResults() async { + final response = await http.get(next); + return SearchResults.fromJson(jsonDecode(response.body)); + } +} + +@freezed +abstract class PackageResult with _$PackageResult { + factory PackageResult({String package}) = _PackageResult; + + factory PackageResult.fromJson(Map json) => + _$PackageResultFromJson(json); +} diff --git a/lib/src/models/search_results_model.freezed.dart b/lib/src/models/search_results_model.freezed.dart new file mode 100644 index 0000000..3d418b9 --- /dev/null +++ b/lib/src/models/search_results_model.freezed.dart @@ -0,0 +1,314 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies + +part of 'search_results_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; +SearchResults _$SearchResultsFromJson(Map json) { + return _SearchResults.fromJson(json); +} + +/// @nodoc +class _$SearchResultsTearOff { + const _$SearchResultsTearOff(); + +// ignore: unused_element + _SearchResults call({List packages, String next}) { + return _SearchResults( + packages: packages, + next: next, + ); + } + +// ignore: unused_element + SearchResults fromJson(Map json) { + return SearchResults.fromJson(json); + } +} + +/// @nodoc +// ignore: unused_element +const $SearchResults = _$SearchResultsTearOff(); + +/// @nodoc +mixin _$SearchResults { + List get packages; + String get next; + + Map toJson(); + $SearchResultsCopyWith get copyWith; +} + +/// @nodoc +abstract class $SearchResultsCopyWith<$Res> { + factory $SearchResultsCopyWith( + SearchResults value, $Res Function(SearchResults) then) = + _$SearchResultsCopyWithImpl<$Res>; + $Res call({List packages, String next}); +} + +/// @nodoc +class _$SearchResultsCopyWithImpl<$Res> + implements $SearchResultsCopyWith<$Res> { + _$SearchResultsCopyWithImpl(this._value, this._then); + + final SearchResults _value; + // ignore: unused_field + final $Res Function(SearchResults) _then; + + @override + $Res call({ + Object packages = freezed, + Object next = freezed, + }) { + return _then(_value.copyWith( + packages: packages == freezed + ? _value.packages + : packages as List, + next: next == freezed ? _value.next : next as String, + )); + } +} + +/// @nodoc +abstract class _$SearchResultsCopyWith<$Res> + implements $SearchResultsCopyWith<$Res> { + factory _$SearchResultsCopyWith( + _SearchResults value, $Res Function(_SearchResults) then) = + __$SearchResultsCopyWithImpl<$Res>; + @override + $Res call({List packages, String next}); +} + +/// @nodoc +class __$SearchResultsCopyWithImpl<$Res> + extends _$SearchResultsCopyWithImpl<$Res> + implements _$SearchResultsCopyWith<$Res> { + __$SearchResultsCopyWithImpl( + _SearchResults _value, $Res Function(_SearchResults) _then) + : super(_value, (v) => _then(v as _SearchResults)); + + @override + _SearchResults get _value => super._value as _SearchResults; + + @override + $Res call({ + Object packages = freezed, + Object next = freezed, + }) { + return _then(_SearchResults( + packages: packages == freezed + ? _value.packages + : packages as List, + next: next == freezed ? _value.next : next as String, + )); + } +} + +@JsonSerializable() + +/// @nodoc +class _$_SearchResults extends _SearchResults { + _$_SearchResults({this.packages, this.next}) : super._(); + + factory _$_SearchResults.fromJson(Map json) => + _$_$_SearchResultsFromJson(json); + + @override + final List packages; + @override + final String next; + + @override + String toString() { + return 'SearchResults(packages: $packages, next: $next)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _SearchResults && + (identical(other.packages, packages) || + const DeepCollectionEquality() + .equals(other.packages, packages)) && + (identical(other.next, next) || + const DeepCollectionEquality().equals(other.next, next))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(packages) ^ + const DeepCollectionEquality().hash(next); + + @override + _$SearchResultsCopyWith<_SearchResults> get copyWith => + __$SearchResultsCopyWithImpl<_SearchResults>(this, _$identity); + + @override + Map toJson() { + return _$_$_SearchResultsToJson(this); + } +} + +abstract class _SearchResults extends SearchResults { + _SearchResults._() : super._(); + factory _SearchResults({List packages, String next}) = + _$_SearchResults; + + factory _SearchResults.fromJson(Map json) = + _$_SearchResults.fromJson; + + @override + List get packages; + @override + String get next; + @override + _$SearchResultsCopyWith<_SearchResults> get copyWith; +} + +PackageResult _$PackageResultFromJson(Map json) { + return _PackageResult.fromJson(json); +} + +/// @nodoc +class _$PackageResultTearOff { + const _$PackageResultTearOff(); + +// ignore: unused_element + _PackageResult call({String package}) { + return _PackageResult( + package: package, + ); + } + +// ignore: unused_element + PackageResult fromJson(Map json) { + return PackageResult.fromJson(json); + } +} + +/// @nodoc +// ignore: unused_element +const $PackageResult = _$PackageResultTearOff(); + +/// @nodoc +mixin _$PackageResult { + String get package; + + Map toJson(); + $PackageResultCopyWith get copyWith; +} + +/// @nodoc +abstract class $PackageResultCopyWith<$Res> { + factory $PackageResultCopyWith( + PackageResult value, $Res Function(PackageResult) then) = + _$PackageResultCopyWithImpl<$Res>; + $Res call({String package}); +} + +/// @nodoc +class _$PackageResultCopyWithImpl<$Res> + implements $PackageResultCopyWith<$Res> { + _$PackageResultCopyWithImpl(this._value, this._then); + + final PackageResult _value; + // ignore: unused_field + final $Res Function(PackageResult) _then; + + @override + $Res call({ + Object package = freezed, + }) { + return _then(_value.copyWith( + package: package == freezed ? _value.package : package as String, + )); + } +} + +/// @nodoc +abstract class _$PackageResultCopyWith<$Res> + implements $PackageResultCopyWith<$Res> { + factory _$PackageResultCopyWith( + _PackageResult value, $Res Function(_PackageResult) then) = + __$PackageResultCopyWithImpl<$Res>; + @override + $Res call({String package}); +} + +/// @nodoc +class __$PackageResultCopyWithImpl<$Res> + extends _$PackageResultCopyWithImpl<$Res> + implements _$PackageResultCopyWith<$Res> { + __$PackageResultCopyWithImpl( + _PackageResult _value, $Res Function(_PackageResult) _then) + : super(_value, (v) => _then(v as _PackageResult)); + + @override + _PackageResult get _value => super._value as _PackageResult; + + @override + $Res call({ + Object package = freezed, + }) { + return _then(_PackageResult( + package: package == freezed ? _value.package : package as String, + )); + } +} + +@JsonSerializable() + +/// @nodoc +class _$_PackageResult implements _PackageResult { + _$_PackageResult({this.package}); + + factory _$_PackageResult.fromJson(Map json) => + _$_$_PackageResultFromJson(json); + + @override + final String package; + + @override + String toString() { + return 'PackageResult(package: $package)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _PackageResult && + (identical(other.package, package) || + const DeepCollectionEquality().equals(other.package, package))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(package); + + @override + _$PackageResultCopyWith<_PackageResult> get copyWith => + __$PackageResultCopyWithImpl<_PackageResult>(this, _$identity); + + @override + Map toJson() { + return _$_$_PackageResultToJson(this); + } +} + +abstract class _PackageResult implements PackageResult { + factory _PackageResult({String package}) = _$_PackageResult; + + factory _PackageResult.fromJson(Map json) = + _$_PackageResult.fromJson; + + @override + String get package; + @override + _$PackageResultCopyWith<_PackageResult> get copyWith; +} diff --git a/lib/src/models/search_results_model.g.dart b/lib/src/models/search_results_model.g.dart new file mode 100644 index 0000000..b9a9713 --- /dev/null +++ b/lib/src/models/search_results_model.g.dart @@ -0,0 +1,35 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'search_results_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_SearchResults _$_$_SearchResultsFromJson(Map json) { + return _$_SearchResults( + packages: (json['packages'] as List) + ?.map((e) => e == null + ? null + : PackageResult.fromJson(e as Map)) + ?.toList(), + next: json['next'] as String, + ); +} + +Map _$_$_SearchResultsToJson(_$_SearchResults instance) => + { + 'packages': instance.packages, + 'next': instance.next, + }; + +_$_PackageResult _$_$_PackageResultFromJson(Map json) { + return _$_PackageResult( + package: json['package'] as String, + ); +} + +Map _$_$_PackageResultToJson(_$_PackageResult instance) => + { + 'package': instance.package, + }; diff --git a/lib/src/pub_api_client_base.dart b/lib/src/pub_api_client_base.dart new file mode 100644 index 0000000..50f3146 --- /dev/null +++ b/lib/src/pub_api_client_base.dart @@ -0,0 +1,56 @@ +import 'dart:convert'; + +import 'package:http/http.dart' as http; + +import 'package:pub_api_client/src/models/package_score_model.dart'; +import 'package:pub_api_client/src/models/pub_package_model.dart'; +import 'package:pub_api_client/src/models/search_results_model.dart'; +import 'package:pub_api_client/src/version.dart'; + +const _urlBase = 'https://pub.dartlang.org'; +const _searchUrl = '$_urlBase/api/search'; +const _packageUrl = '$_urlBase/api/packages'; + +String _packageScoreUrl(String name) => '$_urlBase/api/packages/$name/score'; +String _versionsUrl(String name) => 'https://pub.dev/packages/$name.json'; + +final _httpHeaders = {'User-Agent': 'package:pub_client/$packageVersion'}; + +Future _fetch(dynamic url) async { + return await http.get(url, headers: _httpHeaders); +} + +/// Pub API Client +class PubClient { + PubClient(); + + /// Returns the package information for `name` + Future getPackage(String name) async { + final response = await _fetch('$_packageUrl/$name'); + return PubPackage.fromJson(jsonDecode(response.body)); + } + + /// Returns the score for package `name` + Future getScore(String name) async { + final response = await _fetch(_packageScoreUrl(name)); + return PackageScore.fromJson(jsonDecode(response.body)); + } + + /// Searches pub for `query` and can `page` results. + Future search(String query, {int page = 1}) async { + final response = await _fetch('$_searchUrl?q=$query&page=$page'); + + return SearchResults.fromJson(jsonDecode(response.body)); + } + + /// Returns the versions that are published for package `name` + Future> getVersions(String name) async { + final response = await _fetch(_versionsUrl(name)); + final json = jsonDecode(response.body); + final versions = []; + for (var version in json['versions']) { + versions.add(version); + } + return versions; + } +} diff --git a/lib/src/version.dart b/lib/src/version.dart new file mode 100644 index 0000000..ee68207 --- /dev/null +++ b/lib/src/version.dart @@ -0,0 +1,2 @@ +// Generated code. Do not modify. +const packageVersion = '1.0.3'; diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..cc06cac --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,23 @@ +name: pub_api_client +description: An API Client for Pub to interact with public package information. +version: 1.0.3 +homepage: https://github.com/leoafarias/pub_api_client + +environment: + sdk: '>=2.8.1 <3.0.0' + +dependencies: + http: ^0.12.2 + freezed_annotation: ^0.12.0 + json_annotation: ^3.1.0 + meta: ^1.2.3 + +dev_dependencies: + pedantic: ^1.9.2 + test: ^1.15.4 + build_runner: ^1.10.3 + build_version: ^2.0.1 + test_coverage: ^0.4.3 + freezed: ^0.12.2 + json_serializable: ^3.5.0 + remove_from_coverage: ^1.0.7 diff --git a/test/pubdev_api_test.dart b/test/pubdev_api_test.dart new file mode 100644 index 0000000..fbed34b --- /dev/null +++ b/test/pubdev_api_test.dart @@ -0,0 +1,48 @@ +import 'package:pub_api_client/pub_api_client.dart'; +import 'package:test/test.dart'; + +void main() { + group('PubDev Client', () { + PubClient client; + + setUp(() { + client = PubClient(); + }); + + test('Can Fetch package info', () async { + final packageName = 'fvm'; + final packageInfo = await client.getPackage(packageName); + + final lastPubspec = packageInfo.latest.pubspec; + expect(packageInfo.version, lastPubspec.version); + expect(packageInfo.description, lastPubspec.description); + expect(packageInfo.url, 'https://pub.dev/packages/$packageName'); + expect(packageInfo.name, packageName); + }); + + test('Get package versions', () async { + final packageName = 'fvm'; + final packageInfo = await client.getPackage(packageName); + final payload = await client.getVersions(packageName); + + expect(payload.length, greaterThan(0)); + expect(payload.length, packageInfo.versions.length); + }); + + test('Search for packages', () async { + final payload = await client.search('json'); + final nextPagePayload = await payload.nextResults(); + expect(payload.packages.length, greaterThan(1)); + expect(nextPagePayload.packages.length, greaterThan(1)); + }); + + test('Get Package Score', () async { + final payload = await client.getScore('fvm'); + + expect(payload.lastUpdated, isNotNull); + expect(payload.grantedPoints, isNotNull); + expect(payload.likeCount, greaterThan(50)); + expect(payload.maxPoints, 110); + }); + }); +}