Class: ROX::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rox/client.rb,
lib/rox/folders.rb,
lib/rox/config_tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Client



8
9
10
11
12
13
14
# File 'lib/rox/client.rb', line 8

def initialize(options = nil)
  if options
      host = options[:host] 
      raise "Please specify an option 'host'" unless host
      @webconversation = ROX::WebConversation.new(host)
  end
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



6
7
8
# File 'lib/rox/client.rb', line 6

def session
  @session
end

#webconversationObject

Returns the value of attribute webconversation.



5
6
7
# File 'lib/rox/client.rb', line 5

def webconversation
  @webconversation
end

Instance Method Details

#configObject



20
21
22
# File 'lib/rox/config_tree.rb', line 20

def config
  @config ||= ROX::ConfigTree.new(self)
end

#foldersObject



54
55
56
# File 'lib/rox/folders.rb', line 54

def folders
  Folders.new(self)
end

#get(path, parameters = {}) ⇒ Object



45
46
47
48
# File 'lib/rox/client.rb', line 45

def get(path, parameters = {})
  parameters[:session] ||= @session
  @webconversation.get(path, parameters)
end

#get_response(path, parameters = {}) ⇒ Object

Raises:



55
56
57
58
59
# File 'lib/rox/client.rb', line 55

def get_response(path, parameters = {})
  response = ROX::Response.new(JSON.parse(get(path, parameters)))
  raise ROX::OXException.new(response) if response.error?
  return response;
end

#in_module(moduleName, &block) ⇒ Object



67
68
69
70
71
# File 'lib/rox/client.rb', line 67

def in_module(moduleName, &block)
  mod = self.module(moduleName)
  return mod.instance_eval(&block) if block_given?
  return mod
end

#logged_in?Boolean



41
42
43
# File 'lib/rox/client.rb', line 41

def logged_in?
  !@session.nil?
end

#login(username, password) ⇒ Object

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rox/client.rb', line 16

def (username, password)
  response = @webconversation.get("/ajax/login", :action => :login, :name => username, :password => password)
  response = ROX::Response.new(JSON.parse(response))
  raise OXException.new(response) if response.error?
  @session = response["session"]
  
  if block_given?
    begin
      return yield(self)
    ensure
      logout
    end
  end
  
end

#logoutObject



32
33
34
35
36
37
38
39
# File 'lib/rox/client.rb', line 32

def logout
  response = @webconversation.get("/ajax/login", :action => :logout, :session => session)
  if(response and response != "")
    response = ROX::Response.new(JSON.parse(response))
    raise OXException.new(response) if response.error?
  end
  @session = nil
end

#module(moduleName) ⇒ Object



73
74
75
# File 'lib/rox/client.rb', line 73

def module(moduleName)
  ROX::SimpleModule.new("/ajax/"+moduleName.to_s, self)
end

#put(path, parameters = {}) ⇒ Object



50
51
52
53
# File 'lib/rox/client.rb', line 50

def put(path, parameters = {})
  parameters[:session] ||= @session
  @webconversation.put(path, parameters)
end

#put_response(path, parameters = {}) ⇒ Object

Raises:



61
62
63
64
65
# File 'lib/rox/client.rb', line 61

def put_response(path, parameters = {}) 
  response = ROX::Response.new(JSON.parse(put(path, parameters)))
  raise ROX::OXException.new(response) if response.error?
  return response
end