Class: AllegroGraph::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/allegro_graph/server.rb

Overview

The Server class provides methods to retrieve informations about a AllegroGraph server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { }) ⇒ Server

Returns a new instance of Server.



13
14
15
16
17
18
19
20
# File 'lib/allegro_graph/server.rb', line 13

def initialize(options = { })
  @host     = options[:host] || "localhost"
  @port     = options[:port] || "10035"
  @username = options[:username]
  @password = options[:password]

  @root_catalog = Catalog.new self, "root", :root => true
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/allegro_graph/server.rb', line 7

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



10
11
12
# File 'lib/allegro_graph/server.rb', line 10

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/allegro_graph/server.rb', line 8

def port
  @port
end

#root_catalogObject (readonly)

Returns the value of attribute root_catalog.



11
12
13
# File 'lib/allegro_graph/server.rb', line 11

def root_catalog
  @root_catalog
end

#usernameObject (readonly)

Returns the value of attribute username.



9
10
11
# File 'lib/allegro_graph/server.rb', line 9

def username
  @username
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
# File 'lib/allegro_graph/server.rb', line 22

def ==(other)
  other.is_a?(self.class) && @host == other.host && @port == other.port
end

#catalogsObject



54
55
56
57
58
59
60
61
62
# File 'lib/allegro_graph/server.rb', line 54

def catalogs
  result = [ @root_catalog ]
  catalogs = self.request_json :get, "/catalogs", :expected_status_code => 200
  catalogs.each do |catalog|
    id = catalog["id"]
    result << Catalog.new(self, id.sub(/^\//, "")) unless id == "/"
  end
  result
end

#pathObject



30
31
32
# File 'lib/allegro_graph/server.rb', line 30

def path
  ""
end

#request_http(http_method, path, options = { }) ⇒ Object



38
39
40
# File 'lib/allegro_graph/server.rb', line 38

def request_http(http_method, path, options = { })
  ::Transport::HTTP.request http_method, (self.url + path), credentials.merge(options)
end

#request_json(http_method, path, options = { }) ⇒ Object



42
43
44
# File 'lib/allegro_graph/server.rb', line 42

def request_json(http_method, path, options = { })
  ::Transport::JSON.request http_method, self.url + path, credentials.merge(options)
end

#serverObject



34
35
36
# File 'lib/allegro_graph/server.rb', line 34

def server
  self
end

#urlObject



26
27
28
# File 'lib/allegro_graph/server.rb', line 26

def url
  "http://#{@host}:#{@port}"
end

#versionObject



46
47
48
49
50
51
52
# File 'lib/allegro_graph/server.rb', line 46

def version
  {
    :version  => self.request_http(:get, "/version",          :expected_status_code => 200),
    :date     => self.request_http(:get, "/version/date",     :expected_status_code => 200),
    :revision => self.request_http(:get, "/version/revision", :expected_status_code => 200)
  }
end