Module: Neo4j::Server::Resource
- Included in:
- CypherNode, CypherRelationship, CypherSession, CypherTransaction
- Defined in:
- lib/neo4j-server/resource.rb
Defined Under Namespace
Classes: ServerException
Instance Attribute Summary (collapse)
-
- (Object) resource_data
readonly
Returns the value of attribute resource_data.
-
- (Object) resource_url(key = nil)
readonly
Returns the value of attribute resource_url.
Instance Method Summary (collapse)
- - (Object) convert_from_json_value(value)
- - (Object) expect_response_code(response, expected_code, msg = 'Error for request')
- - (Object) handle_response_error(response, msg = 'Error for request')
- - (Object) init_resource_data(resource_data, resource_url)
- - (Object) resource_headers
- - (Object) resource_url_id(url = resource_url)
- - (Object) response_exception(response)
- - (Object) wrap_resource(connection = Neo4j::Session.current)
Instance Attribute Details
- (Object) resource_data (readonly)
Returns the value of attribute resource_data
7 8 9 |
# File 'lib/neo4j-server/resource.rb', line 7 def resource_data @resource_data end |
- (Object) resource_url(key = nil) (readonly)
Returns the value of attribute resource_url
7 8 9 |
# File 'lib/neo4j-server/resource.rb', line 7 def resource_url @resource_url end |
Instance Method Details
- (Object) convert_from_json_value(value)
54 55 56 |
# File 'lib/neo4j-server/resource.rb', line 54 def convert_from_json_value(value) JSON.parse(value, quirks_mode: true) end |
- (Object) expect_response_code(response, expected_code, msg = 'Error for request')
36 37 38 39 |
# File 'lib/neo4j-server/resource.rb', line 36 def expect_response_code(response, expected_code, msg = 'Error for request') handle_response_error(response, "Expected response code #{expected_code} #{msg}") unless response.status == expected_code response end |
- (Object) handle_response_error(response, msg = 'Error for request')
32 33 34 |
# File 'lib/neo4j-server/resource.rb', line 32 def handle_response_error(response, msg = 'Error for request') fail ServerException, "#{msg} #{response.env && response.env[:url].to_s}, #{response.status}, #{response.status}" end |
- (Object) init_resource_data(resource_data, resource_url)
9 10 11 12 13 14 15 16 17 |
# File 'lib/neo4j-server/resource.rb', line 9 def init_resource_data(resource_data, resource_url) fail "Exception #{resource_data['exception']}" if resource_data['exception'] fail "Expected @resource_data to be Hash got #{resource_data.inspect}" unless resource_data.respond_to?(:[]) @resource_url = resource_url @resource_data = resource_data self end |
- (Object) resource_headers
46 47 48 |
# File 'lib/neo4j-server/resource.rb', line 46 def resource_headers {'Content-Type' => 'application/json', 'Accept' => 'application/json', 'User-Agent' => ::Neo4j::Session.user_agent_string} end |
- (Object) resource_url_id(url = resource_url)
50 51 52 |
# File 'lib/neo4j-server/resource.rb', line 50 def resource_url_id(url = resource_url) url.match(/\/(\d+)$/)[1].to_i end |
- (Object) response_exception(response)
41 42 43 44 |
# File 'lib/neo4j-server/resource.rb', line 41 def response_exception(response) return nil if response.body.nil? || response.body.empty? JSON.parse(response.body)['exception'] end |
- (Object) wrap_resource(connection = Neo4j::Session.current)
19 20 21 22 |
# File 'lib/neo4j-server/resource.rb', line 19 def wrap_resource(connection = Neo4j::Session.current) url = resource_url('transaction') CypherTransaction.new(url, connection) end |