/
provisioning.rb
270 lines (231 loc) 路 8.41 KB
/
provisioning.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
require 'spaceship/connect_api/provisioning/client'
module Spaceship
class ConnectAPI
module Provisioning
module API
def provisioning_request_client=(provisioning_request_client)
@provisioning_request_client = provisioning_request_client
end
def provisioning_request_client
return @provisioning_request_client if @provisioning_request_client
raise TypeError, "You need to instantiate this module with provisioning_request_client"
end
#
# bundleIds
#
def get_bundle_ids(filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
provisioning_request_client.get("bundleIds", params)
end
def get_bundle_id(bundle_id_id: {}, includes: nil)
params = provisioning_request_client.build_params(filter: nil, includes: includes, limit: nil, sort: nil)
provisioning_request_client.get("bundleIds/#{bundle_id_id}", params)
end
def post_bundle_id(name:, platform:, identifier:, seed_id:)
attributes = {
name: name,
platform: platform,
identifier: identifier,
seedId: seed_id
}
body = {
data: {
attributes: attributes,
type: "bundleIds"
}
}
provisioning_request_client.post("bundleIds", body)
end
#
# bundleIdCapability
#
def get_bundle_id_capabilities(bundle_id_id:, includes: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: nil, includes: includes, limit: limit, sort: sort)
provisioning_request_client.get("bundleIds/#{bundle_id_id}/bundleIdCapabilities", params)
end
def get_available_bundle_id_capabilities(bundle_id_id:)
params = provisioning_request_client.build_params(filter: { bundleId: bundle_id_id })
provisioning_request_client.get("capabilities", params)
end
def post_bundle_id_capability(bundle_id_id:, capability_type:, settings: [])
body = {
data: {
attributes: {
capabilityType: capability_type,
settings: settings
},
type: "bundleIdCapabilities",
relationships: {
bundleId: {
data: {
type: "bundleIds",
id: bundle_id_id
}
},
capability: {
data: {
type: "capabilities",
id: capability_type
}
}
}
}
}
provisioning_request_client.post("bundleIdCapabilities", body)
end
def patch_bundle_id_capability(bundle_id_id:, seed_id:, enabled: false, capability_type:, settings: [])
body = {
data: {
type: "bundleIds",
id: bundle_id_id,
attributes: {
teamId: seed_id
},
relationships: {
bundleIdCapabilities: {
data: [
{
type: "bundleIdCapabilities",
attributes: {
enabled: enabled,
settings: settings
},
relationships: {
capability: {
data: {
type: "capabilities",
id: capability_type
}
}
}
}
]
}
}
}
}
provisioning_request_client.patch("bundleIds/#{bundle_id_id}", body)
end
def delete_bundle_id_capability(bundle_id_capability_id:)
provisioning_request_client.delete("bundleIdCapabilities/#{bundle_id_capability_id}")
end
#
# certificates
#
def get_certificates(profile_id: nil, filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
if profile_id.nil?
provisioning_request_client.get("certificates", params)
else
provisioning_request_client.get("profiles/#{profile_id}/certificates", params)
end
end
def get_certificate(certificate_id: nil, includes: nil)
params = provisioning_request_client.build_params(filter: nil, includes: includes, limit: nil, sort: nil)
provisioning_request_client.get("certificates/#{certificate_id}", params)
end
def post_certificate(attributes: {})
body = {
data: {
attributes: attributes,
type: "certificates"
}
}
provisioning_request_client.post("certificates", body)
end
def delete_certificate(certificate_id: nil)
raise "Certificate id is nil" if certificate_id.nil?
provisioning_request_client.delete("certificates/#{certificate_id}")
end
#
# devices
#
def get_devices(profile_id: nil, filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
if profile_id.nil?
provisioning_request_client.get("devices", params)
else
provisioning_request_client.get("profiles/#{profile_id}/devices", params)
end
end
def post_device(name: nil, platform: nil, udid: nil)
attributes = {
name: name,
platform: platform,
udid: udid
}
body = {
data: {
attributes: attributes,
type: "devices"
}
}
provisioning_request_client.post("devices", body)
end
def patch_device(id: nil, status: nil, new_name: nil)
raise "Device id is nil" if id.nil?
attributes = {
name: new_name,
status: status
}
body = {
data: {
attributes: attributes,
id: id,
type: "devices"
}
}
provisioning_request_client.patch("devices/#{id}", body)
end
#
# profiles
#
def get_profiles(filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
provisioning_request_client.get("profiles", params)
end
def post_profiles(bundle_id_id: nil, certificates: nil, devices: nil, attributes: {})
body = {
data: {
attributes: attributes,
type: "profiles",
relationships: {
bundleId: {
data: {
type: "bundleIds",
id: bundle_id_id
}
},
certificates: {
data: certificates.map do |certificate|
{
type: "certificates",
id: certificate
}
end
},
devices: {
data: (devices || []).map do |device|
{
type: "devices",
id: device
}
end
}
}
}
}
provisioning_request_client.post("profiles", body)
end
def get_profile_bundle_id(profile_id: nil)
raise "Profile id is nil" if profile_id.nil?
provisioning_request_client.get("profiles/#{profile_id}/bundleId")
end
def delete_profile(profile_id: nil)
raise "Profile id is nil" if profile_id.nil?
provisioning_request_client.delete("profiles/#{profile_id}")
end
end
end
end
end