text:
module Azure::EventGrid::Mgmt::V2020_06_01
  #
  # Azure EventGrid Management Client
  #
  class Domains
    include MsRestAzure

    #
    # Creates and initializes a new instance of the Domains class.
    # @param client service class for accessing basic functionality.
    #
    def initialize(client)
      @client = client
    end

    # @return [EventGridManagementClient] reference to the EventGridManagementClient
    attr_reader :client

    #
    # Get a domain.
    #
    # Get properties of a domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Domain] operation results.
    #
    def get(resource_group_name, domain_name, custom_headers:nil)
      response = get_async(resource_group_name, domain_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get a domain.
    #
    # Get properties of a domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def get_with_http_info(resource_group_name, domain_name, custom_headers:nil)
      get_async(resource_group_name, domain_name, custom_headers:custom_headers).value!
    end

    #
    # Get a domain.
    #
    # Get properties of a domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def get_async(resource_group_name, domain_name, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'domain_name is nil' if domain_name.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'domainName' => domain_name},
          query_params: {'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::Domain.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Create or update a domain.
    #
    # Asynchronously creates or updates a new domain with the specified parameters.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param domain_info [Domain] Domain information.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Domain] operation results.
    #
    def create_or_update(resource_group_name, domain_name, domain_info, custom_headers:nil)
      response = create_or_update_async(resource_group_name, domain_name, domain_info, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param domain_info [Domain] Domain information.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Concurrent::Promise] promise which provides async access to http
    # response.
    #
    def create_or_update_async(resource_group_name, domain_name, domain_info, custom_headers:nil)
      # Send request
      promise = begin_create_or_update_async(resource_group_name, domain_name, domain_info, custom_headers:custom_headers)

      promise = promise.then do |response|
        # Defining deserialization method.
        deserialize_method = lambda do |parsed_response|
          result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::Domain.mapper()
          parsed_response = @client.deserialize(result_mapper, parsed_response)
        end

        # Waiting for response.
        @client.get_long_running_operation_result(response, deserialize_method)
      end

      promise
    end

    #
    # Delete a domain.
    #
    # Delete existing domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    def delete(resource_group_name, domain_name, custom_headers:nil)
      response = delete_async(resource_group_name, domain_name, custom_headers:custom_headers).value!
      nil
    end

    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Concurrent::Promise] promise which provides async access to http
    # response.
    #
    def delete_async(resource_group_name, domain_name, custom_headers:nil)
      # Send request
      promise = begin_delete_async(resource_group_name, domain_name, custom_headers:custom_headers)

      promise = promise.then do |response|
        # Defining deserialization method.
        deserialize_method = lambda do |parsed_response|
        end

        # Waiting for response.
        @client.get_long_running_operation_result(response, deserialize_method)
      end

      promise
    end

    #
    # Update a domain.
    #
    # Asynchronously updates a domain with the specified parameters.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param domain_update_parameters [DomainUpdateParameters] Domain update
    # information.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Domain] operation results.
    #
    def update(resource_group_name, domain_name, domain_update_parameters, custom_headers:nil)
      response = update_async(resource_group_name, domain_name, domain_update_parameters, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param domain_update_parameters [DomainUpdateParameters] Domain update
    # information.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Concurrent::Promise] promise which provides async access to http
    # response.
    #
    def update_async(resource_group_name, domain_name, domain_update_parameters, custom_headers:nil)
      # Send request
      promise = begin_update_async(resource_group_name, domain_name, domain_update_parameters, custom_headers:custom_headers)

      promise = promise.then do |response|
        # Defining deserialization method.
        deserialize_method = lambda do |parsed_response|
          result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::Domain.mapper()
          parsed_response = @client.deserialize(result_mapper, parsed_response)
        end

        # Waiting for response.
        @client.get_long_running_operation_result(response, deserialize_method)
      end

      promise
    end

    #
    # List domains under an Azure subscription.
    #
    # List all the domains under an Azure subscription.
    #
    # @param filter [String] The query used to filter the search results using
    # OData syntax. Filtering is permitted on the 'name' property only and with
    # limited number of OData operations. These operations are: the 'contains'
    # function as well as the following logical operations: not, and, or, eq (for
    # equal), and ne (for not equal). No arithmetic operations are supported. The
    # following is a valid filter example: $filter=contains(namE, 'PATTERN') and
    # name ne 'PATTERN-1'. The following is not a valid filter example:
    # $filter=location eq 'westus'.
    # @param top [Integer] The number of results to return per page for the list
    # operation. Valid range for top parameter is 1 to 100. If not specified, the
    # default number of results to be returned is 20 items per page.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<Domain>] operation results.
    #
    def list_by_subscription(filter:nil, top:nil, custom_headers:nil)
      first_page = list_by_subscription_as_lazy(filter:filter, top:top, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List domains under an Azure subscription.
    #
    # List all the domains under an Azure subscription.
    #
    # @param filter [String] The query used to filter the search results using
    # OData syntax. Filtering is permitted on the 'name' property only and with
    # limited number of OData operations. These operations are: the 'contains'
    # function as well as the following logical operations: not, and, or, eq (for
    # equal), and ne (for not equal). No arithmetic operations are supported. The
    # following is a valid filter example: $filter=contains(namE, 'PATTERN') and
    # name ne 'PATTERN-1'. The following is not a valid filter example:
    # $filter=location eq 'westus'.
    # @param top [Integer] The number of results to return per page for the list
    # operation. Valid range for top parameter is 1 to 100. If not specified, the
    # default number of results to be returned is 20 items per page.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_by_subscription_with_http_info(filter:nil, top:nil, custom_headers:nil)
      list_by_subscription_async(filter:filter, top:top, custom_headers:custom_headers).value!
    end

    #
    # List domains under an Azure subscription.
    #
    # List all the domains under an Azure subscription.
    #
    # @param filter [String] The query used to filter the search results using
    # OData syntax. Filtering is permitted on the 'name' property only and with
    # limited number of OData operations. These operations are: the 'contains'
    # function as well as the following logical operations: not, and, or, eq (for
    # equal), and ne (for not equal). No arithmetic operations are supported. The
    # following is a valid filter example: $filter=contains(namE, 'PATTERN') and
    # name ne 'PATTERN-1'. The following is not a valid filter example:
    # $filter=location eq 'westus'.
    # @param top [Integer] The number of results to return per page for the list
    # operation. Valid range for top parameter is 1 to 100. If not specified, the
    # default number of results to be returned is 20 items per page.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_by_subscription_async(filter:nil, top:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'subscriptions/{subscriptionId}/providers/Microsoft.EventGrid/domains'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::DomainsListResult.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # List domains under a resource group.
    #
    # List all the domains under a resource group.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param filter [String] The query used to filter the search results using
    # OData syntax. Filtering is permitted on the 'name' property only and with
    # limited number of OData operations. These operations are: the 'contains'
    # function as well as the following logical operations: not, and, or, eq (for
    # equal), and ne (for not equal). No arithmetic operations are supported. The
    # following is a valid filter example: $filter=contains(namE, 'PATTERN') and
    # name ne 'PATTERN-1'. The following is not a valid filter example:
    # $filter=location eq 'westus'.
    # @param top [Integer] The number of results to return per page for the list
    # operation. Valid range for top parameter is 1 to 100. If not specified, the
    # default number of results to be returned is 20 items per page.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<Domain>] operation results.
    #
    def list_by_resource_group(resource_group_name, filter:nil, top:nil, custom_headers:nil)
      first_page = list_by_resource_group_as_lazy(resource_group_name, filter:filter, top:top, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List domains under a resource group.
    #
    # List all the domains under a resource group.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param filter [String] The query used to filter the search results using
    # OData syntax. Filtering is permitted on the 'name' property only and with
    # limited number of OData operations. These operations are: the 'contains'
    # function as well as the following logical operations: not, and, or, eq (for
    # equal), and ne (for not equal). No arithmetic operations are supported. The
    # following is a valid filter example: $filter=contains(namE, 'PATTERN') and
    # name ne 'PATTERN-1'. The following is not a valid filter example:
    # $filter=location eq 'westus'.
    # @param top [Integer] The number of results to return per page for the list
    # operation. Valid range for top parameter is 1 to 100. If not specified, the
    # default number of results to be returned is 20 items per page.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_by_resource_group_with_http_info(resource_group_name, filter:nil, top:nil, custom_headers:nil)
      list_by_resource_group_async(resource_group_name, filter:filter, top:top, custom_headers:custom_headers).value!
    end

    #
    # List domains under a resource group.
    #
    # List all the domains under a resource group.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param filter [String] The query used to filter the search results using
    # OData syntax. Filtering is permitted on the 'name' property only and with
    # limited number of OData operations. These operations are: the 'contains'
    # function as well as the following logical operations: not, and, or, eq (for
    # equal), and ne (for not equal). No arithmetic operations are supported. The
    # following is a valid filter example: $filter=contains(namE, 'PATTERN') and
    # name ne 'PATTERN-1'. The following is not a valid filter example:
    # $filter=location eq 'westus'.
    # @param top [Integer] The number of results to return per page for the list
    # operation. Valid range for top parameter is 1 to 100. If not specified, the
    # default number of results to be returned is 20 items per page.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_by_resource_group_async(resource_group_name, filter:nil, top:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::DomainsListResult.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # List keys for a domain.
    #
    # List the two keys used to publish to a domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [DomainSharedAccessKeys] operation results.
    #
    def list_shared_access_keys(resource_group_name, domain_name, custom_headers:nil)
      response = list_shared_access_keys_async(resource_group_name, domain_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List keys for a domain.
    #
    # List the two keys used to publish to a domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_shared_access_keys_with_http_info(resource_group_name, domain_name, custom_headers:nil)
      list_shared_access_keys_async(resource_group_name, domain_name, custom_headers:custom_headers).value!
    end

    #
    # List keys for a domain.
    #
    # List the two keys used to publish to a domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_shared_access_keys_async(resource_group_name, domain_name, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'domain_name is nil' if domain_name.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}/listKeys'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'domainName' => domain_name},
          query_params: {'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:post, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::DomainSharedAccessKeys.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Regenerate key for a domain.
    #
    # Regenerate a shared access key for a domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param regenerate_key_request [DomainRegenerateKeyRequest] Request body to
    # regenerate key.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [DomainSharedAccessKeys] operation results.
    #
    def regenerate_key(resource_group_name, domain_name, regenerate_key_request, custom_headers:nil)
      response = regenerate_key_async(resource_group_name, domain_name, regenerate_key_request, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Regenerate key for a domain.
    #
    # Regenerate a shared access key for a domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param regenerate_key_request [DomainRegenerateKeyRequest] Request body to
    # regenerate key.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def regenerate_key_with_http_info(resource_group_name, domain_name, regenerate_key_request, custom_headers:nil)
      regenerate_key_async(resource_group_name, domain_name, regenerate_key_request, custom_headers:custom_headers).value!
    end

    #
    # Regenerate key for a domain.
    #
    # Regenerate a shared access key for a domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param regenerate_key_request [DomainRegenerateKeyRequest] Request body to
    # regenerate key.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def regenerate_key_async(resource_group_name, domain_name, regenerate_key_request, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'domain_name is nil' if domain_name.nil?
      fail ArgumentError, 'regenerate_key_request is nil' if regenerate_key_request.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::DomainRegenerateKeyRequest.mapper()
      request_content = @client.serialize(request_mapper,  regenerate_key_request)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}/regenerateKey'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'domainName' => domain_name},
          query_params: {'api-version' => @client.api_version},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:post, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::DomainSharedAccessKeys.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Create or update a domain.
    #
    # Asynchronously creates or updates a new domain with the specified parameters.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param domain_info [Domain] Domain information.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Domain] operation results.
    #
    def begin_create_or_update(resource_group_name, domain_name, domain_info, custom_headers:nil)
      response = begin_create_or_update_async(resource_group_name, domain_name, domain_info, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Create or update a domain.
    #
    # Asynchronously creates or updates a new domain with the specified parameters.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param domain_info [Domain] Domain information.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def begin_create_or_update_with_http_info(resource_group_name, domain_name, domain_info, custom_headers:nil)
      begin_create_or_update_async(resource_group_name, domain_name, domain_info, custom_headers:custom_headers).value!
    end

    #
    # Create or update a domain.
    #
    # Asynchronously creates or updates a new domain with the specified parameters.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param domain_info [Domain] Domain information.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def begin_create_or_update_async(resource_group_name, domain_name, domain_info, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'domain_name is nil' if domain_name.nil?
      fail ArgumentError, 'domain_info is nil' if domain_info.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::Domain.mapper()
      request_content = @client.serialize(request_mapper,  domain_info)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'domainName' => domain_name},
          query_params: {'api-version' => @client.api_version},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:put, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 201
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 201
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::Domain.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Delete a domain.
    #
    # Delete existing domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def begin_delete(resource_group_name, domain_name, custom_headers:nil)
      response = begin_delete_async(resource_group_name, domain_name, custom_headers:custom_headers).value!
      nil
    end

    #
    # Delete a domain.
    #
    # Delete existing domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def begin_delete_with_http_info(resource_group_name, domain_name, custom_headers:nil)
      begin_delete_async(resource_group_name, domain_name, custom_headers:custom_headers).value!
    end

    #
    # Delete a domain.
    #
    # Delete existing domain.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def begin_delete_async(resource_group_name, domain_name, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'domain_name is nil' if domain_name.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'domainName' => domain_name},
          query_params: {'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:delete, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 202 || status_code == 204
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

        result
      end

      promise.execute
    end

    #
    # Update a domain.
    #
    # Asynchronously updates a domain with the specified parameters.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param domain_update_parameters [DomainUpdateParameters] Domain update
    # information.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Domain] operation results.
    #
    def begin_update(resource_group_name, domain_name, domain_update_parameters, custom_headers:nil)
      response = begin_update_async(resource_group_name, domain_name, domain_update_parameters, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Update a domain.
    #
    # Asynchronously updates a domain with the specified parameters.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param domain_update_parameters [DomainUpdateParameters] Domain update
    # information.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def begin_update_with_http_info(resource_group_name, domain_name, domain_update_parameters, custom_headers:nil)
      begin_update_async(resource_group_name, domain_name, domain_update_parameters, custom_headers:custom_headers).value!
    end

    #
    # Update a domain.
    #
    # Asynchronously updates a domain with the specified parameters.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the domain.
    # @param domain_update_parameters [DomainUpdateParameters] Domain update
    # information.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def begin_update_async(resource_group_name, domain_name, domain_update_parameters, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'domain_name is nil' if domain_name.nil?
      fail ArgumentError, 'domain_update_parameters is nil' if domain_update_parameters.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::DomainUpdateParameters.mapper()
      request_content = @client.serialize(request_mapper,  domain_update_parameters)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'domainName' => domain_name},
          query_params: {'api-version' => @client.api_version},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:patch, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200 || status_code == 201
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 201
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::Domain.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # List domains under an Azure subscription.
    #
    # List all the domains under an Azure subscription.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [DomainsListResult] operation results.
    #
    def list_by_subscription_next(next_page_link, custom_headers:nil)
      response = list_by_subscription_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List domains under an Azure subscription.
    #
    # List all the domains under an Azure subscription.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_by_subscription_next_with_http_info(next_page_link, custom_headers:nil)
      list_by_subscription_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List domains under an Azure subscription.
    #
    # List all the domains under an Azure subscription.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_by_subscription_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::DomainsListResult.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # List domains under a resource group.
    #
    # List all the domains under a resource group.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [DomainsListResult] operation results.
    #
    def list_by_resource_group_next(next_page_link, custom_headers:nil)
      response = list_by_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List domains under a resource group.
    #
    # List all the domains under a resource group.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_by_resource_group_next_with_http_info(next_page_link, custom_headers:nil)
      list_by_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List domains under a resource group.
    #
    # List all the domains under a resource group.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_by_resource_group_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2020_06_01::Models::DomainsListResult.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # List domains under an Azure subscription.
    #
    # List all the domains under an Azure subscription.
    #
    # @param filter [String] The query used to filter the search results using
    # OData syntax. Filtering is permitted on the 'name' property only and with
    # limited number of OData operations. These operations are: the 'contains'
    # function as well as the following logical operations: not, and, or, eq (for
    # equal), and ne (for not equal). No arithmetic operations are supported. The
    # following is a valid filter example: $filter=contains(namE, 'PATTERN') and
    # name ne 'PATTERN-1'. The following is not a valid filter example:
    # $filter=location eq 'westus'.
    # @param top [Integer] The number of results to return per page for the list
    # operation. Valid range for top parameter is 1 to 100. If not specified, the
    # default number of results to be returned is 20 items per page.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [DomainsListResult] which provide lazy access to pages of the
    # response.
    #
    def list_by_subscription_as_lazy(filter:nil, top:nil, custom_headers:nil)
      response = list_by_subscription_async(filter:filter, top:top, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_by_subscription_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # List domains under a resource group.
    #
    # List all the domains under a resource group.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param filter [String] The query used to filter the search results using
    # OData syntax. Filtering is permitted on the 'name' property only and with
    # limited number of OData operations. These operations are: the 'contains'
    # function as well as the following logical operations: not, and, or, eq (for
    # equal), and ne (for not equal). No arithmetic operations are supported. The
    # following is a valid filter example: $filter=contains(namE, 'PATTERN') and
    # name ne 'PATTERN-1'. The following is not a valid filter example:
    # $filter=location eq 'westus'.
    # @param top [Integer] The number of results to return per page for the list
    # operation. Valid range for top parameter is 1 to 100. If not specified, the
    # default number of results to be returned is 20 items per page.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [DomainsListResult] which provide lazy access to pages of the
    # response.
    #
    def list_by_resource_group_as_lazy(resource_group_name, filter:nil, top:nil, custom_headers:nil)
      response = list_by_resource_group_async(resource_group_name, filter:filter, top:top, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_by_resource_group_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

  end
end


text:
"""
    jQuery Scripte, die mit der App interagieren, werden hier referenziert...
"""

from app import app, jsonify, request
from colormath import *
from colormath.color_objects import XYZColor, RGBColor, CMYKColor, HSVColor, color_conversions, LabColor

@app.route('/_add_numbers')
def add_numbers():
    """Eine Besipielmethode, die über json mit jquery interagiert..."""
    a = request.args.get('a', 0, type=int)
    b = request.args.get('b', 0, type=int)
    res = a + b
    return jsonify(ergebnis=res)

redpajama_set_name: RedPajamaGithub


text:
module Utils (
  toLower
  , chunkV
  , merge
) where

import qualified Data.Char as C
import qualified Data.Vector as V
import Prelude hiding (map, any)
import Data.ByteString.Char8 (map, ByteString)

-- Faster toLower
toLower :: ByteString -> ByteString
toLower b = map lower b
  where lower c
          | C.isAsciiUpper c = C.toLower c
          | otherwise        = c

-- Chunks items into groups
chunkV :: Int -> V.Vector a -> [V.Vector a]
chunkV amt v
  | V.null v  = []
  | otherwise = c1:(chunkV amt rest)
  where (c1, rest) = V.splitAt amt v

-- Merge facilities for lazy top elements, instead of sorting them all
merge :: Ord b => (a -> b) -> [[a]] -> [a]
merge _ []  = []
merge _ [a] = a
merge f ss = foldr (merge2 f) [] ss

merge2 :: Ord b => (a -> b) -> [a] -> [a] -> [a]
merge2 f (a:as) (b:bs)
  | f(a) < f(b) = a : merge2 f as (b:bs)
  | otherwise   = b : merge2 f (a:as) bs
merge2 _ [] rs = rs
merge2 _ rs [] = rs


text:
<?php
/*
 * Configuration.php
 * Configuration file for API client
 *
 */

class Configuration {
    //The base Uri for API calls
    const BASEURI = 'https://api.vedicrishiastro.com/v1';

    //The username to use with basic authentication
    //TODO: Replace the basicAuthUserName with an appropriate value
    public static $basicAuthUserName = 'TODO: Replace';

    //The password to use with basic authentication
    //TODO: Replace the basicAuthPassword with an appropriate value
    public static $basicAuthPassword = 'TODO: Replace';

}


text:
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Globalization;
using System.Management.Automation;
using System.Security.Permissions;
using Microsoft.Azure.Commands.Automation.Properties;

namespace Microsoft.Azure.Commands.Automation.Cmdlet
{
    /// <summary>
    /// Removes an azure automation Schedule.
    /// </summary>
    [Cmdlet(VerbsCommon.Remove, "AzureAutomationSchedule", SupportsShouldProcess = true, DefaultParameterSetName = ByScheduleName)]
    public class RemoveAzureAutomationSchedule : AzureAutomationBaseCmdlet
    {
        /// <summary>
        /// The get schedule by schedule id parameter set.
        /// </summary>
        private const string ByScheduleId = "ByScheduleId";

        /// <summary>
        /// The get schedule by schedule name parameter set.
        /// </summary>
        private const string ByScheduleName = "ByScheduleName";

        /// <summary>
        /// Gets or sets the schedule id.
        /// </summary>
        [Parameter(ParameterSetName = ByScheduleId, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true,
            HelpMessage = "The schedule id.")]
        public Guid? Id { get; set; }

        /// <summary>
        /// Gets or sets the schedule name.
        /// </summary>
        [Parameter(ParameterSetName = ByScheduleName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true,
            HelpMessage = "The schedule name.")]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the switch parameter not to confirm on removing the schedule.
        /// </summary>
        [Parameter(Mandatory = false, HelpMessage = "Do not confirm on removing the schedule.")]
        public SwitchParameter Force { get; set; }

        /// <summary>
        /// Execute this cmdlet.
        /// </summary>
        [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
        protected override void AutomationExecuteCmdlet()
        {
            this.ConfirmAction(
                this.Force.IsPresent,
                string.Format(CultureInfo.CurrentCulture, Resources.RemoveAzureAutomationScheduleWarning),
                string.Format(CultureInfo.CurrentCulture, Resources.RemoveAzureAutomationScheduleDescription),
                this.Id.HasValue ? this.Id.Value.ToString() : this.Name,
                () =>
                    {
                        if (this.Id.HasValue)
                        {
                            // ByScheduleId
                            this.AutomationClient.DeleteSchedule(this.AutomationAccountName, this.Id.Value);
                        }
                        else
                        {
                            // ByScheduleName
                            this.AutomationClient.DeleteSchedule(this.AutomationAccountName, this.Name);
                        }
                    });
        }
    }
}


text:
ps3publictools by geohot
Originally cloned from: https://github.com/geohot/ps3publictools

---------------------------------------------------------------------

make_self_npdrm makes valid NPDRM selfs from elfs
it does not contain any info on decrypting or removing NPDRM
NPDRM is required for interoperability of our homebrew applications
package_finalize turns your debug packages into psuedoretail packages
psuedoretail packages install on a geohot jailbroken PS3

be sure the elf you are make_self_npdrming is sprxlinked
also be careful with the output file name of make_self_npdrm
most likely, it should be "EBOOT.BIN", it is case sensitive


text:
<!DOCTYPE html>

There should be an image below:


text:
<!DOCTYPE html>

    <meta name="top_category" value="develop" />

    <meta name="subcategory" value="reference" />

      <meta name="book_path" value="/reference/android/support/test/_book.yaml" />

<title>UiCollection</title>

Summary:

  Inherited Constants

  | Ctors

  | Methods

  | Inherited Methods

| [Expand All]

UiCollection

  public

  class
  UiCollection

    extends UiObject

    java.lang.Object

         ↳

    android.support.test.uiautomator.UiObject

         ↳

    android.support.test.uiautomator.UiCollection

  Known Direct Subclasses

              UiScrollable

        UiScrollable

          UiScrollable is a UiCollection and provides support for searching
 for items in scrollable layout elements.

Used to enumerate a container's UI elements for the purpose of counting,
 or targeting a sub elements by a child's text or description.

Summary

Inherited constants

  From
  class

    android.support.test.uiautomator.UiObject

        int

          FINGER_TOUCH_HALF_WIDTH

        int

          SWIPE_MARGIN_LIMIT

        long

          WAIT_FOR_EVENT_TMEOUT

      This constant is deprecated.
    use setScrollAcknowledgmentTimeout(long)

        long

          WAIT_FOR_SELECTOR_POLL

        long

          WAIT_FOR_SELECTOR_TIMEOUT

      This constant is deprecated.
    use setWaitForSelectorTimeout(long)

        long

          WAIT_FOR_WINDOW_TMEOUT

Public constructors

      UiCollection(UiSelector selector)

Constructs an instance as described by the selector

Public methods

        UiObject

      getChildByDescription(UiSelector childPattern, String text)

Searches for child UI element within the constraints of this UiCollection UiSelector
 selector.

        UiObject

      getChildByInstance(UiSelector childPattern, int instance)

Searches for child UI element within the constraints of this UiCollection UiSelector
 selector.

        UiObject

      getChildByText(UiSelector childPattern, String text)

Searches for child UI element within the constraints of this UiCollection UiSelector
 selector.

        int

      getChildCount(UiSelector childPattern)

Counts child UI element instances matching the childPattern
 argument.

Inherited methods

  From
class

    android.support.test.uiautomator.UiObject

        void

      clearTextField()

Clears the existing text contents in an editable field.

        boolean

      click()

Performs a click at the center of the visible bounds of the UI element represented
 by this UiObject.

        boolean

      clickAndWaitForNewWindow()

Waits for window transitions that would typically take longer than the
 usual default timeouts.

        boolean

      clickAndWaitForNewWindow(long timeout)

Performs a click at the center of the visible bounds of the UI element represented
 by this UiObject and waits for window transitions.

        boolean

      clickBottomRight()

Clicks the bottom and right corner of the UI element

        boolean

      clickTopLeft()

Clicks the top and left corner of the UI element

        boolean

      dragTo(UiObject destObj, int steps)

Drags this object to a destination UiObject.

        boolean

      dragTo(int destX, int destY, int steps)

Drags this object to arbitrary coordinates.

        boolean

      exists()

Check if view exists.

        AccessibilityNodeInfo

      findAccessibilityNodeInfo(long timeout)

Finds a matching UI element in the accessibility hierarchy, by
 using the selector for this UiObject.

        Rect

      getBounds()

Returns the view's bounds property.

        UiObject

      getChild(UiSelector selector)

Creates a new UiObject for a child view that is under the present UiObject.

        int

      getChildCount()

Counts the child views immediately under the present UiObject.

        String

      getClassName()

Retrieves the className property of the UI element.

        String

      getContentDescription()

Reads the content_desc property of the UI element

        UiObject

      getFromParent(UiSelector selector)

Creates a new UiObject for a sibling view or a child of the sibling view,
 relative to the present UiObject.

        String

      getPackageName()

Reads the view's package property

        final

        UiSelector

      getSelector()

Debugging helper.

        String

      getText()

Reads the text property of the UI element

        Rect

      getVisibleBounds()

Returns the visible bounds of the view.

        boolean

      isCheckable()

Checks if the UI element's checkable property is currently true.

        boolean

      isChecked()

Check if the UI element's checked property is currently true

        boolean

      isClickable()

Checks if the UI element's clickable property is currently true.

        boolean

      isEnabled()

Checks if the UI element's enabled property is currently true.

        boolean

      isFocusable()

Check if the UI element's focusable property is currently true.

        boolean

      isFocused()

Check if the UI element's focused property is currently true

        boolean

      isLongClickable()

Check if the view's long-clickable property is currently true

        boolean

      isScrollable()

Check if the view's scrollable property is currently true

        boolean

      isSelected()

Checks if the UI element's selected property is currently true.

        boolean

      longClick()

Long clicks the center of the visible bounds of the UI element

        boolean

      longClickBottomRight()

Long clicks bottom and right corner of the UI element

        boolean

      longClickTopLeft()

Long clicks on the top and left corner of the UI element

        boolean

      performMultiPointerGesture(PointerCoords... touches)

Performs a multi-touch gesture.

        boolean

      performTwoPointerGesture(Point startPoint1, Point startPoint2, Point endPoint1, Point endPoint2, int steps)

Generates a two-pointer gesture with arbitrary starting and ending points.

        boolean

      pinchIn(int percent, int steps)

Performs a two-pointer gesture, where each pointer moves diagonally
 toward the other, from the edges to the center of this UiObject .

        boolean

      pinchOut(int percent, int steps)

Performs a two-pointer gesture, where each pointer moves diagonally
 opposite across the other, from the center out towards the edges of the
 this UiObject.

        boolean

      setText(String text)

Sets the text in an editable field, after clearing the field's content.

        boolean

      swipeDown(int steps)

Performs the swipe down action on the UiObject.

        boolean

      swipeLeft(int steps)

Performs the swipe left action on the UiObject.

        boolean

      swipeRight(int steps)

Performs the swipe right action on the UiObject.

        boolean

      swipeUp(int steps)

Performs the swipe up action on the UiObject.

        boolean

      waitForExists(long timeout)

Waits a specified length of time for a view to become visible.

        boolean

      waitUntilGone(long timeout)

Waits a specified length of time for a view to become undetectable.

  From
class

    java.lang.Object

        Object

      clone()

        boolean

      equals(Object arg0)

        void

      finalize()

        final

        Class<?>

      getClass()

        int

      hashCode()

        final

        void

      notify()

        final

        void

      notifyAll()

        String

      toString()

        final

        void

      wait(long arg0, int arg1)

        final

        void

      wait(long arg0)

        final

        void

      wait()

Public constructors

UiCollection

UiCollection (UiSelector selector)

Constructs an instance as described by the selector

Public methods

getChildByDescription

UiObject getChildByDescription (UiSelector childPattern,
                String text)

Searches for child UI element within the constraints of this UiCollection UiSelector
 selector.

 It looks for any child matching the childPattern argument that has
 a child UI element anywhere within its sub hierarchy that has content-description text.
 The returned UiObject will point at the childPattern instance that matched the
 search and not at the identifying child element that matched the content description.

Parameters

        childPattern

          UiSelector:
          UiSelector selector of the child pattern to match and return

        text

          String:
          String of the identifying child contents of of the childPattern

Returns

        UiObject
        UiObject pointing at and instance of childPattern

Throws

          UiObjectNotFoundException

          UiObjectNotFoundException

getChildByInstance

UiObject getChildByInstance (UiSelector childPattern,
                int instance)

Searches for child UI element within the constraints of this UiCollection UiSelector
 selector.

 It looks for any child matching the childPattern argument that has
 a child UI element anywhere within its sub hierarchy that is at the instance
 specified. The operation is performed only on the visible items and no scrolling is performed
 in this case.

Parameters

        childPattern

          UiSelector:
          UiSelector selector of the child pattern to match and return

        instance

          int:
          int the desired matched instance of this childPattern

Returns

        UiObject
        UiObject pointing at and instance of childPattern

Throws

          UiObjectNotFoundException

getChildByText

UiObject getChildByText (UiSelector childPattern,
                String text)

Searches for child UI element within the constraints of this UiCollection UiSelector
 selector.

 It looks for any child matching the childPattern argument that has
 a child UI element anywhere within its sub hierarchy that has text attribute =
 text. The returned UiObject will point at the childPattern
 instance that matched the search and not at the identifying child element that matched the
 text attribute.

Parameters

        childPattern

          UiSelector:
          UiSelector selector of the child pattern to match and return

        text

          String:
          String of the identifying child contents of of the childPattern

Returns

        UiObject
        UiObject pointing at and instance of childPattern

Throws

          UiObjectNotFoundException

          UiObjectNotFoundException

getChildCount

int getChildCount (UiSelector childPattern)

Counts child UI element instances matching the childPattern
 argument. The method returns the number of matching UI elements that are
 currently visible.  The count does not include items of a scrollable list
 that are off-screen.

Parameters

        childPattern

          UiSelector:
          a UiSelector that represents the matching child UI
 elements to count

Returns

        int
        the number of matched childPattern under the current UiCollection

Interfaces

IAutomationSupport

UiWatcher

Classes

By

BySelector

Configurator

EventCondition

SearchCondition

UiAutomatorInstrumentationTestRunner

UiAutomatorTestCase

UiCollection

UiDevice

UiObject

UiObject2

UiObject2Condition

UiScrollable

UiSelector

Until

Enums

Direction

Exceptions

StaleObjectException

UiObjectNotFoundException


text: ES6 cookie management module based on the original "Cookies" implementation of @ScottHamper


text:
<dialog #modal class="mdl-dialog" (click)="$event.stopPropagation()">
	<div #modalHeader class="mdl-dialog__title">
		<ng-content select=".app-modal__header"></ng-content>
	</div>
	<div #modalContent class="mdl-dialog__content">
		<ng-content select=".app-modal__body"></ng-content>
	</div>
	<div class="mdl-dialog__actions">
		<ng-content select=".app-modal__footer"></ng-content>
	</div>
</dialog>


text:
require('../test-environment.js');

describe('Dereferencing tests', function() {
  'use strict';

  describe('Success tests', function() {
    it('should not dereference shorthand pointers if "dereference$Refs" is false',
      function(done) {
        env.parser.parse(env.getPath('good/shorthand-refs.yaml'), {dereference$Refs: false}, function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.resolved.shorthandRefs);
          done();
        });
      }
    );

    it('should not dereference shorthand pointers if "dereferenceInternal$Refs" is false',
      function(done) {
        env.parser.parse(env.getPath('good/shorthand-refs.yaml'), {dereferenceInternal$Refs: false}, function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.resolved.shorthandRefs);
          done();
        });
      }
    );

    it('should dereference shorthand "definition" references',
      function(done) {
        env.parser.parse(env.getPath('good/shorthand-refs.yaml'), function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.dereferenced.shorthandRefs);

          done();
        });
      }
    );

    it('should not dereference external pointers if "resolveExternal$Refs" is false',
      function(done) {
        env.parser.parse(env.getPath('good/external-refs.yaml'), {resolveExternal$Refs: false}, function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.resolved.externalRefs);
          done();
        });
      }
    );

    it('should dereference external pointers if "dereferenceInternal$Refs" is false',
      function(done) {
        env.parser.parse(env.getPath('good/external-refs.yaml'), {dereferenceInternal$Refs: false}, function(err, api) {
          if (err) {
            return done(err);
          }

          if (env.isBrowser) {
            // Browsers differ in how they convert binary data to strings,
            // so we can't compare the exact data for the external image file
            var imageSchema = api.paths['/pets'].post.responses[500].schema;
            expect(imageSchema.example).to.be.a('string').and.not.empty;
            imageSchema.example = '';
          }

          expect(api).to.deep.equal(env.dereferenced.externalRefs);
          done();
        });
      }
    );

    it('should dereference external pointers',
      function(done) {
        env.parser.parse(env.getPath('good/external-refs.yaml'), function(err, api) {
          if (err) {
            return done(err);
          }

          if (env.isBrowser) {
            // Browsers differ in how they convert binary data to strings,
            // so we can't compare the exact data for the external image file
            var imageSchema = api.paths['/pets'].post.responses[500].schema;
            expect(imageSchema.example).to.be.a('string').and.not.empty;
            imageSchema.example = '';
          }

          expect(api).to.deep.equal(env.dereferenced.externalRefs);
          done();
        });
      }
    );

    it('should not dereference anything if "dereference$Refs" is false',
      function(done) {
        env.parser.parse(env.getPath('good/refs.yaml'), {dereference$Refs: false}, function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.resolved.refs);
          done();
        });
      }
    );

    it('should dereference all types of references',
      function(done) {
        env.parser.parse(env.getPath('good/refs.yaml'), function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.dereferenced.refs);
          done();
        });
      }
    );

    it('should only dereference external references if "dereferenceInternal$Refs" is false',
      function(done) {
        env.parser.parse(env.getPath('good/refs.yaml'), {dereferenceInternal$Refs: false}, function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.dereferenced.external.refs);
          done();
        });
      }
    );

    it('should dereference nested references',
      function(done) {
        env.parser.parse(env.getPath('good/nested-refs.yaml'), function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.dereferenced.nestedRefs);
          done();
        });
      }
    );

    it('should dereference internal references in external files',
      function(done) {
        env.parser.parse(env.getPath('good/external-backrefs.yaml'), function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.dereferenced.externalBackRefs);
          done();
        });
      }
    );

    it('should not dereference internal references in external files if "dereferenceInternal$Refs" is false',
      function(done) {
        env.parser.parse(env.getPath('good/external-backrefs.yaml'), {dereferenceInternal$Refs: false}, function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.dereferenced.external.externalBackRefs);
          done();
        });
      }
    );

    it('should dereference non-object references',
      function(done) {
        env.parser.parse(env.getPath('good/non-object-refs.yaml'), function(err, api) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.dereferenced.nonObjectRefs);

          done();
        });
      }
    );

    it('should partially-dereference circular references',
      function(done) {
        env.parser.parse(env.getPath('good/circular-refs.yaml'), function(err, api, metadata) {
          expect(err).to.be.an.instanceOf(ReferenceError);
          expect(err.message).to.equal('5 circular reference(s) detected');
          expect(metadata).to.satisfy(env.isMetadata);

          // The API should be partially dereferenced
          // (only non-circular $refs are resolved)
          expect(api).to.deep.equal(env.dereferenced.circularRefs);

          // The metadata should contain the circular and non-circular $refs
          var $refs = {};
          $refs['person'] = $refs['#/definitions/person'] = env.dereferenced.circularRefsPerson;
          $refs['parent'] = $refs['#/definitions/parent'] = env.dereferenced.circularRefsParent;
          $refs['child'] = $refs['#/definitions/child'] = env.dereferenced.circularRefsChild;
          expect(metadata.$refs).to.deep.equal($refs);

          done();
        });
      }
    );

    it('should ignore $refs that aren\'t strings',
      function(done) {
        env.parser.parse(env.getPath('good/non-refs.yaml'), function(err, api, metadata) {
          if (err) {
            return done(err);
          }

          expect(api).to.deep.equal(env.dereferenced.nonRefs);

          var $refs = {};
          $refs['$ref'] = $refs['#/definitions/$ref'] = env.dereferenced.nonRef;

          expect(metadata).to.satisfy(env.isMetadata);
          expect(metadata.$refs).to.deep.equal($refs);

          done();
        });
      }
    );

    it('should dereference an already-parsed object',
      function(done) {
        env.parser.parse(env.resolved.nestedRefs, function(err, api, metadata) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.dereferenced.nestedRefs);
          expect(metadata).to.satisfy(env.isMetadata);
          done();
        });
      }
    );

    it('should have no effect on an already-dereferenced object',
      function(done) {
        env.parser.parse(env.dereferenced.refs, function(err, api, metadata) {
          if (err) {
            return done(err);
          }
          expect(api).to.deep.equal(env.dereferenced.refs);
          expect(metadata).to.satisfy(env.isMetadata);
          done();
        });
      }
    );
  });

  describe('Reference-equality tests', function() {

    it('should resolve matching shorthand references to the same object instance',
      function(done) {
        env.parser.parse(env.getPath('good/shorthand-refs.yaml'), function(err, api) {
          // Two $ref pointers to "pet"
          var $ref1 = api.paths['/pets'].post.parameters[0].schema;
          var $ref2 = api.paths['/pets'].post.responses['200'].schema;

          // The $refs should all point to the same object instance
          expect($ref1).to.equal(api.definitions.pet);
          expect($ref2).to.equal(api.definitions.pet);

          // The $refs should be fully dereferenced
          expect($ref1).to.deep.equal(env.dereferenced.pet);

          done();
        });
      }
    );

    it('should resolve different-but-matching references to the same object instance',
      function(done) {
        env.parser.parse(env.getPath('good/refs.yaml'), function(err, api) {
          // $ref pointer to "pet"
          var $ref1 = api.paths['/pets'].post.responses['200'].schema;

          // $ref pointer to "#/definitions/pet"
          var $ref2 = api.paths['/pets'].post.parameters[0].schema;

          // $ref pointer to "pet" via "pet.yaml"
          var $ref3 = api.paths['/pets'].post.responses['500'].schema.properties.pet;

          // $ref pointer to "pet" via "#/paths//pets/post/responses/200/schema"
          var $ref4 = api.paths['/pets'].post.responses.default.schema;

          // The $refs should point to the same object instance
          expect($ref1).to.equal(api.definitions.pet);
          expect($ref2).to.equal(api.definitions.pet);
          expect($ref3).to.equal(api.definitions.pet);
          expect($ref4).to.equal(api.definitions.pet);

          // The $refs should be fully dereferenced
          expect(api.definitions.pet).to.deep.equal(env.dereferenced.pet);

          done();
        });
      }
    );

    it('should resolve matching external references to the same object instance',
      function(done) {
        env.parser.parse(env.getPath('good/external-refs.yaml'), function(err, api) {
          // Three $ref pointers to "pet.yaml"
          var $ref1 = api.paths['/pets'].post.parameters[0].schema;
          var $ref2 = api.paths['/pets'].post.responses['200'].schema;
          var $ref3 = api.paths['/pets'].post.responses.default.schema.properties.pet;

          // The $refs should all point to the same object instance
          expect($ref1).to.equal($ref2);
          expect($ref3).to.equal($ref2);

          // The $refs should be fully dereferenced
          expect($ref1).to.deep.equal(env.dereferenced.pet);

          // There is no "definitions" object, because the definitions are external
          expect(api.definitions).to.be.undefined;

          done();
        });
      }
    );

    it('should resolve different external references to different object instances',
      function(done) {
        env.parser.parse(env.getPath('good/different-file-ext.yaml'), function(err, api) {
          // $ref pointer to "pet.yaml"
          var $ref1 = api.paths['/pets'].post.parameters[0].schema;

          // $ref pointer to "pet.json"
          var $ref2 = api.paths['/pets'].post.responses['200'].schema;

          // $ref pointer to "pet.yml"
          var $ref3 = api.paths['/pets'].post.responses.default.schema;

          // The $refs should all reference different object instances
          expect($ref1).not.to.equal($ref2);
          expect($ref1).not.to.equal($ref3);
          expect($ref2).not.to.equal($ref3);

          // The $refs should all have the same value
          expect($ref1).to.deep.equal(env.dereferenced.pet);
          expect($ref2).to.deep.equal(env.dereferenced.pet);
          expect($ref3).to.deep.equal(env.dereferenced.pet);

          done();
        });
      }
    );

    it('should resolve matching nested references to the same object instance',
      function(done) {
        env.parser.parse(env.getPath('good/nested-refs.yaml'), function(err, api) {
          // $ref pointer to "pet"
          var pet$Ref1 = api.paths['/pets'].post.parameters[0].schema;

          // $ref pointer to "#/definitions/pet"
          var pet$Ref2 = api.paths['/pets'].post.responses['200'].schema;

          // nested $ref pointer to "pet" via "error"
          var pet$Ref3 = api.paths['/pets'].post.responses['404'].schema.properties.pet;

          // nested $ref pointer to "pet" via "errorWrapper" and "#/definitions/error"
          var pet$Ref4 = api.paths['/pets'].post.responses['500'].schema.properties.error.properties.pet;

          // nested $ref pointer to "pet" via "#/definitions/error"
          var pet$Ref5 = api.definitions.error.properties.pet;

          // The "pet" $refs should all point to the same object instance
          expect(pet$Ref1).to.equal(api.definitions.pet);
          expect(pet$Ref2).to.equal(api.definitions.pet);
          expect(pet$Ref3).to.equal(api.definitions.pet);
          expect(pet$Ref4).to.equal(api.definitions.pet);
          expect(pet$Ref5).to.equal(api.definitions.pet);

          // $ref pointer to "error"
          var error$Ref1 = api.paths['/pets'].post.responses['404'].schema;

          // $ref pointer to "#/definitions/error" via "errorWrapper"
          var error$Ref2 = api.paths['/pets'].post.responses['500'].schema.properties.error;

          // $ref pointer to "#/definitions/error"
          var error$Ref3 = api.definitions.errorWrapper.properties.error;

          // The "error" $refs should all point to the same object instance
          expect(error$Ref1).to.equal(api.definitions.error);
          expect(error$Ref2).to.equal(api.definitions.error);
          expect(error$Ref3).to.equal(api.definitions.error);

          // The $refs should be fully dereferenced
          expect(api.definitions.pet).to.deep.equal(env.dereferenced.pet);
          expect(api.definitions.error).to.deep.equal(env.dereferenced.error);

          done();
        });
      }
    );

    it('should resolve array references to the same array instance',
      function(done) {
        env.parser.parse(env.getPath('good/non-object-refs.yaml'), function(err, api) {
          // Two $ref pointers to "#/definitions/pet/properties/type/enum" (an array)
          var $ref1 = api.paths['/pets'].post.parameters[0].schema.properties.type.enum;
          var $ref2 = api.paths['/pets'].post.responses.default.schema.properties.message.enum;

          expect($ref1).to.be.an('array');
          expect($ref2).to.be.an('array');

          // The $refs should all point to the same object instance
          expect($ref1).to.equal(api.definitions.pet.properties.type.enum);
          expect($ref2).to.equal(api.definitions.pet.properties.type.enum);

          // The $refs should be fully dereferenced
          expect($ref1).to.have.members(['cat', 'dog', 'bird']);

          done();
        });
      }
    );
  });

  describe('Failure tests', function() {

    it('should return an error for an invalid shorthand "definition" reference',
      function(done) {
        env.parser.parse(env.getPath('bad/invalid-shorthand-refs.yaml'), function(err, api, metadata) {
          expect(err).to.be.an.instanceOf(SyntaxError);
          expect(err.message).to.contain('"doesnotexist" could not be found');
          expect(api).to.be.null;
          expect(metadata).to.satisfy(env.isMetadata);

          done();
        });
      }
    );

    it('should return an error for an invalid document-relative reference',
      function(done) {
        env.parser.parse(env.getPath('bad/invalid-internal-refs.yaml'), function(err, api, metadata) {
          expect(err).to.be.an.instanceOf(SyntaxError);
          expect(err.message).to.contain('"#/definitions/doesnotexist" could not be found');
          expect(api).to.be.null;
          expect(metadata).to.satisfy(env.isMetadata);

          done();
        });
      }
    );

    it('should return an error for an invalid external reference',
      function(done) {
        env.parser.parse(env.getPath('bad/invalid-external-refs.yaml'), function(err, api, metadata) {
          expect(err).to.be.an.instanceOf(SyntaxError);
          expect(err.message).to.match(/ENOENT|Error downloading file ".*doesnotexist\.yaml"/);
          expect(api).to.be.null;
          expect(metadata).to.satisfy(env.isMetadata);

          done();
        });
      }
    );

    it('should return an error for an empty reference',
      function(done) {
        env.parser.parse(env.getPath('bad/empty-refs.yaml'), function(err, api, metadata) {
          expect(err).to.be.an.instanceOf(SyntaxError);
          expect(err.message).to.contain('Empty $ref pointer');
          expect(api).to.be.null;
          expect(metadata).to.satisfy(env.isMetadata);

          done();
        });
      }
    );

    it('should return an error for an invalid nested reference',
      function(done) {
        env.parser.parse(env.getPath('bad/invalid-nested-ref.yaml'), function(err, api, metadata) {
          expect(err).to.be.an.instanceOf(SyntaxError);
          expect(err.message).to.contain('"doesnotexist" could not be found');
          expect(api).to.be.null;
          expect(metadata).to.satisfy(env.isMetadata);

          done();
        });
      }
    );

    it('should return an error for an invalid nested object',
      function(done) {
        env.parser.parse(env.getPath('bad/invalid-nested-obj.yaml'), function(err, api, metadata) {
          expect(err).to.be.an.instanceOf(SyntaxError);
          expect(err.message).to.contain('"foobar" could not be found');
          expect(api).to.be.null;
          expect(metadata).to.satisfy(env.isMetadata);

          done();
        });
      }
    );

  });

});