GNOME Bugzilla – Bug 785885
Expose information about quota usage
Last modified: 2017-08-08 18:54:36 UTC
Right now, libgdata does not have any API to report how much quota exists for the user and how much of it is currently free. Having such an API would let the google-drive GVFS backend report that info back up to clients. (bug 785870) Looks like this info can be found in the /drive/v2/about endpoint: https://developers.google.com/drive/v2/reference/about
I’m unlikely to have time to add this any time soon, but can provide help and feedback if you want to provide a patch. Are you able to do so? If so, that would be great.
Created attachment 357168 [details] [review] Add GDataDocumentsMetadata Here's a first pass. It adds a GDataDocumentsMetadata class and a way to get an instance for the service: gdata_documents_server_get_metadata. My only current interest was the quota information, but there is other bits of info that could be added to the class as time goes on. Most of this patch is pretty obvious, but there were some choices I've made that deserve discussion: 1) I've chosen to only report the usage in aggregate. The per-service information is not exposed at all right now. For one thing, the gmail and picassa usage info seems to go away in v3 of the API. For another, I'm not sure how useful that info is? Without an obvious use case, I didn't want to commit to an API for it. 2) I added support for the concept of an unlimited quota (available for business accounts) by simply reporting -1 for the total quota if quotaType is UNLIMITED. I could not test this in the wild, so I'm not sure what Google itself reports for the total quota in that case. We may also consider a separate API call, but this way seemed simple enough, especially since I couldn't vouch for what would normally be returned by gdata_documents_metadata_get_quota_total in that case if we didn't change it to -1. 3) I did not add any tests. The documents tests were disabled until the API is ported to v3? I didn't want to take that on, so I just skipped it. But I did manually test against my account.
Review of attachment 357168 [details] [review]: This looks good to me; the main problem is that there needs to be an async version of the network request, or the API will block. There are a few other minor comments below. Thanks for working on this. ::: docs/reference/gdata-sections.txt @@ +1821,3 @@ +GDataDocumentsMetadata +GDataDocumentsMetadataClass +gdata_documents_metadata_new Does metadata_new() exist? (It shouldn’t, since all this data is read-only.) ::: gdata/services/documents/gdata-documents-metadata.c @@ +27,3 @@ + * + * For more details of Google Documents' GData API, see the + * <ulink type="http" url="https://developers.google.com/google-apps/documents-list/">online documentation</ulink>. This URI is out of date; it’s now: https://developers.google.com/drive/v2/web/about-sdk @@ +78,3 @@ + * The user quota limit across all services. Measured in bytes. + * + * Since: 0.13.0 This ‘Since’ line is wrong. @@ +91,3 @@ + * The amount of user quota used up across all services. Measured in bytes. + * + * Since: 0.13.0 This ‘Since’ line is wrong. ::: gdata/services/documents/gdata-documents-service.c @@ +423,3 @@ + */ +GDataDocumentsMetadata * +gdata_documents_service_get_metadata (GDataDocumentsService *self, GCancellable *cancellable, GError **error) There should be an _async() version of this method, which should be the preferred way of getting the data, since it does a network request — we don’t want to block the caller while doing so. This otherwise looks good though.
(In reply to Michael Terry from comment #2) > 1) I've chosen to only report the usage in aggregate. The per-service > information is not exposed at all right now. For one thing, the gmail and > picassa usage info seems to go away in v3 of the API. For another, I'm not > sure how useful that info is? Without an obvious use case, I didn't want to > commit to an API for it. Seems reasonable to do this for now. > 2) I added support for the concept of an unlimited quota (available for > business accounts) by simply reporting -1 for the total quota if quotaType > is UNLIMITED. I could not test this in the wild, so I'm not sure what Google > itself reports for the total quota in that case. We may also consider a > separate API call, but this way seemed simple enough, especially since I > couldn't vouch for what would normally be returned by > gdata_documents_metadata_get_quota_total in that case if we didn't change it > to -1. This seems reasonable enough. I just tried with a Google for domains account, but it’s also limited, so returned the same result schema as a free account. > 3) I did not add any tests. The documents tests were disabled until the API > is ported to v3? I didn't want to take that on, so I just skipped it. But > I did manually test against my account. OK, ideally there would be tests, but I don’t expect you to shave that yak.
Created attachment 357203 [details] [review] v2 with async method Here's v2, with an async version and the other issues resolved too. Thanks for the review!
Oh. Should we do some sanity validating here? For example, making sure quota_used>=0 or that when limited, quota_total>=quota_used? Or does libgdata generally leave that to upper layers and simply trusts that Google servers aren't trying to mess with us?
Review of attachment 357203 [details] [review]: Great!
Thank you for the reviews! Ostensibly, I have commit access and could do it myself, but I'm in the middle of getting git access back due to a lost ssh key. So if you want to commit for me, that would be nice. Else I'll do it when the gnome accounts folks restore my account.