keymaker 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.md +71 -11
  2. data/Rakefile +1 -1
  3. data/keymaker.gemspec +46 -15
  4. data/lib/keymaker.rb +25 -12
  5. data/lib/keymaker/configuration.rb +4 -0
  6. data/lib/keymaker/errors.rb +22 -0
  7. data/lib/keymaker/match_method.rb +24 -0
  8. data/lib/keymaker/request.rb +2 -1
  9. data/lib/keymaker/{add_node_to_index_request.rb → requests/add_node_to_index_request.rb} +0 -0
  10. data/lib/keymaker/requests/batch_get_nodes_request.rb +24 -0
  11. data/lib/keymaker/requests/batch_request.rb +18 -0
  12. data/lib/keymaker/{create_node_request.rb → requests/create_node_request.rb} +0 -0
  13. data/lib/keymaker/{create_relationship_request.rb → requests/create_relationship_request.rb} +0 -0
  14. data/lib/keymaker/requests/delete_node_request.rb +18 -0
  15. data/lib/keymaker/{delete_relationship_request.rb → requests/delete_relationship_request.rb} +0 -0
  16. data/lib/keymaker/{execute_cypher_request.rb → requests/execute_cypher_request.rb} +0 -0
  17. data/lib/keymaker/{execute_gremlin_request.rb → requests/execute_gremlin_request.rb} +0 -0
  18. data/lib/keymaker/requests/get_node_request.rb +16 -0
  19. data/lib/keymaker/requests/get_relationship_types_request.rb +18 -0
  20. data/lib/keymaker/{path_traverse_request.rb → requests/path_traverse_request.rb} +0 -0
  21. data/lib/keymaker/{remove_node_from_index_request.rb → requests/remove_node_from_index_request.rb} +0 -0
  22. data/lib/keymaker/requests/service_root_request.rb +11 -0
  23. data/lib/keymaker/{update_node_properties_request.rb → requests/update_node_properties_request.rb} +0 -0
  24. data/lib/keymaker/response.rb +8 -1
  25. data/lib/keymaker/service.rb +17 -43
  26. data/spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_a_201_status_code.yml +204 -0
  27. data/spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_application/json.yml +204 -0
  28. data/spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_the_Neo4j_REST_API_starting_point_response_request.yml +204 -0
  29. data/spec/cassettes/Keymaker_BatchRequest/when_a_resource_is_not_found/raises_BatchRequestError.yml +120 -0
  30. data/spec/cassettes/Keymaker_BatchRequest/when_to_and_method_are_not_set/raises_BatchRequestError.yml +106 -0
  31. data/spec/cassettes/Keymaker_BatchRequest/with_valid_options/returns_a_200_status_code.yml +129 -0
  32. data/spec/cassettes/Keymaker_BatchRequest/with_valid_options/runs_the_commands_and_returns_their_respective_results.yml +129 -0
  33. data/spec/cassettes/Keymaker_GetNodeRequest/with_a_non-existent_node_id/raises_ResourceNotFound.yml +101 -0
  34. data/spec/cassettes/Keymaker_GetNodeRequest/with_an_empty_node_id/raises_ClientError.yml +111 -0
  35. data/spec/cassettes/Keymaker_GetRelationshipTypesRequest/with_existing_relationships/returns_a_unique_array_of_relationship_types.yml +220 -0
  36. data/spec/cassettes/Keymaker_ServiceRootRequest/returns_a_200_status_code.yml +105 -0
  37. data/spec/cassettes/Keymaker_ServiceRootRequest/returns_application/json.yml +105 -0
  38. data/spec/cassettes/Keymaker_ServiceRootRequest/returns_the_Neo4j_REST_API_starting_point_response_request.yml +105 -0
  39. data/spec/{keymaker/configuration_spec.rb → configuration_spec.rb} +0 -0
  40. data/spec/keymaker/requests/add_node_to_index_request_spec.rb +41 -0
  41. data/spec/keymaker/requests/batch_get_nodes_request_spec.rb +23 -0
  42. data/spec/keymaker/requests/batch_request_spec.rb +115 -0
  43. data/spec/keymaker/requests/delete_node_request_spec.rb +37 -0
  44. data/spec/keymaker/requests/get_node_request_spec.rb +24 -0
  45. data/spec/keymaker/requests/get_relationship_types_request_spec.rb +17 -0
  46. data/spec/keymaker/requests/service_root_request_spec.rb +35 -0
  47. data/spec/{keymaker/service_spec.rb → service_spec.rb} +0 -0
  48. data/spec/support/vcr.rb +8 -0
  49. metadata +116 -19
  50. data/lib/keymaker/batch_get_nodes_request.rb +0 -19
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Keymaker::DeleteNodeRequest do
4
+
5
+ let(:delete_node_request) { Keymaker::DeleteNodeRequest.new(Keymaker.service, opts).submit }
6
+
7
+ context "with a node without relationships" do
8
+ let(:node_id) { Keymaker.service.create_node({name: "John Connor"}).neo4j_id }
9
+ let(:opts) { {node_id: node_id} }
10
+ it "deletes the node" do
11
+ delete_node_request.status.should == 204
12
+ end
13
+ end
14
+
15
+ context "with a node with relationships" do
16
+ let(:john) { Keymaker.service.create_node({name: "John Connor"}) }
17
+ let(:john_id) { john.neo4j_id }
18
+ let(:sarah) { Keymaker.service.create_node({name: "Sarah Connor"}) }
19
+ let!(:relationship) { Keymaker.service.create_relationship("knows", john_id, sarah.neo4j_id) }
20
+ let(:opts) { {node_id: john_id} }
21
+ it "does not delete the node" do
22
+ expect {
23
+ delete_node_request
24
+ }.to raise_error(Keymaker::ConflictError)
25
+ end
26
+ end
27
+
28
+ context "with a non-existent node" do
29
+ let(:opts) { {node_id: 9000000009} }
30
+ it "raises ResourceNotFound" do
31
+ expect {
32
+ delete_node_request
33
+ }.to raise_error(Keymaker::ResourceNotFound)
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Keymaker::GetNodeRequest, vcr: true do
4
+ let(:get_node_request) { Keymaker::GetNodeRequest.new(Keymaker.service, opts).submit }
5
+
6
+ context "with a non-existent node id" do
7
+ let(:opts) {{node_id: 42}}
8
+ it "raises ResourceNotFound" do
9
+ expect {
10
+ get_node_request
11
+ }.to raise_error(Keymaker::ResourceNotFound)
12
+ end
13
+ end
14
+
15
+ context "with an empty node id" do
16
+ let(:opts) {{}}
17
+ it "raises ClientError" do
18
+ expect {
19
+ get_node_request
20
+ }.to raise_error(Keymaker::ClientError)
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'keymaker'
3
+
4
+ describe Keymaker::GetRelationshipTypesRequest, vcr: true do
5
+
6
+ let(:get_relationship_types_request) { Keymaker::GetRelationshipTypesRequest.new(Keymaker.service, {}).submit }
7
+
8
+ context "with existing relationships" do
9
+ include_context "John and Sarah nodes"
10
+ before do
11
+ Keymaker.service.create_relationship(:loves, john_node_id, sarah_node_id).neo4j_id
12
+ end
13
+ it "returns a unique array of relationship types" do
14
+ get_relationship_types_request.body.should == ["loves", "knows"]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'keymaker'
3
+
4
+ describe Keymaker::ServiceRootRequest, vcr: true do
5
+
6
+ let(:service_root_request) { Keymaker::ServiceRootRequest.new(Keymaker.service, {}).submit }
7
+
8
+ it "returns the Neo4j REST API starting point response request" do
9
+ service_root_request.body.should include(
10
+ {
11
+ "cypher" => "http://localhost:7477/db/data/cypher",
12
+ "relationship_index" => "http://localhost:7477/db/data/index/relationship",
13
+ "node" => "http://localhost:7477/db/data/node",
14
+ "relationship_types" => "http://localhost:7477/db/data/relationship/types",
15
+ "batch" => "http://localhost:7477/db/data/batch",
16
+ "extensions_info" => "http://localhost:7477/db/data/ext",
17
+ "node_index" => "http://localhost:7477/db/data/index/node",
18
+ "extensions" =>
19
+ {
20
+ "CypherPlugin" => {"execute_query" => "http://localhost:7477/db/data/ext/CypherPlugin/graphdb/execute_query"},
21
+ "GremlinPlugin" => {"execute_script" => "http://localhost:7477/db/data/ext/GremlinPlugin/graphdb/execute_script"}
22
+ }
23
+ }
24
+ )
25
+ end
26
+
27
+ it "returns a 200 status code" do
28
+ service_root_request.status.should == 200
29
+ end
30
+
31
+ it "returns application/json" do
32
+ service_root_request.faraday_response.headers["content-type"].should include("application/json")
33
+ end
34
+
35
+ end
File without changes
@@ -0,0 +1,8 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.hook_into :faraday
5
+ c.cassette_library_dir = 'spec/cassettes'
6
+ c.configure_rspec_metadata!
7
+ c.allow_http_connections_when_no_cassette = true
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keymaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,40 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-15 00:00:00.000000000 Z
13
+ date: 2012-07-19 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activemodel
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: activesupport
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
15
47
  - !ruby/object:Gem::Dependency
16
48
  name: addressable
17
49
  requirement: !ruby/object:Gem::Requirement
@@ -61,14 +93,14 @@ dependencies:
61
93
  - !ruby/object:Gem::Version
62
94
  version: '0'
63
95
  - !ruby/object:Gem::Dependency
64
- name: activemodel
96
+ name: fakeweb
65
97
  requirement: !ruby/object:Gem::Requirement
66
98
  none: false
67
99
  requirements:
68
100
  - - ! '>='
69
101
  - !ruby/object:Gem::Version
70
102
  version: '0'
71
- type: :runtime
103
+ type: :development
72
104
  prerelease: false
73
105
  version_requirements: !ruby/object:Gem::Requirement
74
106
  none: false
@@ -124,6 +156,22 @@ dependencies:
124
156
  - - ! '>='
125
157
  - !ruby/object:Gem::Version
126
158
  version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: vcr
161
+ requirement: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
127
175
  description: A multi-layer REST API wrapper for neo4j.
128
176
  email:
129
177
  - rogelio@therubymug.com
@@ -140,30 +188,58 @@ files:
140
188
  - Rakefile
141
189
  - keymaker.gemspec
142
190
  - lib/keymaker.rb
143
- - lib/keymaker/add_node_to_index_request.rb
144
- - lib/keymaker/batch_get_nodes_request.rb
145
191
  - lib/keymaker/configuration.rb
146
- - lib/keymaker/create_node_request.rb
147
- - lib/keymaker/create_relationship_request.rb
148
- - lib/keymaker/delete_relationship_request.rb
149
- - lib/keymaker/execute_cypher_request.rb
150
- - lib/keymaker/execute_gremlin_request.rb
192
+ - lib/keymaker/errors.rb
151
193
  - lib/keymaker/indexing.rb
194
+ - lib/keymaker/match_method.rb
152
195
  - lib/keymaker/node.rb
153
- - lib/keymaker/path_traverse_request.rb
154
196
  - lib/keymaker/rails_tasks.rb
155
197
  - lib/keymaker/railtie.rb
156
- - lib/keymaker/remove_node_from_index_request.rb
157
198
  - lib/keymaker/request.rb
199
+ - lib/keymaker/requests/add_node_to_index_request.rb
200
+ - lib/keymaker/requests/batch_get_nodes_request.rb
201
+ - lib/keymaker/requests/batch_request.rb
202
+ - lib/keymaker/requests/create_node_request.rb
203
+ - lib/keymaker/requests/create_relationship_request.rb
204
+ - lib/keymaker/requests/delete_node_request.rb
205
+ - lib/keymaker/requests/delete_relationship_request.rb
206
+ - lib/keymaker/requests/execute_cypher_request.rb
207
+ - lib/keymaker/requests/execute_gremlin_request.rb
208
+ - lib/keymaker/requests/get_node_request.rb
209
+ - lib/keymaker/requests/get_relationship_types_request.rb
210
+ - lib/keymaker/requests/path_traverse_request.rb
211
+ - lib/keymaker/requests/remove_node_from_index_request.rb
212
+ - lib/keymaker/requests/service_root_request.rb
213
+ - lib/keymaker/requests/update_node_properties_request.rb
158
214
  - lib/keymaker/response.rb
159
215
  - lib/keymaker/serialization.rb
160
216
  - lib/keymaker/service.rb
161
- - lib/keymaker/update_node_properties_request.rb
162
- - spec/keymaker/configuration_spec.rb
163
- - spec/keymaker/service_spec.rb
217
+ - spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_a_201_status_code.yml
218
+ - spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_application/json.yml
219
+ - spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_the_Neo4j_REST_API_starting_point_response_request.yml
220
+ - spec/cassettes/Keymaker_BatchRequest/when_a_resource_is_not_found/raises_BatchRequestError.yml
221
+ - spec/cassettes/Keymaker_BatchRequest/when_to_and_method_are_not_set/raises_BatchRequestError.yml
222
+ - spec/cassettes/Keymaker_BatchRequest/with_valid_options/returns_a_200_status_code.yml
223
+ - spec/cassettes/Keymaker_BatchRequest/with_valid_options/runs_the_commands_and_returns_their_respective_results.yml
224
+ - spec/cassettes/Keymaker_GetNodeRequest/with_a_non-existent_node_id/raises_ResourceNotFound.yml
225
+ - spec/cassettes/Keymaker_GetNodeRequest/with_an_empty_node_id/raises_ClientError.yml
226
+ - spec/cassettes/Keymaker_GetRelationshipTypesRequest/with_existing_relationships/returns_a_unique_array_of_relationship_types.yml
227
+ - spec/cassettes/Keymaker_ServiceRootRequest/returns_a_200_status_code.yml
228
+ - spec/cassettes/Keymaker_ServiceRootRequest/returns_application/json.yml
229
+ - spec/cassettes/Keymaker_ServiceRootRequest/returns_the_Neo4j_REST_API_starting_point_response_request.yml
230
+ - spec/configuration_spec.rb
231
+ - spec/keymaker/requests/add_node_to_index_request_spec.rb
232
+ - spec/keymaker/requests/batch_get_nodes_request_spec.rb
233
+ - spec/keymaker/requests/batch_request_spec.rb
234
+ - spec/keymaker/requests/delete_node_request_spec.rb
235
+ - spec/keymaker/requests/get_node_request_spec.rb
236
+ - spec/keymaker/requests/get_relationship_types_request_spec.rb
237
+ - spec/keymaker/requests/service_root_request_spec.rb
164
238
  - spec/keymaker_spec.rb
239
+ - spec/service_spec.rb
165
240
  - spec/spec_helper.rb
166
241
  - spec/support/keymaker.rb
242
+ - spec/support/vcr.rb
167
243
  homepage: https://github.com/therubymug/keymaker
168
244
  licenses: []
169
245
  post_install_message:
@@ -178,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
254
  version: '0'
179
255
  segments:
180
256
  - 0
181
- hash: 2124841849284898919
257
+ hash: 2610601547165857650
182
258
  required_rubygems_version: !ruby/object:Gem::Requirement
183
259
  none: false
184
260
  requirements:
@@ -192,8 +268,29 @@ signing_key:
192
268
  specification_version: 2
193
269
  summary: A multi-layer REST API wrapper for neo4j.
194
270
  test_files:
195
- - spec/keymaker/configuration_spec.rb
196
- - spec/keymaker/service_spec.rb
271
+ - spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_a_201_status_code.yml
272
+ - spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_application/json.yml
273
+ - spec/cassettes/Keymaker_AddNodeToIndexRequest/returns_the_Neo4j_REST_API_starting_point_response_request.yml
274
+ - spec/cassettes/Keymaker_BatchRequest/when_a_resource_is_not_found/raises_BatchRequestError.yml
275
+ - spec/cassettes/Keymaker_BatchRequest/when_to_and_method_are_not_set/raises_BatchRequestError.yml
276
+ - spec/cassettes/Keymaker_BatchRequest/with_valid_options/returns_a_200_status_code.yml
277
+ - spec/cassettes/Keymaker_BatchRequest/with_valid_options/runs_the_commands_and_returns_their_respective_results.yml
278
+ - spec/cassettes/Keymaker_GetNodeRequest/with_a_non-existent_node_id/raises_ResourceNotFound.yml
279
+ - spec/cassettes/Keymaker_GetNodeRequest/with_an_empty_node_id/raises_ClientError.yml
280
+ - spec/cassettes/Keymaker_GetRelationshipTypesRequest/with_existing_relationships/returns_a_unique_array_of_relationship_types.yml
281
+ - spec/cassettes/Keymaker_ServiceRootRequest/returns_a_200_status_code.yml
282
+ - spec/cassettes/Keymaker_ServiceRootRequest/returns_application/json.yml
283
+ - spec/cassettes/Keymaker_ServiceRootRequest/returns_the_Neo4j_REST_API_starting_point_response_request.yml
284
+ - spec/configuration_spec.rb
285
+ - spec/keymaker/requests/add_node_to_index_request_spec.rb
286
+ - spec/keymaker/requests/batch_get_nodes_request_spec.rb
287
+ - spec/keymaker/requests/batch_request_spec.rb
288
+ - spec/keymaker/requests/delete_node_request_spec.rb
289
+ - spec/keymaker/requests/get_node_request_spec.rb
290
+ - spec/keymaker/requests/get_relationship_types_request_spec.rb
291
+ - spec/keymaker/requests/service_root_request_spec.rb
197
292
  - spec/keymaker_spec.rb
293
+ - spec/service_spec.rb
198
294
  - spec/spec_helper.rb
199
295
  - spec/support/keymaker.rb
296
+ - spec/support/vcr.rb
@@ -1,19 +0,0 @@
1
- module Keymaker
2
-
3
- class BatchGetNodesRequest < Request
4
-
5
- def submit
6
- service.post(batch_path, batch_get_nodes_properties)
7
- end
8
-
9
- def batch_get_nodes_properties
10
- [].tap do |batch_request|
11
- opts.each_with_index do |node_id, request_id|
12
- batch_request << {id: request_id, to: node_uri(node_id), method: "GET"}
13
- end
14
- end
15
- end
16
-
17
- end
18
-
19
- end