Class: AllegroGraph::Session

Inherits:
Resource show all
Defined in:
lib/allegro_graph/session.rb

Overview

The Session class wrap the corresponding resource on the AllegroGraph server.

Instance Attribute Summary collapse

Attributes inherited from Resource

#geometric, #mapping, #query, #statements

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { }) ⇒ Session

Returns a new instance of Session.



11
12
13
14
15
16
# File 'lib/allegro_graph/session.rb', line 11

def initialize(options = { })
  super
  @url      = options[:url]
  @username = options[:username]
  @password = options[:password]
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Class Method Details

.create(repository_or_server, options = { }) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/allegro_graph/session.rb', line 45

def self.create(repository_or_server, options = { })
  path = repository_or_server.path
  raise ArgumentError, "The :store parameter is missing!" if path.empty? && !options.has_key?(:store)

  response = repository_or_server.request_http :post,
                                               path + "/session",
                                               { :expected_status_code => 200, :parameters => build_parameters(options) }
  url = response.sub(/^"/, "").sub(/"$/, "")
  server = repository_or_server.server
  new :url => url, :username => server.username, :password => server.password
end

Instance Method Details

#commitObject



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

def commit
  self.request_http :post, "/commit", :expected_status_code => 204
  true
end

#pathObject



18
19
20
# File 'lib/allegro_graph/session.rb', line 18

def path
  ""
end

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



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

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



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

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

#rollbackObject



35
36
37
38
# File 'lib/allegro_graph/session.rb', line 35

def rollback
  self.request_http :post, "/rollback", :expected_status_code => 204
  true
end

#sizeObject



40
41
42
43
# File 'lib/allegro_graph/session.rb', line 40

def size
  response = self.request_http :get, "/size", :type => :text, :expected_status_code => 200
  response.to_i
end