Neo4j/REST/Client.pm

filter: Statementstmt 75.0% 6 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 81.8% 9 / 11 CC 1 SCAR 0.9
CC
1
Cov
75%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Neo4j/Role/REST.pm ↑ Summary Neo4j/Types.pm »
1 package Neo4j::REST::Client;
2  
3 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 0 ▶use Data::Printer;
Subroutine BEGIN: called CC=1 SCAR=2.6
6  
7 use REST::Client;
8 use JSON;
9 use Try::Tiny;
10  
11 has 'root_URL' => (
12 required => 1,
13 isa => 'Str',
14 is => 'rw',
15 );
16  
17 has '_client' => (
18 isa => 'REST::Client',
19 is => 'rw',
20 lazy => 1,
21 handles => {
22 GET => 'GET',
23 POST => 'POST',
24 PUT => 'PUT',
25 DELETE => 'DELETE',
26 status => 'responseCode',
27 content => 'responseContent'
28 },
29 builder => '_build_client'
30 );
31  
32 sub _build_client {
33 my $self = shift;
34 my $client = REST::Client->new;
35 $client->addHeader( 'Accept', 'application/json' );
36 $client->addHeader( 'Content-Type', 'application/json' );
37 return $client;
38 }
39  
40 has 'root_endpoints' => (
41 isa => 'HashRef',
42 is => 'rw',
43 lazy => 1,
44 builder => '_build_root_endpoints',
45 traits => ['Hash'],
46 handles => { root_endpoint => 'get'}
47 );
48  
49  
50 sub _build_root_endpoints {
51 my $self = shift;
52  
53 $self->root_URL( ($self->root_URL =~ m!/$!) ? $self->root_URL : $self->root_URL . '/' );
54  
55 $self->GET($self->root_URL);
56 if($self->status eq '200') {
57 my $root_endpoints = decode_json($self->content);
58 # FIX for missing relationships endpoint on the API
59 $root_endpoints->{relationship} = $self->root_URL . 'relationship';
60 return $root_endpoints;
61 } else {
62 die "request not OK";
63 }
64 }
65  
66 # TODO
67 # around [qw(GET POST PUT DELETE)] => sub {
68 # try {
69 # # do the actual talking with the server
70 # } catch {
71 # # network errors
72 # };
73 # };
74  
75 =cut
76 root_endpoints {
77 batch "http://localhost:7474/db/data/batch",
78 cypher "http://localhost:7474/db/data/cypher",
79 extensions {
80 CypherPlugin {
81 execute_query "http://localhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query"
82 },
83 GremlinPlugin {
84 execute_script "http://localhost:7474/db/data/ext/GremlinPlugin/graphdb/execute_script"
85 }
86 },
87 extensions_info "http://localhost:7474/db/data/ext",
88 neo4j_version "1.8.M02-117-g14b66aa-dirty",
89 node "http://localhost:7474/db/data/node",
90 node_index "http://localhost:7474/db/data/index/node",
91 reference_node "http://localhost:7474/db/data/node/0",
92 relationship_index "http://localhost:7474/db/data/index/relationship",
93 relationship_types "http://localhost:7474/db/data/relationship/types"
94 },
95 root_URL "http://localhost:7474/db/data/"
96 =cut
97  
98 1;
« Neo4j/Role/REST.pm ↑ Summary Neo4j/Types.pm »