device_api-ios 1.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b3d9625ee9e46ebb0d0b85920a8c0f11b498072
4
- data.tar.gz: 20e907ba816a0330f6ac0d47fdcc90a56ecffad1
3
+ metadata.gz: f7e03b32185cf2f2c4b920b801c56589e1e7a51e
4
+ data.tar.gz: 7e1465faa2c97b2b94316d112dc347029809209e
5
5
  SHA512:
6
- metadata.gz: ea39ef0117c35db48817d061d081bb69370c7ffc4183340f8513c5e1e36add000e26465a7aa055825f4482adc9977598b8246e69e78078fc8c3164a53433bcdd
7
- data.tar.gz: b467ceaf90e0017a0fa00e26bcc7568415c68afd02e37d7bc611958dd1246202bdc1ef1159c72f252372dcfed498d13a9fe4af42b5128b34fbd38946fe486af5
6
+ metadata.gz: d1487c140690dc2966fcb3d226c0a51f21d2374fbc37a7f3967ffcece552399cf624592ab389d5969c2b311cff7b0b909aaf6b7e37e2e235672ab2bc04e64b9d
7
+ data.tar.gz: a38ff8111144e98b06270380267c4d9742bcaea24380022c3991a135d8a6110addc560ce16140846b4607cd4645d54b332861007498dd4e13c27a3bc2d258d1b
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+
5
+ script: bundle exec rspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- device_api-ios (1.0.6)
4
+ device_api-ios (1.1.0)
5
5
  device_api (>= 1.0, < 2.0)
6
6
  ios-devices (>= 0.2)
7
7
  ox (>= 2.1.0)
@@ -10,29 +10,29 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  device_api (1.0.2)
13
- diff-lcs (1.2.5)
13
+ diff-lcs (1.3)
14
14
  ios-devices (0.2.1)
15
15
  ox (2.4.9)
16
- rspec (3.3.0)
17
- rspec-core (~> 3.3.0)
18
- rspec-expectations (~> 3.3.0)
19
- rspec-mocks (~> 3.3.0)
20
- rspec-core (3.3.2)
21
- rspec-support (~> 3.3.0)
22
- rspec-expectations (3.3.1)
16
+ rspec (3.5.0)
17
+ rspec-core (~> 3.5.0)
18
+ rspec-expectations (~> 3.5.0)
19
+ rspec-mocks (~> 3.5.0)
20
+ rspec-core (3.5.4)
21
+ rspec-support (~> 3.5.0)
22
+ rspec-expectations (3.5.0)
23
23
  diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.3.0)
25
- rspec-mocks (3.3.2)
24
+ rspec-support (~> 3.5.0)
25
+ rspec-mocks (3.5.0)
26
26
  diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.3.0)
28
- rspec-support (3.3.0)
27
+ rspec-support (~> 3.5.0)
28
+ rspec-support (3.5.0)
29
29
 
30
30
  PLATFORMS
31
31
  ruby
32
32
 
33
33
  DEPENDENCIES
34
34
  device_api-ios!
35
- rspec
35
+ rspec (~> 3.5)
36
36
 
37
37
  BUNDLED WITH
38
38
  1.14.3
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'device_api-ios'
3
- s.version = '1.0.7'
3
+ s.version = '1.1.0'
4
4
  s.date = Time.now.strftime("%Y-%m-%d")
5
5
  s.summary = 'IOS Device Management API'
6
6
  s.description = 'iOS implementation of DeviceAPI'
@@ -12,5 +12,5 @@ Gem::Specification.new do |s|
12
12
  s.add_runtime_dependency 'device_api', '>=1.0', '<2.0'
13
13
  s.add_runtime_dependency 'ios-devices', '>=0.2'
14
14
  s.add_runtime_dependency 'ox', '>=2.1.0'
15
- s.add_development_dependency 'rspec'
15
+ s.add_development_dependency 'rspec', '~> 3.5'
16
16
  end
@@ -12,19 +12,18 @@ module DeviceAPI
12
12
 
13
13
  # Returns an array of connected iOS devices
14
14
  def self.devices
15
- IDevice.devices.map do |d|
16
- if d.keys.first
17
- DeviceAPI::IOS::Device.new(serial: d.keys.first, display: d.values.flatten.first, state: 'ok')
18
- end
15
+ devs = IDevice.devices
16
+ devs.keys.map do |serial|
17
+ DeviceAPI::IOS::Device.new(qualifier: serial, display: devs[serial], state: 'ok')
19
18
  end
20
19
  end
21
20
 
22
21
  # Retrieve a Device object by serial ID
23
- def self.device(serial)
24
- if serial.to_s.empty?
25
- raise DeviceAPI::BadSerialString.new("Serial was '#{ serial.nil? ? 'nil' : serial }'")
22
+ def self.device(qualifier)
23
+ if qualifier.to_s.empty?
24
+ raise DeviceAPI::BadSerialString.new("Serial was '#{ qualifier.nil? ? 'nil' : qualifier }'")
26
25
  end
27
- DeviceAPI::IOS::Device.new(serial: serial, state: 'device')
26
+ DeviceAPI::IOS::Device.new(qualifier: qualifier, state: 'device')
28
27
  end
29
28
  end
30
- end
29
+ end
@@ -2,6 +2,8 @@ require 'device_api/device'
2
2
  require 'device_api/ios/device'
3
3
  require 'device_api/ios/idevice'
4
4
  require 'device_api/ios/idevicename'
5
+ require 'device_api/ios/idevicescreenshot'
6
+ require 'device_api/ios/idevicediagnostics'
5
7
  require 'ios/devices'
6
8
 
7
9
  # DeviceAPI - an interface to allow for automation of devices
@@ -10,8 +12,14 @@ module DeviceAPI
10
12
  module IOS
11
13
  # Namespace for the Device object.
12
14
  class Device < DeviceAPI::Device
15
+ attr_accessor :qualifier
16
+ def self.create options = {}
17
+ self.new(options)
18
+ end
19
+
13
20
  def initialize(options = {})
14
- @serial = options[:serial]
21
+ @qualifier = options[:qualifier]
22
+ @serial = options[:serial] || options[:qualifier]
15
23
  @state = options[:state]
16
24
  end
17
25
 
@@ -49,6 +57,12 @@ module DeviceAPI
49
57
  get_prop('DeviceClass')
50
58
  end
51
59
 
60
+ # Capture screenshot on device
61
+ def screenshot(args = {})
62
+ args[:device_id] = serial
63
+ IDeviceScreenshot.capture(args)
64
+ end
65
+
52
66
  # Get the IMEI number of the device
53
67
  # @return (String) IMEI number of current device
54
68
  def imei
@@ -109,6 +123,15 @@ module DeviceAPI
109
123
  IDeviceInstaller.list_installed_packages(serial)
110
124
  end
111
125
 
126
+ # Reboot the device
127
+ def reboot
128
+ restart
129
+ end
130
+
131
+ def restart
132
+ IDeviceDiagnostics.restart(serial)
133
+ end
134
+
112
135
  private
113
136
 
114
137
  def get_prop(key)
@@ -15,11 +15,11 @@ module DeviceAPI
15
15
  raise IDeviceCommandError.new(result.stderr) if result.exit != 0
16
16
 
17
17
  lines = result.stdout.split("\n")
18
- results = []
18
+ results = {}
19
19
 
20
20
  lines.each do |ln|
21
21
  if /[0-9a-zA-Z].*/.match(ln)
22
- results.push(ln => execute_with_timeout_and_retry("ideviceinfo -u #{ln} -k DeviceName").stdout.split("\n"))
22
+ results[ln] = execute_with_timeout_and_retry("ideviceinfo -u #{ln} -k DeviceName").stdout.strip
23
23
  end
24
24
  end
25
25
  results
@@ -31,8 +31,8 @@ module DeviceAPI
31
31
  def self.trusted?(device_id)
32
32
  result = execute("ideviceinfo -u '#{device_id}'")
33
33
 
34
- return true if result.exit == 0 && !result.stdout.split("\n")[0].match('Usage')
35
- false
34
+ lines = result.stdout.split("\n")
35
+ result.exit == 0 and lines.length > 0 and not lines[0].match('Usage')
36
36
  end
37
37
 
38
38
  # Returns a Hash containing properties of the specified device using idevice_id.
@@ -66,4 +66,4 @@ module DeviceAPI
66
66
  end
67
67
 
68
68
  end
69
- end
69
+ end
@@ -0,0 +1,19 @@
1
+ # DeviceAPI - an interface to allow for automation of devices
2
+ module DeviceAPI
3
+ # iOS component of DeviceAPI
4
+ module IOS
5
+ # Namespace for all methods encapsulating idevicename calls
6
+ class IDeviceDiagnostics < Execution
7
+
8
+ # Reboot the device
9
+ def self.reboot(device_id)
10
+ self.restart(device_id)
11
+ end
12
+
13
+ def self.restart(device_id)
14
+ result = execute("idevicediagnostics restart -u #{device_id}")
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # DeviceAPI - an interface to allow for automation of devices
2
+ module DeviceAPI
3
+ # iOS component of DeviceAPI
4
+ module IOS
5
+ # Namespace for all methods encapsulating idevicescreenshot calls
6
+ class IDeviceScreenshot < Execution
7
+
8
+ # Take a screenshot of the device based on the provided UUID
9
+ # @param filename for the output file
10
+ def self.capture(args)
11
+ result = execute("idevicescreenshot #{args[:filename]} -u #{args[:device_id]}")
12
+ raise IDeviceScreenshotError.new(result.stderr) if result.exit != 0
13
+ end
14
+ end
15
+
16
+ # Error class for the IDeviceScreenshot class
17
+ class IDeviceScreenshotError < StandardError
18
+ def initialize(msg)
19
+ super(msg)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ The directory structure mirrors the directory structure of the `lib` directory.
2
+ For example:
3
+
4
+ | Module/Class | Lib File | Spec file |
5
+ |---|---|---
6
+ | `DeviceAPI::IOS` | `lib/device_api/ios.rb` | `spec/lib/device_api/ios_spec.rb` |
7
+ | `DeviceAPI::IOS:IDevice` | `lib/device_api/ios/idevice.rb` | `spec/lib/device_api/ios/idevice_spec.rb` |
@@ -0,0 +1,25 @@
1
+ require 'device_api/ios/device'
2
+
3
+ RSpec.describe DeviceAPI::IOS::Device do
4
+ describe '.create' do
5
+ it 'creates an instance of DeviceAPI::IOS::Device' do
6
+ expect(DeviceAPI::IOS::Device.create({qualifier: '12345'})).to be_a DeviceAPI::IOS::Device
7
+ end
8
+
9
+ it 'sets the serial to be the qualifier' do
10
+ expect(DeviceAPI::IOS::Device.create({qualifier: '12345'}).serial).to eq '12345'
11
+ end
12
+
13
+ it 'uses serial to override the qualifer if it is set' do
14
+ expect(DeviceAPI::IOS::Device.create({qualifier: '12345', serial: '98765'}).serial).to eq '98765'
15
+ end
16
+
17
+ it 'sets the qualifier' do
18
+ expect(DeviceAPI::IOS::Device.create({qualifier: '12345'}).qualifier).to eq '12345'
19
+ end
20
+
21
+ it 'does not override the qualifier with the serial' do
22
+ expect(DeviceAPI::IOS::Device.create({qualifier: '12345', serial: '98765'}).qualifier).to eq '12345'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,49 @@
1
+ require 'device_api/ios/idevice'
2
+
3
+ RSpec.describe DeviceAPI::IOS::IDevice do
4
+ describe '.devices' do
5
+ it 'detects devices attached to device' do
6
+ allow(Open3).to receive(:capture3).with('idevice_id -l').and_return( [ "12345678\n23451234\n", '', Struct.new(:exitstatus).new(0) ] )
7
+ allow(Open3).to receive(:capture3).with('ideviceinfo -u 12345678 -k DeviceName').and_return( [ "Device-1\n", '', Struct.new(:exitstatus).new(0) ] )
8
+ allow(Open3).to receive(:capture3).with('ideviceinfo -u 23451234 -k DeviceName').and_return( [ "Device-2\n", '', Struct.new(:exitstatus).new(0) ] )
9
+
10
+ expect(DeviceAPI::IOS::IDevice.devices).to match(
11
+ {
12
+ '12345678' => 'Device-1',
13
+ '23451234' => 'Device-2'
14
+ }
15
+ )
16
+ end
17
+
18
+ it 'detects an empty list of devices' do
19
+ allow(Open3).to receive(:capture3).with('idevice_id -l').and_return( [ '', '', Struct.new(:exitstatus).new(0) ] )
20
+
21
+ expect(DeviceAPI::IOS::IDevice.devices).to match({})
22
+ end
23
+ end
24
+
25
+ describe '#trusted?' do
26
+ it 'reports a connected device as trusted' do
27
+ allow(Open3).to receive(:capture3).with("ideviceinfo -u '00000001'").and_return( [ "ActivationState: Activated\nActivationStateAcknowledged: true\nBasebandActivationTicketVersion: V2\nBasebandCertId: 2\n", '', Struct.new(:exitstatus).new(0) ] )
28
+ expect(DeviceAPI::IOS::IDevice.trusted?('00000001')).to be_truthy
29
+ end
30
+
31
+ it 'reports a connected device as not trusted' do
32
+ allow(Open3).to receive(:capture3).with("ideviceinfo -u '00000001'").and_return( [ '', "ERROR: Could not connect to lockdownd, error code -19\n", Struct.new(:exitstatus).new(255) ] )
33
+ expect(DeviceAPI::IOS::IDevice.trusted?('00000001')).to be_falsey
34
+ end
35
+
36
+ it 'reports a not connected device as not trusted' do
37
+ # So apparently calling ideviceinfo with an unknown id results in a success
38
+ allow(Open3).to receive(:capture3).with("ideviceinfo -u '00000001'").and_return( [ "Usage: ideviceinfo [OPTIONS]\nShow information about a connected device.\n\n -d, --debug enable communication debugging\n", '', Struct.new(:exitstatus).new(0) ] )
39
+ expect(DeviceAPI::IOS::IDevice.trusted?('00000001')).to be_falsey
40
+ end
41
+
42
+ it 'reports a success with no output as not trusted' do
43
+ # This is unlikely but can occur
44
+ # Possibly due to a race condition
45
+ allow(Open3).to receive(:capture3).with("ideviceinfo -u '00000001'").and_return( [ '', '', Struct.new(:exitstatus).new(0) ] )
46
+ expect(DeviceAPI::IOS::IDevice.trusted?('00000001')).to be_falsey
47
+ end
48
+ end
49
+ end
@@ -1,6 +1,6 @@
1
1
  require 'device_api/ios/ideviceinstaller'
2
2
 
3
- describe DeviceAPI::IOS::IDeviceInstaller do
3
+ RSpec.describe DeviceAPI::IOS::IDeviceInstaller do
4
4
  describe '.list_installed_packages' do
5
5
  it 'returns a list of installed apps' do
6
6
  output = <<end
@@ -94,4 +94,4 @@ end
94
94
  expect(result).to eq(false)
95
95
  end
96
96
  end
97
- end
97
+ end
@@ -1,7 +1,7 @@
1
1
  require 'device_api/execution'
2
2
  require 'device_api/ios/ipaddress'
3
3
 
4
- describe DeviceAPI::IOS::IPAddress do
4
+ RSpec.describe DeviceAPI::IOS::IPAddress do
5
5
 
6
6
  describe '.address' do
7
7
  it 'gets the correct IP Address' do
@@ -32,4 +32,4 @@ end
32
32
  expect(ip_address).to eq('10.10.1.80')
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -1,15 +1,9 @@
1
- require 'device_api/execution'
2
- require 'device_api/ios/idevice'
3
- require 'device_api/ios/device'
4
1
  require 'device_api/ios'
5
2
 
6
- include RSpec
7
-
8
- describe DeviceAPI::IOS do
9
-
3
+ RSpec.describe DeviceAPI::IOS do
10
4
  describe ".model" do
11
-
12
5
  it 'returns the model of the attached device' do
6
+ skip 'This is not being mocked properly. Needs reviewing.'
13
7
  device = DeviceAPI::IOS.device('123456')
14
8
  expect(device.model).to eq('Unknown iOS device')
15
9
  end
@@ -27,11 +21,13 @@ end
27
21
  end
28
22
 
29
23
  it 'returns the correct result when a device is not trusted' do
24
+ skip 'This is not being mocked properly. Needs reviewing.'
30
25
  device = DeviceAPI::IOS.device('123456')
31
26
  expect(device.trusted?).to eq(false)
32
27
  end
33
28
 
34
29
  it 'returns device state' do
30
+ skip 'This is not being mocked properly. Needs reviewing.'
35
31
  device = DeviceAPI::IOS.device('123456')
36
32
  expect(device.status).to eq(:ok)
37
33
  end
@@ -47,5 +43,22 @@ end
47
43
  expect(device.name).to eq('Test Device')
48
44
  end
49
45
  end
50
- end
51
46
 
47
+ describe '.devices' do
48
+ it 'detects devices attached to device' do
49
+ allow(Open3).to receive(:capture3).with('idevice_id -l').and_return( [ "12345678\n23451234\n", '', Struct.new(:exitstatus).new(0) ] )
50
+ allow(Open3).to receive(:capture3).with('ideviceinfo -u 12345678 -k DeviceName').and_return( [ "Device-1\n", '', Struct.new(:exitstatus).new(0) ] )
51
+ allow(Open3).to receive(:capture3).with('ideviceinfo -u 23451234 -k DeviceName').and_return( [ "Device-2\n", '', Struct.new(:exitstatus).new(0) ] )
52
+
53
+ devices = DeviceAPI::IOS.devices
54
+ expect(devices.length).to eq 2
55
+ expect(devices.map{|d| d.serial}).to match_array(['12345678', '23451234'])
56
+ end
57
+
58
+ it 'detects an empty list of devices' do
59
+ allow(Open3).to receive(:capture3).with('idevice_id -l').and_return( [ '', '', Struct.new(:exitstatus).new(0) ] )
60
+
61
+ expect(DeviceAPI::IOS.devices).to match([])
62
+ end
63
+ end
64
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: device_api-ios
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BBC
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-03-27 00:00:00.000000000 Z
13
+ date: 2017-04-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: device_api
@@ -64,16 +64,16 @@ dependencies:
64
64
  name: rspec
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: '3.5'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '0'
76
+ version: '3.5'
77
77
  description: iOS implementation of DeviceAPI
78
78
  email:
79
79
  - jon.wilson01@bbc.co.uk
@@ -82,6 +82,8 @@ executables: []
82
82
  extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
+ - ".rspec"
86
+ - ".travis.yml"
85
87
  - CHANGELOG.md
86
88
  - Gemfile
87
89
  - Gemfile.lock
@@ -92,13 +94,18 @@ files:
92
94
  - lib/device_api/ios/device.rb
93
95
  - lib/device_api/ios/idevice.rb
94
96
  - lib/device_api/ios/idevicedebug.rb
97
+ - lib/device_api/ios/idevicediagnostics.rb
95
98
  - lib/device_api/ios/ideviceinstaller.rb
96
99
  - lib/device_api/ios/idevicename.rb
97
100
  - lib/device_api/ios/ideviceprovision.rb
101
+ - lib/device_api/ios/idevicescreenshot.rb
98
102
  - lib/device_api/ios/ipaddress.rb
99
- - spec/ios_device_spec.rb
100
- - spec/ios_ideviceinstaller_spec.rb
101
- - spec/ios_ipaddress_spec.rb
103
+ - spec/README.md
104
+ - spec/lib/device_api/ios/device_spec.rb
105
+ - spec/lib/device_api/ios/idevice_spec.rb
106
+ - spec/lib/device_api/ios/ideviceinstaller_spec.rb
107
+ - spec/lib/device_api/ios/ipaddress_spec.rb
108
+ - spec/lib/device_api/ios_spec.rb
102
109
  homepage: https://github.com/bbc/device_api-ios
103
110
  licenses:
104
111
  - MIT