Class: FakeDroid

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_droid.rb

Constant Summary collapse

VERSION =
'0.0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port = 5554) ⇒ FakeDroid

Returns a new instance of FakeDroid.



11
12
13
14
15
16
17
# File 'lib/fake_droid.rb', line 11

def initialize(port = 5554)
  @connection = begin
    s = TCPSocket.open('localhost', port)
    welcome = s.gets
    check_status(s)
  end
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

Instance Method Details

#check_status(socket) ⇒ Object



19
20
21
22
23
# File 'lib/fake_droid.rb', line 19

def check_status(socket)
  status = socket.gets.chop
  raise "Invalid status: #{status}" unless status =~ /\AOK/
  socket
end

#command(cmd, *args) ⇒ Object



25
26
27
28
# File 'lib/fake_droid.rb', line 25

def command(cmd, *args)
  connection.puts [cmd, *args].join ' '
  check_status(connection)
end

#fake_smsObject



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

def fake_sms
  send_sms(Faker.numerify("+#########"), Faker::Lorem.sentences(2))
end

#send_sms(from, body) ⇒ Object



30
31
32
# File 'lib/fake_droid.rb', line 30

def send_sms(from, body)
  command("sms send", from, body)
end