be_azure_cognitiveservices_face 0.19.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/lib/1.0/generated/azure_cognitiveservices_face/face.rb +1711 -0
  4. data/lib/1.0/generated/azure_cognitiveservices_face/face_client.rb +159 -0
  5. data/lib/1.0/generated/azure_cognitiveservices_face/face_list_operations.rb +1269 -0
  6. data/lib/1.0/generated/azure_cognitiveservices_face/large_face_list_operations.rb +1894 -0
  7. data/lib/1.0/generated/azure_cognitiveservices_face/large_person_group_operations.rb +886 -0
  8. data/lib/1.0/generated/azure_cognitiveservices_face/large_person_group_person.rb +1477 -0
  9. data/lib/1.0/generated/azure_cognitiveservices_face/models/accessory.rb +59 -0
  10. data/lib/1.0/generated/azure_cognitiveservices_face/models/accessory_type.rb +17 -0
  11. data/lib/1.0/generated/azure_cognitiveservices_face/models/apierror.rb +47 -0
  12. data/lib/1.0/generated/azure_cognitiveservices_face/models/apply_snapshot_request.rb +69 -0
  13. data/lib/1.0/generated/azure_cognitiveservices_face/models/blur.rb +60 -0
  14. data/lib/1.0/generated/azure_cognitiveservices_face/models/blur_level.rb +17 -0
  15. data/lib/1.0/generated/azure_cognitiveservices_face/models/coordinate.rb +57 -0
  16. data/lib/1.0/generated/azure_cognitiveservices_face/models/detected_face.rb +95 -0
  17. data/lib/1.0/generated/azure_cognitiveservices_face/models/detection_model.rb +16 -0
  18. data/lib/1.0/generated/azure_cognitiveservices_face/models/emotion.rb +124 -0
  19. data/lib/1.0/generated/azure_cognitiveservices_face/models/error.rb +57 -0
  20. data/lib/1.0/generated/azure_cognitiveservices_face/models/exposure.rb +62 -0
  21. data/lib/1.0/generated/azure_cognitiveservices_face/models/exposure_level.rb +17 -0
  22. data/lib/1.0/generated/azure_cognitiveservices_face/models/face_attribute_type.rb +28 -0
  23. data/lib/1.0/generated/azure_cognitiveservices_face/models/face_attributes.rb +214 -0
  24. data/lib/1.0/generated/azure_cognitiveservices_face/models/face_landmarks.rb +360 -0
  25. data/lib/1.0/generated/azure_cognitiveservices_face/models/face_list.rb +101 -0
  26. data/lib/1.0/generated/azure_cognitiveservices_face/models/face_rectangle.rb +81 -0
  27. data/lib/1.0/generated/azure_cognitiveservices_face/models/facial_hair.rb +68 -0
  28. data/lib/1.0/generated/azure_cognitiveservices_face/models/find_similar_match_mode.rb +16 -0
  29. data/lib/1.0/generated/azure_cognitiveservices_face/models/find_similar_request.rb +143 -0
  30. data/lib/1.0/generated/azure_cognitiveservices_face/models/gender.rb +16 -0
  31. data/lib/1.0/generated/azure_cognitiveservices_face/models/glasses_type.rb +18 -0
  32. data/lib/1.0/generated/azure_cognitiveservices_face/models/group_request.rb +58 -0
  33. data/lib/1.0/generated/azure_cognitiveservices_face/models/group_result.rb +83 -0
  34. data/lib/1.0/generated/azure_cognitiveservices_face/models/hair.rb +80 -0
  35. data/lib/1.0/generated/azure_cognitiveservices_face/models/hair_color.rb +60 -0
  36. data/lib/1.0/generated/azure_cognitiveservices_face/models/hair_color_type.rb +22 -0
  37. data/lib/1.0/generated/azure_cognitiveservices_face/models/head_pose.rb +68 -0
  38. data/lib/1.0/generated/azure_cognitiveservices_face/models/identify_candidate.rb +59 -0
  39. data/lib/1.0/generated/azure_cognitiveservices_face/models/identify_request.rb +123 -0
  40. data/lib/1.0/generated/azure_cognitiveservices_face/models/identify_result.rb +69 -0
  41. data/lib/1.0/generated/azure_cognitiveservices_face/models/image_url.rb +47 -0
  42. data/lib/1.0/generated/azure_cognitiveservices_face/models/large_face_list.rb +81 -0
  43. data/lib/1.0/generated/azure_cognitiveservices_face/models/large_person_group.rb +81 -0
  44. data/lib/1.0/generated/azure_cognitiveservices_face/models/makeup.rb +59 -0
  45. data/lib/1.0/generated/azure_cognitiveservices_face/models/meta_data_contract.rb +72 -0
  46. data/lib/1.0/generated/azure_cognitiveservices_face/models/name_and_user_data_contract.rb +64 -0
  47. data/lib/1.0/generated/azure_cognitiveservices_face/models/noise.rb +62 -0
  48. data/lib/1.0/generated/azure_cognitiveservices_face/models/noise_level.rb +17 -0
  49. data/lib/1.0/generated/azure_cognitiveservices_face/models/occlusion.rb +70 -0
  50. data/lib/1.0/generated/azure_cognitiveservices_face/models/operation_status.rb +112 -0
  51. data/lib/1.0/generated/azure_cognitiveservices_face/models/operation_status_type.rb +18 -0
  52. data/lib/1.0/generated/azure_cognitiveservices_face/models/persisted_face.rb +63 -0
  53. data/lib/1.0/generated/azure_cognitiveservices_face/models/person.rb +89 -0
  54. data/lib/1.0/generated/azure_cognitiveservices_face/models/person_group.rb +81 -0
  55. data/lib/1.0/generated/azure_cognitiveservices_face/models/recognition_model.rb +16 -0
  56. data/lib/1.0/generated/azure_cognitiveservices_face/models/similar_face.rb +73 -0
  57. data/lib/1.0/generated/azure_cognitiveservices_face/models/snapshot.rb +136 -0
  58. data/lib/1.0/generated/azure_cognitiveservices_face/models/snapshot_apply_mode.rb +15 -0
  59. data/lib/1.0/generated/azure_cognitiveservices_face/models/snapshot_object_type.rb +18 -0
  60. data/lib/1.0/generated/azure_cognitiveservices_face/models/take_snapshot_request.rb +101 -0
  61. data/lib/1.0/generated/azure_cognitiveservices_face/models/training_status.rb +107 -0
  62. data/lib/1.0/generated/azure_cognitiveservices_face/models/training_status_type.rb +18 -0
  63. data/lib/1.0/generated/azure_cognitiveservices_face/models/update_face_request.rb +50 -0
  64. data/lib/1.0/generated/azure_cognitiveservices_face/models/update_snapshot_request.rb +73 -0
  65. data/lib/1.0/generated/azure_cognitiveservices_face/models/verify_face_to_face_request.rb +57 -0
  66. data/lib/1.0/generated/azure_cognitiveservices_face/models/verify_face_to_person_request.rb +95 -0
  67. data/lib/1.0/generated/azure_cognitiveservices_face/models/verify_result.rb +62 -0
  68. data/lib/1.0/generated/azure_cognitiveservices_face/module_definition.rb +9 -0
  69. data/lib/1.0/generated/azure_cognitiveservices_face/person_group_operations.rb +865 -0
  70. data/lib/1.0/generated/azure_cognitiveservices_face/person_group_person.rb +1528 -0
  71. data/lib/1.0/generated/azure_cognitiveservices_face/snapshot_operations.rb +983 -0
  72. data/lib/1.0/generated/azure_cognitiveservices_face.rb +94 -0
  73. data/lib/azure_cognitiveservices_face.rb +6 -0
  74. data/lib/module_definition.rb +7 -0
  75. data/lib/profiles/latest/face_latest_profile_client.rb +38 -0
  76. data/lib/profiles/latest/face_module_definition.rb +8 -0
  77. data/lib/profiles/latest/modules/face_profile_module.rb +309 -0
  78. data/lib/version.rb +7 -0
  79. metadata +196 -0
@@ -0,0 +1,983 @@
1
+ # encoding: utf-8
2
+ # Code generated by Microsoft (R) AutoRest Code Generator.
3
+ # Changes may cause incorrect behavior and will be lost if the code is
4
+ # regenerated.
5
+
6
+ module Azure::CognitiveServices::Face::V1_0
7
+ #
8
+ # An API for face detection, verification, and identification.
9
+ #
10
+ class SnapshotOperations
11
+ include MsRestAzure
12
+
13
+ #
14
+ # Creates and initializes a new instance of the SnapshotOperations class.
15
+ # @param client service class for accessing basic functionality.
16
+ #
17
+ def initialize(client)
18
+ @client = client
19
+ end
20
+
21
+ # @return [FaceClient] reference to the FaceClient
22
+ attr_reader :client
23
+
24
+ #
25
+ # Submit an operation to take a snapshot of face list, large face list, person
26
+ # group or large person group, with user-specified snapshot type, source object
27
+ # id, apply scope and an optional user data.<br />
28
+ # The snapshot interfaces are for users to backup and restore their face data
29
+ # from one face subscription to another, inside same region or across regions.
30
+ # The workflow contains two phases, user first calls Snapshot - Take to create
31
+ # a copy of the source object and store it as a snapshot, then calls Snapshot -
32
+ # Apply to paste the snapshot to target subscription. The snapshots are stored
33
+ # in a centralized location (per Azure instance), so that they can be applied
34
+ # cross accounts and regions.<br />
35
+ # Taking snapshot is an asynchronous operation. An operation id can be obtained
36
+ # from the "Operation-Location" field in response header, to be used in
37
+ # OperationStatus - Get for tracking the progress of creating the snapshot. The
38
+ # snapshot id will be included in the "resourceLocation" field in
39
+ # OperationStatus - Get response when the operation status is "succeeded".<br
40
+ # />
41
+ # Snapshot taking time depends on the number of person and face entries in the
42
+ # source object. It could be in seconds, or up to several hours for 1,000,000
43
+ # persons with multiple faces.<br />
44
+ # Snapshots will be automatically expired and cleaned in 48 hours after it is
45
+ # created by Snapshot - Take. User can delete the snapshot using Snapshot -
46
+ # Delete by themselves any time before expiration.<br />
47
+ # Taking snapshot for a certain object will not block any other operations
48
+ # against the object. All read-only operations (Get/List and
49
+ # Identify/FindSimilar/Verify) can be conducted as usual. For all writable
50
+ # operations, including Add/Update/Delete the source object or its
51
+ # persons/faces and Train, they are not blocked but not recommended because
52
+ # writable updates may not be reflected on the snapshot during its taking.
53
+ # After snapshot taking is completed, all readable and writable operations can
54
+ # work as normal. Snapshot will also include the training results of the source
55
+ # object, which means target subscription the snapshot applied to does not need
56
+ # re-train the target object before calling Identify/FindSimilar.<br />
57
+ # * Free-tier subscription quota: 100 take operations per month.
58
+ # * S0-tier subscription quota: 100 take operations per day.
59
+ #
60
+ # @param type [SnapshotObjectType] User specified type for the source object to
61
+ # take snapshot from. Currently FaceList, PersonGroup, LargeFaceList and
62
+ # LargePersonGroup are supported. Possible values include: 'FaceList',
63
+ # 'LargeFaceList', 'LargePersonGroup', 'PersonGroup'
64
+ # @param object_id [String] User specified source object id to take snapshot
65
+ # from.
66
+ # @param apply_scope User specified array of target Face subscription ids for
67
+ # the snapshot. For each snapshot, only subscriptions included in the
68
+ # applyScope of Snapshot - Take can apply it.
69
+ # @param user_data [String] User specified data about the snapshot for any
70
+ # purpose. Length should not exceed 16KB.
71
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
72
+ # will be added to the HTTP request.
73
+ #
74
+ #
75
+ def take(type, object_id, apply_scope, user_data:nil, custom_headers:nil)
76
+ response = take_async(type, object_id, apply_scope, user_data:user_data, custom_headers:custom_headers).value!
77
+ nil
78
+ end
79
+
80
+ #
81
+ # Submit an operation to take a snapshot of face list, large face list, person
82
+ # group or large person group, with user-specified snapshot type, source object
83
+ # id, apply scope and an optional user data.<br />
84
+ # The snapshot interfaces are for users to backup and restore their face data
85
+ # from one face subscription to another, inside same region or across regions.
86
+ # The workflow contains two phases, user first calls Snapshot - Take to create
87
+ # a copy of the source object and store it as a snapshot, then calls Snapshot -
88
+ # Apply to paste the snapshot to target subscription. The snapshots are stored
89
+ # in a centralized location (per Azure instance), so that they can be applied
90
+ # cross accounts and regions.<br />
91
+ # Taking snapshot is an asynchronous operation. An operation id can be obtained
92
+ # from the "Operation-Location" field in response header, to be used in
93
+ # OperationStatus - Get for tracking the progress of creating the snapshot. The
94
+ # snapshot id will be included in the "resourceLocation" field in
95
+ # OperationStatus - Get response when the operation status is "succeeded".<br
96
+ # />
97
+ # Snapshot taking time depends on the number of person and face entries in the
98
+ # source object. It could be in seconds, or up to several hours for 1,000,000
99
+ # persons with multiple faces.<br />
100
+ # Snapshots will be automatically expired and cleaned in 48 hours after it is
101
+ # created by Snapshot - Take. User can delete the snapshot using Snapshot -
102
+ # Delete by themselves any time before expiration.<br />
103
+ # Taking snapshot for a certain object will not block any other operations
104
+ # against the object. All read-only operations (Get/List and
105
+ # Identify/FindSimilar/Verify) can be conducted as usual. For all writable
106
+ # operations, including Add/Update/Delete the source object or its
107
+ # persons/faces and Train, they are not blocked but not recommended because
108
+ # writable updates may not be reflected on the snapshot during its taking.
109
+ # After snapshot taking is completed, all readable and writable operations can
110
+ # work as normal. Snapshot will also include the training results of the source
111
+ # object, which means target subscription the snapshot applied to does not need
112
+ # re-train the target object before calling Identify/FindSimilar.<br />
113
+ # * Free-tier subscription quota: 100 take operations per month.
114
+ # * S0-tier subscription quota: 100 take operations per day.
115
+ #
116
+ # @param type [SnapshotObjectType] User specified type for the source object to
117
+ # take snapshot from. Currently FaceList, PersonGroup, LargeFaceList and
118
+ # LargePersonGroup are supported. Possible values include: 'FaceList',
119
+ # 'LargeFaceList', 'LargePersonGroup', 'PersonGroup'
120
+ # @param object_id [String] User specified source object id to take snapshot
121
+ # from.
122
+ # @param apply_scope User specified array of target Face subscription ids for
123
+ # the snapshot. For each snapshot, only subscriptions included in the
124
+ # applyScope of Snapshot - Take can apply it.
125
+ # @param user_data [String] User specified data about the snapshot for any
126
+ # purpose. Length should not exceed 16KB.
127
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
128
+ # will be added to the HTTP request.
129
+ #
130
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
131
+ #
132
+ def take_with_http_info(type, object_id, apply_scope, user_data:nil, custom_headers:nil)
133
+ take_async(type, object_id, apply_scope, user_data:user_data, custom_headers:custom_headers).value!
134
+ end
135
+
136
+ #
137
+ # Submit an operation to take a snapshot of face list, large face list, person
138
+ # group or large person group, with user-specified snapshot type, source object
139
+ # id, apply scope and an optional user data.<br />
140
+ # The snapshot interfaces are for users to backup and restore their face data
141
+ # from one face subscription to another, inside same region or across regions.
142
+ # The workflow contains two phases, user first calls Snapshot - Take to create
143
+ # a copy of the source object and store it as a snapshot, then calls Snapshot -
144
+ # Apply to paste the snapshot to target subscription. The snapshots are stored
145
+ # in a centralized location (per Azure instance), so that they can be applied
146
+ # cross accounts and regions.<br />
147
+ # Taking snapshot is an asynchronous operation. An operation id can be obtained
148
+ # from the "Operation-Location" field in response header, to be used in
149
+ # OperationStatus - Get for tracking the progress of creating the snapshot. The
150
+ # snapshot id will be included in the "resourceLocation" field in
151
+ # OperationStatus - Get response when the operation status is "succeeded".<br
152
+ # />
153
+ # Snapshot taking time depends on the number of person and face entries in the
154
+ # source object. It could be in seconds, or up to several hours for 1,000,000
155
+ # persons with multiple faces.<br />
156
+ # Snapshots will be automatically expired and cleaned in 48 hours after it is
157
+ # created by Snapshot - Take. User can delete the snapshot using Snapshot -
158
+ # Delete by themselves any time before expiration.<br />
159
+ # Taking snapshot for a certain object will not block any other operations
160
+ # against the object. All read-only operations (Get/List and
161
+ # Identify/FindSimilar/Verify) can be conducted as usual. For all writable
162
+ # operations, including Add/Update/Delete the source object or its
163
+ # persons/faces and Train, they are not blocked but not recommended because
164
+ # writable updates may not be reflected on the snapshot during its taking.
165
+ # After snapshot taking is completed, all readable and writable operations can
166
+ # work as normal. Snapshot will also include the training results of the source
167
+ # object, which means target subscription the snapshot applied to does not need
168
+ # re-train the target object before calling Identify/FindSimilar.<br />
169
+ # * Free-tier subscription quota: 100 take operations per month.
170
+ # * S0-tier subscription quota: 100 take operations per day.
171
+ #
172
+ # @param type [SnapshotObjectType] User specified type for the source object to
173
+ # take snapshot from. Currently FaceList, PersonGroup, LargeFaceList and
174
+ # LargePersonGroup are supported. Possible values include: 'FaceList',
175
+ # 'LargeFaceList', 'LargePersonGroup', 'PersonGroup'
176
+ # @param object_id [String] User specified source object id to take snapshot
177
+ # from.
178
+ # @param apply_scope User specified array of target Face subscription ids for
179
+ # the snapshot. For each snapshot, only subscriptions included in the
180
+ # applyScope of Snapshot - Take can apply it.
181
+ # @param user_data [String] User specified data about the snapshot for any
182
+ # purpose. Length should not exceed 16KB.
183
+ # @param [Hash{String => String}] A hash of custom headers that will be added
184
+ # to the HTTP request.
185
+ #
186
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
187
+ #
188
+ def take_async(type, object_id, apply_scope, user_data:nil, custom_headers:nil)
189
+ fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
190
+ fail ArgumentError, 'type is nil' if type.nil?
191
+ fail ArgumentError, 'object_id is nil' if object_id.nil?
192
+ fail ArgumentError, "'object_id' should satisfy the constraint - 'MaxLength': '64'" if !object_id.nil? && object_id.length > 64
193
+ fail ArgumentError, "'object_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !object_id.nil? && object_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
194
+ fail ArgumentError, 'apply_scope is nil' if apply_scope.nil?
195
+ fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '16384'" if !user_data.nil? && user_data.length > 16384
196
+
197
+ body = TakeSnapshotRequest.new
198
+ unless type.nil? && object_id.nil? && apply_scope.nil? && user_data.nil?
199
+ body.type = type
200
+ body.object_id = object_id
201
+ body.apply_scope = apply_scope
202
+ body.user_data = user_data
203
+ end
204
+
205
+ request_headers = {}
206
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
207
+
208
+ # Set Headers
209
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
210
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
211
+
212
+ # Serialize Request
213
+ request_mapper = Azure::CognitiveServices::Face::V1_0::Models::TakeSnapshotRequest.mapper()
214
+ request_content = @client.serialize(request_mapper, body)
215
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
216
+
217
+ path_template = 'snapshots'
218
+
219
+ request_url = @base_url || @client.base_url
220
+ request_url = request_url.gsub('{Endpoint}', @client.endpoint)
221
+
222
+ options = {
223
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
224
+ body: request_content,
225
+ headers: request_headers.merge(custom_headers || {}),
226
+ base_url: request_url
227
+ }
228
+ promise = @client.make_request_async(:post, path_template, options)
229
+
230
+ promise = promise.then do |result|
231
+ http_response = result.response
232
+ status_code = http_response.status
233
+ response_content = http_response.body
234
+ unless status_code == 202
235
+ error_model = JSON.load(response_content)
236
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
237
+ end
238
+
239
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
240
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
241
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
242
+
243
+ result
244
+ end
245
+
246
+ promise.execute
247
+ end
248
+
249
+ #
250
+ # List all accessible snapshots with related information, including snapshots
251
+ # that were taken by the user, or snapshots to be applied to the user
252
+ # (subscription id was included in the applyScope in Snapshot - Take).
253
+ #
254
+ # @param type [SnapshotObjectType] User specified object type as a search
255
+ # filter. Possible values include: 'FaceList', 'LargeFaceList',
256
+ # 'LargePersonGroup', 'PersonGroup'
257
+ # @param apply_scope User specified snapshot apply scopes as a search filter.
258
+ # ApplyScope is an array of the target Azure subscription ids for the snapshot,
259
+ # specified by the user who created the snapshot by Snapshot - Take.
260
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
261
+ # will be added to the HTTP request.
262
+ #
263
+ # @return [Array] operation results.
264
+ #
265
+ def list(type:nil, apply_scope:nil, custom_headers:nil)
266
+ response = list_async(type:type, apply_scope:apply_scope, custom_headers:custom_headers).value!
267
+ response.body unless response.nil?
268
+ end
269
+
270
+ #
271
+ # List all accessible snapshots with related information, including snapshots
272
+ # that were taken by the user, or snapshots to be applied to the user
273
+ # (subscription id was included in the applyScope in Snapshot - Take).
274
+ #
275
+ # @param type [SnapshotObjectType] User specified object type as a search
276
+ # filter. Possible values include: 'FaceList', 'LargeFaceList',
277
+ # 'LargePersonGroup', 'PersonGroup'
278
+ # @param apply_scope User specified snapshot apply scopes as a search filter.
279
+ # ApplyScope is an array of the target Azure subscription ids for the snapshot,
280
+ # specified by the user who created the snapshot by Snapshot - Take.
281
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
282
+ # will be added to the HTTP request.
283
+ #
284
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
285
+ #
286
+ def list_with_http_info(type:nil, apply_scope:nil, custom_headers:nil)
287
+ list_async(type:type, apply_scope:apply_scope, custom_headers:custom_headers).value!
288
+ end
289
+
290
+ #
291
+ # List all accessible snapshots with related information, including snapshots
292
+ # that were taken by the user, or snapshots to be applied to the user
293
+ # (subscription id was included in the applyScope in Snapshot - Take).
294
+ #
295
+ # @param type [SnapshotObjectType] User specified object type as a search
296
+ # filter. Possible values include: 'FaceList', 'LargeFaceList',
297
+ # 'LargePersonGroup', 'PersonGroup'
298
+ # @param apply_scope User specified snapshot apply scopes as a search filter.
299
+ # ApplyScope is an array of the target Azure subscription ids for the snapshot,
300
+ # specified by the user who created the snapshot by Snapshot - Take.
301
+ # @param [Hash{String => String}] A hash of custom headers that will be added
302
+ # to the HTTP request.
303
+ #
304
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
305
+ #
306
+ def list_async(type:nil, apply_scope:nil, custom_headers:nil)
307
+ fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
308
+
309
+
310
+ request_headers = {}
311
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
312
+
313
+ # Set Headers
314
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
315
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
316
+ path_template = 'snapshots'
317
+
318
+ request_url = @base_url || @client.base_url
319
+ request_url = request_url.gsub('{Endpoint}', @client.endpoint)
320
+
321
+ options = {
322
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
323
+ query_params: {'type' => type,'applyScope' => apply_scope.nil? ? nil : apply_scope.join(',')},
324
+ headers: request_headers.merge(custom_headers || {}),
325
+ base_url: request_url
326
+ }
327
+ promise = @client.make_request_async(:get, path_template, options)
328
+
329
+ promise = promise.then do |result|
330
+ http_response = result.response
331
+ status_code = http_response.status
332
+ response_content = http_response.body
333
+ unless status_code == 200
334
+ error_model = JSON.load(response_content)
335
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
336
+ end
337
+
338
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
339
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
340
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
341
+ # Deserialize Response
342
+ if status_code == 200
343
+ begin
344
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
345
+ result_mapper = {
346
+ client_side_validation: true,
347
+ required: false,
348
+ serialized_name: 'parsed_response',
349
+ type: {
350
+ name: 'Sequence',
351
+ element: {
352
+ client_side_validation: true,
353
+ required: false,
354
+ serialized_name: 'SnapshotElementType',
355
+ type: {
356
+ name: 'Composite',
357
+ class_name: 'Snapshot'
358
+ }
359
+ }
360
+ }
361
+ }
362
+ result.body = @client.deserialize(result_mapper, parsed_response)
363
+ rescue Exception => e
364
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
365
+ end
366
+ end
367
+
368
+ result
369
+ end
370
+
371
+ promise.execute
372
+ end
373
+
374
+ #
375
+ # Retrieve information about a snapshot. Snapshot is only accessible to the
376
+ # source subscription who took it, and target subscriptions included in the
377
+ # applyScope in Snapshot - Take.
378
+ #
379
+ # @param snapshot_id Id referencing a particular snapshot.
380
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
381
+ # will be added to the HTTP request.
382
+ #
383
+ # @return [Snapshot] operation results.
384
+ #
385
+ def get(snapshot_id, custom_headers:nil)
386
+ response = get_async(snapshot_id, custom_headers:custom_headers).value!
387
+ response.body unless response.nil?
388
+ end
389
+
390
+ #
391
+ # Retrieve information about a snapshot. Snapshot is only accessible to the
392
+ # source subscription who took it, and target subscriptions included in the
393
+ # applyScope in Snapshot - Take.
394
+ #
395
+ # @param snapshot_id Id referencing a particular snapshot.
396
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
397
+ # will be added to the HTTP request.
398
+ #
399
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
400
+ #
401
+ def get_with_http_info(snapshot_id, custom_headers:nil)
402
+ get_async(snapshot_id, custom_headers:custom_headers).value!
403
+ end
404
+
405
+ #
406
+ # Retrieve information about a snapshot. Snapshot is only accessible to the
407
+ # source subscription who took it, and target subscriptions included in the
408
+ # applyScope in Snapshot - Take.
409
+ #
410
+ # @param snapshot_id Id referencing a particular snapshot.
411
+ # @param [Hash{String => String}] A hash of custom headers that will be added
412
+ # to the HTTP request.
413
+ #
414
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
415
+ #
416
+ def get_async(snapshot_id, custom_headers:nil)
417
+ fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
418
+ fail ArgumentError, 'snapshot_id is nil' if snapshot_id.nil?
419
+
420
+
421
+ request_headers = {}
422
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
423
+
424
+ # Set Headers
425
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
426
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
427
+ path_template = 'snapshots/{snapshotId}'
428
+
429
+ request_url = @base_url || @client.base_url
430
+ request_url = request_url.gsub('{Endpoint}', @client.endpoint)
431
+
432
+ options = {
433
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
434
+ path_params: {'snapshotId' => snapshot_id},
435
+ headers: request_headers.merge(custom_headers || {}),
436
+ base_url: request_url
437
+ }
438
+ promise = @client.make_request_async(:get, path_template, options)
439
+
440
+ promise = promise.then do |result|
441
+ http_response = result.response
442
+ status_code = http_response.status
443
+ response_content = http_response.body
444
+ unless status_code == 200
445
+ error_model = JSON.load(response_content)
446
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
447
+ end
448
+
449
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
450
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
451
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
452
+ # Deserialize Response
453
+ if status_code == 200
454
+ begin
455
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
456
+ result_mapper = Azure::CognitiveServices::Face::V1_0::Models::Snapshot.mapper()
457
+ result.body = @client.deserialize(result_mapper, parsed_response)
458
+ rescue Exception => e
459
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
460
+ end
461
+ end
462
+
463
+ result
464
+ end
465
+
466
+ promise.execute
467
+ end
468
+
469
+ #
470
+ # Update the information of a snapshot. Only the source subscription who took
471
+ # the snapshot can update the snapshot.
472
+ #
473
+ # @param snapshot_id Id referencing a particular snapshot.
474
+ # @param apply_scope Array of the target Face subscription ids for the
475
+ # snapshot, specified by the user who created the snapshot when calling
476
+ # Snapshot - Take. For each snapshot, only subscriptions included in the
477
+ # applyScope of Snapshot - Take can apply it.
478
+ # @param user_data [String] User specified data about the snapshot for any
479
+ # purpose. Length should not exceed 16KB.
480
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
481
+ # will be added to the HTTP request.
482
+ #
483
+ #
484
+ def update(snapshot_id, apply_scope:nil, user_data:nil, custom_headers:nil)
485
+ response = update_async(snapshot_id, apply_scope:apply_scope, user_data:user_data, custom_headers:custom_headers).value!
486
+ nil
487
+ end
488
+
489
+ #
490
+ # Update the information of a snapshot. Only the source subscription who took
491
+ # the snapshot can update the snapshot.
492
+ #
493
+ # @param snapshot_id Id referencing a particular snapshot.
494
+ # @param apply_scope Array of the target Face subscription ids for the
495
+ # snapshot, specified by the user who created the snapshot when calling
496
+ # Snapshot - Take. For each snapshot, only subscriptions included in the
497
+ # applyScope of Snapshot - Take can apply it.
498
+ # @param user_data [String] User specified data about the snapshot for any
499
+ # purpose. Length should not exceed 16KB.
500
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
501
+ # will be added to the HTTP request.
502
+ #
503
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
504
+ #
505
+ def update_with_http_info(snapshot_id, apply_scope:nil, user_data:nil, custom_headers:nil)
506
+ update_async(snapshot_id, apply_scope:apply_scope, user_data:user_data, custom_headers:custom_headers).value!
507
+ end
508
+
509
+ #
510
+ # Update the information of a snapshot. Only the source subscription who took
511
+ # the snapshot can update the snapshot.
512
+ #
513
+ # @param snapshot_id Id referencing a particular snapshot.
514
+ # @param apply_scope Array of the target Face subscription ids for the
515
+ # snapshot, specified by the user who created the snapshot when calling
516
+ # Snapshot - Take. For each snapshot, only subscriptions included in the
517
+ # applyScope of Snapshot - Take can apply it.
518
+ # @param user_data [String] User specified data about the snapshot for any
519
+ # purpose. Length should not exceed 16KB.
520
+ # @param [Hash{String => String}] A hash of custom headers that will be added
521
+ # to the HTTP request.
522
+ #
523
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
524
+ #
525
+ def update_async(snapshot_id, apply_scope:nil, user_data:nil, custom_headers:nil)
526
+ fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
527
+ fail ArgumentError, 'snapshot_id is nil' if snapshot_id.nil?
528
+ fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '16384'" if !user_data.nil? && user_data.length > 16384
529
+
530
+ body = UpdateSnapshotRequest.new
531
+ unless apply_scope.nil? && user_data.nil?
532
+ body.apply_scope = apply_scope
533
+ body.user_data = user_data
534
+ end
535
+
536
+ request_headers = {}
537
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
538
+
539
+ # Set Headers
540
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
541
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
542
+
543
+ # Serialize Request
544
+ request_mapper = Azure::CognitiveServices::Face::V1_0::Models::UpdateSnapshotRequest.mapper()
545
+ request_content = @client.serialize(request_mapper, body)
546
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
547
+
548
+ path_template = 'snapshots/{snapshotId}'
549
+
550
+ request_url = @base_url || @client.base_url
551
+ request_url = request_url.gsub('{Endpoint}', @client.endpoint)
552
+
553
+ options = {
554
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
555
+ path_params: {'snapshotId' => snapshot_id},
556
+ body: request_content,
557
+ headers: request_headers.merge(custom_headers || {}),
558
+ base_url: request_url
559
+ }
560
+ promise = @client.make_request_async(:patch, path_template, options)
561
+
562
+ promise = promise.then do |result|
563
+ http_response = result.response
564
+ status_code = http_response.status
565
+ response_content = http_response.body
566
+ unless status_code == 200
567
+ error_model = JSON.load(response_content)
568
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
569
+ end
570
+
571
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
572
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
573
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
574
+
575
+ result
576
+ end
577
+
578
+ promise.execute
579
+ end
580
+
581
+ #
582
+ # Delete an existing snapshot according to the snapshotId. All object data and
583
+ # information in the snapshot will also be deleted. Only the source
584
+ # subscription who took the snapshot can delete the snapshot. If the user does
585
+ # not delete a snapshot with this API, the snapshot will still be automatically
586
+ # deleted in 48 hours after creation.
587
+ #
588
+ # @param snapshot_id Id referencing a particular snapshot.
589
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
590
+ # will be added to the HTTP request.
591
+ #
592
+ #
593
+ def delete(snapshot_id, custom_headers:nil)
594
+ response = delete_async(snapshot_id, custom_headers:custom_headers).value!
595
+ nil
596
+ end
597
+
598
+ #
599
+ # Delete an existing snapshot according to the snapshotId. All object data and
600
+ # information in the snapshot will also be deleted. Only the source
601
+ # subscription who took the snapshot can delete the snapshot. If the user does
602
+ # not delete a snapshot with this API, the snapshot will still be automatically
603
+ # deleted in 48 hours after creation.
604
+ #
605
+ # @param snapshot_id Id referencing a particular snapshot.
606
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
607
+ # will be added to the HTTP request.
608
+ #
609
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
610
+ #
611
+ def delete_with_http_info(snapshot_id, custom_headers:nil)
612
+ delete_async(snapshot_id, custom_headers:custom_headers).value!
613
+ end
614
+
615
+ #
616
+ # Delete an existing snapshot according to the snapshotId. All object data and
617
+ # information in the snapshot will also be deleted. Only the source
618
+ # subscription who took the snapshot can delete the snapshot. If the user does
619
+ # not delete a snapshot with this API, the snapshot will still be automatically
620
+ # deleted in 48 hours after creation.
621
+ #
622
+ # @param snapshot_id Id referencing a particular snapshot.
623
+ # @param [Hash{String => String}] A hash of custom headers that will be added
624
+ # to the HTTP request.
625
+ #
626
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
627
+ #
628
+ def delete_async(snapshot_id, custom_headers:nil)
629
+ fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
630
+ fail ArgumentError, 'snapshot_id is nil' if snapshot_id.nil?
631
+
632
+
633
+ request_headers = {}
634
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
635
+
636
+ # Set Headers
637
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
638
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
639
+ path_template = 'snapshots/{snapshotId}'
640
+
641
+ request_url = @base_url || @client.base_url
642
+ request_url = request_url.gsub('{Endpoint}', @client.endpoint)
643
+
644
+ options = {
645
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
646
+ path_params: {'snapshotId' => snapshot_id},
647
+ headers: request_headers.merge(custom_headers || {}),
648
+ base_url: request_url
649
+ }
650
+ promise = @client.make_request_async(:delete, path_template, options)
651
+
652
+ promise = promise.then do |result|
653
+ http_response = result.response
654
+ status_code = http_response.status
655
+ response_content = http_response.body
656
+ unless status_code == 200
657
+ error_model = JSON.load(response_content)
658
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
659
+ end
660
+
661
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
662
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
663
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
664
+
665
+ result
666
+ end
667
+
668
+ promise.execute
669
+ end
670
+
671
+ #
672
+ # Submit an operation to apply a snapshot to current subscription. For each
673
+ # snapshot, only subscriptions included in the applyScope of Snapshot - Take
674
+ # can apply it.<br />
675
+ # The snapshot interfaces are for users to backup and restore their face data
676
+ # from one face subscription to another, inside same region or across regions.
677
+ # The workflow contains two phases, user first calls Snapshot - Take to create
678
+ # a copy of the source object and store it as a snapshot, then calls Snapshot -
679
+ # Apply to paste the snapshot to target subscription. The snapshots are stored
680
+ # in a centralized location (per Azure instance), so that they can be applied
681
+ # cross accounts and regions.<br />
682
+ # Applying snapshot is an asynchronous operation. An operation id can be
683
+ # obtained from the "Operation-Location" field in response header, to be used
684
+ # in OperationStatus - Get for tracking the progress of applying the snapshot.
685
+ # The target object id will be included in the "resourceLocation" field in
686
+ # OperationStatus - Get response when the operation status is "succeeded".<br
687
+ # />
688
+ # Snapshot applying time depends on the number of person and face entries in
689
+ # the snapshot object. It could be in seconds, or up to 1 hour for 1,000,000
690
+ # persons with multiple faces.<br />
691
+ # Snapshots will be automatically expired and cleaned in 48 hours after it is
692
+ # created by Snapshot - Take. So the target subscription is required to apply
693
+ # the snapshot in 48 hours since its creation.<br />
694
+ # Applying a snapshot will not block any other operations against the target
695
+ # object, however it is not recommended because the correctness cannot be
696
+ # guaranteed during snapshot applying. After snapshot applying is completed,
697
+ # all operations towards the target object can work as normal. Snapshot also
698
+ # includes the training results of the source object, which means target
699
+ # subscription the snapshot applied to does not need re-train the target object
700
+ # before calling Identify/FindSimilar.<br />
701
+ # One snapshot can be applied multiple times in parallel, while currently only
702
+ # CreateNew apply mode is supported, which means the apply operation will fail
703
+ # if target subscription already contains an object of same type and using the
704
+ # same objectId. Users can specify the "objectId" in request body to avoid such
705
+ # conflicts.<br />
706
+ # * Free-tier subscription quota: 100 apply operations per month.
707
+ # * S0-tier subscription quota: 100 apply operations per day.
708
+ #
709
+ # @param snapshot_id Id referencing a particular snapshot.
710
+ # @param object_id [String] User specified target object id to be created from
711
+ # the snapshot.
712
+ # @param mode [SnapshotApplyMode] Snapshot applying mode. Currently only
713
+ # CreateNew is supported, which means the apply operation will fail if target
714
+ # subscription already contains an object of same type and using the same
715
+ # objectId. Users can specify the "objectId" in request body to avoid such
716
+ # conflicts. Possible values include: 'CreateNew'
717
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
718
+ # will be added to the HTTP request.
719
+ #
720
+ #
721
+ def apply(snapshot_id, object_id, mode:nil, custom_headers:nil)
722
+ response = apply_async(snapshot_id, object_id, mode:mode, custom_headers:custom_headers).value!
723
+ nil
724
+ end
725
+
726
+ #
727
+ # Submit an operation to apply a snapshot to current subscription. For each
728
+ # snapshot, only subscriptions included in the applyScope of Snapshot - Take
729
+ # can apply it.<br />
730
+ # The snapshot interfaces are for users to backup and restore their face data
731
+ # from one face subscription to another, inside same region or across regions.
732
+ # The workflow contains two phases, user first calls Snapshot - Take to create
733
+ # a copy of the source object and store it as a snapshot, then calls Snapshot -
734
+ # Apply to paste the snapshot to target subscription. The snapshots are stored
735
+ # in a centralized location (per Azure instance), so that they can be applied
736
+ # cross accounts and regions.<br />
737
+ # Applying snapshot is an asynchronous operation. An operation id can be
738
+ # obtained from the "Operation-Location" field in response header, to be used
739
+ # in OperationStatus - Get for tracking the progress of applying the snapshot.
740
+ # The target object id will be included in the "resourceLocation" field in
741
+ # OperationStatus - Get response when the operation status is "succeeded".<br
742
+ # />
743
+ # Snapshot applying time depends on the number of person and face entries in
744
+ # the snapshot object. It could be in seconds, or up to 1 hour for 1,000,000
745
+ # persons with multiple faces.<br />
746
+ # Snapshots will be automatically expired and cleaned in 48 hours after it is
747
+ # created by Snapshot - Take. So the target subscription is required to apply
748
+ # the snapshot in 48 hours since its creation.<br />
749
+ # Applying a snapshot will not block any other operations against the target
750
+ # object, however it is not recommended because the correctness cannot be
751
+ # guaranteed during snapshot applying. After snapshot applying is completed,
752
+ # all operations towards the target object can work as normal. Snapshot also
753
+ # includes the training results of the source object, which means target
754
+ # subscription the snapshot applied to does not need re-train the target object
755
+ # before calling Identify/FindSimilar.<br />
756
+ # One snapshot can be applied multiple times in parallel, while currently only
757
+ # CreateNew apply mode is supported, which means the apply operation will fail
758
+ # if target subscription already contains an object of same type and using the
759
+ # same objectId. Users can specify the "objectId" in request body to avoid such
760
+ # conflicts.<br />
761
+ # * Free-tier subscription quota: 100 apply operations per month.
762
+ # * S0-tier subscription quota: 100 apply operations per day.
763
+ #
764
+ # @param snapshot_id Id referencing a particular snapshot.
765
+ # @param object_id [String] User specified target object id to be created from
766
+ # the snapshot.
767
+ # @param mode [SnapshotApplyMode] Snapshot applying mode. Currently only
768
+ # CreateNew is supported, which means the apply operation will fail if target
769
+ # subscription already contains an object of same type and using the same
770
+ # objectId. Users can specify the "objectId" in request body to avoid such
771
+ # conflicts. Possible values include: 'CreateNew'
772
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
773
+ # will be added to the HTTP request.
774
+ #
775
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
776
+ #
777
+ def apply_with_http_info(snapshot_id, object_id, mode:nil, custom_headers:nil)
778
+ apply_async(snapshot_id, object_id, mode:mode, custom_headers:custom_headers).value!
779
+ end
780
+
781
+ #
782
+ # Submit an operation to apply a snapshot to current subscription. For each
783
+ # snapshot, only subscriptions included in the applyScope of Snapshot - Take
784
+ # can apply it.<br />
785
+ # The snapshot interfaces are for users to backup and restore their face data
786
+ # from one face subscription to another, inside same region or across regions.
787
+ # The workflow contains two phases, user first calls Snapshot - Take to create
788
+ # a copy of the source object and store it as a snapshot, then calls Snapshot -
789
+ # Apply to paste the snapshot to target subscription. The snapshots are stored
790
+ # in a centralized location (per Azure instance), so that they can be applied
791
+ # cross accounts and regions.<br />
792
+ # Applying snapshot is an asynchronous operation. An operation id can be
793
+ # obtained from the "Operation-Location" field in response header, to be used
794
+ # in OperationStatus - Get for tracking the progress of applying the snapshot.
795
+ # The target object id will be included in the "resourceLocation" field in
796
+ # OperationStatus - Get response when the operation status is "succeeded".<br
797
+ # />
798
+ # Snapshot applying time depends on the number of person and face entries in
799
+ # the snapshot object. It could be in seconds, or up to 1 hour for 1,000,000
800
+ # persons with multiple faces.<br />
801
+ # Snapshots will be automatically expired and cleaned in 48 hours after it is
802
+ # created by Snapshot - Take. So the target subscription is required to apply
803
+ # the snapshot in 48 hours since its creation.<br />
804
+ # Applying a snapshot will not block any other operations against the target
805
+ # object, however it is not recommended because the correctness cannot be
806
+ # guaranteed during snapshot applying. After snapshot applying is completed,
807
+ # all operations towards the target object can work as normal. Snapshot also
808
+ # includes the training results of the source object, which means target
809
+ # subscription the snapshot applied to does not need re-train the target object
810
+ # before calling Identify/FindSimilar.<br />
811
+ # One snapshot can be applied multiple times in parallel, while currently only
812
+ # CreateNew apply mode is supported, which means the apply operation will fail
813
+ # if target subscription already contains an object of same type and using the
814
+ # same objectId. Users can specify the "objectId" in request body to avoid such
815
+ # conflicts.<br />
816
+ # * Free-tier subscription quota: 100 apply operations per month.
817
+ # * S0-tier subscription quota: 100 apply operations per day.
818
+ #
819
+ # @param snapshot_id Id referencing a particular snapshot.
820
+ # @param object_id [String] User specified target object id to be created from
821
+ # the snapshot.
822
+ # @param mode [SnapshotApplyMode] Snapshot applying mode. Currently only
823
+ # CreateNew is supported, which means the apply operation will fail if target
824
+ # subscription already contains an object of same type and using the same
825
+ # objectId. Users can specify the "objectId" in request body to avoid such
826
+ # conflicts. Possible values include: 'CreateNew'
827
+ # @param [Hash{String => String}] A hash of custom headers that will be added
828
+ # to the HTTP request.
829
+ #
830
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
831
+ #
832
+ def apply_async(snapshot_id, object_id, mode:nil, custom_headers:nil)
833
+ fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
834
+ fail ArgumentError, 'snapshot_id is nil' if snapshot_id.nil?
835
+ fail ArgumentError, 'object_id is nil' if object_id.nil?
836
+ fail ArgumentError, "'object_id' should satisfy the constraint - 'MaxLength': '64'" if !object_id.nil? && object_id.length > 64
837
+ fail ArgumentError, "'object_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !object_id.nil? && object_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
838
+
839
+ body = ApplySnapshotRequest.new
840
+ unless object_id.nil? && mode.nil?
841
+ body.object_id = object_id
842
+ body.mode = mode
843
+ end
844
+
845
+ request_headers = {}
846
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
847
+
848
+ # Set Headers
849
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
850
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
851
+
852
+ # Serialize Request
853
+ request_mapper = Azure::CognitiveServices::Face::V1_0::Models::ApplySnapshotRequest.mapper()
854
+ request_content = @client.serialize(request_mapper, body)
855
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
856
+
857
+ path_template = 'snapshots/{snapshotId}/apply'
858
+
859
+ request_url = @base_url || @client.base_url
860
+ request_url = request_url.gsub('{Endpoint}', @client.endpoint)
861
+
862
+ options = {
863
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
864
+ path_params: {'snapshotId' => snapshot_id},
865
+ body: request_content,
866
+ headers: request_headers.merge(custom_headers || {}),
867
+ base_url: request_url
868
+ }
869
+ promise = @client.make_request_async(:post, path_template, options)
870
+
871
+ promise = promise.then do |result|
872
+ http_response = result.response
873
+ status_code = http_response.status
874
+ response_content = http_response.body
875
+ unless status_code == 202
876
+ error_model = JSON.load(response_content)
877
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
878
+ end
879
+
880
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
881
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
882
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
883
+
884
+ result
885
+ end
886
+
887
+ promise.execute
888
+ end
889
+
890
+ #
891
+ # Retrieve the status of a take/apply snapshot operation.
892
+ #
893
+ # @param operation_id Id referencing a particular take/apply snapshot
894
+ # operation.
895
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
896
+ # will be added to the HTTP request.
897
+ #
898
+ # @return [OperationStatus] operation results.
899
+ #
900
+ def get_operation_status(operation_id, custom_headers:nil)
901
+ response = get_operation_status_async(operation_id, custom_headers:custom_headers).value!
902
+ response.body unless response.nil?
903
+ end
904
+
905
+ #
906
+ # Retrieve the status of a take/apply snapshot operation.
907
+ #
908
+ # @param operation_id Id referencing a particular take/apply snapshot
909
+ # operation.
910
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
911
+ # will be added to the HTTP request.
912
+ #
913
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
914
+ #
915
+ def get_operation_status_with_http_info(operation_id, custom_headers:nil)
916
+ get_operation_status_async(operation_id, custom_headers:custom_headers).value!
917
+ end
918
+
919
+ #
920
+ # Retrieve the status of a take/apply snapshot operation.
921
+ #
922
+ # @param operation_id Id referencing a particular take/apply snapshot
923
+ # operation.
924
+ # @param [Hash{String => String}] A hash of custom headers that will be added
925
+ # to the HTTP request.
926
+ #
927
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
928
+ #
929
+ def get_operation_status_async(operation_id, custom_headers:nil)
930
+ fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
931
+ fail ArgumentError, 'operation_id is nil' if operation_id.nil?
932
+
933
+
934
+ request_headers = {}
935
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
936
+
937
+ # Set Headers
938
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
939
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
940
+ path_template = 'operations/{operationId}'
941
+
942
+ request_url = @base_url || @client.base_url
943
+ request_url = request_url.gsub('{Endpoint}', @client.endpoint)
944
+
945
+ options = {
946
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
947
+ path_params: {'operationId' => operation_id},
948
+ headers: request_headers.merge(custom_headers || {}),
949
+ base_url: request_url
950
+ }
951
+ promise = @client.make_request_async(:get, path_template, options)
952
+
953
+ promise = promise.then do |result|
954
+ http_response = result.response
955
+ status_code = http_response.status
956
+ response_content = http_response.body
957
+ unless status_code == 200
958
+ error_model = JSON.load(response_content)
959
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
960
+ end
961
+
962
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
963
+ result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
964
+ result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
965
+ # Deserialize Response
966
+ if status_code == 200
967
+ begin
968
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
969
+ result_mapper = Azure::CognitiveServices::Face::V1_0::Models::OperationStatus.mapper()
970
+ result.body = @client.deserialize(result_mapper, parsed_response)
971
+ rescue Exception => e
972
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
973
+ end
974
+ end
975
+
976
+ result
977
+ end
978
+
979
+ promise.execute
980
+ end
981
+
982
+ end
983
+ end