class MokiRuby::Device
Attributes
checked_out[R]
client_id[RW]
id[RW]
last_seen[R]
nickname[R]
title[R]
token[RW]
Public Class Methods
new(identifier)
click to toggle source
# File lib/moki_ruby/device.rb, line 7 def initialize(identifier) if is_serial?(identifier) @identifier_type = :serial elsif is_udid?(identifier) @identifier_type = :udid else raise "Valid UDID or Serial Number required" end @id = identifier end
Public Instance Methods
add_profile(profile)
click to toggle source
# File lib/moki_ruby/device.rb, line 62 def add_profile(profile) raise "TenantIOSProfile required" unless profile && profile.is_a?(TenantIOSProfile) data = MokiAPI.perform_action(device_id_param, profile.install_hash).value return nil unless data.status == 200 Action.from_hash(data.body) end
device_id_param()
click to toggle source
# File lib/moki_ruby/device.rb, line 97 def device_id_param if identifier_type == :serial "sn-!-#{ id }" else id end end
get_action(action_id)
click to toggle source
# File lib/moki_ruby/device.rb, line 80 def get_action(action_id) data = MokiAPI.action(device_id_param, action_id).value return nil unless data.status == 200 Action.from_hash(data.body) end
install_app(tenant_managed_app)
click to toggle source
# File lib/moki_ruby/device.rb, line 44 def install_app(tenant_managed_app) raise "Tenant Managed App required" unless tenant_managed_app && tenant_managed_app.kind_of?(TenantManagedApp) data = MokiAPI.perform_action(device_id_param, tenant_managed_app.install_hash).value return nil unless data.status == 200 Action.from_hash(data.body) end
load_details()
click to toggle source
# File lib/moki_ruby/device.rb, line 18 def load_details data = MokiAPI.device_details(device_id_param).value return nil unless data.status == 200 @nickname = data.body["nickname"] @title = data.body["title"] @last_seen = Time.at(data.body["lastSeen"]/1000) @checked_out = data.body["checkedOut"] return self end
managed_apps()
click to toggle source
# File lib/moki_ruby/device.rb, line 37 def managed_apps data = MokiAPI.device_managed_app_list(device_id_param).value return nil unless data.status == 200 data.body.map { |app| DeviceManagedApp.from_hash(app) } end
pre_enroll()
click to toggle source
# File lib/moki_ruby/device.rb, line 87 def pre_enroll data = MokiAPI.pre_enroll([enroll_hash]).value if data.status == 200 return true else return nil end end
profiles()
click to toggle source
# File lib/moki_ruby/device.rb, line 30 def profiles data = MokiAPI.device_profile_list(device_id_param).value return nil unless data.status == 200 data.body.map { |profile| DeviceIOSProfile.from_hash(profile) } end
remove_profile(profile)
click to toggle source
# File lib/moki_ruby/device.rb, line 71 def remove_profile(profile) raise "DeviceIOSProfile required" unless profile && profile.is_a?(DeviceIOSProfile) data = MokiAPI.perform_action(device_id_param, profile.removal_hash).value return nil unless data.status == 200 Action.from_hash(data.body) end
uninstall_app(device_managed_app)
click to toggle source
# File lib/moki_ruby/device.rb, line 53 def uninstall_app(device_managed_app) raise "DeviceManagedApp required" unless device_managed_app && device_managed_app.is_a?(DeviceManagedApp) data = MokiAPI.perform_action(device_id_param, device_managed_app.uninstall_hash).value return nil unless data.status == 200 Action.from_hash(data.body) end
Private Instance Methods
enroll_hash()
click to toggle source
# File lib/moki_ruby/device.rb, line 119 def enroll_hash raise "Need Serial Number on Device for Enrollment" unless ((identifier_type == :serial) && !id.nil?) hash = { "serialNumber" => id, "clientCode" => nil, "token" => nil } unless token.nil? || token == "" || client_id.nil? || client_id == "" hash = hash.merge({ "clientCode" => client_id.to_s, "token" => token }) end return hash end
is_id?(id)
click to toggle source
# File lib/moki_ruby/device.rb, line 115 def is_id?(id) !(/\A[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\Z/.match(id)).nil? end
is_serial?(id)
click to toggle source
# File lib/moki_ruby/device.rb, line 107 def is_serial?(id) (!id.nil? && id.length == 12) end
is_udid?(id)
click to toggle source
# File lib/moki_ruby/device.rb, line 111 def is_udid?(id) !(/\A[a-f0-9]{40}\Z/.match(id)).nil? end