Class: Em::Sessions::Client
- Inherits:
-
Object
- Object
- Em::Sessions::Client
- Defined in:
- lib/em/sessions/client.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#http_url ⇒ Object
readonly
Returns the value of attribute http_url.
Instance Method Summary collapse
- #activity?(seconds = 600, app = nil) ⇒ Boolean
- #create(id, out_time = 7200, ip = '0.0.0.0', app = nil) ⇒ Object
- #delete_all(app = nil) ⇒ Object
- #delete_by_id(id, app = nil) ⇒ Object
- #delete_by_token(user_token, app = nil) ⇒ Object
- #find_by_id(id, app = nil) ⇒ Object
- #find_by_token(user_token, app = nil) ⇒ Object
-
#initialize(url, app) ⇒ Client
constructor
A new instance of Client.
- #set_params_by_token(user_token, params = {}, app = nil) ⇒ Object
Constructor Details
#initialize(url, app) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/em/sessions/client.rb', line 9 def initialize(url, app) if url.nil? || app.nil? raise 'http_url is blank or app is blank!' end if url.strip.empty? http_url = 'http://localhost:3000/' else http_url = url =~ /^https?\/\// ? url : "http://#{url}" end @app = app @http_url = http_url =~ /\/$/ ? http_url[0..-2] : http_url end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
7 8 9 |
# File 'lib/em/sessions/client.rb', line 7 def app @app end |
#http_url ⇒ Object (readonly)
Returns the value of attribute http_url.
7 8 9 |
# File 'lib/em/sessions/client.rb', line 7 def http_url @http_url end |
Instance Method Details
#activity?(seconds = 600, app = nil) ⇒ Boolean
65 66 67 68 69 |
# File 'lib/em/sessions/client.rb', line 65 def activity?(seconds = 600, app = nil) app_name = get_app_name app run_http_url = %Q{#{@http_url}/#{app_name}/activity?dt=#{seconds}} return run_em 'get', run_http_url end |
#create(id, out_time = 7200, ip = '0.0.0.0', app = nil) ⇒ Object
22 23 24 25 26 |
# File 'lib/em/sessions/client.rb', line 22 def create(id, out_time = 7200, ip = '0.0.0.0', app = nil) app_name = get_app_name app run_http_url = %Q{#{@http_url}/#{app_name}/create/#{id}?ip=#{ip}&ttl=#{out_time}} return run_em 'put', run_http_url end |
#delete_all(app = nil) ⇒ Object
53 54 55 56 57 |
# File 'lib/em/sessions/client.rb', line 53 def delete_all(app = nil) app_name = get_app_name app run_http_url = %Q{#{@http_url}/#{app_name}/killall} return run_em 'delete', run_http_url end |
#delete_by_id(id, app = nil) ⇒ Object
47 48 49 50 51 |
# File 'lib/em/sessions/client.rb', line 47 def delete_by_id(id, app = nil) app_name = get_app_name app run_http_url = %Q{#{@http_url}/#{app_name}/killsoid/#{ id }} return run_em 'delete', run_http_url end |
#delete_by_token(user_token, app = nil) ⇒ Object
41 42 43 44 45 |
# File 'lib/em/sessions/client.rb', line 41 def delete_by_token(user_token, app = nil) app_name = get_app_name app run_http_url = %Q{#{@http_url}/#{app_name}/kill/#{ user_token }} return run_em 'delete', run_http_url end |
#find_by_id(id, app = nil) ⇒ Object
35 36 37 38 39 |
# File 'lib/em/sessions/client.rb', line 35 def find_by_id(id, app = nil) app_name = get_app_name app run_http_url = %Q{#{@http_url}/#{app_name}/soid/#{ id }} return run_em 'get', run_http_url end |
#find_by_token(user_token, app = nil) ⇒ Object
28 29 30 31 32 |
# File 'lib/em/sessions/client.rb', line 28 def find_by_token(user_token, app = nil) app_name = get_app_name app run_http_url = %Q{#{@http_url}/#{app_name}/get/#{ user_token }} return run_em 'get', run_http_url end |
#set_params_by_token(user_token, params = {}, app = nil) ⇒ Object
59 60 61 62 63 |
# File 'lib/em/sessions/client.rb', line 59 def set_params_by_token(user_token, params = {}, app = nil) app_name = get_app_name app run_http_url = %Q{#{@http_url}/#{app_name}/set/#{ user_token }} return run_em 'post', run_http_url, { 'Content-Type'=>'application/json'}, params end |