Class: OpenSTF::Device

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

Constant Summary collapse

DEVICE_TIMEOUT =

2hours, milli second unit

60 * 60 * 2 * 1000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data: {}, serial: nil) ⇒ Device

Returns a new instance of Device.



6
7
8
9
# File 'lib/openstf/device.rb', line 6

def initialize(data: {}, serial: nil)
  @data   = data
  @serial = data['serial'] || serial
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/openstf/device.rb', line 4

def data
  @data
end

#remote_connect_urlObject

Returns the value of attribute remote_connect_url.



4
5
6
# File 'lib/openstf/device.rb', line 4

def remote_connect_url
  @remote_connect_url
end

#serialObject

Returns the value of attribute serial.



4
5
6
# File 'lib/openstf/device.rb', line 4

def serial
  @serial
end

Instance Method Details

#connectObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/openstf/device.rb', line 11

def connect
  device = ::OpenSTF::Client::Devices.get_device_by_serial(
      serial: @serial,
  fields: 'serial,present,ready,using,owner').body['device']
  if !device['present'] || !device['ready'] || device['using'] || device['owner']
    raise("Device #{@serial} is not available")
  end

  added = ::OpenSTF::Client::User::Devices.add_user_device(
      serial: @serial,
      timeout:DEVICE_TIMEOUT
  ).body

  raise("Could not connect to device #{@serial}")unless added['success']

  connected = ::OpenSTF::Client::User::Devices::RemoteConnect.remote_connect_user_device_by_serial(serial: @serial).body

  raise("#{connected['description']}: #{@serial}") unless connected['success']

  return connected['remoteConnectUrl']
end

#disconnectObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/openstf/device.rb', line 33

def disconnect
  user_devices = OpenSTF::Client::User::Devices
                     .get_user_device_by_serial(
                         serial: @serial,
                         fields: 'serial,present,ready,using,owner'
                     ).body
  raise("#{user_devices['description']}: #{@serial}") unless user_devices['success']

  deleted = OpenSTF::Client::User::Devices
                .delete_user_device_by_serial(
                    serial: @serial
                ).body

  raise("#{deleted['description']}: #{@serial}") unless deleted['success']
end