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.



7
8
9
10
11
12
13
14
15
16
# 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

Instance Attribute Details

#checked_outObject (readonly)

Returns the value of attribute checked_out.



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

def checked_out
  @checked_out
end

#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.



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

def id
  @id
end

#last_seenObject (readonly)

Returns the value of attribute last_seen.



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

def last_seen
  @last_seen
end

#nicknameObject (readonly)

Returns the value of attribute nickname.



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

def nickname
  @nickname
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
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



62
63
64
65
66
67
68
69
# 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_paramObject



97
98
99
100
101
102
103
# 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) ⇒ Object



80
81
82
83
84
85
# 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) ⇒ Object



44
45
46
47
48
49
50
51
# 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_detailsObject



18
19
20
21
22
23
24
25
26
27
28
# 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_appsObject



37
38
39
40
41
42
# 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_enrollObject



87
88
89
90
91
92
93
94
95
# 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

#profilesObject



30
31
32
33
34
35
# 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) ⇒ Object



71
72
73
74
75
76
77
78
# 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) ⇒ Object



53
54
55
56
57
58
59
60
# 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