Skip Menu |
 

This queue is for tickets about the MetaCPAN-API CPAN distribution.

Report information
The Basics
Id: 69814
Status: resolved
Priority: 0/
Queue: MetaCPAN-API

People
Owner: Nobody in particular
Requestors: TIMB [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Doesn't support POST queries
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 260
Download (untitled) / with headers
text/plain 260b
For example, I'd like to be able to do this kind of query via the API: http://explorer.metacpan.org/? url=%2Frelease&content=%7B%22query%22%3A%7B%22match_all%22%3A%7B%7D%7D%2C%22filte r%22%3A%7B%22prefix%22%3A%7B%22archive%22%3A%22Cache-Cache-1.06%22%7D%7D%7D
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-12441-1311689745-230.69814-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 754
Download (untitled) / with headers
text/plain 754b
On Tue Jul 26 08:19:21 2011, TIMB wrote: Show quoted text
> For example, I'd like to be able to do this kind of query via the API: > > http://explorer.metacpan.org/? >
url=%2Frelease&content=%7B%22query%22%3A%7B%22match_all%22%3A%7B%7D%7D%2C%22filte Show quoted text
> r%22%3A%7B%22prefix%22%3A%7B%22archive%22%3A%22Cache-Cache- > 1.06%22%7D%7D%7D
Hi, Tim! :) That's a very good idea and I intend to develop the module even more. This is certainly a good point to use as reference. I've opened this ticket on Github Issues (where I keep MetaCPAN::API project) and I'll keep this ticket open as well until the issue is resolved. MetaCPANExplorer certainly contains a few good examples of ways to extend MetaCPAN::API and I've starred it the other day on my RSS reader to remember it.
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-12441-1311689745-230.69814-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-12441-1311689745-230.69814-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-12439-1311842155-1697.69814-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 718
Download (untitled) / with headers
text/plain 718b
I have just release 0.20 which supports complex GET requests (such as those demonstrated in the MetaCPAN docs and MetaCPANExplorer. The next goal is this ticket, which will help close all outstanding API method implementations as far as I know. I'm still unsure on how to do this, but I'm thinking of splitting it to two parts: - $mcpan->post_json(...) which will allow to write any JSON string you want to search with. - MetaCPAN::API::Predefined which will include custom searches as those that appear in MetaCPAN and MetaCPANExplorer. Stuff like $mcpan->find_latest_by_author( author => ..., ... ) and the likes. I'd be happy to get your thoughts on this, as you're the only MetaCPAN::API user I know. :)
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-12439-1311842155-1697.69814-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-12441-1311689745-230.69814-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-12439-1311842155-1697.69814-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-12439-1311867720-487.69814-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 1129
Download (untitled) / with headers
text/plain 1.1k
The first step would be to add a fetch()-like method to handle POST Here's my monkey-patched quick hack that "works for me": { package MetaCPAN::API; # XXX MONKEY_PATCH use JSON; sub post_query { my $self = shift; my $url = shift; my $query = shift; my $base = $self->base_url; my $query_json = encode_json($query); my $result = $self->ua->request('POST', "$base/$url", { headers => { "Content-Type" => "application/json" }, content => $query_json }); my $decoded_result; $result->{'success'} or croak "Failed to fetch '$url': " . $result->{'reason'}." (Post content: $query_json)"; defined ( my $content = $result->{'content'} ) or croak 'Missing content in return value'; try { $decoded_result = decode_json $content } catch { croak "Couldn't decode '$content': $_" }; return $decoded_result; } } The second half of that is the same as fetch() so ought to be factored out. I call it like $results = $mcpan->post_query("/file", { ... }); A MetaCPAN::API::Predefined seems like a good idea, but is separate from this issue (though dependent on it).
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-12434-1311980148-877.69814-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 575
Download (untitled) / with headers
text/plain 575b
I have used your code (albeit refactored it a bit) and just released MetaCPAN::API 0.30, which allows you to do complex POST queries. The example query you gave was: http://explorer.metacpan.org/?url=/release&content={"query":{"match_all":{}},"filter":{"prefix":{"archive":"Cache-Cache-1.06"}}} You can now do this as such: my $result = $mcpan->fetch( 'release', { query => { match_all => {} }, filter => { prefix => { archive => 'Cache-Cache-1.06' } }, }, ); This example is also available in the POD. Thanks! :)


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.