Class: Azure::ARM::CDN::NameAvailability

Inherits:
Object
  • Object
show all
Includes:
Models, MsRestAzure
Defined in:
lib/azure_mgmt_cdn/name_availability.rb

Overview

Use these APIs to manage Azure CDN resources through the Azure Resource Manager. You must make sure that requests made to these resources are secure. For more information, see <a href=“msdn.microsoft.com/en-us/library/azure/dn790557.aspx”>Authenticating Azure Resource Manager requests.</a>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ NameAvailability

Creates and initializes a new instance of the NameAvailability class.

Parameters:

  • client

    service class for accessing basic functionality.



22
23
24
# File 'lib/azure_mgmt_cdn/name_availability.rb', line 22

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns reference to the CdnManagementClient.

Returns:

  • reference to the CdnManagementClient



27
28
29
# File 'lib/azure_mgmt_cdn/name_availability.rb', line 27

def client
  @client
end

Instance Method Details

#check_name_availability(check_name_availability_input, custom_headers = nil) ⇒ Concurrent::Promise

Check the availability of a resource name. This is needed for resources where name is globally unique (ex: endpoint). With this operation checks if the name is available or not without creating the resource.

check applied to HTTP request.

response.

Parameters:

  • check_name_availability_input (CheckNameAvailabilityInput)

    input to

  • The (Hash{String => String})

    hash of custom headers need to be

Returns:

  • (Concurrent::Promise)

    Promise object which allows to get HTTP



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/azure_mgmt_cdn/name_availability.rb', line 42

def check_name_availability(check_name_availability_input, custom_headers = nil)
  fail ArgumentError, 'check_name_availability_input is nil' if check_name_availability_input.nil?
  check_name_availability_input.validate unless check_name_availability_input.nil?
  fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
  request_headers = {}

  # 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_headers['Content-Type'] = 'application/json; charset=utf-8'
  unless check_name_availability_input.nil?
    check_name_availability_input = CheckNameAvailabilityInput.serialize_object(check_name_availability_input)
  end
  request_content = JSON.generate(check_name_availability_input, quirks_mode: true)
  path_template = '/providers/Microsoft.Cdn/checkNameAvailability'
  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'api-version' => @client.api_version},
      body: request_content,
      headers: request_headers.merge(custom_headers || {})
  }
  request = MsRest::HttpOperationRequest.new(@base_url || @client.base_url, path_template, :post, options)
  promise = request.run_promise do |req|
    @client.credentials.sign_request(req) unless @client.credentials.nil?
  end

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

    # Create Result
    result = MsRestAzure::AzureOperationResponse.new(request, http_response)
    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        unless parsed_response.nil?
          parsed_response = CheckNameAvailabilityOutput.deserialize_object(parsed_response)
        end
        result.body = 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