-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNeoapi.php
More file actions
executable file
·97 lines (79 loc) · 2.26 KB
/
Neoapi.php
File metadata and controls
executable file
·97 lines (79 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
Author : Rohit. Manohar
Email : rohit.manohar@gmail.com
Date : Sept 13th 2011
*/
class Neoapi{
function string_begins_with($string, $search){
return (strncmp($string, $search, strlen($search)) == 0);
}
function isServerOnline(){
if ($this->request ('http://localhost:7474/') == NULL)
return (false) ;
else
return (true) ;
}
function request($service, $data=NULL, $return_type="array", $delete=false){
if (!$this->string_begins_with ($service, 'http://')) {
$url = 'http://localhost:7474/'.$service ;
} else {
$url = $service ;
}
$fields = $data ;
$fields_string = '' ;
//url-ify the data for the POST
if ($data != NULL)
$post_data = json_encode($data) ;
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
if ($data != NULL){
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$headers = array(
'Content-Length: ' . strlen($post_data),
'Content-Type: application/json',
'Accept: application/json'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
} else {
if ($delete)
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
else
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
}
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true) ;
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
if ($result){
if ($return_type == "array")
return (json_decode($result, true)) ;
else
return (json_decode($result)) ;
}
}
public function delete($service, $data=NULL, $return_type="array"){
return ($this->request ($service, $data=NULL, $return_type="array", true)) ;
}
public function nodeExists($id){
$response = $this->request('db/data/node/'.$id) ;
if (isset($response["exception"]))
return (false) ;
else
return (true) ;
}
public function getNodeId($node){
if (isset ($node['self'])){
return (substr (strrchr($node['self'], '/'),1)) ;
} else {
return (false) ;
}
}
}