class SwaggerPetstore(object): """This is a sample server Petstore server. You can find out more about Swagger at <a href="http://swagger.io">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key "special-key" to test the authorization filters :ivar config: Configuration for client. :vartype config: SwaggerPetstoreConfiguration :param str base_url: Service URL :param str filepath: Existing config """ def __init__( self, base_url=None, filepath=None): self.config = SwaggerPetstoreConfiguration(base_url, filepath) self._client = ServiceClient(None, self.config) client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) def add_pet_using_byte_array( self, body=None, custom_headers=None, raw=False, **operation_config): """Fake endpoint to test byte array in body parameter for adding a new pet to the store. :param body: Pet object in the form of byte array :type body: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/pet' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'str') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, **operation_config) if response.status_code not in [405]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def add_pet( self, body=None, custom_headers=None, raw=False, **operation_config): """Add a new pet to the store. Adds a new pet to the store. You may receive an HTTP invalid input if your pet is invalid. :param body: Pet object that needs to be added to the store :type body: :class:`Pet <Petstore.models.Pet>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/pet' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'Pet') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, **operation_config) if response.status_code not in [405]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def update_pet( self, body=None, custom_headers=None, raw=False, **operation_config): """Update an existing pet. :param body: Pet object that needs to be added to the store :type body: :class:`Pet <Petstore.models.Pet>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/pet' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'Pet') else: body_content = None # Construct and send request request = self._client.put(url, query_parameters) response = self._client.send( request, header_parameters, body_content, **operation_config) if response.status_code not in [405, 404, 400]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def find_pets_by_status( self, status=None, custom_headers=None, raw=False, **operation_config): """Finds Pets by status. Multiple status values can be provided with comma seperated strings. :param status: Status values that need to be considered for filter :type status: list of str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: list of :class:`Pet <Petstore.models.Pet>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/pet/findByStatus' # Construct parameters query_parameters = {} if status is not None: query_parameters['status'] = self._serialize.query("status", status, '[str]', div=',') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('[Pet]', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def find_pets_by_tags( self, tags=None, custom_headers=None, raw=False, **operation_config): """Finds Pets by tags. Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. :param tags: Tags to filter by :type tags: list of str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: list of :class:`Pet <Petstore.models.Pet>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/pet/findByTags' # Construct parameters query_parameters = {} if tags is not None: query_parameters['tags'] = self._serialize.query("tags", tags, '[str]', div=',') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('[Pet]', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def find_pets_with_byte_array( self, pet_id, custom_headers=None, raw=False, **operation_config): """Fake endpoint to test byte array return by 'Find pet by ID'. Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions. :param pet_id: ID of pet that needs to be fetched :type pet_id: long :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: str :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/pet/{petId}' path_format_arguments = { 'petId': self._serialize.url("pet_id", pet_id, 'long') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('str', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def get_pet_by_id( self, pet_id, custom_headers=None, raw=False, **operation_config): """Find pet by ID. Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions. :param pet_id: ID of pet that needs to be fetched :type pet_id: long :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: :class:`Pet <Petstore.models.Pet>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/pet/{petId}' path_format_arguments = { 'petId': self._serialize.url("pet_id", pet_id, 'long') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('Pet', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def update_pet_with_form( self, pet_id, name=None, status=None, custom_headers=None, raw=False, **operation_config): """Updates a pet in the store with form data. :param pet_id: ID of pet that needs to be updated :type pet_id: str :param name: Updated name of the pet :type name: str :param status: Updated status of the pet :type status: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/pet/{petId}' path_format_arguments = { 'petId': self._serialize.url("pet_id", pet_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/x-www-form-urlencoded' if custom_headers: header_parameters.update(custom_headers) # Construct form data form_data_content = { 'name': name, 'status': status, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata( request, header_parameters, form_data_content, **operation_config) if response.status_code not in [405]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def delete_pet( self, pet_id, api_key=None, custom_headers=None, raw=False, **operation_config): """Deletes a pet. :param pet_id: Pet id to delete :type pet_id: long :param api_key: :type api_key: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/pet/{petId}' path_format_arguments = { 'petId': self._serialize.url("pet_id", pet_id, 'long') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) if api_key is not None: header_parameters['api_key'] = self._serialize.header("api_key", api_key, 'str') # Construct and send request request = self._client.delete(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [400]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def upload_file( self, pet_id, additional_metadata=None, file=None, custom_headers=None, raw=False, **operation_config): """uploads an image. :param pet_id: ID of pet to update :type pet_id: long :param additional_metadata: Additional data to pass to server :type additional_metadata: str :param file: file to upload :type file: Generator :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/pet/{petId}/uploadImage' path_format_arguments = { 'petId': self._serialize.url("pet_id", pet_id, 'long') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'multipart/form-data' if custom_headers: header_parameters.update(custom_headers) # Construct form data form_data_content = { 'additionalMetadata': additional_metadata, 'file': file, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata( request, header_parameters, form_data_content, **operation_config) if response.status_code < 200 or response.status_code >= 300: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def get_inventory( self, custom_headers=None, raw=False, **operation_config): """Returns pet inventories by status. Returns a map of status codes to quantities. :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: dict :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/store/inventory' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('{int}', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def place_order( self, body=None, custom_headers=None, raw=False, **operation_config): """Place an order for a pet. :param body: order placed for purchasing the pet :type body: :class:`Order <Petstore.models.Order>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: :class:`Order <Petstore.models.Order>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/store/order' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'Order') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, **operation_config) if response.status_code not in [200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('Order', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def get_order_by_id( self, order_id, custom_headers=None, raw=False, **operation_config): """Find purchase order by ID. For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions. :param order_id: ID of pet that needs to be fetched :type order_id: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: :class:`Order <Petstore.models.Order>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/store/order/{orderId}' path_format_arguments = { 'orderId': self._serialize.url("order_id", order_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('Order', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def delete_order( self, order_id, custom_headers=None, raw=False, **operation_config): """Delete purchase order by ID. For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors. :param order_id: ID of the order that needs to be deleted :type order_id: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/store/order/{orderId}' path_format_arguments = { 'orderId': self._serialize.url("order_id", order_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.delete(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 400]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def create_user( self, body=None, custom_headers=None, raw=False, **operation_config): """Create user. This can only be done by the logged in user. :param body: Created user object :type body: :class:`User <Petstore.models.User>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/user' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'User') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, **operation_config) if response.status_code < 200 or response.status_code >= 300: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def create_users_with_array_input( self, body=None, custom_headers=None, raw=False, **operation_config): """Creates list of users with given input array. :param body: List of user object :type body: list of :class:`User <Petstore.models.User>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/user/createWithArray' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, '[User]') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, **operation_config) if response.status_code < 200 or response.status_code >= 300: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def create_users_with_list_input( self, body=None, custom_headers=None, raw=False, **operation_config): """Creates list of users with given input array. :param body: List of user object :type body: list of :class:`User <Petstore.models.User>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/user/createWithList' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, '[User]') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, **operation_config) if response.status_code < 200 or response.status_code >= 300: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def login_user( self, username=None, password=None, custom_headers=None, raw=False, **operation_config): """Logs user into the system. :param username: The user name for login :type username: str :param password: The password for login in clear text :type password: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: str :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/user/login' # Construct parameters query_parameters = {} if username is not None: query_parameters['username'] = self._serialize.query("username", username, 'str') if password is not None: query_parameters['password'] = self._serialize.query("password", password, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('str', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def logout_user( self, custom_headers=None, raw=False, **operation_config): """Logs out current logged in user session. :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/user/logout' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code < 200 or response.status_code >= 300: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def get_user_by_name( self, username, custom_headers=None, raw=False, **operation_config): """Get user by user name. :param username: The name that needs to be fetched. Use user1 for testing. :type username: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: :class:`User <Petstore.models.User>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/user/{username}' path_format_arguments = { 'username': self._serialize.url("username", username, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('User', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def update_user( self, username, body=None, custom_headers=None, raw=False, **operation_config): """Updated user. This can only be done by the logged in user. :param username: name that need to be deleted :type username: str :param body: Updated user object :type body: :class:`User <Petstore.models.User>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/user/{username}' path_format_arguments = { 'username': self._serialize.url("username", username, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'User') else: body_content = None # Construct and send request request = self._client.put(url, query_parameters) response = self._client.send( request, header_parameters, body_content, **operation_config) if response.status_code not in [404, 400]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def delete_user( self, username, custom_headers=None, raw=False, **operation_config): """Delete user. This can only be done by the logged in user. :param username: The name that needs to be deleted :type username: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true """ # Construct URL url = '/user/{username}' path_format_arguments = { 'username': self._serialize.url("username", username, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.delete(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 400]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response
class SpellCheckAPI(object): """The Spell Check API - V7 lets you check a text string for spelling and grammar errors. :ivar config: Configuration for client. :vartype config: SpellCheckAPIConfiguration :param credentials: Subscription credentials which uniquely identify client subscription. :type credentials: None :param str base_url: Service URL """ def __init__( self, credentials, base_url=None): self.config = SpellCheckAPIConfiguration(credentials, base_url) self._client = ServiceClient(self.config.credentials, self.config) client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} self.api_version = '1.0' self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) def spell_checker( self, text, accept_language=None, pragma=None, user_agent=None, client_id=None, client_ip=None, location=None, action_type=None, app_name=None, country_code=None, client_machine_name=None, doc_id=None, market=None, session_id=None, set_lang=None, user_id=None, mode=None, pre_context_text=None, post_context_text=None, custom_headers=None, raw=False, **operation_config): """The Bing Spell Check API lets you perform contextual grammar and spell checking. Bing has developed a web-based spell-checker that leverages machine learning and statistical machine translation to dynamically train a constantly evolving and highly contextual algorithm. The spell-checker is based on a massive corpus of web searches and documents. :param text: The text string to check for spelling and grammar errors. The combined length of the text string, preContextText string, and postContextText string may not exceed 10,000 characters. You may specify this parameter in the query string of a GET request or in the body of a POST request. Because of the query string length limit, you'll typically use a POST request unless you're checking only short strings. :type text: str :param accept_language: A comma-delimited list of one or more languages to use for user interface strings. The list is in decreasing order of preference. For additional information, including expected format, see [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the setLang query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify the cc query parameter. Bing will use the first supported language it finds from the list, and combine that language with the cc parameter value to determine the market to return results for. If the list does not include a supported language, Bing will find the closest language and market that supports the request, and may use an aggregated or default market for the results instead of a specified one. You should use this header and the cc query parameter only if you specify multiple languages; otherwise, you should use the mkt and setLang query parameters. A user interface string is a string that's used as a label in a user interface. There are very few user interface strings in the JSON response objects. Any links in the response objects to Bing.com properties will apply the specified language. :type accept_language: str :param pragma: By default, Bing returns cached content, if available. To prevent Bing from returning cached content, set the Pragma header to no-cache (for example, Pragma: no-cache). :type pragma: str :param user_agent: The user agent originating the request. Bing uses the user agent to provide mobile users with an optimized experience. Although optional, you are strongly encouraged to always specify this header. The user-agent should be the same string that any commonly used browser would send. For information about user agents, see [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). :type user_agent: str :param client_id: Bing uses this header to provide users with consistent behavior across Bing API calls. Bing often flights new features and improvements, and it uses the client ID as a key for assigning traffic on different flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an inconsistent user experience. For example, if the second request has a different flight assignment than the first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that client ID’s search history, providing a richer experience for the user. Bing also uses this header to help improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client ID across multiple requests for the same end user and device combination enables 1) the API consumer to receive a consistent user experience, and 2) higher click-through rates via better quality of results from the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client ID. If you do not include this header in the request, Bing generates an ID and returns it in the X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the first time the user uses your app on that device. Use the client ID for each Bing API request that your app makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses your app on that device, get the client ID that you persisted. Bing responses may or may not include this header. If the response includes this header, capture the client ID and use it for all subsequent Bing requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in the request. :type client_id: str :param client_ip: The IPv4 or IPv6 address of the client device. The IP address is used to discover the user's location. Bing uses the location information to determine safe search behavior. Although optional, you are encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for example, by changing the last octet to 0). Obfuscating the address results in the location not being anywhere near the device's actual location, which may result in Bing serving erroneous results. :type client_ip: str :param location: A semicolon-delimited list of key/value pairs that describe the client's geographical location. Bing uses the location information to determine safe search behavior and to return relevant local content. Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and positive values indicate northern latitudes. long (required): The longitude of the client's location, in degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative values indicate western longitudes and positive values indicate eastern longitudes. re (required): The radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation, and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360, counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional): The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional): The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the keys are optional, the more information that you provide, the more accurate the location results are. Although optional, you are encouraged to always specify the user's geographical location. Providing the location is especially important if the client's IP address does not accurately reflect the user's physical location (for example, if the client uses VPN). For optimal results, you should include this header and the X-Search-ClientIP header, but at a minimum, you should include this header. :type location: str :param action_type: A string that's used by logging to determine whether the request is coming from an interactive session or a page load. The following are the possible values. 1) Edit—The request is from an interactive session 2) Load—The request is from a page load. Possible values include: 'Edit', 'Load' :type action_type: str or ~azure.cognitiveservices.language.spellcheck.models.ActionType :param app_name: The unique name of your app. The name must be known by Bing. Do not include this parameter unless you have previously contacted Bing to get a unique app name. To get a unique name, contact your Bing Business Development manager. :type app_name: str :param country_code: A 2-character country code of the country where the results come from. This API supports only the United States market. If you specify this query parameter, it must be set to us. If you set this parameter, you must also specify the Accept-Language header. Bing uses the first supported language it finds from the languages list, and combine that language with the country code that you specify to determine the market to return results for. If the languages list does not include a supported language, Bing finds the closest language and market that supports the request, or it may use an aggregated or default market for the results instead of a specified one. You should use this query parameter and the Accept-Language query parameter only if you specify multiple languages; otherwise, you should use the mkt and setLang query parameters. This parameter and the mkt query parameter are mutually exclusive—do not specify both. :type country_code: str :param client_machine_name: A unique name of the device that the request is being made from. Generate a unique value for each device (the value is unimportant). The service uses the ID to help debug issues and improve the quality of corrections. :type client_machine_name: str :param doc_id: A unique ID that identifies the document that the text belongs to. Generate a unique value for each document (the value is unimportant). The service uses the ID to help debug issues and improve the quality of corrections. :type doc_id: str :param market: The market where the results come from. You are strongly encouraged to always specify the market, if known. Specifying the market helps Bing route the request and return an appropriate and optimal response. This parameter and the cc query parameter are mutually exclusive—do not specify both. :type market: str :param session_id: A unique ID that identifies this user session. Generate a unique value for each user session (the value is unimportant). The service uses the ID to help debug issues and improve the quality of corrections :type session_id: str :param set_lang: The language to use for user interface strings. Specify the language using the ISO 639-1 2-letter language code. For example, the language code for English is EN. The default is EN (English). Although optional, you should always specify the language. Typically, you set setLang to the same language specified by mkt unless the user wants the user interface strings displayed in a different language. This parameter and the Accept-Language header are mutually exclusive—do not specify both. A user interface string is a string that's used as a label in a user interface. There are few user interface strings in the JSON response objects. Also, any links to Bing.com properties in the response objects apply the specified language. :type set_lang: str :param user_id: A unique ID that identifies the user. Generate a unique value for each user (the value is unimportant). The service uses the ID to help debug issues and improve the quality of corrections. :type user_id: str :param mode: The type of spelling and grammar checks to perform. The following are the possible values (the values are case insensitive). The default is Proof. 1) Proof—Finds most spelling and grammar mistakes. 2) Spell—Finds most spelling mistakes but does not find some of the grammar errors that Proof catches (for example, capitalization and repeated words). Possible values include: 'Proof', 'Spell' :type mode: str :param pre_context_text: A string that gives context to the text string. For example, the text string petal is valid. However, if you set preContextText to bike, the context changes and the text string becomes not valid. In this case, the API suggests that you change petal to pedal (as in bike pedal). This text is not checked for grammar or spelling errors. The combined length of the text string, preContextText string, and postContextText string may not exceed 10,000 characters. You may specify this parameter in the query string of a GET request or in the body of a POST request. :type pre_context_text: str :param post_context_text: A string that gives context to the text string. For example, the text string read is valid. However, if you set postContextText to carpet, the context changes and the text string becomes not valid. In this case, the API suggests that you change read to red (as in red carpet). This text is not checked for grammar or spelling errors. The combined length of the text string, preContextText string, and postContextText string may not exceed 10,000 characters. You may specify this parameter in the query string of a GET request or in the body of a POST request. :type post_context_text: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: SpellCheck or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.language.spellcheck.models.SpellCheck or ~msrest.pipeline.ClientRawResponse :raises: :class:`ErrorResponseException<azure.cognitiveservices.language.spellcheck.models.ErrorResponseException>` """ x_bing_apis_sdk = "true" # Construct URL url = '/spellcheck' # Construct parameters query_parameters = {} if action_type is not None: query_parameters['ActionType'] = self._serialize.query("action_type", action_type, 'str') if app_name is not None: query_parameters['AppName'] = self._serialize.query("app_name", app_name, 'str') if country_code is not None: query_parameters['cc'] = self._serialize.query("country_code", country_code, 'str') if client_machine_name is not None: query_parameters['ClientMachineName'] = self._serialize.query("client_machine_name", client_machine_name, 'str') if doc_id is not None: query_parameters['DocId'] = self._serialize.query("doc_id", doc_id, 'str') if market is not None: query_parameters['mkt'] = self._serialize.query("market", market, 'str') if session_id is not None: query_parameters['SessionId'] = self._serialize.query("session_id", session_id, 'str') if set_lang is not None: query_parameters['SetLang'] = self._serialize.query("set_lang", set_lang, 'str') if user_id is not None: query_parameters['UserId'] = self._serialize.query("user_id", user_id, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/x-www-form-urlencoded' if custom_headers: header_parameters.update(custom_headers) header_parameters['X-BingApis-SDK'] = self._serialize.header("x_bing_apis_sdk", x_bing_apis_sdk, 'str') if accept_language is not None: header_parameters['Accept-Language'] = self._serialize.header("accept_language", accept_language, 'str') if pragma is not None: header_parameters['Pragma'] = self._serialize.header("pragma", pragma, 'str') if user_agent is not None: header_parameters['User-Agent'] = self._serialize.header("user_agent", user_agent, 'str') if client_id is not None: header_parameters['X-MSEdge-ClientID'] = self._serialize.header("client_id", client_id, 'str') if client_ip is not None: header_parameters['X-MSEdge-ClientIP'] = self._serialize.header("client_ip", client_ip, 'str') if location is not None: header_parameters['X-Search-Location'] = self._serialize.header("location", location, 'str') # Construct form data form_data_content = { 'Text': text, 'Mode': mode, 'PreContextText': pre_context_text, 'PostContextText': post_context_text, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata( request, header_parameters, form_data_content, stream=False, **operation_config) if response.status_code not in [200]: raise models.ErrorResponseException(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('SpellCheck', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
class SwaggerPetstore(object): """This is a sample server Petstore server. You can find out more about Swagger at <a href="http://swagger.io">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key "special-key" to test the authorization filters :ivar config: Configuration for client. :vartype config: SwaggerPetstoreConfiguration :param str base_url: Service URL """ def __init__(self, base_url=None): self.config = SwaggerPetstoreConfiguration(base_url) self._client = ServiceClient(None, self.config) client_models = { k: v for k, v in models.__dict__.items() if isinstance(v, type) } self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) def add_pet_using_byte_array(self, body=None, custom_headers=None, raw=False, **operation_config): """Fake endpoint to test byte array in body parameter for adding a new pet to the store. :param body: Pet object in the form of byte array :type body: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/pet' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'str') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send(request, header_parameters, body_content, **operation_config) if response.status_code not in [405]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def add_pet(self, body=None, custom_headers=None, raw=False, **operation_config): """Add a new pet to the store. Adds a new pet to the store. You may receive an HTTP invalid input if your pet is invalid. :param body: Pet object that needs to be added to the store :type body: :class:`Pet <petstore.models.Pet>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/pet' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'Pet') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send(request, header_parameters, body_content, **operation_config) if response.status_code not in [405]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def update_pet(self, body=None, custom_headers=None, raw=False, **operation_config): """Update an existing pet. :param body: Pet object that needs to be added to the store :type body: :class:`Pet <petstore.models.Pet>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/pet' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'Pet') else: body_content = None # Construct and send request request = self._client.put(url, query_parameters) response = self._client.send(request, header_parameters, body_content, **operation_config) if response.status_code not in [405, 404, 400]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def find_pets_by_status(self, status=None, custom_headers=None, raw=False, **operation_config): """Finds Pets by status. Multiple status values can be provided with comma seperated strings. :param status: Status values that need to be considered for filter :type status: list of str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: list of :class:`Pet <petstore.models.Pet>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/pet/findByStatus' # Construct parameters query_parameters = {} if status is not None: query_parameters['status'] = self._serialize.query("status", status, '[str]', div=',') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('[Pet]', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def find_pets_by_tags(self, tags=None, custom_headers=None, raw=False, **operation_config): """Finds Pets by tags. Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. :param tags: Tags to filter by :type tags: list of str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: list of :class:`Pet <petstore.models.Pet>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/pet/findByTags' # Construct parameters query_parameters = {} if tags is not None: query_parameters['tags'] = self._serialize.query("tags", tags, '[str]', div=',') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('[Pet]', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def find_pets_with_byte_array(self, pet_id, custom_headers=None, raw=False, **operation_config): """Fake endpoint to test byte array return by 'Find pet by ID'. Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions. :param pet_id: ID of pet that needs to be fetched :type pet_id: long :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: str :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/pet/{petId}' path_format_arguments = { 'petId': self._serialize.url("pet_id", pet_id, 'long') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('str', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def get_pet_by_id(self, pet_id, custom_headers=None, raw=False, **operation_config): """Find pet by ID. Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions. :param pet_id: ID of pet that needs to be fetched :type pet_id: long :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: :class:`Pet <petstore.models.Pet>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/pet/{petId}' path_format_arguments = { 'petId': self._serialize.url("pet_id", pet_id, 'long') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('Pet', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def update_pet_with_form(self, pet_id, name=None, status=None, custom_headers=None, raw=False, **operation_config): """Updates a pet in the store with form data. :param pet_id: ID of pet that needs to be updated :type pet_id: str :param name: Updated name of the pet :type name: str :param status: Updated status of the pet :type status: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/pet/{petId}' path_format_arguments = { 'petId': self._serialize.url("pet_id", pet_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/x-www-form-urlencoded' if custom_headers: header_parameters.update(custom_headers) # Construct form data form_data_content = { 'name': name, 'status': status, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata(request, header_parameters, form_data_content, **operation_config) if response.status_code not in [405]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def delete_pet(self, pet_id, api_key=None, custom_headers=None, raw=False, **operation_config): """Deletes a pet. :param pet_id: Pet id to delete :type pet_id: long :param api_key: :type api_key: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/pet/{petId}' path_format_arguments = { 'petId': self._serialize.url("pet_id", pet_id, 'long') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) if api_key is not None: header_parameters['api_key'] = self._serialize.header( "api_key", api_key, 'str') # Construct and send request request = self._client.delete(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [400]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def upload_file(self, pet_id, additional_metadata=None, file=None, custom_headers=None, raw=False, **operation_config): """uploads an image. :param pet_id: ID of pet to update :type pet_id: long :param additional_metadata: Additional data to pass to server :type additional_metadata: str :param file: file to upload :type file: Generator :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/pet/{petId}/uploadImage' path_format_arguments = { 'petId': self._serialize.url("pet_id", pet_id, 'long') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'multipart/form-data' if custom_headers: header_parameters.update(custom_headers) # Construct form data form_data_content = { 'additionalMetadata': additional_metadata, 'file': file, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata(request, header_parameters, form_data_content, **operation_config) if response.status_code < 200 or response.status_code >= 300: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def get_inventory(self, custom_headers=None, raw=False, **operation_config): """Returns pet inventories by status. Returns a map of status codes to quantities. :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: dict :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/store/inventory' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('{int}', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def place_order(self, body=None, custom_headers=None, raw=False, **operation_config): """Place an order for a pet. :param body: order placed for purchasing the pet :type body: :class:`Order <petstore.models.Order>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: :class:`Order <petstore.models.Order>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/store/order' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'Order') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send(request, header_parameters, body_content, **operation_config) if response.status_code not in [200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('Order', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def get_order_by_id(self, order_id, custom_headers=None, raw=False, **operation_config): """Find purchase order by ID. For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions. :param order_id: ID of pet that needs to be fetched :type order_id: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: :class:`Order <petstore.models.Order>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/store/order/{orderId}' path_format_arguments = { 'orderId': self._serialize.url("order_id", order_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('Order', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def delete_order(self, order_id, custom_headers=None, raw=False, **operation_config): """Delete purchase order by ID. For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors. :param order_id: ID of the order that needs to be deleted :type order_id: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/store/order/{orderId}' path_format_arguments = { 'orderId': self._serialize.url("order_id", order_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.delete(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 400]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def create_user(self, body=None, custom_headers=None, raw=False, **operation_config): """Create user. This can only be done by the logged in user. :param body: Created user object :type body: :class:`User <petstore.models.User>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/user' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'User') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send(request, header_parameters, body_content, **operation_config) if response.status_code < 200 or response.status_code >= 300: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def create_users_with_array_input(self, body=None, custom_headers=None, raw=False, **operation_config): """Creates list of users with given input array. :param body: List of user object :type body: list of :class:`User <petstore.models.User>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/user/createWithArray' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, '[User]') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send(request, header_parameters, body_content, **operation_config) if response.status_code < 200 or response.status_code >= 300: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def create_users_with_list_input(self, body=None, custom_headers=None, raw=False, **operation_config): """Creates list of users with given input array. :param body: List of user object :type body: list of :class:`User <petstore.models.User>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/user/createWithList' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, '[User]') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send(request, header_parameters, body_content, **operation_config) if response.status_code < 200 or response.status_code >= 300: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def login_user(self, username=None, password=None, custom_headers=None, raw=False, **operation_config): """Logs user into the system. :param username: The user name for login :type username: str :param password: The password for login in clear text :type password: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: str :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/user/login' # Construct parameters query_parameters = {} if username is not None: query_parameters['username'] = self._serialize.query( "username", username, 'str') if password is not None: query_parameters['password'] = self._serialize.query( "password", password, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('str', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def logout_user(self, custom_headers=None, raw=False, **operation_config): """Logs out current logged in user session. :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/user/logout' # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code < 200 or response.status_code >= 300: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def get_user_by_name(self, username, custom_headers=None, raw=False, **operation_config): """Get user by user name. :param username: The name that needs to be fetched. Use user1 for testing. :type username: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: :class:`User <petstore.models.User>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/user/{username}' path_format_arguments = { 'username': self._serialize.url("username", username, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 200, 400]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('User', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def update_user(self, username, body=None, custom_headers=None, raw=False, **operation_config): """Updated user. This can only be done by the logged in user. :param username: name that need to be deleted :type username: str :param body: Updated user object :type body: :class:`User <petstore.models.User>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/user/{username}' path_format_arguments = { 'username': self._serialize.url("username", username, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct body if body is not None: body_content = self._serialize.body(body, 'User') else: body_content = None # Construct and send request request = self._client.put(url, query_parameters) response = self._client.send(request, header_parameters, body_content, **operation_config) if response.status_code not in [404, 400]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response def delete_user(self, username, custom_headers=None, raw=False, **operation_config): """Delete user. This can only be done by the logged in user. :param username: The name that needs to be deleted :type username: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: None :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/user/{username}' path_format_arguments = { 'username': self._serialize.url("username", username, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) # Construct and send request request = self._client.delete(url, query_parameters) response = self._client.send(request, header_parameters, **operation_config) if response.status_code not in [404, 400]: raise HttpOperationError(self._deserialize, response) if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response
class Prediction(object): """Prediction :ivar config: Configuration for client. :vartype config: PredictionConfiguration :param str base_url: Service URL """ def __init__(self, base_url=None): self.config = PredictionConfiguration(base_url) self._client = ServiceClient(None, self.config) client_models = { k: v for k, v in models.__dict__.items() if isinstance(v, type) } self.api_version = '1.0' self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) def evaluate_url(self, project_id, iteration_id=None, prediction_key=None, prediction_key1=None, image_url=None, custom_headers=None, raw=False, **operation_config): """Evaluate an image url. :param project_id: Format - uuid. The project to evaluate against :type project_id: str :param iteration_id: Format - uuid. Optional. Specifies the id of a particular project iteration to evaluate against. The default iteration will be used when not provided :type iteration_id: str :param prediction_key: subscription key in url :type prediction_key: str :param prediction_key1: subscription key in header :type prediction_key1: str :param image_url: An {Iris.Web.Api.Models.ImageUrl} that contains the url of the image to be evaluated :type image_url: :class:`ImageUrl <prediction.models.ImageUrl>` :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: :class:`ImageEvaluation <prediction.models.ImageEvaluation>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/{projectId}/url' path_format_arguments = { 'projectId': self._serialize.url("project_id", project_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if iteration_id is not None: query_parameters['iterationId'] = self._serialize.query( "iteration_id", iteration_id, 'str') if prediction_key is not None: query_parameters['Prediction-key'] = self._serialize.query( "prediction_key", prediction_key, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) if prediction_key1 is not None: header_parameters['Prediction-key'] = self._serialize.header( "prediction_key1", prediction_key1, 'str') # Construct body if image_url is not None: body_content = self._serialize.body(image_url, 'ImageUrl') else: body_content = None # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send(request, header_parameters, body_content, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('ImageEvaluation', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def evaluate_image(self, project_id, image_data, iteration_id=None, prediction_key=None, prediction_key1=None, custom_headers=None, raw=False, **operation_config): """Evaluate an image. :param project_id: Format - uuid. The project to evaluate against :type project_id: str :param image_data: :type image_data: str :param iteration_id: Format - uuid. Optional. Specifies the id of a particular project iteration to evaluate against. The default iteration will be used when not provided :type iteration_id: str :param prediction_key: subscription key in url :type prediction_key: str :param prediction_key1: subscription key in header :type prediction_key1: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :rtype: :class:`ImageEvaluation <prediction.models.ImageEvaluation>` :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if raw=true :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/{projectId}/image' path_format_arguments = { 'projectId': self._serialize.url("project_id", project_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if iteration_id is not None: query_parameters['iterationId'] = self._serialize.query( "iteration_id", iteration_id, 'str') if prediction_key is not None: query_parameters['Prediction-key'] = self._serialize.query( "prediction_key", prediction_key, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'multipart/form-data' if custom_headers: header_parameters.update(custom_headers) if prediction_key1 is not None: header_parameters['Prediction-key'] = self._serialize.header( "prediction_key1", prediction_key1, 'str') # Construct form data form_data_content = { 'imageData': image_data, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata(request, header_parameters, form_data_content, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('ImageEvaluation', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
class PredictionEndpoint(object): """PredictionEndpoint :ivar config: Configuration for client. :vartype config: PredictionEndpointConfiguration :param api_key: :type api_key: str :param str base_url: Service URL """ def __init__(self, api_key, base_url=None): self.config = PredictionEndpointConfiguration(api_key, base_url) self._client = ServiceClient(None, self.config) client_models = { k: v for k, v in models.__dict__.items() if isinstance(v, type) } self.api_version = '1.1' self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) def predict_image_url(self, project_id, iteration_id=None, application=None, url=None, custom_headers=None, raw=False, **operation_config): """Predict an image url and saves the result. :param project_id: The project id :type project_id: str :param iteration_id: Optional. Specifies the id of a particular iteration to evaluate against. The default iteration for the project will be used when not specified :type iteration_id: str :param application: Optional. Specifies the name of application using the endpoint :type application: str :param url: :type url: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: ImagePredictionResultModel or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.customvision.prediction.models.ImagePredictionResultModel or ~msrest.pipeline.ClientRawResponse :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ image_url = models.ImageUrl(url=url) # Construct URL url = '/{projectId}/url' path_format_arguments = { 'projectId': self._serialize.url("project_id", project_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if iteration_id is not None: query_parameters['iterationId'] = self._serialize.query( "iteration_id", iteration_id, 'str') if application is not None: query_parameters['application'] = self._serialize.query( "application", application, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) header_parameters['Prediction-Key'] = self._serialize.header( "self.config.api_key", self.config.api_key, 'str') # Construct body body_content = self._serialize.body(image_url, 'ImageUrl') # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send(request, header_parameters, body_content, stream=False, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('ImagePredictionResultModel', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def predict_image(self, project_id, image_data, iteration_id=None, application=None, custom_headers=None, raw=False, **operation_config): """Predict an image and saves the result. :param project_id: The project id :type project_id: str :param image_data: :type image_data: Generator :param iteration_id: Optional. Specifies the id of a particular iteration to evaluate against. The default iteration for the project will be used when not specified :type iteration_id: str :param application: Optional. Specifies the name of application using the endpoint :type application: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: ImagePredictionResultModel or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.customvision.prediction.models.ImagePredictionResultModel or ~msrest.pipeline.ClientRawResponse :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/{projectId}/image' path_format_arguments = { 'projectId': self._serialize.url("project_id", project_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if iteration_id is not None: query_parameters['iterationId'] = self._serialize.query( "iteration_id", iteration_id, 'str') if application is not None: query_parameters['application'] = self._serialize.query( "application", application, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'multipart/form-data' if custom_headers: header_parameters.update(custom_headers) header_parameters['Prediction-Key'] = self._serialize.header( "self.config.api_key", self.config.api_key, 'str') # Construct form data form_data_content = { 'imageData': image_data, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata(request, header_parameters, form_data_content, stream=False, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('ImagePredictionResultModel', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def predict_image_url_with_no_store(self, project_id, iteration_id=None, application=None, url=None, custom_headers=None, raw=False, **operation_config): """Predict an image url without saving the result. :param project_id: The project id :type project_id: str :param iteration_id: Optional. Specifies the id of a particular iteration to evaluate against. The default iteration for the project will be used when not specified :type iteration_id: str :param application: Optional. Specifies the name of application using the endpoint :type application: str :param url: :type url: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: ImagePredictionResultModel or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.customvision.prediction.models.ImagePredictionResultModel or ~msrest.pipeline.ClientRawResponse :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ image_url = models.ImageUrl(url=url) # Construct URL url = '/{projectId}/url/nostore' path_format_arguments = { 'projectId': self._serialize.url("project_id", project_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if iteration_id is not None: query_parameters['iterationId'] = self._serialize.query( "iteration_id", iteration_id, 'str') if application is not None: query_parameters['application'] = self._serialize.query( "application", application, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) header_parameters['Prediction-Key'] = self._serialize.header( "self.config.api_key", self.config.api_key, 'str') # Construct body body_content = self._serialize.body(image_url, 'ImageUrl') # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send(request, header_parameters, body_content, stream=False, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('ImagePredictionResultModel', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def predict_image_with_no_store(self, project_id, image_data, iteration_id=None, application=None, custom_headers=None, raw=False, **operation_config): """Predict an image without saving the result. :param project_id: The project id :type project_id: str :param image_data: :type image_data: Generator :param iteration_id: Optional. Specifies the id of a particular iteration to evaluate against. The default iteration for the project will be used when not specified :type iteration_id: str :param application: Optional. Specifies the name of application using the endpoint :type application: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: ImagePredictionResultModel or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.customvision.prediction.models.ImagePredictionResultModel or ~msrest.pipeline.ClientRawResponse :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/{projectId}/image/nostore' path_format_arguments = { 'projectId': self._serialize.url("project_id", project_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if iteration_id is not None: query_parameters['iterationId'] = self._serialize.query( "iteration_id", iteration_id, 'str') if application is not None: query_parameters['application'] = self._serialize.query( "application", application, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'multipart/form-data' if custom_headers: header_parameters.update(custom_headers) header_parameters['Prediction-Key'] = self._serialize.header( "self.config.api_key", self.config.api_key, 'str') # Construct form data form_data_content = { 'imageData': image_data, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata(request, header_parameters, form_data_content, stream=False, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('ImagePredictionResultModel', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
class SpellCheckAPI(object): """The Spell Check API - V7 lets you check a text string for spelling and grammar errors. :ivar config: Configuration for client. :vartype config: SpellCheckAPIConfiguration :param credentials: Subscription credentials which uniquely identify client subscription. :type credentials: None :param str base_url: Service URL """ def __init__(self, credentials, base_url=None): self.config = SpellCheckAPIConfiguration(credentials, base_url) self._client = ServiceClient(self.config.credentials, self.config) client_models = { k: v for k, v in models.__dict__.items() if isinstance(v, type) } self.api_version = '1.0' self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) def spell_checker(self, text, accept_language=None, pragma=None, user_agent=None, client_id=None, client_ip=None, location=None, action_type=None, app_name=None, country_code=None, client_machine_name=None, doc_id=None, market=None, session_id=None, set_lang=None, user_id=None, mode=None, pre_context_text=None, post_context_text=None, custom_headers=None, raw=False, **operation_config): """The Bing Spell Check API lets you perform contextual grammar and spell checking. Bing has developed a web-based spell-checker that leverages machine learning and statistical machine translation to dynamically train a constantly evolving and highly contextual algorithm. The spell-checker is based on a massive corpus of web searches and documents. :param text: The text string to check for spelling and grammar errors. The combined length of the text string, preContextText string, and postContextText string may not exceed 10,000 characters. You may specify this parameter in the query string of a GET request or in the body of a POST request. Because of the query string length limit, you'll typically use a POST request unless you're checking only short strings. :type text: str :param accept_language: A comma-delimited list of one or more languages to use for user interface strings. The list is in decreasing order of preference. For additional information, including expected format, see [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This header and the setLang query parameter are mutually exclusive; do not specify both. If you set this header, you must also specify the cc query parameter. Bing will use the first supported language it finds from the list, and combine that language with the cc parameter value to determine the market to return results for. If the list does not include a supported language, Bing will find the closest language and market that supports the request, and may use an aggregated or default market for the results instead of a specified one. You should use this header and the cc query parameter only if you specify multiple languages; otherwise, you should use the mkt and setLang query parameters. A user interface string is a string that's used as a label in a user interface. There are very few user interface strings in the JSON response objects. Any links in the response objects to Bing.com properties will apply the specified language. :type accept_language: str :param pragma: By default, Bing returns cached content, if available. To prevent Bing from returning cached content, set the Pragma header to no-cache (for example, Pragma: no-cache). :type pragma: str :param user_agent: The user agent originating the request. Bing uses the user agent to provide mobile users with an optimized experience. Although optional, you are strongly encouraged to always specify this header. The user-agent should be the same string that any commonly used browser would send. For information about user agents, see [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). :type user_agent: str :param client_id: Bing uses this header to provide users with consistent behavior across Bing API calls. Bing often flights new features and improvements, and it uses the client ID as a key for assigning traffic on different flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an inconsistent user experience. For example, if the second request has a different flight assignment than the first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that client ID’s search history, providing a richer experience for the user. Bing also uses this header to help improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client ID across multiple requests for the same end user and device combination enables 1) the API consumer to receive a consistent user experience, and 2) higher click-through rates via better quality of results from the Bing APIs. Each user that uses your application on the device must have a unique, Bing generated client ID. If you do not include this header in the request, Bing generates an ID and returns it in the X-MSEdge-ClientID response header. The only time that you should NOT include this header in a request is the first time the user uses your app on that device. Use the client ID for each Bing API request that your app makes for this user on the device. Persist the client ID. To persist the ID in a browser app, use a persistent HTTP cookie to ensure the ID is used across all sessions. Do not use a session cookie. For other apps such as mobile apps, use the device's persistent storage to persist the ID. The next time the user uses your app on that device, get the client ID that you persisted. Bing responses may or may not include this header. If the response includes this header, capture the client ID and use it for all subsequent Bing requests for the user on that device. If you include the X-MSEdge-ClientID, you must not include cookies in the request. :type client_id: str :param client_ip: The IPv4 or IPv6 address of the client device. The IP address is used to discover the user's location. Bing uses the location information to determine safe search behavior. Although optional, you are encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for example, by changing the last octet to 0). Obfuscating the address results in the location not being anywhere near the device's actual location, which may result in Bing serving erroneous results. :type client_ip: str :param location: A semicolon-delimited list of key/value pairs that describe the client's geographical location. Bing uses the location information to determine safe search behavior and to return relevant local content. Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's location. lat (required): The latitude of the client's location, in degrees. The latitude must be greater than or equal to -90.0 and less than or equal to +90.0. Negative values indicate southern latitudes and positive values indicate northern latitudes. long (required): The longitude of the client's location, in degrees. The longitude must be greater than or equal to -180.0 and less than or equal to +180.0. Negative values indicate western longitudes and positive values indicate eastern longitudes. re (required): The radius, in meters, which specifies the horizontal accuracy of the coordinates. Pass the value returned by the device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m for cell tower triangulation, and 18,000m for reverse IP lookup. ts (optional): The UTC UNIX timestamp of when the client was at the location. (The UNIX timestamp is the number of seconds since January 1, 1970.) head (optional): The client's relative heading or direction of travel. Specify the direction of travel as degrees from 0 through 360, counting clockwise relative to true north. Specify this key only if the sp key is nonzero. sp (optional): The horizontal velocity (speed), in meters per second, that the client device is traveling. alt (optional): The altitude of the client device, in meters. are (optional): The radius, in meters, that specifies the vertical accuracy of the coordinates. Specify this key only if you specify the alt key. Although many of the keys are optional, the more information that you provide, the more accurate the location results are. Although optional, you are encouraged to always specify the user's geographical location. Providing the location is especially important if the client's IP address does not accurately reflect the user's physical location (for example, if the client uses VPN). For optimal results, you should include this header and the X-Search-ClientIP header, but at a minimum, you should include this header. :type location: str :param action_type: A string that's used by logging to determine whether the request is coming from an interactive session or a page load. The following are the possible values. 1) Edit—The request is from an interactive session 2) Load—The request is from a page load. Possible values include: 'Edit', 'Load' :type action_type: str or ~azure.cognitiveservices.language.spellcheck.models.ActionType :param app_name: The unique name of your app. The name must be known by Bing. Do not include this parameter unless you have previously contacted Bing to get a unique app name. To get a unique name, contact your Bing Business Development manager. :type app_name: str :param country_code: A 2-character country code of the country where the results come from. This API supports only the United States market. If you specify this query parameter, it must be set to us. If you set this parameter, you must also specify the Accept-Language header. Bing uses the first supported language it finds from the languages list, and combine that language with the country code that you specify to determine the market to return results for. If the languages list does not include a supported language, Bing finds the closest language and market that supports the request, or it may use an aggregated or default market for the results instead of a specified one. You should use this query parameter and the Accept-Language query parameter only if you specify multiple languages; otherwise, you should use the mkt and setLang query parameters. This parameter and the mkt query parameter are mutually exclusive—do not specify both. :type country_code: str :param client_machine_name: A unique name of the device that the request is being made from. Generate a unique value for each device (the value is unimportant). The service uses the ID to help debug issues and improve the quality of corrections. :type client_machine_name: str :param doc_id: A unique ID that identifies the document that the text belongs to. Generate a unique value for each document (the value is unimportant). The service uses the ID to help debug issues and improve the quality of corrections. :type doc_id: str :param market: The market where the results come from. You are strongly encouraged to always specify the market, if known. Specifying the market helps Bing route the request and return an appropriate and optimal response. This parameter and the cc query parameter are mutually exclusive—do not specify both. :type market: str :param session_id: A unique ID that identifies this user session. Generate a unique value for each user session (the value is unimportant). The service uses the ID to help debug issues and improve the quality of corrections :type session_id: str :param set_lang: The language to use for user interface strings. Specify the language using the ISO 639-1 2-letter language code. For example, the language code for English is EN. The default is EN (English). Although optional, you should always specify the language. Typically, you set setLang to the same language specified by mkt unless the user wants the user interface strings displayed in a different language. This parameter and the Accept-Language header are mutually exclusive—do not specify both. A user interface string is a string that's used as a label in a user interface. There are few user interface strings in the JSON response objects. Also, any links to Bing.com properties in the response objects apply the specified language. :type set_lang: str :param user_id: A unique ID that identifies the user. Generate a unique value for each user (the value is unimportant). The service uses the ID to help debug issues and improve the quality of corrections. :type user_id: str :param mode: The type of spelling and grammar checks to perform. The following are the possible values (the values are case insensitive). The default is Proof. 1) Proof—Finds most spelling and grammar mistakes. 2) Spell—Finds most spelling mistakes but does not find some of the grammar errors that Proof catches (for example, capitalization and repeated words). Possible values include: 'Proof', 'Spell' :type mode: str :param pre_context_text: A string that gives context to the text string. For example, the text string petal is valid. However, if you set preContextText to bike, the context changes and the text string becomes not valid. In this case, the API suggests that you change petal to pedal (as in bike pedal). This text is not checked for grammar or spelling errors. The combined length of the text string, preContextText string, and postContextText string may not exceed 10,000 characters. You may specify this parameter in the query string of a GET request or in the body of a POST request. :type pre_context_text: str :param post_context_text: A string that gives context to the text string. For example, the text string read is valid. However, if you set postContextText to carpet, the context changes and the text string becomes not valid. In this case, the API suggests that you change read to red (as in red carpet). This text is not checked for grammar or spelling errors. The combined length of the text string, preContextText string, and postContextText string may not exceed 10,000 characters. You may specify this parameter in the query string of a GET request or in the body of a POST request. :type post_context_text: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: SpellCheck or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.language.spellcheck.models.SpellCheck or ~msrest.pipeline.ClientRawResponse :raises: :class:`ErrorResponseException<azure.cognitiveservices.language.spellcheck.models.ErrorResponseException>` """ x_bing_apis_sdk = "true" # Construct URL url = '/spellcheck' # Construct parameters query_parameters = {} if action_type is not None: query_parameters['ActionType'] = self._serialize.query( "action_type", action_type, 'str') if app_name is not None: query_parameters['AppName'] = self._serialize.query( "app_name", app_name, 'str') if country_code is not None: query_parameters['cc'] = self._serialize.query( "country_code", country_code, 'str') if client_machine_name is not None: query_parameters['ClientMachineName'] = self._serialize.query( "client_machine_name", client_machine_name, 'str') if doc_id is not None: query_parameters['DocId'] = self._serialize.query( "doc_id", doc_id, 'str') if market is not None: query_parameters['mkt'] = self._serialize.query( "market", market, 'str') if session_id is not None: query_parameters['SessionId'] = self._serialize.query( "session_id", session_id, 'str') if set_lang is not None: query_parameters['SetLang'] = self._serialize.query( "set_lang", set_lang, 'str') if user_id is not None: query_parameters['UserId'] = self._serialize.query( "user_id", user_id, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/x-www-form-urlencoded' if custom_headers: header_parameters.update(custom_headers) header_parameters['X-BingApis-SDK'] = self._serialize.header( "x_bing_apis_sdk", x_bing_apis_sdk, 'str') if accept_language is not None: header_parameters['Accept-Language'] = self._serialize.header( "accept_language", accept_language, 'str') if pragma is not None: header_parameters['Pragma'] = self._serialize.header( "pragma", pragma, 'str') if user_agent is not None: header_parameters['User-Agent'] = self._serialize.header( "user_agent", user_agent, 'str') if client_id is not None: header_parameters['X-MSEdge-ClientID'] = self._serialize.header( "client_id", client_id, 'str') if client_ip is not None: header_parameters['X-MSEdge-ClientIP'] = self._serialize.header( "client_ip", client_ip, 'str') if location is not None: header_parameters['X-Search-Location'] = self._serialize.header( "location", location, 'str') # Construct form data form_data_content = { 'Text': text, 'Mode': mode, 'PreContextText': pre_context_text, 'PostContextText': post_context_text, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata(request, header_parameters, form_data_content, stream=False, **operation_config) if response.status_code not in [200]: raise models.ErrorResponseException(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('SpellCheck', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
class PredictionEndpoint(object): """PredictionEndpoint :ivar config: Configuration for client. :vartype config: PredictionEndpointConfiguration :param api_key: :type api_key: str :param str base_url: Service URL """ def __init__( self, api_key, base_url=None): self.config = PredictionEndpointConfiguration(api_key, base_url) self._client = ServiceClient(None, self.config) client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} self.api_version = '1.1' self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) def predict_image_url( self, project_id, iteration_id=None, application=None, url=None, custom_headers=None, raw=False, **operation_config): """Predict an image url and saves the result. :param project_id: The project id :type project_id: str :param iteration_id: Optional. Specifies the id of a particular iteration to evaluate against. The default iteration for the project will be used when not specified :type iteration_id: str :param application: Optional. Specifies the name of application using the endpoint :type application: str :param url: :type url: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: ImagePredictionResultModel or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.customvision.prediction.models.ImagePredictionResultModel or ~msrest.pipeline.ClientRawResponse :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ image_url = models.ImageUrl(url=url) # Construct URL url = '/{projectId}/url' path_format_arguments = { 'projectId': self._serialize.url("project_id", project_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if iteration_id is not None: query_parameters['iterationId'] = self._serialize.query("iteration_id", iteration_id, 'str') if application is not None: query_parameters['application'] = self._serialize.query("application", application, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) header_parameters['Prediction-Key'] = self._serialize.header("self.config.api_key", self.config.api_key, 'str') # Construct body body_content = self._serialize.body(image_url, 'ImageUrl') # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, stream=False, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('ImagePredictionResultModel', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def predict_image( self, project_id, image_data, iteration_id=None, application=None, custom_headers=None, raw=False, **operation_config): """Predict an image and saves the result. :param project_id: The project id :type project_id: str :param image_data: :type image_data: Generator :param iteration_id: Optional. Specifies the id of a particular iteration to evaluate against. The default iteration for the project will be used when not specified :type iteration_id: str :param application: Optional. Specifies the name of application using the endpoint :type application: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: ImagePredictionResultModel or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.customvision.prediction.models.ImagePredictionResultModel or ~msrest.pipeline.ClientRawResponse :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/{projectId}/image' path_format_arguments = { 'projectId': self._serialize.url("project_id", project_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if iteration_id is not None: query_parameters['iterationId'] = self._serialize.query("iteration_id", iteration_id, 'str') if application is not None: query_parameters['application'] = self._serialize.query("application", application, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'multipart/form-data' if custom_headers: header_parameters.update(custom_headers) header_parameters['Prediction-Key'] = self._serialize.header("self.config.api_key", self.config.api_key, 'str') # Construct form data form_data_content = { 'imageData': image_data, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata( request, header_parameters, form_data_content, stream=False, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('ImagePredictionResultModel', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def predict_image_url_with_no_store( self, project_id, iteration_id=None, application=None, url=None, custom_headers=None, raw=False, **operation_config): """Predict an image url without saving the result. :param project_id: The project id :type project_id: str :param iteration_id: Optional. Specifies the id of a particular iteration to evaluate against. The default iteration for the project will be used when not specified :type iteration_id: str :param application: Optional. Specifies the name of application using the endpoint :type application: str :param url: :type url: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: ImagePredictionResultModel or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.customvision.prediction.models.ImagePredictionResultModel or ~msrest.pipeline.ClientRawResponse :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ image_url = models.ImageUrl(url=url) # Construct URL url = '/{projectId}/url/nostore' path_format_arguments = { 'projectId': self._serialize.url("project_id", project_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if iteration_id is not None: query_parameters['iterationId'] = self._serialize.query("iteration_id", iteration_id, 'str') if application is not None: query_parameters['application'] = self._serialize.query("application", application, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if custom_headers: header_parameters.update(custom_headers) header_parameters['Prediction-Key'] = self._serialize.header("self.config.api_key", self.config.api_key, 'str') # Construct body body_content = self._serialize.body(image_url, 'ImageUrl') # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, stream=False, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('ImagePredictionResultModel', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized def predict_image_with_no_store( self, project_id, image_data, iteration_id=None, application=None, custom_headers=None, raw=False, **operation_config): """Predict an image without saving the result. :param project_id: The project id :type project_id: str :param image_data: :type image_data: Generator :param iteration_id: Optional. Specifies the id of a particular iteration to evaluate against. The default iteration for the project will be used when not specified :type iteration_id: str :param application: Optional. Specifies the name of application using the endpoint :type application: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: ImagePredictionResultModel or ClientRawResponse if raw=true :rtype: ~azure.cognitiveservices.vision.customvision.prediction.models.ImagePredictionResultModel or ~msrest.pipeline.ClientRawResponse :raises: :class:`HttpOperationError<msrest.exceptions.HttpOperationError>` """ # Construct URL url = '/{projectId}/image/nostore' path_format_arguments = { 'projectId': self._serialize.url("project_id", project_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if iteration_id is not None: query_parameters['iterationId'] = self._serialize.query("iteration_id", iteration_id, 'str') if application is not None: query_parameters['application'] = self._serialize.query("application", application, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'multipart/form-data' if custom_headers: header_parameters.update(custom_headers) header_parameters['Prediction-Key'] = self._serialize.header("self.config.api_key", self.config.api_key, 'str') # Construct form data form_data_content = { 'imageData': image_data, } # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send_formdata( request, header_parameters, form_data_content, stream=False, **operation_config) if response.status_code not in [200]: raise HttpOperationError(self._deserialize, response) deserialized = None if response.status_code == 200: deserialized = self._deserialize('ImagePredictionResultModel', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized