Class: Keymaker::Service
- Inherits:
-
Object
- Object
- Keymaker::Service
- Extended by:
- MatchMethodMacros
- 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.
-
#batch_get_nodes(node_ids) ⇒ Object
Batch GET Nodes.
- #connection ⇒ Object
- #connection=(connection) ⇒ Object
-
#create_node(attrs) ⇒ Object
Nodes Create Node.
-
#create_relationship(rel_type, start_node_id, end_node_id, data = {}) ⇒ Object
Create Relationship.
- #delete(url, body = {}) ⇒ Object
-
#delete_node(node_id) ⇒ Object
Delete Node.
-
#delete_relationship(relationship_id) ⇒ Object
Delete Relationship.
-
#execute_query(query, params) ⇒ Object
Cypher Query.
-
#execute_script(script, params = {}) ⇒ Object
Gremlin Script.
-
#get(url, body) ⇒ Object
HTTP Verbs.
- #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
Path Traverse.
- #post(url, body) ⇒ Object
- #put(url, body) ⇒ Object
-
#remove_node_from_index(index_name, key, value, node_id) ⇒ Object
Remove Node from Index.
-
#update_node_properties(node_id, attrs) ⇒ Object
Update Node properties.
Methods included from MatchMethodMacros
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) # match_method uses modules, so we can use super to delegate to # the generated #method_missing definitions. 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
Add Node to Index
73 74 75 |
# File 'lib/keymaker/service.rb', line 73 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
Batch GET Nodes
89 90 91 |
# File 'lib/keymaker/service.rb', line 89 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.use FaradayMiddleware::Mashify conn.request :json 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
Nodes Create Node
41 42 43 44 |
# File 'lib/keymaker/service.rb', line 41 def create_node(attrs) # TODO: parse response into manageable Ruby objects create_node_request(attrs) end |
#create_relationship(rel_type, start_node_id, end_node_id, data = {}) ⇒ Object
Create Relationship
63 64 65 |
# File 'lib/keymaker/service.rb', line 63 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
109 110 111 112 |
# File 'lib/keymaker/service.rb', line 109 def delete(url, body={}) faraday_response = connection.delete(parse_url(url), body) Keymaker::Response.new(self, faraday_response) end |
#delete_node(node_id) ⇒ Object
Delete Node
58 59 60 |
# File 'lib/keymaker/service.rb', line 58 def delete_node(node_id) delete_node_request(node_id: node_id) end |
#delete_relationship(relationship_id) ⇒ Object
Delete Relationship
68 69 70 |
# File 'lib/keymaker/service.rb', line 68 def delete_relationship(relationship_id) delete_relationship_request(relationship_id: relationship_id) end |
#execute_query(query, params) ⇒ Object
Cypher Query
94 95 96 |
# File 'lib/keymaker/service.rb', line 94 def execute_query(query, params) execute_cypher_request({query: query, params: params}).body end |
#execute_script(script, params = {}) ⇒ Object
Gremlin Script
99 100 101 |
# File 'lib/keymaker/service.rb', line 99 def execute_script(script, params={}) execute_gremlin_request({script: script, params: params}) end |
#get(url, body) ⇒ Object
HTTP Verbs
104 105 106 107 |
# File 'lib/keymaker/service.rb', line 104 def get(url, body) faraday_response = connection.get(parse_url(url), body) Keymaker::Response.new(self, faraday_response) end |
#get_node(node_id) ⇒ Object
46 47 48 49 50 |
# File 'lib/keymaker/service.rb', line 46 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
124 125 126 127 128 129 130 |
# File 'lib/keymaker/service.rb', line 124 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
Path Traverse
83 84 85 |
# File 'lib/keymaker/service.rb', line 83 def path_traverse(start_node_id, data={}) traverse_path_request({node_id: start_node_id}.merge(data)) end |
#post(url, body) ⇒ Object
114 115 116 117 |
# File 'lib/keymaker/service.rb', line 114 def post(url, body) faraday_response = connection.post(parse_url(url), body) Keymaker::Response.new(self, faraday_response) end |
#put(url, body) ⇒ Object
119 120 121 122 |
# File 'lib/keymaker/service.rb', line 119 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
78 79 80 |
# File 'lib/keymaker/service.rb', line 78 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
Update Node properties
53 54 55 |
# File 'lib/keymaker/service.rb', line 53 def update_node_properties(node_id, attrs) update_node_properties_request({node_id: node_id}.merge(attrs)) end |