Module: N4j::Request::ClassMethods

Defined in:
lib/n4j/request.rb

Instance Method Summary collapse

Instance Method Details

#batch(commands) ⇒ Object

”, ‘method’ => ”, ‘body’ => ”, ‘id’ => 0,…


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/n4j/request.rb', line 21

def batch(commands) # [{'to'=> '', 'method' => '', 'body' => '', 'id' => 0},...]
  commands.flatten!
  commands.each_with_index {|command, index| command[:id] ||= index }
  # puts "Batch job: #{commands.inspect}"
  begin
    result = RestClient.post("#{neo4j_url_prefix}/batch",
                              commands.to_json,
                              :accept => :json,
                              :content_type => :json)
    JSON.parse(result)
  rescue RestClient::InternalServerError => e
    message = JSON.parse(JSON.parse(e.response)['message'])['message']
    exception = JSON.parse(JSON.parse(e.response)['message'])['exception']
    puts "Neo4j error: #{message}" if message
    puts "Neo4j excpetion: #{exception}" if exception
  rescue JSON::ParserError => e
    puts "JSON::ParserError ... raw result:\n #{result}"
  end
end

#neo4j_hash?(hsh) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/n4j/request.rb', line 17

def neo4j_hash?(hsh)
  hsh && hsh['self'] && hsh['property'] && hsh['properties']
end

#neo4j_url_prefixObject



8
9
10
# File 'lib/n4j/request.rb', line 8

def neo4j_url_prefix
  @neo4j_url_prefix ||= "http://localhost:#{port}/db/data"
end

#portObject



12
13
14
15
# File 'lib/n4j/request.rb', line 12

def port
  config = YAML.load_file("#{Rails.root}/config/n4j.yml")
  config[Rails.env]['port']
end