Class: MokiRuby::Device

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier) ⇒ Device

Returns a new instance of Device.



6
7
8
9
10
11
12
13
14
15
# File 'lib/moki_ruby/device.rb', line 6

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

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



3
4
5
# File 'lib/moki_ruby/device.rb', line 3

def client_id
  @client_id
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#tokenObject

Returns the value of attribute token.



3
4
5
# File 'lib/moki_ruby/device.rb', line 3

def token
  @token
end

Instance Method Details

#add_profile(profile) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/moki_ruby/device.rb', line 40

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_paramObject



75
76
77
78
79
80
81
# File 'lib/moki_ruby/device.rb', line 75

def device_id_param
  if identifier_type == :serial
    "sn-!-#{ id }"
  else
    id
  end
end

#get_action(action_id) ⇒ Object



58
59
60
61
62
63
# File 'lib/moki_ruby/device.rb', line 58

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) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/moki_ruby/device.rb', line 31

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

#managed_appsObject



24
25
26
27
28
29
# File 'lib/moki_ruby/device.rb', line 24

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_enrollObject



65
66
67
68
69
70
71
72
73
# File 'lib/moki_ruby/device.rb', line 65

def pre_enroll
  data = MokiAPI.pre_enroll(enroll_hash).value

  if data.status == 200
    return true
  else
    return nil
  end
end

#profilesObject



17
18
19
20
21
22
# File 'lib/moki_ruby/device.rb', line 17

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) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/moki_ruby/device.rb', line 49

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