azure_cognitiveservices_face 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/lib/1.0/generated/azure_cognitiveservices_face.rb +78 -0
  4. data/lib/1.0/generated/azure_cognitiveservices_face/face.rb +955 -0
  5. data/lib/1.0/generated/azure_cognitiveservices_face/face_client.rb +145 -0
  6. data/lib/1.0/generated/azure_cognitiveservices_face/face_list_operations.rb +857 -0
  7. data/lib/1.0/generated/azure_cognitiveservices_face/models/accessory.rb +59 -0
  8. data/lib/1.0/generated/azure_cognitiveservices_face/models/accessory_type.rb +17 -0
  9. data/lib/1.0/generated/azure_cognitiveservices_face/models/apierror.rb +47 -0
  10. data/lib/1.0/generated/azure_cognitiveservices_face/models/azure_regions.rb +26 -0
  11. data/lib/1.0/generated/azure_cognitiveservices_face/models/blur.rb +60 -0
  12. data/lib/1.0/generated/azure_cognitiveservices_face/models/blur_level.rb +17 -0
  13. data/lib/1.0/generated/azure_cognitiveservices_face/models/coordinate.rb +57 -0
  14. data/lib/1.0/generated/azure_cognitiveservices_face/models/detected_face.rb +82 -0
  15. data/lib/1.0/generated/azure_cognitiveservices_face/models/emotion.rb +124 -0
  16. data/lib/1.0/generated/azure_cognitiveservices_face/models/error.rb +57 -0
  17. data/lib/1.0/generated/azure_cognitiveservices_face/models/exposure.rb +62 -0
  18. data/lib/1.0/generated/azure_cognitiveservices_face/models/exposure_level.rb +17 -0
  19. data/lib/1.0/generated/azure_cognitiveservices_face/models/face_attribute_type.rb +28 -0
  20. data/lib/1.0/generated/azure_cognitiveservices_face/models/face_attributes.rb +214 -0
  21. data/lib/1.0/generated/azure_cognitiveservices_face/models/face_landmarks.rb +360 -0
  22. data/lib/1.0/generated/azure_cognitiveservices_face/models/face_list.rb +92 -0
  23. data/lib/1.0/generated/azure_cognitiveservices_face/models/face_rectangle.rb +81 -0
  24. data/lib/1.0/generated/azure_cognitiveservices_face/models/facial_hair.rb +68 -0
  25. data/lib/1.0/generated/azure_cognitiveservices_face/models/find_similar_match_mode.rb +16 -0
  26. data/lib/1.0/generated/azure_cognitiveservices_face/models/find_similar_request.rb +121 -0
  27. data/lib/1.0/generated/azure_cognitiveservices_face/models/gender.rb +17 -0
  28. data/lib/1.0/generated/azure_cognitiveservices_face/models/glasses_type.rb +18 -0
  29. data/lib/1.0/generated/azure_cognitiveservices_face/models/group_request.rb +58 -0
  30. data/lib/1.0/generated/azure_cognitiveservices_face/models/group_result.rb +83 -0
  31. data/lib/1.0/generated/azure_cognitiveservices_face/models/hair.rb +80 -0
  32. data/lib/1.0/generated/azure_cognitiveservices_face/models/hair_color.rb +60 -0
  33. data/lib/1.0/generated/azure_cognitiveservices_face/models/hair_color_type.rb +22 -0
  34. data/lib/1.0/generated/azure_cognitiveservices_face/models/head_pose.rb +68 -0
  35. data/lib/1.0/generated/azure_cognitiveservices_face/models/identify_candidate.rb +59 -0
  36. data/lib/1.0/generated/azure_cognitiveservices_face/models/identify_request.rb +105 -0
  37. data/lib/1.0/generated/azure_cognitiveservices_face/models/identify_result.rb +69 -0
  38. data/lib/1.0/generated/azure_cognitiveservices_face/models/image_url.rb +47 -0
  39. data/lib/1.0/generated/azure_cognitiveservices_face/models/makeup.rb +59 -0
  40. data/lib/1.0/generated/azure_cognitiveservices_face/models/name_and_user_data_contract.rb +64 -0
  41. data/lib/1.0/generated/azure_cognitiveservices_face/models/noise.rb +62 -0
  42. data/lib/1.0/generated/azure_cognitiveservices_face/models/noise_level.rb +17 -0
  43. data/lib/1.0/generated/azure_cognitiveservices_face/models/occlusion.rb +70 -0
  44. data/lib/1.0/generated/azure_cognitiveservices_face/models/persisted_face.rb +63 -0
  45. data/lib/1.0/generated/azure_cognitiveservices_face/models/person.rb +89 -0
  46. data/lib/1.0/generated/azure_cognitiveservices_face/models/person_group.rb +72 -0
  47. data/lib/1.0/generated/azure_cognitiveservices_face/models/similar_face.rb +73 -0
  48. data/lib/1.0/generated/azure_cognitiveservices_face/models/training_status.rb +89 -0
  49. data/lib/1.0/generated/azure_cognitiveservices_face/models/training_status_type.rb +18 -0
  50. data/lib/1.0/generated/azure_cognitiveservices_face/models/update_person_face_request.rb +50 -0
  51. data/lib/1.0/generated/azure_cognitiveservices_face/models/verify_face_to_face_request.rb +57 -0
  52. data/lib/1.0/generated/azure_cognitiveservices_face/models/verify_face_to_person_request.rb +75 -0
  53. data/lib/1.0/generated/azure_cognitiveservices_face/models/verify_result.rb +62 -0
  54. data/lib/1.0/generated/azure_cognitiveservices_face/module_definition.rb +9 -0
  55. data/lib/1.0/generated/azure_cognitiveservices_face/person_group_operations.rb +678 -0
  56. data/lib/1.0/generated/azure_cognitiveservices_face/person_group_person.rb +1121 -0
  57. data/lib/azure_cognitiveservices_face.rb +6 -0
  58. data/lib/module_definition.rb +7 -0
  59. data/lib/profiles/latest/face_latest_profile_client.rb +38 -0
  60. data/lib/profiles/latest/face_module_definition.rb +8 -0
  61. data/lib/profiles/latest/modules/face_profile_module.rb +253 -0
  62. data/lib/version.rb +7 -0
  63. metadata +180 -0
@@ -0,0 +1,145 @@
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
+ # A service client - single point of access to the REST API.
9
+ #
10
+ class FaceClient < MsRestAzure::AzureServiceClient
11
+ include MsRestAzure
12
+ include MsRestAzure::Serialization
13
+
14
+ # @return [String] the base URI of the service.
15
+ attr_reader :base_url
16
+
17
+ # @return Credentials needed for the client to connect to Azure.
18
+ attr_reader :credentials1
19
+
20
+ # @return [AzureRegions] Supported Azure regions for Cognitive Services
21
+ # endpoints. Possible values include: 'westus', 'westeurope',
22
+ # 'southeastasia', 'eastus2', 'westcentralus', 'westus2', 'eastus',
23
+ # 'southcentralus', 'northeurope', 'eastasia', 'australiaeast',
24
+ # 'brazilsouth'
25
+ attr_accessor :azure_region
26
+
27
+ # @return Subscription credentials which uniquely identify client
28
+ # subscription.
29
+ attr_accessor :credentials
30
+
31
+ # @return [String] Gets or sets the preferred language for the response.
32
+ attr_accessor :accept_language
33
+
34
+ # @return [Integer] Gets or sets the retry timeout in seconds for Long
35
+ # Running Operations. Default value is 30.
36
+ attr_accessor :long_running_operation_retry_timeout
37
+
38
+ # @return [Boolean] When set to true a unique x-ms-client-request-id value
39
+ # is generated and included in each request. Default is true.
40
+ attr_accessor :generate_client_request_id
41
+
42
+ # @return [Face] face
43
+ attr_reader :face
44
+
45
+ # @return [PersonGroupPerson] person_group_person
46
+ attr_reader :person_group_person
47
+
48
+ # @return [PersonGroupOperations] person_group_operations
49
+ attr_reader :person_group_operations
50
+
51
+ # @return [FaceListOperations] face_list_operations
52
+ attr_reader :face_list_operations
53
+
54
+ #
55
+ # Creates initializes a new instance of the FaceClient class.
56
+ # @param credentials [MsRest::ServiceClientCredentials] credentials to authorize HTTP requests made by the service client.
57
+ # @param options [Array] filters to be applied to the HTTP requests.
58
+ #
59
+ def initialize(credentials = nil, options = nil)
60
+ super(credentials, options)
61
+ @base_url = 'https://{AzureRegion}.api.cognitive.microsoft.com/face/v1.0'
62
+
63
+ fail ArgumentError, 'invalid type of credentials input parameter' unless credentials.is_a?(MsRest::ServiceClientCredentials) unless credentials.nil?
64
+ @credentials = credentials
65
+
66
+ @face = Face.new(self)
67
+ @person_group_person = PersonGroupPerson.new(self)
68
+ @person_group_operations = PersonGroupOperations.new(self)
69
+ @face_list_operations = FaceListOperations.new(self)
70
+ @accept_language = 'en-US'
71
+ @long_running_operation_retry_timeout = 30
72
+ @generate_client_request_id = true
73
+ add_telemetry
74
+ end
75
+
76
+ #
77
+ # Makes a request and returns the body of the response.
78
+ # @param method [Symbol] with any of the following values :get, :put, :post, :patch, :delete.
79
+ # @param path [String] the path, relative to {base_url}.
80
+ # @param options [Hash{String=>String}] specifying any request options like :body.
81
+ # @return [Hash{String=>String}] containing the body of the response.
82
+ # Example:
83
+ #
84
+ # request_content = "{'location':'westus','tags':{'tag1':'val1','tag2':'val2'}}"
85
+ # path = "/path"
86
+ # options = {
87
+ # body: request_content,
88
+ # query_params: {'api-version' => '2016-02-01'}
89
+ # }
90
+ # result = @client.make_request(:put, path, options)
91
+ #
92
+ def make_request(method, path, options = {})
93
+ result = make_request_with_http_info(method, path, options)
94
+ result.body unless result.nil?
95
+ end
96
+
97
+ #
98
+ # Makes a request and returns the operation response.
99
+ # @param method [Symbol] with any of the following values :get, :put, :post, :patch, :delete.
100
+ # @param path [String] the path, relative to {base_url}.
101
+ # @param options [Hash{String=>String}] specifying any request options like :body.
102
+ # @return [MsRestAzure::AzureOperationResponse] Operation response containing the request, response and status.
103
+ #
104
+ def make_request_with_http_info(method, path, options = {})
105
+ result = make_request_async(method, path, options).value!
106
+ result.body = result.response.body.to_s.empty? ? nil : JSON.load(result.response.body)
107
+ result
108
+ end
109
+
110
+ #
111
+ # Makes a request asynchronously.
112
+ # @param method [Symbol] with any of the following values :get, :put, :post, :patch, :delete.
113
+ # @param path [String] the path, relative to {base_url}.
114
+ # @param options [Hash{String=>String}] specifying any request options like :body.
115
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
116
+ #
117
+ def make_request_async(method, path, options = {})
118
+ fail ArgumentError, 'method is nil' if method.nil?
119
+ fail ArgumentError, 'path is nil' if path.nil?
120
+
121
+ request_url = options[:base_url] || @base_url
122
+ if(!options[:headers].nil? && !options[:headers]['Content-Type'].nil?)
123
+ @request_headers['Content-Type'] = options[:headers]['Content-Type']
124
+ end
125
+
126
+ request_headers = @request_headers
127
+ request_headers.merge!({'accept-language' => @accept_language}) unless @accept_language.nil?
128
+ options.merge!({headers: request_headers.merge(options[:headers] || {})})
129
+ options.merge!({credentials: @credentials}) unless @credentials.nil?
130
+
131
+ super(request_url, method, path, options)
132
+ end
133
+
134
+
135
+ private
136
+ #
137
+ # Adds telemetry information.
138
+ #
139
+ def add_telemetry
140
+ sdk_information = 'azure_cognitiveservices_face'
141
+ sdk_information = "#{sdk_information}/0.16.0"
142
+ add_user_agent_information(sdk_information)
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,857 @@
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 FaceListOperations
11
+ include MsRestAzure
12
+
13
+ #
14
+ # Creates and initializes a new instance of the FaceListOperations 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
+ # Create an empty face list. Up to 64 face lists are allowed to exist in one
26
+ # subscription.
27
+ #
28
+ # @param face_list_id [String] Id referencing a particular face list.
29
+ # @param name [String] User defined name, maximum length is 128.
30
+ # @param user_data [String] User specified data. Length should not exceed 16KB.
31
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
32
+ # will be added to the HTTP request.
33
+ #
34
+ #
35
+ def create(face_list_id, name:nil, user_data:nil, custom_headers:nil)
36
+ response = create_async(face_list_id, name:name, user_data:user_data, custom_headers:custom_headers).value!
37
+ nil
38
+ end
39
+
40
+ #
41
+ # Create an empty face list. Up to 64 face lists are allowed to exist in one
42
+ # subscription.
43
+ #
44
+ # @param face_list_id [String] Id referencing a particular face list.
45
+ # @param name [String] User defined name, maximum length is 128.
46
+ # @param user_data [String] User specified data. Length should not exceed 16KB.
47
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
48
+ # will be added to the HTTP request.
49
+ #
50
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
51
+ #
52
+ def create_with_http_info(face_list_id, name:nil, user_data:nil, custom_headers:nil)
53
+ create_async(face_list_id, name:name, user_data:user_data, custom_headers:custom_headers).value!
54
+ end
55
+
56
+ #
57
+ # Create an empty face list. Up to 64 face lists are allowed to exist in one
58
+ # subscription.
59
+ #
60
+ # @param face_list_id [String] Id referencing a particular face list.
61
+ # @param name [String] User defined name, maximum length is 128.
62
+ # @param user_data [String] User specified data. Length should not exceed 16KB.
63
+ # @param [Hash{String => String}] A hash of custom headers that will be added
64
+ # to the HTTP request.
65
+ #
66
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
67
+ #
68
+ def create_async(face_list_id, name:nil, user_data:nil, custom_headers:nil)
69
+ fail ArgumentError, '@client.azure_region is nil' if @client.azure_region.nil?
70
+ fail ArgumentError, 'face_list_id is nil' if face_list_id.nil?
71
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'MaxLength': '64'" if !face_list_id.nil? && face_list_id.length > 64
72
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !face_list_id.nil? && face_list_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
73
+ fail ArgumentError, "'name' should satisfy the constraint - 'MaxLength': '128'" if !name.nil? && name.length > 128
74
+ fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '16384'" if !user_data.nil? && user_data.length > 16384
75
+
76
+ body = NameAndUserDataContract.new
77
+ unless name.nil? && user_data.nil?
78
+ body.name = name
79
+ body.user_data = user_data
80
+ end
81
+
82
+ request_headers = {}
83
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
84
+
85
+ # Set Headers
86
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
87
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
88
+
89
+ # Serialize Request
90
+ request_mapper = Azure::CognitiveServices::Face::V1_0::Models::NameAndUserDataContract.mapper()
91
+ request_content = @client.serialize(request_mapper, body)
92
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
93
+
94
+ path_template = 'facelists/{faceListId}'
95
+
96
+ request_url = @base_url || @client.base_url
97
+ request_url = request_url.gsub('{AzureRegion}', @client.azure_region)
98
+
99
+ options = {
100
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
101
+ path_params: {'faceListId' => face_list_id},
102
+ body: request_content,
103
+ headers: request_headers.merge(custom_headers || {}),
104
+ base_url: request_url
105
+ }
106
+ promise = @client.make_request_async(:put, path_template, options)
107
+
108
+ promise = promise.then do |result|
109
+ http_response = result.response
110
+ status_code = http_response.status
111
+ response_content = http_response.body
112
+ unless status_code == 200
113
+ error_model = JSON.load(response_content)
114
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
115
+ end
116
+
117
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
118
+
119
+ result
120
+ end
121
+
122
+ promise.execute
123
+ end
124
+
125
+ #
126
+ # Retrieve a face list's information.
127
+ #
128
+ # @param face_list_id [String] Id referencing a particular face list.
129
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
130
+ # will be added to the HTTP request.
131
+ #
132
+ # @return [FaceList] operation results.
133
+ #
134
+ def get(face_list_id, custom_headers:nil)
135
+ response = get_async(face_list_id, custom_headers:custom_headers).value!
136
+ response.body unless response.nil?
137
+ end
138
+
139
+ #
140
+ # Retrieve a face list's information.
141
+ #
142
+ # @param face_list_id [String] Id referencing a particular face list.
143
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
144
+ # will be added to the HTTP request.
145
+ #
146
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
147
+ #
148
+ def get_with_http_info(face_list_id, custom_headers:nil)
149
+ get_async(face_list_id, custom_headers:custom_headers).value!
150
+ end
151
+
152
+ #
153
+ # Retrieve a face list's information.
154
+ #
155
+ # @param face_list_id [String] Id referencing a particular face list.
156
+ # @param [Hash{String => String}] A hash of custom headers that will be added
157
+ # to the HTTP request.
158
+ #
159
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
160
+ #
161
+ def get_async(face_list_id, custom_headers:nil)
162
+ fail ArgumentError, '@client.azure_region is nil' if @client.azure_region.nil?
163
+ fail ArgumentError, 'face_list_id is nil' if face_list_id.nil?
164
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'MaxLength': '64'" if !face_list_id.nil? && face_list_id.length > 64
165
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !face_list_id.nil? && face_list_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
166
+
167
+
168
+ request_headers = {}
169
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
170
+
171
+ # Set Headers
172
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
173
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
174
+ path_template = 'facelists/{faceListId}'
175
+
176
+ request_url = @base_url || @client.base_url
177
+ request_url = request_url.gsub('{AzureRegion}', @client.azure_region)
178
+
179
+ options = {
180
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
181
+ path_params: {'faceListId' => face_list_id},
182
+ headers: request_headers.merge(custom_headers || {}),
183
+ base_url: request_url
184
+ }
185
+ promise = @client.make_request_async(:get, path_template, options)
186
+
187
+ promise = promise.then do |result|
188
+ http_response = result.response
189
+ status_code = http_response.status
190
+ response_content = http_response.body
191
+ unless status_code == 200
192
+ error_model = JSON.load(response_content)
193
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
194
+ end
195
+
196
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
197
+ # Deserialize Response
198
+ if status_code == 200
199
+ begin
200
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
201
+ result_mapper = Azure::CognitiveServices::Face::V1_0::Models::FaceList.mapper()
202
+ result.body = @client.deserialize(result_mapper, parsed_response)
203
+ rescue Exception => e
204
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
205
+ end
206
+ end
207
+
208
+ result
209
+ end
210
+
211
+ promise.execute
212
+ end
213
+
214
+ #
215
+ # Update information of a face list.
216
+ #
217
+ # @param face_list_id [String] Id referencing a particular face list.
218
+ # @param name [String] User defined name, maximum length is 128.
219
+ # @param user_data [String] User specified data. Length should not exceed 16KB.
220
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
221
+ # will be added to the HTTP request.
222
+ #
223
+ #
224
+ def update(face_list_id, name:nil, user_data:nil, custom_headers:nil)
225
+ response = update_async(face_list_id, name:name, user_data:user_data, custom_headers:custom_headers).value!
226
+ nil
227
+ end
228
+
229
+ #
230
+ # Update information of a face list.
231
+ #
232
+ # @param face_list_id [String] Id referencing a particular face list.
233
+ # @param name [String] User defined name, maximum length is 128.
234
+ # @param user_data [String] User specified data. Length should not exceed 16KB.
235
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
236
+ # will be added to the HTTP request.
237
+ #
238
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
239
+ #
240
+ def update_with_http_info(face_list_id, name:nil, user_data:nil, custom_headers:nil)
241
+ update_async(face_list_id, name:name, user_data:user_data, custom_headers:custom_headers).value!
242
+ end
243
+
244
+ #
245
+ # Update information of a face list.
246
+ #
247
+ # @param face_list_id [String] Id referencing a particular face list.
248
+ # @param name [String] User defined name, maximum length is 128.
249
+ # @param user_data [String] User specified data. Length should not exceed 16KB.
250
+ # @param [Hash{String => String}] A hash of custom headers that will be added
251
+ # to the HTTP request.
252
+ #
253
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
254
+ #
255
+ def update_async(face_list_id, name:nil, user_data:nil, custom_headers:nil)
256
+ fail ArgumentError, '@client.azure_region is nil' if @client.azure_region.nil?
257
+ fail ArgumentError, 'face_list_id is nil' if face_list_id.nil?
258
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'MaxLength': '64'" if !face_list_id.nil? && face_list_id.length > 64
259
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !face_list_id.nil? && face_list_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
260
+ fail ArgumentError, "'name' should satisfy the constraint - 'MaxLength': '128'" if !name.nil? && name.length > 128
261
+ fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '16384'" if !user_data.nil? && user_data.length > 16384
262
+
263
+ body = NameAndUserDataContract.new
264
+ unless name.nil? && user_data.nil?
265
+ body.name = name
266
+ body.user_data = user_data
267
+ end
268
+
269
+ request_headers = {}
270
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
271
+
272
+ # Set Headers
273
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
274
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
275
+
276
+ # Serialize Request
277
+ request_mapper = Azure::CognitiveServices::Face::V1_0::Models::NameAndUserDataContract.mapper()
278
+ request_content = @client.serialize(request_mapper, body)
279
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
280
+
281
+ path_template = 'facelists/{faceListId}'
282
+
283
+ request_url = @base_url || @client.base_url
284
+ request_url = request_url.gsub('{AzureRegion}', @client.azure_region)
285
+
286
+ options = {
287
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
288
+ path_params: {'faceListId' => face_list_id},
289
+ body: request_content,
290
+ headers: request_headers.merge(custom_headers || {}),
291
+ base_url: request_url
292
+ }
293
+ promise = @client.make_request_async(:patch, path_template, options)
294
+
295
+ promise = promise.then do |result|
296
+ http_response = result.response
297
+ status_code = http_response.status
298
+ response_content = http_response.body
299
+ unless status_code == 200
300
+ error_model = JSON.load(response_content)
301
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
302
+ end
303
+
304
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
305
+
306
+ result
307
+ end
308
+
309
+ promise.execute
310
+ end
311
+
312
+ #
313
+ # Delete an existing face list according to faceListId. Persisted face images
314
+ # in the face list will also be deleted.
315
+ #
316
+ # @param face_list_id [String] Id referencing a particular face list.
317
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
318
+ # will be added to the HTTP request.
319
+ #
320
+ #
321
+ def delete(face_list_id, custom_headers:nil)
322
+ response = delete_async(face_list_id, custom_headers:custom_headers).value!
323
+ nil
324
+ end
325
+
326
+ #
327
+ # Delete an existing face list according to faceListId. Persisted face images
328
+ # in the face list will also be deleted.
329
+ #
330
+ # @param face_list_id [String] Id referencing a particular face list.
331
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
332
+ # will be added to the HTTP request.
333
+ #
334
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
335
+ #
336
+ def delete_with_http_info(face_list_id, custom_headers:nil)
337
+ delete_async(face_list_id, custom_headers:custom_headers).value!
338
+ end
339
+
340
+ #
341
+ # Delete an existing face list according to faceListId. Persisted face images
342
+ # in the face list will also be deleted.
343
+ #
344
+ # @param face_list_id [String] Id referencing a particular face list.
345
+ # @param [Hash{String => String}] A hash of custom headers that will be added
346
+ # to the HTTP request.
347
+ #
348
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
349
+ #
350
+ def delete_async(face_list_id, custom_headers:nil)
351
+ fail ArgumentError, '@client.azure_region is nil' if @client.azure_region.nil?
352
+ fail ArgumentError, 'face_list_id is nil' if face_list_id.nil?
353
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'MaxLength': '64'" if !face_list_id.nil? && face_list_id.length > 64
354
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !face_list_id.nil? && face_list_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
355
+
356
+
357
+ request_headers = {}
358
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
359
+
360
+ # Set Headers
361
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
362
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
363
+ path_template = 'facelists/{faceListId}'
364
+
365
+ request_url = @base_url || @client.base_url
366
+ request_url = request_url.gsub('{AzureRegion}', @client.azure_region)
367
+
368
+ options = {
369
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
370
+ path_params: {'faceListId' => face_list_id},
371
+ headers: request_headers.merge(custom_headers || {}),
372
+ base_url: request_url
373
+ }
374
+ promise = @client.make_request_async(:delete, path_template, options)
375
+
376
+ promise = promise.then do |result|
377
+ http_response = result.response
378
+ status_code = http_response.status
379
+ response_content = http_response.body
380
+ unless status_code == 200
381
+ error_model = JSON.load(response_content)
382
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
383
+ end
384
+
385
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
386
+
387
+ result
388
+ end
389
+
390
+ promise.execute
391
+ end
392
+
393
+ #
394
+ # Retrieve information about all existing face lists. Only faceListId, name and
395
+ # userData will be returned.
396
+ #
397
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
398
+ # will be added to the HTTP request.
399
+ #
400
+ # @return [Array] operation results.
401
+ #
402
+ def list(custom_headers:nil)
403
+ response = list_async(custom_headers:custom_headers).value!
404
+ response.body unless response.nil?
405
+ end
406
+
407
+ #
408
+ # Retrieve information about all existing face lists. Only faceListId, name and
409
+ # userData will be returned.
410
+ #
411
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
412
+ # will be added to the HTTP request.
413
+ #
414
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
415
+ #
416
+ def list_with_http_info(custom_headers:nil)
417
+ list_async(custom_headers:custom_headers).value!
418
+ end
419
+
420
+ #
421
+ # Retrieve information about all existing face lists. Only faceListId, name and
422
+ # userData will be returned.
423
+ #
424
+ # @param [Hash{String => String}] A hash of custom headers that will be added
425
+ # to the HTTP request.
426
+ #
427
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
428
+ #
429
+ def list_async(custom_headers:nil)
430
+ fail ArgumentError, '@client.azure_region is nil' if @client.azure_region.nil?
431
+
432
+
433
+ request_headers = {}
434
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
435
+
436
+ # Set Headers
437
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
438
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
439
+ path_template = 'facelists'
440
+
441
+ request_url = @base_url || @client.base_url
442
+ request_url = request_url.gsub('{AzureRegion}', @client.azure_region)
443
+
444
+ options = {
445
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
446
+ headers: request_headers.merge(custom_headers || {}),
447
+ base_url: request_url
448
+ }
449
+ promise = @client.make_request_async(:get, path_template, options)
450
+
451
+ promise = promise.then do |result|
452
+ http_response = result.response
453
+ status_code = http_response.status
454
+ response_content = http_response.body
455
+ unless status_code == 200
456
+ error_model = JSON.load(response_content)
457
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
458
+ end
459
+
460
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
461
+ # Deserialize Response
462
+ if status_code == 200
463
+ begin
464
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
465
+ result_mapper = {
466
+ client_side_validation: true,
467
+ required: false,
468
+ serialized_name: 'parsed_response',
469
+ type: {
470
+ name: 'Sequence',
471
+ element: {
472
+ client_side_validation: true,
473
+ required: false,
474
+ serialized_name: 'FaceListElementType',
475
+ type: {
476
+ name: 'Composite',
477
+ class_name: 'FaceList'
478
+ }
479
+ }
480
+ }
481
+ }
482
+ result.body = @client.deserialize(result_mapper, parsed_response)
483
+ rescue Exception => e
484
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
485
+ end
486
+ end
487
+
488
+ result
489
+ end
490
+
491
+ promise.execute
492
+ end
493
+
494
+ #
495
+ # Delete an existing face from a face list (given by a persisitedFaceId and a
496
+ # faceListId). Persisted image related to the face will also be deleted.
497
+ #
498
+ # @param face_list_id [String] Id referencing a particular face list.
499
+ # @param persisted_face_id Id referencing a particular persistedFaceId of an
500
+ # existing face.
501
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
502
+ # will be added to the HTTP request.
503
+ #
504
+ #
505
+ def delete_face(face_list_id, persisted_face_id, custom_headers:nil)
506
+ response = delete_face_async(face_list_id, persisted_face_id, custom_headers:custom_headers).value!
507
+ nil
508
+ end
509
+
510
+ #
511
+ # Delete an existing face from a face list (given by a persisitedFaceId and a
512
+ # faceListId). Persisted image related to the face will also be deleted.
513
+ #
514
+ # @param face_list_id [String] Id referencing a particular face list.
515
+ # @param persisted_face_id Id referencing a particular persistedFaceId of an
516
+ # existing face.
517
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
518
+ # will be added to the HTTP request.
519
+ #
520
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
521
+ #
522
+ def delete_face_with_http_info(face_list_id, persisted_face_id, custom_headers:nil)
523
+ delete_face_async(face_list_id, persisted_face_id, custom_headers:custom_headers).value!
524
+ end
525
+
526
+ #
527
+ # Delete an existing face from a face list (given by a persisitedFaceId and a
528
+ # faceListId). Persisted image related to the face will also be deleted.
529
+ #
530
+ # @param face_list_id [String] Id referencing a particular face list.
531
+ # @param persisted_face_id Id referencing a particular persistedFaceId of an
532
+ # existing face.
533
+ # @param [Hash{String => String}] A hash of custom headers that will be added
534
+ # to the HTTP request.
535
+ #
536
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
537
+ #
538
+ def delete_face_async(face_list_id, persisted_face_id, custom_headers:nil)
539
+ fail ArgumentError, '@client.azure_region is nil' if @client.azure_region.nil?
540
+ fail ArgumentError, 'face_list_id is nil' if face_list_id.nil?
541
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'MaxLength': '64'" if !face_list_id.nil? && face_list_id.length > 64
542
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !face_list_id.nil? && face_list_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
543
+ fail ArgumentError, 'persisted_face_id is nil' if persisted_face_id.nil?
544
+
545
+
546
+ request_headers = {}
547
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
548
+
549
+ # Set Headers
550
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
551
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
552
+ path_template = 'facelists/{faceListId}/persistedFaces/{persistedFaceId}'
553
+
554
+ request_url = @base_url || @client.base_url
555
+ request_url = request_url.gsub('{AzureRegion}', @client.azure_region)
556
+
557
+ options = {
558
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
559
+ path_params: {'faceListId' => face_list_id,'persistedFaceId' => persisted_face_id},
560
+ headers: request_headers.merge(custom_headers || {}),
561
+ base_url: request_url
562
+ }
563
+ promise = @client.make_request_async(:delete, path_template, options)
564
+
565
+ promise = promise.then do |result|
566
+ http_response = result.response
567
+ status_code = http_response.status
568
+ response_content = http_response.body
569
+ unless status_code == 200
570
+ error_model = JSON.load(response_content)
571
+ fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
572
+ end
573
+
574
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
575
+
576
+ result
577
+ end
578
+
579
+ promise.execute
580
+ end
581
+
582
+ #
583
+ # Add a face to a face list. The input face is specified as an image with a
584
+ # targetFace rectangle. It returns a persistedFaceId representing the added
585
+ # face, and persistedFaceId will not expire.
586
+ #
587
+ # @param face_list_id [String] Id referencing a particular face list.
588
+ # @param url [String]
589
+ # @param user_data [String] User-specified data about the face for any purpose.
590
+ # The maximum length is 1KB.
591
+ # @param target_face [Array<Integer>] A face rectangle to specify the target
592
+ # face to be added to a person in the format of
593
+ # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
594
+ # is more than one face in the image, targetFace is required to specify which
595
+ # face to add. No targetFace means there is only one face detected in the
596
+ # entire image.
597
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
598
+ # will be added to the HTTP request.
599
+ #
600
+ # @return [PersistedFace] operation results.
601
+ #
602
+ def add_face_from_url(face_list_id, url, user_data:nil, target_face:nil, custom_headers:nil)
603
+ response = add_face_from_url_async(face_list_id, url, user_data:user_data, target_face:target_face, custom_headers:custom_headers).value!
604
+ response.body unless response.nil?
605
+ end
606
+
607
+ #
608
+ # Add a face to a face list. The input face is specified as an image with a
609
+ # targetFace rectangle. It returns a persistedFaceId representing the added
610
+ # face, and persistedFaceId will not expire.
611
+ #
612
+ # @param face_list_id [String] Id referencing a particular face list.
613
+ # @param url [String]
614
+ # @param user_data [String] User-specified data about the face for any purpose.
615
+ # The maximum length is 1KB.
616
+ # @param target_face [Array<Integer>] A face rectangle to specify the target
617
+ # face to be added to a person in the format of
618
+ # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
619
+ # is more than one face in the image, targetFace is required to specify which
620
+ # face to add. No targetFace means there is only one face detected in the
621
+ # entire image.
622
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
623
+ # will be added to the HTTP request.
624
+ #
625
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
626
+ #
627
+ def add_face_from_url_with_http_info(face_list_id, url, user_data:nil, target_face:nil, custom_headers:nil)
628
+ add_face_from_url_async(face_list_id, url, user_data:user_data, target_face:target_face, custom_headers:custom_headers).value!
629
+ end
630
+
631
+ #
632
+ # Add a face to a face list. The input face is specified as an image with a
633
+ # targetFace rectangle. It returns a persistedFaceId representing the added
634
+ # face, and persistedFaceId will not expire.
635
+ #
636
+ # @param face_list_id [String] Id referencing a particular face list.
637
+ # @param url [String]
638
+ # @param user_data [String] User-specified data about the face for any purpose.
639
+ # The maximum length is 1KB.
640
+ # @param target_face [Array<Integer>] A face rectangle to specify the target
641
+ # face to be added to a person in the format of
642
+ # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
643
+ # is more than one face in the image, targetFace is required to specify which
644
+ # face to add. No targetFace means there is only one face detected in the
645
+ # entire image.
646
+ # @param [Hash{String => String}] A hash of custom headers that will be added
647
+ # to the HTTP request.
648
+ #
649
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
650
+ #
651
+ def add_face_from_url_async(face_list_id, url, user_data:nil, target_face:nil, custom_headers:nil)
652
+ fail ArgumentError, '@client.azure_region is nil' if @client.azure_region.nil?
653
+ fail ArgumentError, 'face_list_id is nil' if face_list_id.nil?
654
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'MaxLength': '64'" if !face_list_id.nil? && face_list_id.length > 64
655
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !face_list_id.nil? && face_list_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
656
+ fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '1024'" if !user_data.nil? && user_data.length > 1024
657
+ fail ArgumentError, 'url is nil' if url.nil?
658
+
659
+ image_url = ImageUrl.new
660
+ unless url.nil?
661
+ image_url.url = url
662
+ end
663
+
664
+ request_headers = {}
665
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
666
+
667
+ # Set Headers
668
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
669
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
670
+
671
+ # Serialize Request
672
+ request_mapper = Azure::CognitiveServices::Face::V1_0::Models::ImageUrl.mapper()
673
+ request_content = @client.serialize(request_mapper, image_url)
674
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
675
+
676
+ path_template = 'facelists/{faceListId}/persistedFaces'
677
+
678
+ request_url = @base_url || @client.base_url
679
+ request_url = request_url.gsub('{AzureRegion}', @client.azure_region)
680
+
681
+ options = {
682
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
683
+ path_params: {'faceListId' => face_list_id},
684
+ query_params: {'userData' => user_data,'targetFace' => target_face.nil? ? nil : target_face.join(',')},
685
+ body: request_content,
686
+ headers: request_headers.merge(custom_headers || {}),
687
+ base_url: request_url
688
+ }
689
+ promise = @client.make_request_async(:post, path_template, options)
690
+
691
+ promise = promise.then do |result|
692
+ http_response = result.response
693
+ status_code = http_response.status
694
+ response_content = http_response.body
695
+ unless status_code == 200
696
+ error_model = JSON.load(response_content)
697
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
698
+ end
699
+
700
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
701
+ # Deserialize Response
702
+ if status_code == 200
703
+ begin
704
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
705
+ result_mapper = Azure::CognitiveServices::Face::V1_0::Models::PersistedFace.mapper()
706
+ result.body = @client.deserialize(result_mapper, parsed_response)
707
+ rescue Exception => e
708
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
709
+ end
710
+ end
711
+
712
+ result
713
+ end
714
+
715
+ promise.execute
716
+ end
717
+
718
+ #
719
+ # Add a face to a face list. The input face is specified as an image with a
720
+ # targetFace rectangle. It returns a persistedFaceId representing the added
721
+ # face, and persistedFaceId will not expire.
722
+ #
723
+ # @param face_list_id [String] Id referencing a particular face list.
724
+ # @param image An image stream.
725
+ # @param user_data [String] User-specified data about the face for any purpose.
726
+ # The maximum length is 1KB.
727
+ # @param target_face [Array<Integer>] A face rectangle to specify the target
728
+ # face to be added to a person in the format of
729
+ # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
730
+ # is more than one face in the image, targetFace is required to specify which
731
+ # face to add. No targetFace means there is only one face detected in the
732
+ # entire image.
733
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
734
+ # will be added to the HTTP request.
735
+ #
736
+ # @return [PersistedFace] operation results.
737
+ #
738
+ def add_face_from_stream(face_list_id, image, user_data:nil, target_face:nil, custom_headers:nil)
739
+ response = add_face_from_stream_async(face_list_id, image, user_data:user_data, target_face:target_face, custom_headers:custom_headers).value!
740
+ response.body unless response.nil?
741
+ end
742
+
743
+ #
744
+ # Add a face to a face list. The input face is specified as an image with a
745
+ # targetFace rectangle. It returns a persistedFaceId representing the added
746
+ # face, and persistedFaceId will not expire.
747
+ #
748
+ # @param face_list_id [String] Id referencing a particular face list.
749
+ # @param image An image stream.
750
+ # @param user_data [String] User-specified data about the face for any purpose.
751
+ # The maximum length is 1KB.
752
+ # @param target_face [Array<Integer>] A face rectangle to specify the target
753
+ # face to be added to a person in the format of
754
+ # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
755
+ # is more than one face in the image, targetFace is required to specify which
756
+ # face to add. No targetFace means there is only one face detected in the
757
+ # entire image.
758
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
759
+ # will be added to the HTTP request.
760
+ #
761
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
762
+ #
763
+ def add_face_from_stream_with_http_info(face_list_id, image, user_data:nil, target_face:nil, custom_headers:nil)
764
+ add_face_from_stream_async(face_list_id, image, user_data:user_data, target_face:target_face, custom_headers:custom_headers).value!
765
+ end
766
+
767
+ #
768
+ # Add a face to a face list. The input face is specified as an image with a
769
+ # targetFace rectangle. It returns a persistedFaceId representing the added
770
+ # face, and persistedFaceId will not expire.
771
+ #
772
+ # @param face_list_id [String] Id referencing a particular face list.
773
+ # @param image An image stream.
774
+ # @param user_data [String] User-specified data about the face for any purpose.
775
+ # The maximum length is 1KB.
776
+ # @param target_face [Array<Integer>] A face rectangle to specify the target
777
+ # face to be added to a person in the format of
778
+ # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
779
+ # is more than one face in the image, targetFace is required to specify which
780
+ # face to add. No targetFace means there is only one face detected in the
781
+ # entire image.
782
+ # @param [Hash{String => String}] A hash of custom headers that will be added
783
+ # to the HTTP request.
784
+ #
785
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
786
+ #
787
+ def add_face_from_stream_async(face_list_id, image, user_data:nil, target_face:nil, custom_headers:nil)
788
+ fail ArgumentError, '@client.azure_region is nil' if @client.azure_region.nil?
789
+ fail ArgumentError, 'face_list_id is nil' if face_list_id.nil?
790
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'MaxLength': '64'" if !face_list_id.nil? && face_list_id.length > 64
791
+ fail ArgumentError, "'face_list_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !face_list_id.nil? && face_list_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
792
+ fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '1024'" if !user_data.nil? && user_data.length > 1024
793
+ fail ArgumentError, 'image is nil' if image.nil?
794
+
795
+
796
+ request_headers = {}
797
+ request_headers['Content-Type'] = 'application/octet-stream'
798
+
799
+ # Set Headers
800
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
801
+ request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
802
+
803
+ # Serialize Request
804
+ request_mapper = {
805
+ client_side_validation: true,
806
+ required: true,
807
+ serialized_name: 'Image',
808
+ type: {
809
+ name: 'Stream'
810
+ }
811
+ }
812
+ request_content = @client.serialize(request_mapper, image)
813
+
814
+ path_template = 'facelists/{faceListId}/persistedFaces'
815
+
816
+ request_url = @base_url || @client.base_url
817
+ request_url = request_url.gsub('{AzureRegion}', @client.azure_region)
818
+
819
+ options = {
820
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
821
+ path_params: {'faceListId' => face_list_id},
822
+ query_params: {'userData' => user_data,'targetFace' => target_face.nil? ? nil : target_face.join(',')},
823
+ body: request_content,
824
+ headers: request_headers.merge(custom_headers || {}),
825
+ base_url: request_url
826
+ }
827
+ promise = @client.make_request_async(:post, path_template, options)
828
+
829
+ promise = promise.then do |result|
830
+ http_response = result.response
831
+ status_code = http_response.status
832
+ response_content = http_response.body
833
+ unless status_code == 200
834
+ error_model = JSON.load(response_content)
835
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
836
+ end
837
+
838
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
839
+ # Deserialize Response
840
+ if status_code == 200
841
+ begin
842
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
843
+ result_mapper = Azure::CognitiveServices::Face::V1_0::Models::PersistedFace.mapper()
844
+ result.body = @client.deserialize(result_mapper, parsed_response)
845
+ rescue Exception => e
846
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
847
+ end
848
+ end
849
+
850
+ result
851
+ end
852
+
853
+ promise.execute
854
+ end
855
+
856
+ end
857
+ end