Class: Keymaker::Service
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_node_to_index(index_name, key, value, node_id) ⇒ Object
-
#batch_get_nodes(node_ids) ⇒ Object
-
#connection ⇒ Object
-
#connection=(connection) ⇒ Object
-
#create_node(attrs) ⇒ Object
-
#create_relationship(rel_type, start_node_id, end_node_id, data = {}) ⇒ Object
-
#delete(url, body = {}) ⇒ Object
-
#delete_node(node_id) ⇒ Object
-
#delete_relationship(relationship_id) ⇒ Object
-
#execute_cypher(query, params) ⇒ Object
-
#execute_script(script, params = {}) ⇒ Object
-
#get(url, body) ⇒ Object
-
#get_node(node_id) ⇒ Object
-
#initialize(config) ⇒ Service
constructor
A new instance of Service.
-
#method_missing(name, *args) ⇒ Object
-
#parse_url(url) ⇒ Object
-
#path_traverse(start_node_id, data = {}) ⇒ Object
-
#post(url, body) ⇒ Object
-
#put(url, body) ⇒ Object
-
#remove_node_from_index(index_name, key, value, node_id) ⇒ Object
-
#update_node_properties(node_id, attrs) ⇒ Object
match_method
Constructor Details
#initialize(config) ⇒ Service
Returns a new instance of Service.
11
12
13
|
# File 'lib/keymaker/service.rb', line 11
def initialize(config)
self.config = config
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
33
34
35
36
37
|
# File 'lib/keymaker/service.rb', line 33
def method_missing(name, *args)
super
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9
10
11
|
# File 'lib/keymaker/service.rb', line 9
def config
@config
end
|
Instance Method Details
#add_node_to_index(index_name, key, value, node_id) ⇒ Object
66
67
68
|
# File 'lib/keymaker/service.rb', line 66
def add_node_to_index(index_name, key, value, node_id)
add_node_to_index_request(index_name: index_name, key: key, value: value, node_id: node_id)
end
|
#batch_get_nodes(node_ids) ⇒ Object
78
79
80
|
# File 'lib/keymaker/service.rb', line 78
def batch_get_nodes(node_ids)
batch_get_nodes_request(node_ids)
end
|
#connection ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/keymaker/service.rb', line 19
def connection
@connection ||= Faraday.new(url: config.connection_service_root_url) do |conn|
conn.request :json
conn.response :mashify
conn.response :json, :content_type => /\bjson$/
conn.adapter :net_http
end
end
|
#connection=(connection) ⇒ Object
15
16
17
|
# File 'lib/keymaker/service.rb', line 15
def connection=(connection)
@connection = connection
end
|
#create_node(attrs) ⇒ Object
39
40
41
42
|
# File 'lib/keymaker/service.rb', line 39
def create_node(attrs)
create_node_request(attrs)
end
|
#create_relationship(rel_type, start_node_id, end_node_id, data = {}) ⇒ Object
58
59
60
|
# File 'lib/keymaker/service.rb', line 58
def create_relationship(rel_type, start_node_id, end_node_id, data={})
create_relationship_request({node_id: start_node_id, rel_type: rel_type, end_node_id: end_node_id, data: data})
end
|
#delete(url, body = {}) ⇒ Object
96
97
98
99
|
# File 'lib/keymaker/service.rb', line 96
def delete(url, body={})
faraday_response = connection.delete(parse_url(url), body)
Keymaker::Response.new(self, faraday_response)
end
|
#delete_node(node_id) ⇒ Object
54
55
56
|
# File 'lib/keymaker/service.rb', line 54
def delete_node(node_id)
delete_node_request(node_id: node_id)
end
|
#delete_relationship(relationship_id) ⇒ Object
62
63
64
|
# File 'lib/keymaker/service.rb', line 62
def delete_relationship(relationship_id)
delete_relationship_request(relationship_id: relationship_id)
end
|
#execute_cypher(query, params) ⇒ Object
82
83
84
85
|
# File 'lib/keymaker/service.rb', line 82
def execute_cypher(query, params)
response = execute_cypher_request({query: query, params: params})
Keymaker::CypherResponseParser.parse(response.body)
end
|
#execute_script(script, params = {}) ⇒ Object
87
88
89
|
# File 'lib/keymaker/service.rb', line 87
def execute_script(script, params={})
execute_gremlin_request({script: script, params: params})
end
|
#get(url, body) ⇒ Object
91
92
93
94
|
# File 'lib/keymaker/service.rb', line 91
def get(url, body)
faraday_response = connection.get(parse_url(url), body)
Keymaker::Response.new(self, faraday_response)
end
|
#get_node(node_id) ⇒ Object
44
45
46
47
48
|
# File 'lib/keymaker/service.rb', line 44
def get_node(node_id)
response = get_node_request({node_id: node_id})
data = response.body.data
data.merge!("neo4j_id" => response.neo4j_id, "__raw_response__" => response)
end
|
#parse_url(url) ⇒ Object
111
112
113
114
115
116
117
|
# File 'lib/keymaker/service.rb', line 111
def parse_url(url)
connection.build_url(url).tap do |uri|
if uri.port != Integer(config.port)
raise RuntimeError, "bad port"
end
end
end
|
#path_traverse(start_node_id, data = {}) ⇒ Object
74
75
76
|
# File 'lib/keymaker/service.rb', line 74
def path_traverse(start_node_id, data={})
traverse_path_request({node_id: start_node_id}.merge(data))
end
|
#post(url, body) ⇒ Object
101
102
103
104
|
# File 'lib/keymaker/service.rb', line 101
def post(url, body)
faraday_response = connection.post(parse_url(url), body)
Keymaker::Response.new(self, faraday_response)
end
|
#put(url, body) ⇒ Object
106
107
108
109
|
# File 'lib/keymaker/service.rb', line 106
def put(url, body)
faraday_response = connection.put(parse_url(url), body)
Keymaker::Response.new(self, faraday_response)
end
|
#remove_node_from_index(index_name, key, value, node_id) ⇒ Object
70
71
72
|
# File 'lib/keymaker/service.rb', line 70
def remove_node_from_index(index_name, key, value, node_id)
remove_node_from_index_request(index_name: index_name, key: key, value: value, node_id: node_id)
end
|
#update_node_properties(node_id, attrs) ⇒ Object
50
51
52
|
# File 'lib/keymaker/service.rb', line 50
def update_node_properties(node_id, attrs)
update_node_properties_request({node_id: node_id}.merge(attrs))
end
|