Class: OpenX::Services::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/openx/services/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Session

Returns a new instance of Session.



6
7
8
9
10
# File 'lib/openx/services/session.rb', line 6

def initialize(url)
  @uri    = URI.parse(url)
  @client = XmlrpcClient.new(self.url)
  @id     = nil
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/openx/services/session.rb', line 4

def id
  @id
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/openx/services/session.rb', line 4

def password
  @password
end

#uriObject

Returns the value of attribute uri.



4
5
6
# File 'lib/openx/services/session.rb', line 4

def uri
  @uri
end

#userObject

Returns the value of attribute user.



4
5
6
# File 'lib/openx/services/session.rb', line 4

def user
  @user
end

Instance Method Details

#create(user, password) ⇒ Object



24
25
26
27
28
# File 'lib/openx/services/session.rb', line 24

def create(user, password)
  self.user     = user
  self.password = password
  recreate!
end

#destroyObject



36
37
38
39
40
# File 'lib/openx/services/session.rb', line 36

def destroy
  @client.call('ox.logoff', id)
  self.id = nil
  self
end

#hostObject



16
17
18
# File 'lib/openx/services/session.rb', line 16

def host
  url.sub(/#{Regexp.escape(uri.path)}$/, '')
end

#recreate!Object



30
31
32
33
34
# File 'lib/openx/services/session.rb', line 30

def recreate!
  raise "Unable to refresh Session" unless user && password
  self.id = @client.call('ox.logon', user, password)
  self
end

#remoteObject



20
21
22
# File 'lib/openx/services/session.rb', line 20

def remote
  @remote ||= XmlrpcSessionClient.new(self)
end

#urlObject



12
13
14
# File 'lib/openx/services/session.rb', line 12

def url
  uri.to_s
end