Class: Beeline::Client

Inherits:
Object
  • Object
show all
Includes:
Config
Defined in:
lib/beeline/client.rb

Direct Known Subclasses

Bot

Constant Summary collapse

INITIAL_LATCH =
0.01
MAX_LATCH =
3.0

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @session = options[:session]
  @url = options[:url] || BEE_WS_URL
  @commands = options[:commands] || {}
  @messages = options[:messages] || {}
  @prefix = options[:prefix] || '$'
  @latch = INITIAL_LATCH
  @socket = nil
  @thread_running = false
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



9
10
11
# File 'lib/beeline/client.rb', line 9

def commands
  @commands
end

#messagesObject (readonly)

Returns the value of attribute messages.



9
10
11
# File 'lib/beeline/client.rb', line 9

def messages
  @messages
end

Instance Method Details

#pingObject



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_sessionObject



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(options = {async: false})
  async = !!options[:async]
  start_thread(async) unless !!@thread_running
  
  socket
end

#run_loopObject



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