Coder Social home page Coder Social logo

leoafarias / pub_api_client Goto Github PK

View Code? Open in Web Editor NEW
92.0 2.0 19.0 260 KB

The most complete & unofficial API Client for Dart Pub.dev

Home Page: https://pub.dev/packages/pub_api_client

License: MIT License

Dart 100.00%
pub api dart flutter

pub_api_client's People

Contributors

ashutosh2014 avatar gmpassos avatar jxstxn1 avatar kevmoo avatar leoafarias avatar rexios80 avatar tsuruobiz avatar xvrh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pub_api_client's Issues

packageNameCompletion() does not work

Looking at the source, trying to find something that would just list all the available package names, I found the below function:

/// Returns a List<String> of all packages listed on pub.dev
Future<List> packageNameCompletion() async

Unfortunately, that does not appear to work, but causes an unhandled exception:

Unhandled exception:

#0 responseValidOrThrow (package:pub_api_client/src/helpers/exceptions.dart:55:7)
#1 PubClient._fetch (package:pub_api_client/src/pub_api_client_base.dart:54:5)

#2 PubClient.packageNameCompletion (package:pub_api_client/src/pub_api_client_base.dart:126:18)

Add repository and issue_tracker to pubspec data

If we make the following GET request: https://pub.dev/api/packages/go_router/versions/13.2.0 which is reflected in the Package as packageVersionInfo we receive in the pubspec section repository and issue_tracker.

It would be great if we could add them as nullable strings to this package

Expose model classes

Would it be possible to expose the model classes from src too ? (like SearchResults)

Now we're not able to have type annotations for them. :'(

Thanks for the package!

How to authenticate the user for likes

Hey,
First and foremost, thank you for this awesome package.

So I have a very simple application where users can like pub packages. However as mentioned in the documentation, I will need to authenticate the user. Could you perhaps elaborate on how to authenticate?

Thank you.

feature request: expand fetchFlutterFavorites

Hi everyone, for one of my side projects I'm using this package to create a desktop app to browse pub.dev using the same concept of the AppStore, Windows Store, or other stores on Linux distros.

In my case I need to create a section with the list of packages of the Flutter Favorite program and those associated with Google that can be retrieved respectively with this two APIs:

  • fetchGooglePackages
  • fetchFlutterFavorites

Unfortunately, these two functions only return the List <String> with the package names while in my case I would need the complete information about the package represented by the PubPackage object. Right now I solved this issue by calling the fetchFlutterFavorites and after that in another widget call the packageInfo API to get all the info, something like that using Riverpod:

final allFlutterFavoritesProvider = FutureProvider.autoDispose<List<String>>((ref) async {
  return await PubClient().fetchFlutterFavorites();
});

final singlePackageProvider = FutureProvider.autoDispose.family<PubPackage, String>((ref, packageName) async {
  return await PubClient().packageInfo(packageName);
});

[...]

Widget build(BuildContext context, WidgetRef ref) {
    AsyncValue<List<String>> allFlutterFavoritesList = ref.watch(allFlutterFavoritesProvider);

    return Column(
      children: [
        ...
        allFlutterFavoritesList.when(
          loading: ...
          error: ...
          data: (list) {
            return GridView.builder(
              shrinkWrap: true,
              gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 3,
                  crossAxisSpacing: kDefaultPagePadding,
                  mainAxisSpacing: kDefaultPagePadding),
              itemCount: list.length,
              itemBuilder: (_, int index) {
                return PackageGridBox(
                  packageName: list.elementAt(index),
                );
              },
            );
          },
        ),
      ],
    );
  }

[...]

class PackageGridBox extends ConsumerWidget {
  const PackageGridBox({Key? key, required this.packageName}) : super(key: key);

  final String packageName;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    AsyncValue<PubPackage> singlePackage = ref.watch(singlePackageProvider(packageName));

    return singlePackage.when(
      loading: ...
      error: ...
      data: (package) {
        return Container(
          decoration: kDefaultBoxDecoration(context),
          child: Text(package.toString()),
        );
      },
    );
  }
}

Do you think it might be useful to add an API that allows you to immediately have all the information about the packages and not just the package name? Something like that:

/// Retrieves all the flutter favorites PubPackage
Future<List<PubPackage>> fetchFlutterFavoritesPubPackage() async {
  final searchResults = await search('is:flutter-favorite');
  final results = await recursivePaging(this, searchResults);
  return await Future.wait(
    results.map((r) => packageInfo(r.package)).toList());
}

I know that for all the packages you must wait for all the packageInfo calls but it might be useful to someone.

Best regards,
Alberto

PubClientException assumes valid json for toString method.

Problem

Experimented with some client mocking and mocked that a 404 request was returned with and empty response body = "".

Then I wanted to log the error message and called the toString() method on the exception.

final data = jsonDecode(_response.body);

Unfortunately the jsonDecode method seems to assume valid formatted json and throws an exception if the body is empty.

The same exception can be reproduced with the following example:

void main() {
  jsonDecode("");
}

Why this is an issue

Since we are already in exception land this additional exception is likely to jump the try/catch boundary we are currently operating in.

For example:

void main(String packageName) {
  try {
    var client = PubClient();
    client.packageVersions(packageName);
  } catch (e) {
    // Json decode exception is thrown here
    print(e);
  }
}

Suggested solution

Don't assume valid json formatting if the request has failed. Possibly try and decode the message but use a default error message if it fails.

Hangs before exit

I have a bit of code that calls await packageInfo(packageName) in a loop. The info is properly returned for each package queried.

Yet when I end the loop to exit the program, I don't get a prompt or in the android studio debugger the stop button is enabled as if the program were still running.

There's some sort of timeout that once reached, the program does exit.

I have tried using a single Client instance and one per query, with the same results.

If I were to guess, I'd say the HTTP socket is keep-alive and the code won't exit until that socket is closed.

If this is the case, my suggestion would be some sort of destroy(), close(), or cleanup() on the client instance to force close the socket.

I don't see one here:

https://pub.dev/documentation/pub_api_client/latest/pub_api_client/pub_api_client-library.html or

https://pub.dev/documentation/pub_api_client/latest/pub_api_client/PubClient-class.html

It's probably a good idea to implement such a function, even if it simply returns (for now).

PackageVersion.archiveUrl is never populated

Reason being that package pubspec has key archive_url, but toMap and fromMap refer to achiveUrl.

Fix in pub_package_model.dart is:

@@ -73,7 +73,7 @@ class PackageVersion {
   Map<String, dynamic> toMap() => {
         'version': version,
         'pubspec': pubspec.toJson(),
-        'archiveUrl': archiveUrl,
+        'archive_url': archiveUrl,
         'published': published.millisecondsSinceEpoch,
       };
 
@@ -81,7 +81,7 @@ class PackageVersion {
         version: map['version'] as String? ?? '',
         pubspec:
             PubSpec.fromJson(map['pubspec'] as Map<String, dynamic>? ?? {}),
-        archiveUrl: map['archiveUrl'] as String? ?? '',
+        archiveUrl: map['archive_url'] as String? ?? '',
         published: DateTime.parse(map['published'] as String? ?? ''),
       );

PackageScore fields can be null

If a package was recently updated, some of the information in PackageScore can be null. For example: grantedPubPoints and popularityScore. These should be handled by the client.

checkLatest is referenced in the readme but no longer exists

I like the idea of having this feature, but right now it doesn't exist. Should we remove it from the readme or add it back to the client?

Ideally the client could get the package name and version from the local pubspec.yaml if desired, but maybe that's outside the scope of what this package should do.

Dependency upgrade failed with freezed

In one of my app I was trying to bump the version of freezed_annotation to the current version 2.1.0 and freezed version 2.1.0+1 but when I run flutter pub get the terminal shows me:

Running "flutter pub get" in pubhub...                          
Because pub_api_client 2.2.1 depends on freezed_annotation ^1.1.0 and no versions of pub_api_client match >2.2.1 <3.0.0, pub_api_client ^2.2.1 requires freezed_annotation ^1.1.0.
So, because pubhub depends on both freezed_annotation ^2.1.0 and pub_api_client ^2.2.1, version solving failed.
pub get failed (1; So, because pubhub depends on both freezed_annotation ^2.1.0 and pub_api_client ^2.2.1, version solving failed.)
exit code 1

So I have to leave freezed* versions like that:

dependencies:
  flutter:
    sdk: flutter
  ...
  freezed_annotation: ^1.1.0

dev_dependencies:
  ...
  freezed: ^1.1.1

Is it possible to upgrade freezed* versions to the latest 2.x.y?

Thanks,
Alberto

feature request: add support for Cloudsmith

I'm curious how much of a lift you feel it would be (or whether it's even possible) to expand this package to be able to interact with a third party hosting service such as Cloudsmith.

They must have a similar API set up at least for fetching package info and the latest version etc.

My guess is it's probably a better idea to create a separate client, but it would be really cool if we had something like a packages_info that supported querying for pub.dev packages as well as hosted packages.

My Use Case:

  1. We have an internal CLI tool written in Dart and published on Cloudsmith. I would like to add an "auto-update" feature where it checks every few hours if the package has a new version.
  2. I would like to add PR checks to my packages published on cloudsmith to make sure they are not about to publish a package version that is already published to Cloudsmith.

Any thoughts would be appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.