Skip to content

Commit

Permalink
Merge pull request #19 from bbc/device_name
Browse files Browse the repository at this point in the history
Return a devices' assigned name
  • Loading branch information
Asimk21 committed Feb 3, 2016
2 parents 1b2842b + df11a40 commit 70be81b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/device_api/ios.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'device_api/ios/idevicedebug'
require 'device_api/ios/ipaddress'
require 'device_api/ios/ideviceprovision'
require 'device_api/ios/idevicename'

module DeviceAPI
module IOS
Expand Down
7 changes: 7 additions & 0 deletions lib/device_api/ios/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'device_api/ios/device'
require 'device_api/ios/idevice'
require 'device_api/ios/plistutil'
require 'device_api/ios/idevicename'
require 'ios/devices'

# DeviceAPI - an interface to allow for automation of devices
Expand All @@ -25,6 +26,12 @@ def status
}[@state]
end

# Look up device name - i.e. Bob's iPhone
# @return (String) iOS device name
def name
IDeviceName.name(serial)
end

# Look up device model using the ios-devices gem - changing 'iPad4,7' to 'iPad mini 3'
# @return (String) human readable model and version (where applicable)
def model
Expand Down
25 changes: 25 additions & 0 deletions lib/device_api/ios/idevicename.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# DeviceAPI - an interface to allow for automation of devices
module DeviceAPI
# iOS component of DeviceAPI
module IOS
# Namespace for all methods encapsulating idevicename calls
class IDeviceName < Execution

# Returns the device name based on the provided UUID
# @param device_id uuid of the device
# @return device name if device is connected
def self.name(device_id)
result = execute("idevicename -u #{device_id}")
return IDeviceNameError.new(result.stderr) if result.exit != 0
result.stdout.strip
end
end

# Error class for the IDeviceName class
class IDeviceNameError < StandardError
def initialize(msg)
super(msg)
end
end
end
end
11 changes: 11 additions & 0 deletions spec/ios_device_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
device = DeviceAPI::IOS.device('123456')
expect(device.status).to eq(:ok)
end

it 'returns the device name' do
output = <<-end
Test Device
end
allow(Open3).to receive(:capture3) {
[output, '', (Struct.new(:exitstatus)).new(0)]
}
device = DeviceAPI::IOS.device('123456')
expect(device.name).to eq('Test Device')
end
end
end

0 comments on commit 70be81b

Please sign in to comment.