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) ⇒ Object



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

def self.create(repository)
  response = repository.request_http :post, repository.path + "/session", :expected_status_code => 200
  url = response.sub(/^"/, "").sub(/"$/, "")
  server = repository.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