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

Instance Method Summary collapse

Instance Attribute Details

#resource_dataObject (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

#resource_url(key = nil) ⇒ Object (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

#convert_from_json_value(value) ⇒ Object



52
53
54
# File 'lib/neo4j-server/resource.rb', line 52

def convert_from_json_value(value)
  JSON.parse(value, quirks_mode: true)
end

#expect_response_code!(response, expected_code, msg = 'Error for request') ⇒ Object



30
31
32
33
# File 'lib/neo4j-server/resource.rb', line 30

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

#handle_response_error!(response, msg = 'Error for request') ⇒ Object



35
36
37
# File 'lib/neo4j-server/resource.rb', line 35

def handle_response_error!(response, msg = 'Error for request')
  fail ServerException, "#{msg} #{response.env && response.env[:url].to_s}, #{response.status}"
end

#init_resource_data(resource_data, resource_url) ⇒ Object



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_data = resource_data
  @resource_url = resource_url

  self
end

#resource_headersObject



44
45
46
# File 'lib/neo4j-server/resource.rb', line 44

def resource_headers
  {'Content-Type' => 'application/json', 'Accept' => 'application/json; charset=UTF-8', 'User-Agent' => ::Neo4j::Session.user_agent_string}
end

#resource_url_id(url = resource_url) ⇒ Object



48
49
50
# File 'lib/neo4j-server/resource.rb', line 48

def resource_url_id(url = resource_url)
  url.match(%r{/(\d+)$})[1].to_i
end

#response_exception(response) ⇒ Object



39
40
41
42
# File 'lib/neo4j-server/resource.rb', line 39

def response_exception(response)
  return nil if response.body.nil? || response.body.empty?
  JSON.parse(response.body)[:exception]
end

#wrap_resource(connection) ⇒ Object



19
20
21
# File 'lib/neo4j-server/resource.rb', line 19

def wrap_resource(connection)
  CypherTransaction.new(resource_url(:transaction), connection)
end