Class: Atheme::Session
- Inherits:
-
Object
- Object
- Atheme::Session
- Defined in:
- lib/atheme/session.rb
Constant Summary collapse
- DEFAULT_CONNECTION_SETTINGS =
{ protocol: 'http', hostname: 'localhost', port: '8080' }
- DEFAULT_IP =
'127.0.0.1'
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #hostname ⇒ Object
- #hostname=(h) ⇒ Object
-
#initialize(opts = {}) {|_self| ... } ⇒ Session
constructor
A new instance of Session.
- #logged_in? ⇒ Boolean
- #login(user, password, ip = DEFAULT_IP) ⇒ Object
- #logout ⇒ Object
- #port ⇒ Object
- #port=(p) ⇒ Object
- #protocol ⇒ Object
- #protocol=(p) ⇒ Object
- #relogin(cookie, user, ip = DEFAULT_IP) ⇒ Object
- #service_call(service, method, *args) ⇒ Object
Constructor Details
#initialize(opts = {}) {|_self| ... } ⇒ Session
Returns a new instance of Session.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/atheme/session.rb', line 11 def initialize(opts={}) opts.each_key do |k| if self.respond_to?("#{k}=") self.send("#{k}=", opts[k]) else raise ArgumentError, "Argument '#{k}' is not allowed" end end yield self if block_given? @cookie, @user, @ip = '.', '.', DEFAULT_IP end |
Instance Method Details
#call(*args) ⇒ Object
46 47 48 49 |
# File 'lib/atheme/session.rb', line 46 def call(*args) @server ||= connect_client @server.call(*args) end |
#hostname ⇒ Object
71 72 73 |
# File 'lib/atheme/session.rb', line 71 def hostname @hostname || DEFAULT_CONNECTION_SETTINGS[:hostname] end |
#hostname=(h) ⇒ Object
59 60 61 |
# File 'lib/atheme/session.rb', line 59 def hostname=(h) @hostname = h end |
#logged_in? ⇒ Boolean
42 43 44 |
# File 'lib/atheme/session.rb', line 42 def logged_in? @cookie && @cookie!='.' ? true : false end |
#login(user, password, ip = DEFAULT_IP) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/atheme/session.rb', line 24 def login(user, password, ip=DEFAULT_IP) return true if logged_in? @cookie = self.call("atheme.login", user, password, ip) @user, @ip = user, ip @cookie end |
#logout ⇒ Object
35 36 37 38 39 40 |
# File 'lib/atheme/session.rb', line 35 def logout return true unless logged_in? self.call("atheme.logout", @cookie, @user, @ip) @cookie, @user, @ip = '.', '.', DEFAULT_IP true end |
#port ⇒ Object
75 76 77 |
# File 'lib/atheme/session.rb', line 75 def port @port || DEFAULT_CONNECTION_SETTINGS[:port] end |
#port=(p) ⇒ Object
63 64 65 |
# File 'lib/atheme/session.rb', line 63 def port=(p) @port = p.to_i end |
#protocol ⇒ Object
67 68 69 |
# File 'lib/atheme/session.rb', line 67 def protocol @protocol || DEFAULT_CONNECTION_SETTINGS[:protocol] end |
#protocol=(p) ⇒ Object
55 56 57 |
# File 'lib/atheme/session.rb', line 55 def protocol=(p) @protocol = p end |
#relogin(cookie, user, ip = DEFAULT_IP) ⇒ Object
31 32 33 |
# File 'lib/atheme/session.rb', line 31 def relogin(, user, ip=DEFAULT_IP) @cookie, @user, @ip = , user, ip end |
#service_call(service, method, *args) ⇒ Object
51 52 53 |
# File 'lib/atheme/session.rb', line 51 def service_call(service, method, *args) self.call("atheme.command", @cookie, @user, @ip, service, method, *args) end |