Class: Beeline::Client
Direct Known Subclasses
Constant Summary collapse
- INITIAL_LATCH =
0.01
- MAX_LATCH =
3.0
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #ping ⇒ Object
- #reset_session ⇒ Object
- #run(options = {async: false}) ⇒ Object
- #run_loop ⇒ Object
Methods included from Config
#friendships, #hive_account, #hive_posting_wif, #hive_public_key
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/beeline/client.rb', line 14 def initialize( = {}) @session = [:session] @url = [:url] || BEE_WS_URL @commands = [:commands] || {} = [:messages] || {} @prefix = [:prefix] || '$' @latch = INITIAL_LATCH @socket = nil @thread_running = false end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
9 10 11 |
# File 'lib/beeline/client.rb', line 9 def commands @commands end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
9 10 11 |
# File 'lib/beeline/client.rb', line 9 def end |
Instance Method Details
#ping ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/beeline/client.rb', line 44 def ping start = Time.now puts 'Ping ... ' socket.ping('Ping!') do puts "Pong! (#{Time.now - start})" end end |
#reset_session ⇒ Object
25 26 27 |
# File 'lib/beeline/client.rb', line 25 def reset_session @session = nil end |
#run(options = {async: false}) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/beeline/client.rb', line 29 def run( = {async: false}) async = !![:async] start_thread(async) unless !!@thread_running socket end |
#run_loop ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/beeline/client.rb', line 36 def run_loop loop do start_thread(false) unless !!@thread_running sleep [@latch *= 2, MAX_LATCH].min end end |