moki_ruby 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/lib/moki_ruby/device.rb +13 -0
- data/lib/moki_ruby/moki_api.rb +4 -0
- data/lib/moki_ruby/version.rb +1 -1
- data/spec/lib/device_spec.rb +22 -7
- data/spec/lib/moki_api_spec.rb +12 -1
- data/spec/support/common_stubs.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d474a75dcbd7d4a9647efc8f71e9cfb95104e6f4
|
4
|
+
data.tar.gz: 47a78d25c089f12ead74db8a3f4d95004d232852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 845fb16cbeae3dcbf444d8ca00862d56adf78e00705b04f440fc81efa35c9cc5a5e2e19e3d204b7ab29402ed7635f3420051dd1b198ad1b0b20219926de87799
|
7
|
+
data.tar.gz: 12281d8968ad005525ee9537d479b489d1887eb20dcd9901d385dc9b6a209d9cd30d9d13003f83a444ca72c78212adf8ccc6bb52210297429582c158ec13e798
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -53,6 +53,9 @@ MokiRuby::Device.new(udid)
|
|
53
53
|
|
54
54
|
Using this device, there are several methods available:
|
55
55
|
|
56
|
+
- `device.load_details` will populate the device's nickname, title, time
|
57
|
+
it was last seen, and whether or not it is checked out. This will
|
58
|
+
return the updated `Device` object.
|
56
59
|
- `device.profiles` returns all profiles currently installed on a
|
57
60
|
device. This will return an array of `DeviceIOSProfile` objects.
|
58
61
|
- `device.managed_apps` returns all managed applications installed on a
|
data/lib/moki_ruby/device.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module MokiRuby
|
2
2
|
class Device
|
3
3
|
attr_accessor :client_id, :token
|
4
|
+
attr_reader :nickname, :title, :last_seen, :checked_out
|
4
5
|
attr :id, :identifier_type
|
5
6
|
|
6
7
|
def initialize(identifier)
|
@@ -14,6 +15,18 @@ module MokiRuby
|
|
14
15
|
@id = identifier
|
15
16
|
end
|
16
17
|
|
18
|
+
def load_details
|
19
|
+
data = MokiAPI.device_details(device_id_param).value
|
20
|
+
return nil unless data.status == 200
|
21
|
+
|
22
|
+
@nickname = data.body["nickname"]
|
23
|
+
@title = data.body["title"]
|
24
|
+
@last_seen = Time.at(data.body["lastSeen"]/1000)
|
25
|
+
@checked_out = data.body["checkedOut"]
|
26
|
+
|
27
|
+
return self
|
28
|
+
end
|
29
|
+
|
17
30
|
def profiles
|
18
31
|
data = MokiAPI.device_profile_list(device_id_param).value
|
19
32
|
return nil unless data.status == 200
|
data/lib/moki_ruby/moki_api.rb
CHANGED
@@ -13,6 +13,10 @@ module MokiRuby
|
|
13
13
|
issue_request(:get, full_url('/iosprofiles'), {})
|
14
14
|
end
|
15
15
|
|
16
|
+
def self.device_details(device_id)
|
17
|
+
issue_request(:get, full_url("/devices/#{ device_id }"), {})
|
18
|
+
end
|
19
|
+
|
16
20
|
def self.device_profile_list(device_id)
|
17
21
|
issue_request(:get, full_url("/devices/#{ device_id }/profiles"), {})
|
18
22
|
end
|
data/lib/moki_ruby/version.rb
CHANGED
data/spec/lib/device_spec.rb
CHANGED
@@ -5,19 +5,18 @@ describe MokiRuby::Device do
|
|
5
5
|
let(:sn) { "ABCDEFGHIJ12" }
|
6
6
|
let(:udid) { "abcd1234-1234-1234-1234-abcdef123456" }
|
7
7
|
let(:device) { MokiRuby::Device.new(udid) }
|
8
|
+
let(:serial_device) { MokiRuby::Device.new(sn) }
|
8
9
|
|
9
10
|
describe 'initialization' do
|
10
11
|
context "with serial number" do
|
11
12
|
it "is valid" do
|
12
|
-
|
13
|
-
expect(
|
14
|
-
expect(device.identifier_type).to eq :serial
|
13
|
+
expect(serial_device.id).to eq sn
|
14
|
+
expect(serial_device.identifier_type).to eq :serial
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context "with UDID" do
|
19
19
|
it "is valid" do
|
20
|
-
device = MokiRuby::Device.new(udid)
|
21
20
|
expect(device.id).to eq udid
|
22
21
|
end
|
23
22
|
end
|
@@ -32,19 +31,35 @@ describe MokiRuby::Device do
|
|
32
31
|
describe "#device_id_param" do
|
33
32
|
describe "Serial Number" do
|
34
33
|
it "prepends serial number data" do
|
35
|
-
|
36
|
-
expect(device.device_id_param).to eq "sn-!-#{ sn }"
|
34
|
+
expect(serial_device.device_id_param).to eq "sn-!-#{ sn }"
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
38
|
describe "UDID" do
|
41
39
|
it "prepends serial number data" do
|
42
|
-
device = MokiRuby::Device.new(udid)
|
43
40
|
expect(device.device_id_param).to eq udid
|
44
41
|
end
|
45
42
|
end
|
46
43
|
end
|
47
44
|
|
45
|
+
describe "#load_details" do
|
46
|
+
it "calls MokiAPI.device_details with the correct params" do
|
47
|
+
expect(MokiAPI).to receive_message_chain(:device_details, :value).and_return(Hashie::Mash.new({ body: {} }))
|
48
|
+
device.load_details
|
49
|
+
end
|
50
|
+
|
51
|
+
it "loads the details of the device info response into the object" do
|
52
|
+
load_good_stubs
|
53
|
+
current_id_param = device.device_id_param
|
54
|
+
expected_last_seen = Time.at(@device_info_stub_response["lastSeen"]/1000)
|
55
|
+
expect(device.load_details.device_id_param).to eq(current_id_param)
|
56
|
+
expect(device.nickname).to eq(@device_info_stub_response["nickname"])
|
57
|
+
expect(device.title).to eq(@device_info_stub_response["title"])
|
58
|
+
expect(device.last_seen).to eq(expected_last_seen)
|
59
|
+
expect(device.checked_out).to eq(@device_info_stub_response["checkedOut"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
48
63
|
describe "#profiles" do
|
49
64
|
it "calls MokiAPI.device_profile_list with correct params" do
|
50
65
|
expect(MokiAPI).to receive_message_chain(:device_profile_list, :value).and_return(Hashie::Mash.new({ body: [] }))
|
data/spec/lib/moki_api_spec.rb
CHANGED
@@ -40,9 +40,20 @@ describe MokiAPI do
|
|
40
40
|
MokiAPI.ios_profiles
|
41
41
|
end
|
42
42
|
|
43
|
+
describe "device details" do
|
44
|
+
it 'issues a get request using the device parameter' do
|
45
|
+
param = "sn-!-ABCDEFGHIJ12"
|
46
|
+
expect(MokiAPI).to receive(:issue_request) { |method, url, options|
|
47
|
+
expect(method).to eq(:get)
|
48
|
+
expect(url).to eq("http://localhost:9292/rest/v1/api/tenants/#{ ENV['MOKI_TENANT_ID'] }/devices/#{ param }")
|
49
|
+
}.and_return('{}')
|
50
|
+
MokiAPI.device_details(param)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
43
54
|
describe "device profile list" do
|
44
55
|
it 'issues a get request using device parameter' do
|
45
|
-
param = "sn-!-ABCDEFGHIJ12"
|
56
|
+
param = "sn-!-ABCDEFGHIJ12"
|
46
57
|
expect(MokiAPI).to receive(:issue_request) { |method, url, options|
|
47
58
|
expect(method).to eq(:get)
|
48
59
|
expect(url).to eq("http://localhost:9292/rest/v1/api/tenants/#{ ENV['MOKI_TENANT_ID'] }/devices/#{ param }/profiles")
|
@@ -4,6 +4,12 @@ def load_base_stubs
|
|
4
4
|
{"id"=>"462d3468-face-0300-4321-abcdef123456", "lastSeen"=>1415637997309, "name"=>"Test Profile 3", "displayName"=>"Test Profile 3", "description"=>"Test Profile 3", "identifier"=>"com.belly.1e968fa0-other03.TestProfile3"},
|
5
5
|
{"id"=>"fcd2bfb0-face-0400-4321-abcdef123456", "lastSeen"=>1423524426266, "name"=>"Test Profile 4", "displayName"=>"Test Profile 4", "description"=>"Test Profile 4", "identifier"=>"com.belly.1e968fa0-other04.TestProfile4"}]
|
6
6
|
|
7
|
+
@device_info_stub_response = { "udid" => "886e136ec721b8474eb8f64a1c0f29a20881d167",
|
8
|
+
"nickname" => "Test iPad",
|
9
|
+
"title" => "iPad",
|
10
|
+
"lastSeen" => 1425073329355,
|
11
|
+
"checkedOut" => false }
|
12
|
+
|
7
13
|
@device_managed_app_stub_response = [{ "Status" => "Managed", "appIdentifier" => "com.belly.moki.gem.enterprise", "ManagementFlags" => 1 },
|
8
14
|
{ "Status" => "Managed", "appIdentifier" => "com.belly.flop.html.enterprise", "ManagementFlags" => 0 }]
|
9
15
|
|
@@ -84,6 +90,11 @@ def load_good_stubs
|
|
84
90
|
status: 200,
|
85
91
|
headers: {}}))
|
86
92
|
|
93
|
+
allow(MokiAPI).to receive_message_chain(:device_details, :value).
|
94
|
+
and_return(Hashie::Mash.new({ body: @device_info_stub_response,
|
95
|
+
status: 200,
|
96
|
+
headers: {}}))
|
97
|
+
|
87
98
|
allow(MokiAPI).to receive_message_chain(:device_profile_list, :value).
|
88
99
|
and_return(Hashie::Mash.new({ body: @iosprofiles_stub_response,
|
89
100
|
status: 200,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moki_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trey Springer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|