Class: ROX::Client
- Inherits:
-
Object
- Object
- ROX::Client
- Defined in:
- lib/rox/client.rb,
lib/rox/folders.rb,
lib/rox/config_tree.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
Returns the value of attribute session.
-
#webconversation ⇒ Object
Returns the value of attribute webconversation.
Instance Method Summary collapse
- #config ⇒ Object
- #folders ⇒ Object
- #get(path, parameters = {}) ⇒ Object
- #get_response(path, parameters = {}) ⇒ Object
- #in_module(moduleName, &block) ⇒ Object
-
#initialize(options = nil) ⇒ Client
constructor
A new instance of Client.
- #logged_in? ⇒ Boolean
- #login(username, password) ⇒ Object
- #logout ⇒ Object
- #module(moduleName) ⇒ Object
- #put(path, parameters = {}) ⇒ Object
- #put_response(path, parameters = {}) ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ Client
8 9 10 11 12 13 14 |
# File 'lib/rox/client.rb', line 8 def initialize( = nil) if host = [:host] raise "Please specify an option 'host'" unless host @webconversation = ROX::WebConversation.new(host) end end |
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
6 7 8 |
# File 'lib/rox/client.rb', line 6 def session @session end |
#webconversation ⇒ Object
Returns the value of attribute webconversation.
5 6 7 |
# File 'lib/rox/client.rb', line 5 def webconversation @webconversation end |
Instance Method Details
#config ⇒ Object
20 21 22 |
# File 'lib/rox/config_tree.rb', line 20 def config @config ||= ROX::ConfigTree.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
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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rox/client.rb', line 16 def login(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 |
#logout ⇒ Object
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 |