Class: Fishbowl::Connection

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/fishbowl/connection.rb

Class Method Summary collapse

Class Method Details

.closeObject



58
59
60
61
# File 'lib/fishbowl/connection.rb', line 58

def self.close
  @connection.close
  @connection = nil
end

.connectObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/fishbowl/connection.rb', line 7

def self.connect()
  raise Fishbowl::Errors::MissingHost if Fishbowl.configuration.host.nil?

  @host = Fishbowl.configuration.host
  @port = Fishbowl.configuration.port.nil? ? 28192 : Fishbowl.configuration.port

  @connection = TCPSocket.new @host, @port

  self.instance
end

.hostObject



34
35
36
# File 'lib/fishbowl/connection.rb', line 34

def self.host
  @host
end

.loginObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fishbowl/connection.rb', line 18

def self.()
  raise Fishbowl::Errors::ConnectionNotEstablished if @connection.nil?
  raise Fishbowl::Errors::MissingUsername if Fishbowl.configuration.host.nil?
  raise Fishbowl::Errors::MissingPassword if Fishbowl.configuration.host.nil?

  @username = Fishbowl.configuration.username
  @password = Fishbowl.configuration.password

  code, _ = Fishbowl::Objects::BaseObject.new.send_request()
  Fishbowl::Errors.confirm_success_or_raise(code)

  raise "Login failed" unless code.eql? "1000"

  self.instance
end

.passwordObject



46
47
48
# File 'lib/fishbowl/connection.rb', line 46

def self.password
  @password
end

.portObject



38
39
40
# File 'lib/fishbowl/connection.rb', line 38

def self.port
  @port
end

.send(request, expected_response = 'FbiMsgsRs') ⇒ Object



50
51
52
53
54
55
56
# File 'lib/fishbowl/connection.rb', line 50

def self.send(request, expected_response = 'FbiMsgsRs')
  puts 'opening connection...' if Fishbowl.configuration.debug.eql? true
  puts request if Fishbowl.configuration.debug.eql? true
  puts 'waiting for response...' if Fishbowl.configuration.debug.eql? true
  write(request)
  get_response(expected_response)
end

.usernameObject



42
43
44
# File 'lib/fishbowl/connection.rb', line 42

def self.username
  @username
end