keymaker 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/README.md +36 -10
  2. data/keymaker.gemspec +37 -33
  3. data/lib/keymaker.rb +3 -2
  4. data/lib/keymaker/configuration.rb +14 -24
  5. data/lib/keymaker/node.rb +1 -1
  6. data/lib/keymaker/request.rb +0 -2
  7. data/lib/keymaker/requests/add_node_to_index_request.rb +10 -1
  8. data/lib/keymaker/requests/create_relationship_request.rb +8 -1
  9. data/lib/keymaker/requests/delete_relationship_request.rb +10 -1
  10. data/lib/keymaker/requests/execute_cypher_request.rb +8 -3
  11. data/lib/keymaker/requests/execute_gremlin_request.rb +8 -3
  12. data/lib/keymaker/requests/remove_node_from_index_request.rb +0 -2
  13. data/lib/keymaker/requests/service_root_request.rb +1 -1
  14. data/lib/keymaker/requests/{path_traverse_request.rb → traverse_path_request.rb} +16 -4
  15. data/lib/keymaker/requests/update_node_properties_request.rb +8 -1
  16. data/lib/keymaker/response.rb +1 -0
  17. data/lib/keymaker/service.rb +16 -4
  18. data/spec/cassettes/Keymaker_AddNodeToIndexRequest/{returns_a_201_status_code.yml → with_valid_options/returns_a_201_status_code.yml} +54 -55
  19. data/spec/cassettes/Keymaker_AddNodeToIndexRequest/{returns_application → with_valid_options/returns_application}/json.yml +54 -55
  20. data/spec/cassettes/Keymaker_AddNodeToIndexRequest/{returns_the_Neo4j_REST_API_starting_point_response_request.yml → with_valid_options/returns_the_Neo4j_REST_API_starting_point_response_request.yml} +54 -55
  21. data/spec/cassettes/Keymaker_CreateNodeRequest/returns_a_201_status_code.yml +112 -0
  22. data/spec/cassettes/Keymaker_CreateNodeRequest/returns_application/json.yml +112 -0
  23. data/spec/cassettes/Keymaker_CreateNodeRequest/with_properties/creates_a_node_with_the_given_properties.yml +112 -0
  24. data/spec/cassettes/Keymaker_CreateNodeRequest/without_properties/creates_an_empty_node.yml +112 -0
  25. data/spec/cassettes/Keymaker_CreateRelationshipRequest/with_invalid_options/raises_ClientError.yml +201 -0
  26. data/spec/cassettes/Keymaker_CreateRelationshipRequest/with_properties/creates_a_node_with_the_given_properties.yml +233 -0
  27. data/spec/cassettes/Keymaker_CreateRelationshipRequest/with_properties/returns_a_201_status_code.yml +196 -0
  28. data/spec/cassettes/Keymaker_CreateRelationshipRequest/with_properties/returns_application/json.yml +196 -0
  29. data/spec/cassettes/Keymaker_CreateRelationshipRequest/without_properties/creates_an_empty_relationship_of_type_birthed_.yml +195 -0
  30. data/spec/cassettes/Keymaker_DeleteRelationshipRequest/with_a_non-existent_relationship/raises_ResourceNotFound.yml +191 -0
  31. data/spec/cassettes/Keymaker_DeleteRelationshipRequest/with_an_existing_relationship/deletes_the_relationship.yml +219 -0
  32. data/spec/cassettes/Keymaker_ExecuteCypherRequest/with_a_valid_Cypher_Query/returns_a_200_status_code.yml +111 -0
  33. data/spec/cassettes/Keymaker_ExecuteCypherRequest/with_an_invalid_Cypher_Query/raises_ClientError.yml +108 -0
  34. data/spec/cassettes/Keymaker_ExecuteGremlinRequest/with_a_valid_Gremlin_Script/returns_a_200_status_code.yml +98 -0
  35. data/spec/cassettes/Keymaker_ExecuteGremlinRequest/with_an_invalid_Gremlin_Script/raises_ClientError.yml +107 -0
  36. data/spec/cassettes/Keymaker_TraversePathRequest/_traverse_path_properties/with_options/builds_the_query_properties_with_defaults.yml +157 -0
  37. data/spec/cassettes/Keymaker_TraversePathRequest/with_invalid_options/raise_a_ClientError.yml +193 -0
  38. data/spec/cassettes/Keymaker_TraversePathRequest/with_valid_options/returns_status_code_200.yml +269 -0
  39. data/spec/cassettes/Keymaker_UpdateNodePropertiesRequest/_node_properties/excludes_the_node_id.yml +157 -0
  40. data/spec/cassettes/Keymaker_UpdateNodePropertiesRequest/with_invalid_options/raises_a_ClientError.yml +193 -0
  41. data/spec/cassettes/Keymaker_UpdateNodePropertiesRequest/with_valid_options/returns_a_status_of_204.yml +182 -0
  42. data/spec/cassettes/Keymaker_UpdateNodePropertiesRequest/with_valid_options/updates_the_properties.yml +214 -0
  43. data/spec/keymaker/requests/add_node_to_index_request_spec.rb +30 -28
  44. data/spec/keymaker/requests/batch_get_nodes_request_spec.rb +4 -4
  45. data/spec/keymaker/requests/batch_request_spec.rb +33 -33
  46. data/spec/keymaker/requests/create_node_request_spec.rb +34 -0
  47. data/spec/keymaker/requests/create_relationship_request_spec.rb +58 -0
  48. data/spec/keymaker/requests/delete_relationship_request_spec.rb +28 -0
  49. data/spec/keymaker/requests/execute_cypher_request_spec.rb +23 -0
  50. data/spec/keymaker/requests/execute_gremlin_request_spec.rb +23 -0
  51. data/spec/keymaker/requests/service_root_request_spec.rb +9 -9
  52. data/spec/keymaker/requests/traverse_path_request_spec.rb +50 -0
  53. data/spec/keymaker/requests/update_node_properties_request_spec.rb +50 -0
  54. data/spec/keymaker/service_spec.rb +31 -0
  55. data/spec/keymaker_spec.rb +26 -2
  56. data/spec/support/keymaker.rb +10 -4
  57. metadata +86 -10
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  A multi-layer REST API Ruby wrapper for the Neo4j graph database built on top of [Faraday][].
4
4
 
5
+ - Layer 1 interacts with the Neo4j REST API raw requests
6
+ - Layer 2 binds the raw HTTP requests into Ruby Objects
7
+ - Layer 3 implements ActiveModel and treats Nodes and Relationships as Ruby Objects
8
+
5
9
  ```
6
10
  Oracle: Our time is up. Listen to me, Neo.
7
11
  You can save Zion if you reach The Source,
@@ -24,7 +28,7 @@ rake neo4j:start RAILS_ENV=test
24
28
  Add this line to your application's Gemfile:
25
29
 
26
30
  ```ruby
27
- gem 'keymaker'
31
+ gem "keymaker"
28
32
  ```
29
33
 
30
34
  And then execute:
@@ -52,18 +56,18 @@ Then, create a Rails initializer `config/initializers/keymaker.rb`:
52
56
 
53
57
  ```ruby
54
58
  if Rails.env.development? || Rails.env.test?
55
- database_config = YAML::load_file('config/neo4j.yml')
59
+ database_config = YAML::load_file("config/neo4j.yml")
56
60
  Keymaker.configure do |c|
57
- c.server = database_config["#{Rails.env}"]['server']
58
- c.port = database_config["#{Rails.env}"]['port']
61
+ c.server = database_config["#{Rails.env}"]["server"]
62
+ c.port = database_config["#{Rails.env}"]["port"]
59
63
  end
60
64
  else
61
65
  # Heroku neo4j add-on
62
66
  Keymaker.configure do |c|
63
- c.server = ENV['NEO4J_HOST']
64
- c.port = ENV['NEO4J_PORT'].to_i
65
- c.username = ENV['NEO4J_LOGIN']
66
- c.password = ENV['NEO4J_PASSWORD']
67
+ c.server = ENV["NEO4J_HOST"]
68
+ c.port = ENV["NEO4J_PORT"]
69
+ c.username = ENV["NEO4J_LOGIN"]
70
+ c.password = ENV["NEO4J_PASSWORD"]
67
71
  end
68
72
  end
69
73
  ```
@@ -79,18 +83,40 @@ end
79
83
 
80
84
  ## Create a node ##
81
85
 
82
- response = Keymaker.service.create_node_request({:name => 'John Connor', :catch_phrase => 'No problemo'})
86
+ terminator_response = Keymaker.service.create_node_request({:name => "Terminator",
87
+ :catch_phrase => "I'll be back"})
88
+ terminator = Keymaker.service.get_node(terminator_response.neo4j_id)
89
+
90
+ john_response = Keymaker.service.create_node_request({:name => "John Connor",
91
+ :catch_phrase => "No problemo"})
92
+
93
+ john_connor = Keymaker.service.get_node(john_response.neo4j_id)
94
+ john_connor.name # => "John Connor"
95
+ john_connor.catch_phrase # => "No problemo"
83
96
 
84
97
  ## Update node properties ##
85
98
 
99
+ Keymaker.service.update_node_properties_request({:node_id => john_connor.neo4j_id,
100
+ :catch_phrase => "Easy money!"})
101
+ john_connor.catch_phrase # => "Easy money!"
102
+
86
103
  ## Delete a node ##
87
104
 
105
+ Keymaker.service.delete_node_request({:node_id => john_connor.neo4j_id})
106
+ Keymaker.service.get_node_request({:node_id => john_connor.neo4j_id})
107
+ # => Keymaker::ResourceNotFound raised
108
+
88
109
  ## Create a relationship ##
89
110
 
90
- ## Update relationship properties ##
111
+ rel = Keymaker.service.create_relationship_request({:node_id => john_connor.neo4j_id,
112
+ :end_node_id => terminator.neo4j_id,
113
+ :rel_type => "knows",
114
+ :data => {:since => "Summer of 1984"})
91
115
 
92
116
  ## Delete a relationship ##
93
117
 
118
+ Keymaker.service.delete_relationship_request(:relationship_id => rel.neo4j_id)
119
+
94
120
  ```
95
121
 
96
122
  ### Nodes
@@ -1,55 +1,31 @@
1
1
  # -*- encoding: utf-8 -*-
2
- ## This is the rakegem gemspec template. Make sure you read and understand
3
- ## all of the comments. Some sections require modification, and others can
4
- ## be deleted if you don't need them. Once you understand the contents of
5
- ## this file, feel free to delete any comments that begin with two hash marks.
6
- ## You can find comprehensive Gem::Specification documentation, at
7
- ## http://docs.rubygems.org/read/chapter/20
8
2
  Gem::Specification.new do |s|
9
3
  s.specification_version = 2 if s.respond_to? :specification_version=
10
4
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
5
  s.rubygems_version = '1.3.5'
12
6
 
13
- ## Leave these as is they will be modified for you by the rake gemspec task.
14
- ## If your rubyforge_project name is different, then edit it and comment out
15
- ## the sub! line in the Rakefile
16
7
  s.name = 'keymaker'
17
- s.version = '0.0.8'
18
- s.date = '2012-07-19'
8
+ s.version = '0.0.9'
9
+ s.date = '2012-09-22'
19
10
 
20
- ## Make sure your summary is short. The description may be as long
21
- ## as you like.
22
11
  s.description = %q{A multi-layer REST API wrapper for neo4j.}
23
12
  s.summary = %q{A multi-layer REST API wrapper for neo4j.}
24
13
 
25
- ## List the primary authors. If there are a bunch of authors, it's probably
26
- ## better to set the email to an email list or something. If you don't have
27
- ## a custom homepage, consider using your GitHub URL or the like.
28
14
  s.authors = ["Rogelio J. Samour", "Travis L. Anderson"]
29
15
  s.email = ["rogelio@therubymug.com", "travis@travisleeanderson.com"]
30
16
  s.homepage = "https://github.com/therubymug/keymaker"
31
17
 
32
- ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
33
- ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
34
18
  s.require_paths = %w[lib]
35
19
 
36
- ## Specify any RDoc options here. You'll want to add your README and
37
- ## LICENSE files to the extra_rdoc_files list.
38
- ## s.rdoc_options = ["--charset=UTF-8"]
39
20
  s.extra_rdoc_files = %w[README.md LICENSE.md]
40
21
 
41
- ## List your runtime dependencies here. Runtime dependencies are those
42
- ## that are needed for an end user to actually USE your code.
43
- ## s.add_dependency('DEPNAME', [">= 1.1.0", "< 2.0.0"])
44
22
  s.add_dependency 'activemodel'
45
23
  s.add_dependency 'activesupport'
46
24
  s.add_dependency 'addressable'
25
+ s.add_dependency 'hashie'
47
26
  s.add_dependency 'faraday'
48
27
  s.add_dependency 'faraday_middleware'
49
28
 
50
- ## List your development dependencies here. Development dependencies are
51
- ## those that are only needed during development
52
- ## s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"])
53
29
  s.add_development_dependency 'fakeweb'
54
30
  s.add_development_dependency 'rake'
55
31
  s.add_development_dependency 'rspec'
@@ -86,34 +62,64 @@ Gem::Specification.new do |s|
86
62
  lib/keymaker/requests/execute_gremlin_request.rb
87
63
  lib/keymaker/requests/get_node_request.rb
88
64
  lib/keymaker/requests/get_relationship_types_request.rb
89
- lib/keymaker/requests/path_traverse_request.rb
90
65
  lib/keymaker/requests/remove_node_from_index_request.rb
91
66
  lib/keymaker/requests/service_root_request.rb
67
+ lib/keymaker/requests/traverse_path_request.rb
92
68
  lib/keymaker/requests/update_node_properties_request.rb
93
69
  lib/keymaker/response.rb
94
70
  lib/keymaker/serialization.rb
95
71
  lib/keymaker/service.rb
96
- spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_a_201_status_code.yml
97
- spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_application/json.yml
98
- spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_the_Neo4j_REST_API_starting_point_response_request.yml
72
+ spec/cassettes/Keymaker_AddNodeToIndexRequest/with_valid_options/returns_a_201_status_code.yml
73
+ spec/cassettes/Keymaker_AddNodeToIndexRequest/with_valid_options/returns_application/json.yml
74
+ spec/cassettes/Keymaker_AddNodeToIndexRequest/with_valid_options/returns_the_Neo4j_REST_API_starting_point_response_request.yml
99
75
  spec/cassettes/Keymaker_BatchRequest/when_a_resource_is_not_found/raises_BatchRequestError.yml
100
76
  spec/cassettes/Keymaker_BatchRequest/when_to_and_method_are_not_set/raises_BatchRequestError.yml
101
77
  spec/cassettes/Keymaker_BatchRequest/with_valid_options/returns_a_200_status_code.yml
102
78
  spec/cassettes/Keymaker_BatchRequest/with_valid_options/runs_the_commands_and_returns_their_respective_results.yml
79
+ spec/cassettes/Keymaker_CreateNodeRequest/returns_a_201_status_code.yml
80
+ spec/cassettes/Keymaker_CreateNodeRequest/returns_application/json.yml
81
+ spec/cassettes/Keymaker_CreateNodeRequest/with_properties/creates_a_node_with_the_given_properties.yml
82
+ spec/cassettes/Keymaker_CreateNodeRequest/without_properties/creates_an_empty_node.yml
83
+ spec/cassettes/Keymaker_CreateRelationshipRequest/with_invalid_options/raises_ClientError.yml
84
+ spec/cassettes/Keymaker_CreateRelationshipRequest/with_properties/creates_a_node_with_the_given_properties.yml
85
+ spec/cassettes/Keymaker_CreateRelationshipRequest/with_properties/returns_a_201_status_code.yml
86
+ spec/cassettes/Keymaker_CreateRelationshipRequest/with_properties/returns_application/json.yml
87
+ spec/cassettes/Keymaker_CreateRelationshipRequest/without_properties/creates_an_empty_relationship_of_type_birthed_.yml
88
+ spec/cassettes/Keymaker_DeleteRelationshipRequest/with_a_non-existent_relationship/raises_ResourceNotFound.yml
89
+ spec/cassettes/Keymaker_DeleteRelationshipRequest/with_an_existing_relationship/deletes_the_relationship.yml
90
+ spec/cassettes/Keymaker_ExecuteCypherRequest/with_a_valid_Cypher_Query/returns_a_200_status_code.yml
91
+ spec/cassettes/Keymaker_ExecuteCypherRequest/with_an_invalid_Cypher_Query/raises_ClientError.yml
92
+ spec/cassettes/Keymaker_ExecuteGremlinRequest/with_a_valid_Gremlin_Script/returns_a_200_status_code.yml
93
+ spec/cassettes/Keymaker_ExecuteGremlinRequest/with_an_invalid_Gremlin_Script/raises_ClientError.yml
103
94
  spec/cassettes/Keymaker_GetNodeRequest/with_a_non-existent_node_id/raises_ResourceNotFound.yml
104
95
  spec/cassettes/Keymaker_GetNodeRequest/with_an_empty_node_id/raises_ClientError.yml
105
96
  spec/cassettes/Keymaker_GetRelationshipTypesRequest/with_existing_relationships/returns_a_unique_array_of_relationship_types.yml
106
97
  spec/cassettes/Keymaker_ServiceRootRequest/returns_a_200_status_code.yml
107
98
  spec/cassettes/Keymaker_ServiceRootRequest/returns_application/json.yml
108
99
  spec/cassettes/Keymaker_ServiceRootRequest/returns_the_Neo4j_REST_API_starting_point_response_request.yml
100
+ spec/cassettes/Keymaker_TraversePathRequest/_traverse_path_properties/with_options/builds_the_query_properties_with_defaults.yml
101
+ spec/cassettes/Keymaker_TraversePathRequest/with_invalid_options/raise_a_ClientError.yml
102
+ spec/cassettes/Keymaker_TraversePathRequest/with_valid_options/returns_status_code_200.yml
103
+ spec/cassettes/Keymaker_UpdateNodePropertiesRequest/_node_properties/excludes_the_node_id.yml
104
+ spec/cassettes/Keymaker_UpdateNodePropertiesRequest/with_invalid_options/raises_a_ClientError.yml
105
+ spec/cassettes/Keymaker_UpdateNodePropertiesRequest/with_valid_options/returns_a_status_of_204.yml
106
+ spec/cassettes/Keymaker_UpdateNodePropertiesRequest/with_valid_options/updates_the_properties.yml
109
107
  spec/configuration_spec.rb
110
108
  spec/keymaker/requests/add_node_to_index_request_spec.rb
111
109
  spec/keymaker/requests/batch_get_nodes_request_spec.rb
112
110
  spec/keymaker/requests/batch_request_spec.rb
111
+ spec/keymaker/requests/create_node_request_spec.rb
112
+ spec/keymaker/requests/create_relationship_request_spec.rb
113
113
  spec/keymaker/requests/delete_node_request_spec.rb
114
+ spec/keymaker/requests/delete_relationship_request_spec.rb
115
+ spec/keymaker/requests/execute_cypher_request_spec.rb
116
+ spec/keymaker/requests/execute_gremlin_request_spec.rb
114
117
  spec/keymaker/requests/get_node_request_spec.rb
115
118
  spec/keymaker/requests/get_relationship_types_request_spec.rb
116
119
  spec/keymaker/requests/service_root_request_spec.rb
120
+ spec/keymaker/requests/traverse_path_request_spec.rb
121
+ spec/keymaker/requests/update_node_properties_request_spec.rb
122
+ spec/keymaker/service_spec.rb
117
123
  spec/keymaker_spec.rb
118
124
  spec/service_spec.rb
119
125
  spec/spec_helper.rb
@@ -122,7 +128,5 @@ Gem::Specification.new do |s|
122
128
  ]
123
129
  # = MANIFEST =
124
130
 
125
- ## Test files will be grabbed from the file list. Make sure the path glob
126
- ## matches what you actually use.
127
131
  s.test_files = s.files.grep(%r{^spec/})
128
132
  end
@@ -1,5 +1,6 @@
1
1
  require 'faraday'
2
2
  require 'faraday_middleware'
3
+ require 'hashie'
3
4
  require 'active_model'
4
5
  require 'active_support/core_ext/string/inflections'
5
6
 
@@ -28,7 +29,7 @@ require 'keymaker/requests/get_relationship_types_request'
28
29
 
29
30
  require 'keymaker/requests/execute_cypher_request'
30
31
  require 'keymaker/requests/execute_gremlin_request'
31
- require 'keymaker/requests/path_traverse_request'
32
+ require 'keymaker/requests/traverse_path_request'
32
33
  require 'keymaker/requests/service_root_request'
33
34
 
34
35
  require 'keymaker/indexing'
@@ -39,7 +40,7 @@ require 'keymaker/railtie' if defined? Rails::Railtie
39
40
 
40
41
  module Keymaker
41
42
 
42
- VERSION = "0.0.8"
43
+ VERSION = "0.0.9"
43
44
 
44
45
  def self.service
45
46
  @service ||= Keymaker::Service.new(Keymaker::Configuration.new)
@@ -3,25 +3,21 @@ require "addressable/uri"
3
3
  module Keymaker
4
4
  class Configuration
5
5
 
6
- attr_accessor :protocol, :server, :port,
7
- :data_directory, :cypher_path, :gremlin_path,
8
- :log_file, :log_enabled, :logger,
6
+ attr_accessor :protocol, :server, :port, :data_directory,
9
7
  :authentication, :username, :password
10
8
 
11
9
  def initialize(attrs={})
12
10
  self.protocol = attrs.fetch(:protocol) {'http'}
13
11
  self.server = attrs.fetch(:server) {'localhost'}
14
12
  self.port = attrs.fetch(:port) {7474}
15
- self.data_directory = attrs.fetch(:data_directory) {'db/data'}
16
- self.cypher_path = attrs.fetch(:cypher_path) {'cypher'}
17
- self.gremlin_path = attrs.fetch(:gremlin_path) {'ext/GremlinPlugin/graphdb/execute_script'}
18
13
  self.authentication = attrs.fetch(:authentication) {{}}
19
14
  self.username = attrs.fetch(:username) {nil}
20
15
  self.password = attrs.fetch(:password) {nil}
16
+ self.data_directory = 'db/data'
21
17
  end
22
18
 
23
19
  def service_root
24
- service_root_url.to_s
20
+ @service_root ||= Keymaker.service.service_root_request.body
25
21
  end
26
22
 
27
23
  def service_root_url
@@ -47,32 +43,30 @@ module Keymaker
47
43
  end
48
44
  end
49
45
 
46
+ # paths
47
+
50
48
  def full_cypher_path
51
- [service_root, data_directory, cypher_path].join("/")
49
+ service_root.cypher
52
50
  end
53
51
 
54
52
  def full_gremlin_path
55
- [service_root, data_directory, gremlin_path].join("/")
53
+ service_root.extensions.fetch('GremlinPlugin', {}).fetch('execute_script', nil)
56
54
  end
57
55
 
58
56
  def node_path
59
- [data_directory, "node"].join("/")
57
+ service_root.node
60
58
  end
61
59
 
62
60
  def node_properties_path(node_id)
63
- [node_path, node_id.to_s, "properties"].join("/")
64
- end
65
-
66
- def path_traverse_node_path(node_id)
67
- [node_path, node_id.to_s, "traverse", "path"].join("/")
61
+ [node_path, node_id.to_s, 'properties'].join('/')
68
62
  end
69
63
 
70
- def batch_node_path(node_id)
71
- ["/node", node_id.to_s].join("/")
64
+ def node_uri(node_id)
65
+ [node_path, node_id.to_s].join("/")
72
66
  end
73
67
 
74
68
  def batch_path
75
- [data_directory, "batch"].join("/")
69
+ service_root.batch
76
70
  end
77
71
 
78
72
  def relationship_path(relationship_id)
@@ -80,7 +74,7 @@ module Keymaker
80
74
  end
81
75
 
82
76
  def relationship_types_path
83
- [data_directory, "relationship", "types"].join("/")
77
+ service_root.relationship_types
84
78
  end
85
79
 
86
80
  def relationships_path_for_node(node_id)
@@ -92,11 +86,7 @@ module Keymaker
92
86
  end
93
87
 
94
88
  def node_index_path(index_name)
95
- [data_directory, "index", "node", index_name.to_s].join("/")
96
- end
97
-
98
- def node_uri(node_id)
99
- [service_root, node_path, node_id.to_s].join("/")
89
+ [service_root.node_index, index_name.to_s].join("/")
100
90
  end
101
91
 
102
92
  end
@@ -96,8 +96,8 @@ module Keymaker
96
96
  neo_service.create_node(sanitize(attributes)).on_success do |response|
97
97
  self.node_id = response.neo4j_id
98
98
  self.new_node = false
99
- self
100
99
  end
100
+ self
101
101
  end
102
102
  end
103
103
 
@@ -3,7 +3,6 @@ module Keymaker
3
3
 
4
4
  extend Forwardable
5
5
 
6
- def_delegator :config, :batch_node_path
7
6
  def_delegator :config, :batch_path
8
7
  def_delegator :config, :data_directory_path
9
8
  def_delegator :config, :full_cypher_path
@@ -13,7 +12,6 @@ module Keymaker
13
12
  def_delegator :config, :node_path
14
13
  def_delegator :config, :node_properties_path
15
14
  def_delegator :config, :node_uri
16
- def_delegator :config, :path_traverse_node_path
17
15
  def_delegator :config, :relationship_path
18
16
  def_delegator :config, :relationships_path_for_node
19
17
  def_delegator :config, :relationship_types_path
@@ -2,7 +2,16 @@ module Keymaker
2
2
  class AddNodeToIndexRequest < Request
3
3
 
4
4
  def submit
5
- service.post(node_index_path(opts[:index_name]), {key: opts[:key], value: opts[:value], uri: node_uri(opts[:node_id])})
5
+ service.post(node_index_path(opts[:index_name]), {key: opts[:key], value: opts[:value], uri: node_uri(opts[:node_id])}).on_error do |response|
6
+ case response.status
7
+ when 404
8
+ raise ResourceNotFound.new(response, response.body)
9
+ when (400..499)
10
+ raise ClientError.new(response, response.body)
11
+ when (500..599)
12
+ raise ServerError.new(response, response.body)
13
+ end
14
+ end
6
15
  end
7
16
 
8
17
  end
@@ -10,7 +10,14 @@ module Keymaker
10
10
  class CreateRelationshipRequest < Request
11
11
 
12
12
  def submit
13
- service.post(relationships_path_for_node(opts[:node_id]), rel_properties)
13
+ service.post(relationships_path_for_node(opts[:node_id]), rel_properties).on_error do |response|
14
+ case response.status
15
+ when (400..499)
16
+ raise ClientError.new(response, response.body)
17
+ when (500..599)
18
+ raise ServerError.new(response, response.body)
19
+ end
20
+ end
14
21
  end
15
22
 
16
23
  def rel_properties
@@ -9,7 +9,16 @@ module Keymaker
9
9
  class DeleteRelationshipRequest < Request
10
10
 
11
11
  def submit
12
- service.delete(relationship_path(opts[:relationship_id]))
12
+ service.delete(relationship_path(opts[:relationship_id])).on_error do |response|
13
+ case response.status
14
+ when 404
15
+ raise ResourceNotFound.new(response, response.body)
16
+ when (400..499)
17
+ raise ClientError.new(response, response.body)
18
+ when (500..599)
19
+ raise ServerError.new(response, response.body)
20
+ end
21
+ end
13
22
  end
14
23
 
15
24
  end
@@ -1,9 +1,14 @@
1
1
  module Keymaker
2
2
  class ExecuteCypherRequest < Request
3
-
4
3
  def submit
5
- service.post(full_cypher_path, opts).body
4
+ service.post(full_cypher_path, opts).on_error do |response|
5
+ case response.status
6
+ when (400..499)
7
+ raise ClientError.new(response, response.body)
8
+ when (500..599)
9
+ raise ServerError.new(response, response.body)
10
+ end
11
+ end
6
12
  end
7
-
8
13
  end
9
14
  end
@@ -1,9 +1,14 @@
1
1
  module Keymaker
2
2
  class ExecuteGremlinRequest < Request
3
-
4
3
  def submit
5
- service.post(full_gremlin_path, opts).body
4
+ service.post(full_gremlin_path, opts).on_error do |response|
5
+ case response.status
6
+ when (400..499)
7
+ raise ClientError.new(response, response.body)
8
+ when (500..599)
9
+ raise ServerError.new(response, response.body)
10
+ end
11
+ end
6
12
  end
7
-
8
13
  end
9
14
  end