1
1
module Neography
2
2
class Rest
3
3
include HTTParty
4
- base_uri 'http://localhost:9999'
4
+ base_uri Neography :: Config . to_s
5
5
format :json
6
6
7
7
class << self
8
8
9
9
def get_root
10
- rescue_ij { get ( '/' ) }
10
+ rescue_ij { get ( '/db/data/ ' ) }
11
11
end
12
12
13
13
def create_node ( *args )
14
14
if args [ 0 ] . respond_to? ( :each_pair ) && args [ 0 ]
15
15
options = { :body => args [ 0 ] . to_json , :headers => { 'Content-Type' => 'application/json' } }
16
- rescue_ij { post ( "/node" , options ) }
16
+ rescue_ij { post ( "/db/data/ node" , options ) }
17
17
else
18
- rescue_ij { post ( "/node" ) }
18
+ rescue_ij { post ( "/db/data/ node" ) }
19
19
end
20
20
end
21
21
22
22
def get_node ( id )
23
- rescue_ij { get ( "/node/#{ id } " ) }
23
+ rescue_ij { get ( "/db/data/ node/#{ id } " ) }
24
24
end
25
25
26
26
def reset_node_properties ( id , properties )
27
27
options = { :body => properties . to_json , :headers => { 'Content-Type' => 'application/json' } }
28
- rescue_ij { put ( "/node/#{ id } /properties" , options ) }
28
+ rescue_ij { put ( "/db/data/ node/#{ id } /properties" , options ) }
29
29
end
30
30
31
31
def get_node_properties ( id , properties = nil )
32
32
if properties . nil?
33
- rescue_ij { get ( "/node/#{ id } /properties" ) }
33
+ rescue_ij { get ( "/db/data/ node/#{ id } /properties" ) }
34
34
else
35
35
node_properties = Hash . new
36
36
properties . to_a . each do |property |
37
- value = rescue_ij { get ( "/node/#{ id } /properties/#{ property } " ) }
37
+ value = rescue_ij { get ( "/db/data/ node/#{ id } /properties/#{ property } " ) }
38
38
node_properties [ property ] = value unless value . nil?
39
39
end
40
40
return nil if node_properties . empty?
@@ -44,42 +44,42 @@ def get_node_properties(id, properties = nil)
44
44
45
45
def remove_node_properties ( id , properties = nil )
46
46
if properties . nil?
47
- rescue_ij { delete ( "/node/#{ id } /properties" ) }
47
+ rescue_ij { delete ( "/db/data/ node/#{ id } /properties" ) }
48
48
else
49
49
properties . to_a . each do |property |
50
- rescue_ij { delete ( "/node/#{ id } /properties/#{ property } " ) }
50
+ rescue_ij { delete ( "/db/data/ node/#{ id } /properties/#{ property } " ) }
51
51
end
52
52
end
53
53
end
54
54
55
55
def set_node_properties ( id , properties )
56
56
properties . each do |key , value |
57
57
options = { :body => value . to_json , :headers => { 'Content-Type' => 'application/json' } }
58
- rescue_ij { put ( "/node/#{ id } /properties/#{ key } " , options ) }
58
+ rescue_ij { put ( "/db/data/ node/#{ id } /properties/#{ key } " , options ) }
59
59
end
60
60
end
61
61
62
62
def delete_node ( id )
63
- rescue_ij { delete ( "/node/#{ id } " ) }
63
+ rescue_ij { delete ( "/db/data/ node/#{ id } " ) }
64
64
end
65
65
66
66
def create_relationship ( type , from , to , props = nil )
67
67
options = { :body => { :to => Neography ::Config . to_s + "/node/#{ to } " , :data => props , :type => type } . to_json , :headers => { 'Content-Type' => 'application/json' } }
68
- rescue_ij { post ( "/node/#{ from } /relationships" , options ) }
68
+ rescue_ij { post ( "/db/data/ node/#{ from } /relationships" , options ) }
69
69
end
70
70
71
71
def reset_relationship_properties ( id , properties )
72
72
options = { :body => properties . to_json , :headers => { 'Content-Type' => 'application/json' } }
73
- rescue_ij { put ( "/relationship/#{ id } /properties" , options ) }
73
+ rescue_ij { put ( "/db/data/ relationship/#{ id } /properties" , options ) }
74
74
end
75
75
76
76
def get_relationship_properties ( id , properties = nil )
77
77
if properties . nil?
78
- rescue_ij { get ( "/relationship/#{ id } /properties" ) }
78
+ rescue_ij { get ( "/db/data/ relationship/#{ id } /properties" ) }
79
79
else
80
80
relationship_properties = Hash . new
81
81
properties . to_a . each do |property |
82
- value = rescue_ij { get ( "/relationship/#{ id } /properties/#{ property } " ) }
82
+ value = rescue_ij { get ( "/db/data/ relationship/#{ id } /properties/#{ property } " ) }
83
83
relationship_properties [ property ] = value unless value . nil?
84
84
end
85
85
return nil if relationship_properties . empty?
@@ -89,32 +89,32 @@ def get_relationship_properties(id, properties = nil)
89
89
90
90
def remove_relationship_properties ( id , properties = nil )
91
91
if properties . nil?
92
- rescue_ij { delete ( "/relationship/#{ id } /properties" ) }
92
+ rescue_ij { delete ( "/db/data/ relationship/#{ id } /properties" ) }
93
93
else
94
94
properties . to_a . each do |property |
95
- rescue_ij { delete ( "/relationship/#{ id } /properties/#{ property } " ) }
95
+ rescue_ij { delete ( "/db/data/ relationship/#{ id } /properties/#{ property } " ) }
96
96
end
97
97
end
98
98
end
99
99
100
100
def set_relationship_properties ( id , properties )
101
101
properties . each do |key , value |
102
102
options = { :body => value . to_json , :headers => { 'Content-Type' => 'application/json' } }
103
- rescue_ij { put ( "/relationship/#{ id } /properties/#{ key } " , options ) }
103
+ rescue_ij { put ( "/db/data/ relationship/#{ id } /properties/#{ key } " , options ) }
104
104
end
105
105
end
106
106
107
107
def delete_relationship ( id )
108
- rescue_ij { delete ( "/relationship/#{ id } " ) }
108
+ rescue_ij { delete ( "/db/data/ relationship/#{ id } " ) }
109
109
end
110
110
111
111
def get_node_relationships ( id , dir = nil , types = nil )
112
112
dir = get_dir ( dir )
113
113
114
114
if types . nil?
115
- node_relationships = rescue_ij { get ( "/node/#{ id } /relationships/#{ dir } " ) } || Array . new
115
+ node_relationships = rescue_ij { get ( "/db/data/ node/#{ id } /relationships/#{ dir } " ) } || Array . new
116
116
else
117
- node_relationships = rescue_ij { get ( "/node/#{ id } /relationships/#{ dir } /#{ types . to_a . join ( '&' ) } " ) } || Array . new
117
+ node_relationships = rescue_ij { get ( "/db/data/ node/#{ id } /relationships/#{ dir } /#{ types . to_a . join ( '&' ) } " ) } || Array . new
118
118
end
119
119
return nil if node_relationships . empty?
120
120
node_relationships
@@ -123,36 +123,36 @@ def get_node_relationships(id, dir=nil, types=nil)
123
123
def delete_node! ( id )
124
124
relationships = get_node_relationships ( id )
125
125
relationships . each { |r | delete_relationship ( r [ "self" ] . split ( '/' ) . last ) } unless relationships . nil?
126
- rescue_ij { delete ( "/node/#{ id } " ) }
126
+ rescue_ij { delete ( "/db/data/ node/#{ id } " ) }
127
127
end
128
128
129
129
def list_indexes
130
- rescue_ij { get ( "/index" ) }
130
+ rescue_ij { get ( "/db/data/ index" ) }
131
131
end
132
132
133
133
def add_to_index ( key , value , id )
134
134
options = { :body => ( Neography ::Config . to_s + "/node/#{ id } " ) . to_json , :headers => { 'Content-Type' => 'application/json' } }
135
- rescue_ij { post ( "/index/node/#{ key } /#{ value } " , options ) }
135
+ rescue_ij { post ( "/db/data/ index/node/#{ key } /#{ value } " , options ) }
136
136
end
137
137
138
138
def remove_from_index ( key , value , id )
139
- rescue_ij { delete ( "/index/node/#{ key } /#{ value } /#{ id } " ) }
139
+ rescue_ij { delete ( "/db/data/ index/node/#{ key } /#{ value } /#{ id } " ) }
140
140
end
141
141
142
142
def get_index ( key , value )
143
- index = rescue_ij { get ( "/index/node/#{ key } /#{ value } " ) } || Array . new
143
+ index = rescue_ij { get ( "/db/data/ index/node/#{ key } /#{ value } " ) } || Array . new
144
144
return nil if index . empty?
145
145
index
146
146
end
147
147
148
148
def get_path ( from , to , relationships , depth = 1 , algorithm = "allPaths" )
149
149
options = { :body => { "to" => Neography ::Config . to_s + "/node/#{ to } " , "relationships" => relationships , "max depth" => depth , "algorithm" => get_algorithm ( algorithm ) } . to_json , :headers => { 'Content-Type' => 'application/json' } }
150
- path = rescue_ij { post ( "/node/#{ from } /path" , options ) } || Hash . new
150
+ path = rescue_ij { post ( "/db/data/ node/#{ from } /path" , options ) } || Hash . new
151
151
end
152
152
153
153
def get_paths ( from , to , relationships , depth = 1 , algorithm = "allPaths" )
154
154
options = { :body => { "to" => Neography ::Config . to_s + "/node/#{ to } " , "relationships" => relationships , "max depth" => depth , "algorithm" => get_algorithm ( algorithm ) } . to_json , :headers => { 'Content-Type' => 'application/json' } }
155
- paths = rescue_ij { post ( "/node/#{ from } /paths" , options ) } || Array . new
155
+ paths = rescue_ij { post ( "/db/data/ node/#{ from } /paths" , options ) } || Array . new
156
156
end
157
157
158
158
private
0 commit comments