Class: Keymaker::Service
- Inherits:
-
Object
- Object
- Keymaker::Service
- Defined in:
- lib/keymaker/service.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#add_node_to_index(index_name, key, value, node_id) ⇒ Object
Add Node to Index.
- #add_node_to_index_request(opts) ⇒ Object
-
#batch_get_nodes(node_ids) ⇒ Object
Batch GET Nodes.
- #batch_get_nodes_request(opts) ⇒ Object
- #connection ⇒ Object
- #connection=(connection) ⇒ Object
-
#create_node(attrs) ⇒ Object
Create Node.
- #create_node_request(opts) ⇒ Object
-
#create_relationship(rel_type, start_node_id, end_node_id, data = {}) ⇒ Object
Create Relationship.
- #create_relationship_request(opts) ⇒ Object
- #delete(url) ⇒ Object
-
#delete_relationship(relationship_id) ⇒ Object
Delete Relationship.
- #delete_relationship_request(opts) ⇒ Object
- #execute_cypher_request(opts) ⇒ Object
- #execute_gremlin_request(opts) ⇒ Object
-
#execute_query(query, params) ⇒ Object
Cypher Query.
-
#execute_script(script, params = {}) ⇒ Object
Gremlin Script.
-
#get(url, body) ⇒ Object
HTTP Verbs.
-
#initialize(config) ⇒ Service
constructor
A new instance of Service.
- #parse_url(url) ⇒ Object
-
#path_traverse(start_node_id, data = {}) ⇒ Object
Path Traverse.
- #path_traverse_request(opts) ⇒ Object
- #post(url, body) ⇒ Object
- #put(url, body) ⇒ Object
-
#remove_node_from_index(index_name, key, value, node_id) ⇒ Object
Remove Node from Index.
- #remove_node_from_index_request(opts) ⇒ Object
-
#update_node_properties(node_id, attrs) ⇒ Object
Update Node properties.
- #update_node_properties_request(opts) ⇒ Object
Constructor Details
#initialize(config) ⇒ Service
Returns a new instance of Service.
9 10 11 |
# File 'lib/keymaker/service.rb', line 9 def initialize(config) self.config = config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/keymaker/service.rb', line 7 def config @config end |
Instance Method Details
#add_node_to_index(index_name, key, value, node_id) ⇒ Object
Add Node to Index
62 63 64 |
# File 'lib/keymaker/service.rb', line 62 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 |
#add_node_to_index_request(opts) ⇒ Object
66 67 68 |
# File 'lib/keymaker/service.rb', line 66 def add_node_to_index_request(opts) AddNodeToIndexRequest.new(self, opts).submit end |
#batch_get_nodes(node_ids) ⇒ Object
Batch GET Nodes
90 91 92 |
# File 'lib/keymaker/service.rb', line 90 def batch_get_nodes(node_ids) batch_get_nodes_request(node_ids) end |
#batch_get_nodes_request(opts) ⇒ Object
94 95 96 |
# File 'lib/keymaker/service.rb', line 94 def batch_get_nodes_request(opts) BatchGetNodesRequest.new(self, opts).submit end |
#connection ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/keymaker/service.rb', line 17 def connection @connection ||= Faraday.new(url: config.connection_service_root_url) do |conn| conn.request :json conn.use FaradayMiddleware::ParseJson, content_type: /\bjson$/ conn.adapter :net_http end end |
#connection=(connection) ⇒ Object
13 14 15 |
# File 'lib/keymaker/service.rb', line 13 def connection=(connection) @connection = connection end |
#create_node(attrs) ⇒ Object
Create Node
26 27 28 |
# File 'lib/keymaker/service.rb', line 26 def create_node(attrs) create_node_request(attrs) end |
#create_node_request(opts) ⇒ Object
30 31 32 |
# File 'lib/keymaker/service.rb', line 30 def create_node_request(opts) CreateNodeRequest.new(self, opts).submit end |
#create_relationship(rel_type, start_node_id, end_node_id, data = {}) ⇒ Object
Create Relationship
44 45 46 |
# File 'lib/keymaker/service.rb', line 44 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 |
#create_relationship_request(opts) ⇒ Object
48 49 50 |
# File 'lib/keymaker/service.rb', line 48 def create_relationship_request(opts) CreateRelationshipRequest.new(self, opts).submit end |
#delete(url) ⇒ Object
123 124 125 126 |
# File 'lib/keymaker/service.rb', line 123 def delete(url) faraday_response = connection.delete(parse_url(url)) Keymaker::Response.new(self, faraday_response) end |
#delete_relationship(relationship_id) ⇒ Object
Delete Relationship
53 54 55 |
# File 'lib/keymaker/service.rb', line 53 def delete_relationship(relationship_id) delete_relationship_request(relationship_id: relationship_id) end |
#delete_relationship_request(opts) ⇒ Object
57 58 59 |
# File 'lib/keymaker/service.rb', line 57 def delete_relationship_request(opts) DeleteRelationshipRequest.new(self, opts).submit end |
#execute_cypher_request(opts) ⇒ Object
103 104 105 |
# File 'lib/keymaker/service.rb', line 103 def execute_cypher_request(opts) ExecuteCypherRequest.new(self, opts).submit end |
#execute_gremlin_request(opts) ⇒ Object
112 113 114 |
# File 'lib/keymaker/service.rb', line 112 def execute_gremlin_request(opts) ExecuteGremlinRequest.new(self, opts).submit end |
#execute_query(query, params) ⇒ Object
Cypher Query
99 100 101 |
# File 'lib/keymaker/service.rb', line 99 def execute_query(query, params) execute_cypher_request({query: query, params: params}) end |
#execute_script(script, params = {}) ⇒ Object
Gremlin Script
108 109 110 |
# File 'lib/keymaker/service.rb', line 108 def execute_script(script, params={}) execute_gremlin_request({script: script, params: params}) end |
#get(url, body) ⇒ Object
HTTP Verbs
118 119 120 121 |
# File 'lib/keymaker/service.rb', line 118 def get(url, body) faraday_response = connection.get(parse_url(url), body) Keymaker::Response.new(self, faraday_response) end |
#parse_url(url) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/keymaker/service.rb', line 138 def parse_url(url) connection.build_url(url).tap do |uri| if uri.port != config.port raise RuntimeError, "bad port" end end end |
#path_traverse(start_node_id, data = {}) ⇒ Object
Path Traverse
80 81 82 |
# File 'lib/keymaker/service.rb', line 80 def path_traverse(start_node_id, data={}) path_traverse_request({node_id: start_node_id}.merge(data)) end |
#path_traverse_request(opts) ⇒ Object
84 85 86 |
# File 'lib/keymaker/service.rb', line 84 def path_traverse_request(opts) PathTraverseRequest.new(self, opts).submit end |
#post(url, body) ⇒ Object
128 129 130 131 |
# File 'lib/keymaker/service.rb', line 128 def post(url, body) faraday_response = connection.post(parse_url(url), body) Keymaker::Response.new(self, faraday_response) end |
#put(url, body) ⇒ Object
133 134 135 136 |
# File 'lib/keymaker/service.rb', line 133 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
Remove Node from Index
71 72 73 |
# File 'lib/keymaker/service.rb', line 71 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 |
#remove_node_from_index_request(opts) ⇒ Object
75 76 77 |
# File 'lib/keymaker/service.rb', line 75 def remove_node_from_index_request(opts) RemoveNodeFromIndexRequest.new(self, opts).submit end |
#update_node_properties(node_id, attrs) ⇒ Object
Update Node properties
35 36 37 |
# File 'lib/keymaker/service.rb', line 35 def update_node_properties(node_id, attrs) update_node_properties_request({node_id: node_id}.merge(attrs)) end |
#update_node_properties_request(opts) ⇒ Object
39 40 41 |
# File 'lib/keymaker/service.rb', line 39 def update_node_properties_request(opts) UpdateNodePropertiesRequest.new(self, opts).submit end |