package Webservice::InterMine::Parser::JSON;
=head1 NAME
Webservice::InterMine::Parser::JSON - parse rows of JSON results
=head1 DESCRIPTION
One of the parsers used to intepret results sent from
the webservice.
=cut
use Moose;
with 'Webservice::InterMine::Parser';
use JSON::XS;
use MooseX::Types::Moose qw(Str);
use InterMine::Model::Types qw(Model);
=head1 IMPLEMENTED PARSER METHODS
The
)
reports whether the header has been parsed yet.
Here, this reports whether the beginning of the JSON
object has been seen, and whether the results array
is open.
=item * parse_header($line)
Parse
=head1 NAME
Webservice::InterMine::Parser::JSON::HashRefs -
parse rows of JSON results into hash-refs
=head1 DESCRIPTION
One of the parsers used to intepret results sent from
the webservice.
=cu
ebservice::InterMine::Parser::JSON::HashRefs;
use Moose;
extends 'Webservice::InterMine::Parser::JSON';
use InterMine::Model::Types qw(PathList);
=head1 ATTRIBUTES
=head2 view - The view used to se
package Webservice::InterMine::Parser::JSON::ResultRows;
=head1 NAME
Webservice::InterMine::Parser::JSON::ResultRows -
parse rows of JSON results into L<ResultRow>s
=head1 DESCRIPTION
One of the
pret results sent from
the webservice.
=cut
use Moose;
extends 'Webservice::InterMine::Parser::JSON';
use Webservice::InterMine::ResultRow;
use InterMine::Model::Types qw/PathList/;
has view => (
package Webservice::InterMine::Parser::JSON::ArrayRefs;
=head1 NAME
Webservice::InterMine::Parser::JSON::ArrayRefs -
parse rows of JSON results into array-refs
=head1 DESCRIPTION
One of the parse
pret results sent from
the webservice.
=cut
use Moose;
extends 'Webservice::InterMine::Parser::JSON';
=head1 IMPLEMENTED PROCESSOR METHODS
The following methods implement the Processor interface.
;
require Set::Object;
use constant {
LIST_APPEND_PATH => '/lists/append/json',
RENAME_PATH => '/lists/rename/json',
LISTABLE => 'Webservice::InterMine::Role::Listable',
LIST => 'Webs
ot . ENRICHMENT_PATH);
my $iterator = $self->service->get_results_iterator($uri, \%form, [], "json", "perl", []);
return $iterator;
}
=head2 to_query
Return a L<Webservice::InterMine::Query>
terating over rows of results.
The formats that are supported by the possible values service
are jsonobjects (the default), and count formats. However, for accessing
counts, and even values, it is pr
my $format = shift || 'jsonobjects';
my $service = $self->{service};
my $uri = $service->root . $service->POSSIBLE_VALUES_PATH;
require JSON;
my $json = JSON->new;
my $params =
{
path => $self->{path},
typeConstraints => $json->encode($self->{subtypes}),
};
my $iter = $service->get_results_iterator(
$uri, $params, [], $format, 'perl', []);
Listables
ListOperable ListOfListOperables
RowParser
RowFormat
JsonFormat
RequestFormat
TSVFormat
File
NotAllLowerCase
Date
'jsonobjects', 'jsonrows', 'jsondatatable', 'count', 'json'];
enum JsonFormat, ['perl', 'inflate', 'instantiate'];
enum RequestFormat, ['tab', 'csv', 'count', 'jsonobjects', 'jsonrows', 'xml', 'jsond
atatable', 'json'];
subtype TSVFormat, as Str, where {/^tsv$/i};
class_type ResultIterator, {class => 'Webservice::InterMine::ResultIterator'};
coerce RowFormat, from NotAllLowerCase, via { lc($_) }
ost(
$service->build_uri($service->root . '/ids'),
'Content-Type' => 'application/json',
'Content' => $service->encode($self->as_submission)
);
if ( $resp->is_error ) {
hift;
return 1 if $self->completed;
$self->_backoff;
my $data = $self->service->fetch_json('/ids/' . $self->uid . '/status');
$self->_register_poll;
my $status = $data->{status};
r this job.
=cut
sub fetch_results {
my $self = shift;
my $data = $self->service->fetch_json('/ids/' . $self->uid . '/result');
return $data->{results};
}
=head2 delete()
Delete this j
use Moose;
with 'Webservice::InterMine::Role::Serviced';
with 'Webservice::InterMine::Role::KnowsJSON';
use Webservice::InterMine::List;
use Webservice::InterMine::Types qw(List ListOperable File Li
=> '/lists/json',
DELETION_PATH => '/lists/json',
UNION_PATH => '/lists/union/json',
INTERSECTION_PATH => '/lists/intersect/json',
SUBTRACTION_PATH => '/lists/subtract/json',
DIFF
ERENCE_PATH => '/lists/diff/json',
LIST_TAG_PATH => '/list/tags/json',
};
=head2 get_list( $name ) -> List
Get the list with the given name, if it exists. Returns undef
if the given list is not
ice::InterMine::Role::KnowsJSON';
use LWP::UserAgent;
use Webservice::InterMine::Types qw/UserAgent/;
use constant REGISTRY => 'http://www.intermine.org/registry/mines.json';
has ua => (
is => '
impractical to hold in memory.
Parameters:
=over 4
=item as => tsv|csv|arrayrefs|hashrefs|jsonobjects|jsonrows|count:
How each line should be returned.
=item size => Int:
How many results to retur
iendly/path:
Whether to add headers to the output (default: false)
=item json => inflate|instantiate|perl:
How to handle json (default: perl)
=item %parameters:
The template parameters
=back
Retur
erator_with {
my $self = shift;
my %args = @_;
my @keys = qw/as size start addheaders json/;
my @values = delete(@args{@keys});
my $clone = $self->get_adjusted_template(%args);
le opened for writing.
=item * as => $format
Possible values: (tsv|csv|arrayrefs|hashrefs|jsonobjects|jsonrows|count)
The format to print results in. The default is C<tsv>
=item * size => $size
T
m * json => $json_processor
Possible values: (inflate|instantiate|perl)
What to do with JSON results. The results can be returned as inflated objects,
full instantiated Moose objects, a raw json str
Mine::Role::KnowsJSON;
use Moose::Role;
use JSON -support_by_pp;
has json => (
isa => 'JSON',
is => 'ro',
lazy_build => 1,
handles => ['decode'],
);
sub _build_json {
my $self =
shift;
# Be as generous as possible to input.
return JSON->new->relaxed->allow_singlequote->allow_barekey->allow_nonref;
}
1;
my $self = shift;
my $constraints = shift;
my $results_args = shift || {as => 'jsonobjects', json => 'instantiate'};
if (ref $constraints eq 'HASH') {
while (my ($path, $con) =
se Webservice::InterMine::Path;
use Webservice::InterMine::Model;
my @JSON_FORMATS = (qw/jsonobjects jsonrows jsondatatable json/);
my @SIMPLE_FORMATS = (qw/tsv tab csv count xml/);
=head2 new( $url
'/query/upload',
QUERY_LIST_PATH => '/query/tolist/json',
QUERY_LIST_APPEND_PATH => '/query/append/tolist/json',
MODEL_PATH => '/model',
TEMPLATES_PAT
ate/upload',
TEMPLATE_LIST_PATH => '/template/tolist/json',
TEMPLATE_LIST_APPEND_PATH => '/template/append/tolist/json',
VERSION_PATH => '/version',
RELEASE_PAT
expressions or strings will cause exceptions to be thrown.
=head2 results([as => $format], [json => $jsonhandler])
Gets the results for this query in a variety of formats. (see
L<Webservice::InterM
item * jsonobjects
By default returns an arrayref of native perl data structures (hashrefs) which
correspond to the data format of InterMine jsonobjects
(L<http://www.intermine.org/wiki/JSONObjectF
ormat>).
Optionally it can return the jsonobjects processed as:
=over 8
=item * raw: the raw text string
=item * inflate: inflated objects using autoload
The inflated objects allow method access
ions are available:
=over 4
=item * as => $format
Possible values: (rr|ro|objects|string|jsonobjects|jsonrows|count)
The format to request results in.
=over 8
=item * C<rr> ResultRows (default)
L<Webservice::InterMine::ResultObject>s will be returned (it is a
synonym for C<< as => "jsonobjects", json => "inflate" >>).
=item * C<objects> Instantiated L<InterMine::Model> objects.
Fully in
selected, then the results will be unparsed tab delimited rows.
=item * json[objects|rows] - raw data structures
The two json formats allow low-level access to the data-structures returned
by the we