Module: AppleDEPClient::Device

Defined in:
lib/apple_dep_client/device.rb

Constant Summary collapse

FETCH_PATH =
"/server/devices"
FETCH_LIMIT =

must be between 100 and 1000

1000
SYNC_PATH =
"/devices/sync"
DETAILS_PATH =
"/devices/details"
DISOWN_PATH =
"/devices/disown"

Class Method Summary collapse

Class Method Details

.details(devices) ⇒ Object



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

def self.details(devices)
  body = devices
  body = JSON.dump body
  response = AppleDEPClient::Request.make_request(AppleDEPClient::Request.make_url(DETAILS_PATH), :post, body)
  response["devices"]
end

.disown(devices) ⇒ Object

Accepts an array of device ID strings WARNING - this will remove devices from DEP accounts and may render devices permanently inoperable DEPRECATED by Apple



53
54
55
56
57
58
59
# File 'lib/apple_dep_client/device.rb', line 53

def self.disown(devices)
  Kernel.warn "Disown is a deprecated request and may not be supported in the future"
  body = { "devices" => devices }
  body = JSON.dump body
  response = AppleDEPClient::Request.make_request(AppleDEPClient::Request.make_url(DISOWN_PATH), :post, body)
  response["devices"]
end

.fetch(cursor: nil, url: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/apple_dep_client/device.rb', line 13

def self.fetch(cursor: nil, url: nil)
  url ||= FETCH_PATH
  response = { "cursor" => cursor, "more_to_follow" => "true" }
  while response["more_to_follow"] == "true"
    response = make_fetch_request response["cursor"], url
    response["devices"].each do |device|
      yield device
    end
  end
  response["cursor"]
end

.fetch_body(cursor) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/apple_dep_client/device.rb', line 30

def self.fetch_body(cursor)
  body = { "limit" => FETCH_LIMIT }
  if cursor
    body["cursor"] = cursor
  end
  JSON.dump body
end

.make_fetch_request(cursor, url) ⇒ Object



25
26
27
28
# File 'lib/apple_dep_client/device.rb', line 25

def self.make_fetch_request(cursor, url)
  body = fetch_body(cursor)
  AppleDEPClient::Request.make_request(AppleDEPClient::Request.make_url(url), :post, body)
end

.sync(cursor, &block) ⇒ Object



38
39
40
# File 'lib/apple_dep_client/device.rb', line 38

def self.sync(cursor, &block)
  fetch(cursor: cursor, url: SYNC_PATH, &block)
end