Module: N4j::Request::ClassMethods

Defined in:
lib/n4j/request.rb

Instance Method Summary collapse

Instance Method Details

#batch(commands) ⇒ Object

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


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/n4j/request.rb', line 36

def batch(commands) # [{'to'=> '', 'method' => '', 'body' => '', 'id' => 0},...]
  commands.flatten!
  # commands.each_with_index {|command, index| command[:id] ||= index }
  commands.inject(0) do |index, command|
    command[:id] = command[:id] || (index + 1)
  end
  puts "Batch job: "
  commands.each {|c| puts "  #{c}"}
  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

#destroy_everything!Object



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

def destroy_everything!
  clean_path = N4j.neo4j_url_prefix.sub('/db/data','/cleandb/all-gone')
  RestClient.delete(clean_path)
end

#hostObject



27
28
29
30
# File 'lib/n4j/request.rb', line 27

def host
  config = YAML.load_file("config/n4j.yml")
  config[Rails.env]['host'] || 'localhost'
end

#neo4j_hash?(hsh) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/n4j/request.rb', line 32

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

#neo4j_url_prefixObject



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

def neo4j_url_prefix
  @neo4j_url_prefix ||= ENV['NEO4J_REST_URL'] || "http://#{host}:#{port}/db/data"
end

#neo4j_url_prefix=(url) ⇒ Object



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

def neo4j_url_prefix=(url)
  @neo4j_url_prefix = url
end

#portObject



22
23
24
25
# File 'lib/n4j/request.rb', line 22

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