Class: Applocate::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/applocate/api.rb

Class Method Summary collapse

Class Method Details

.active_commands(udid) ⇒ Object

expected params, udid = “ABCD-DCCDDC-12394812389-CDC”



24
25
26
27
# File 'lib/applocate/api.rb', line 24

def self.active_commands(udid)
  response = self.get("/api/devices/#{udid}/active_commands", { headers: authentication })
  JSON.parse response.body rescue []
end

.app_list(options = {}) ⇒ Object

expected options { udid: “ABCD-DCCDDC-12394812389-CDC” }



82
83
84
85
# File 'lib/applocate/api.rb', line 82

def self.app_list(options = {})
  response = self.post('/deploy/app_list', { body: options.to_json, headers: authentication })
  JSON.parse response.body rescue []
end

.apply_named_restrictions(udid, name, options = {}) ⇒ Object

expected params: udid = “ABCD-DCCDDC-12394812389-CDC”, name = “me.example.restrictions” options { … Apple MDM Restrictions Profile … }



48
49
50
51
52
53
# File 'lib/applocate/api.rb', line 48

def self.apply_named_restrictions(udid, name, options = {})
  escaped_name = CGI.escape(name)
  escaped_name = escaped_name.gsub(/[.]/, '%2E') unless escaped_name.nil?
  response = self.post("/api/devices/#{udid}/profiles/#{escaped_name}", { body: options.to_json, headers: authentication })
  JSON.parse response.body rescue {}
end

.authenticationObject



111
112
113
# File 'lib/applocate/api.rb', line 111

def self.authentication
  { "X-Applocate-Secret" => secret, "X-Applocate-Token" => token, 'Content-Type' => "application/json" }
end

.cancel_commmand(udid, commmand_uuid) ⇒ Object

expected params, udid = “ABCD-DCCDDC-12394812389-CDC”, commmand_uuid = “xxxx-xxx-xxxx-xxxxxxxxxxx”



30
31
32
33
# File 'lib/applocate/api.rb', line 30

def self.cancel_commmand(udid, commmand_uuid)
  response = self.get("/api/devices/#{udid}/commands/#{commmand_uuid}", { headers: authentication })
  JSON.parse response.body rescue {}
end

.delete_device(options) ⇒ Object

expected options { device_id: 12345 }

OR { udid: "ABCD-DCCDDC-12394812389-CDC" }


106
107
108
109
# File 'lib/applocate/api.rb', line 106

def self.delete_device(options)
  response = self.delete("/api/devices", { body: options.to_json, headers: authentication })
  response.code == 200
end

.install_app(options = {}) ⇒ Object

expected options { udid: “ABCD-DCCDDC-12394812389-CDC”, itunes_id: “284910350” }



76
77
78
79
# File 'lib/applocate/api.rb', line 76

def self.install_app(options = {})
  response = self.post('/deploy/app', { body: options.to_json, headers: authentication })
  JSON.parse response.body rescue []
end

.list_devicesObject



99
100
101
102
# File 'lib/applocate/api.rb', line 99

def self.list_devices
  response = self.get('/api/devices', { headers: authentication })
  JSON.parse response.body rescue []
end

.mdm_app_list(options = {}) ⇒ Object

expected options { udid: “ABCD-DCCDDC-12394812389-CDC” }



88
89
90
91
# File 'lib/applocate/api.rb', line 88

def self.mdm_app_list(options = {})
  response = self.post('/deploy/mdm_app_list', { body: options.to_json, headers: authentication })
  JSON.parse response.body rescue []
end

.profile_list(udid) ⇒ Object

expected params, udid = “ABCD-DCCDDC-12394812389-CDC”



42
43
44
45
# File 'lib/applocate/api.rb', line 42

def self.profile_list(udid)
  response = self.get("/api/devices/#{udid}/profiles", { headers: authentication })
  JSON.parse response.body rescue []
end

.recent_checkins(udid) ⇒ Object

expected params, udid = “ABCD-DCCDDC-12394812389-CDC”



12
13
14
15
# File 'lib/applocate/api.rb', line 12

def self.recent_checkins(udid)
  response = self.get("/api/devices/#{udid}/recent_checkins", { headers: authentication })
  JSON.parse response.body rescue []
end

.recent_commands(udid) ⇒ Object

expected params, udid = “ABCD-DCCDDC-12394812389-CDC”



18
19
20
21
# File 'lib/applocate/api.rb', line 18

def self.recent_commands(udid)
  response = self.get("/api/devices/#{udid}/recent_commands", { headers: authentication })
  JSON.parse response.body rescue []
end

.register_device(options = {}) ⇒ Object

expected options { name: “Steve J’s iPad Air”, identifier: “XXX-123456 APPLE INC.”, configuration: “default” }



94
95
96
97
# File 'lib/applocate/api.rb', line 94

def self.register_device(options = {})
  response = self.post('/api/devices', { body: options.to_json, headers: authentication })
  JSON.parse response.body rescue []
end

.remove_named_restrictions(udid, name) ⇒ Object

expected params, udid = “ABCD-DCCDDC-12394812389-CDC”, name = “me.example.restrictions”



56
57
58
59
60
61
# File 'lib/applocate/api.rb', line 56

def self.remove_named_restrictions(udid, name)
  escaped_name = CGI.escape(name)
  escaped_name = escaped_name.gsub(/[.]/, '%2E') unless escaped_name.nil?
  response = self.delete("/api/devices/#{udid}/profiles/#{escaped_name}", { headers: authentication })
  JSON.parse response.body rescue {}
end

.restrict(options = {}) ⇒ Object

expected options { udid: “ABCD-DCCDDC-12394812389-CDC” }



64
65
66
67
# File 'lib/applocate/api.rb', line 64

def self.restrict(options = {})
  response = self.post('/deploy/profile', { body: options.to_json, headers: authentication })
  JSON.parse response.body rescue []
end

.restrictions(udid) ⇒ Object

expected params, udid = “ABCD-DCCDDC-12394812389-CDC”



36
37
38
39
# File 'lib/applocate/api.rb', line 36

def self.restrictions(udid)
  response = self.get("/api/devices/#{udid}/restrictions", { headers: authentication })
  JSON.parse response.body rescue []
end

.secretObject



119
120
121
# File 'lib/applocate/api.rb', line 119

def self.secret
  Applocate.configuration.secret
end

.tokenObject



115
116
117
# File 'lib/applocate/api.rb', line 115

def self.token
  Applocate.configuration.token
end

.unrestrict(options = {}) ⇒ Object

expected options { udid: “ABCD-DCCDDC-12394812389-CDC” }



70
71
72
73
# File 'lib/applocate/api.rb', line 70

def self.unrestrict(options = {})
  response = self.delete('/deploy/profile', { body: options.to_json, headers: authentication })
  JSON.parse response.body rescue []
end