Class: Bandwidth::Domain

Inherits:
Object
  • Object
show all
Extended by:
ClientWrapper
Includes:
ApiItem
Defined in:
lib/bandwidth/domain.rb

Overview

The Domain resource allows you create domains, add endpoints to it.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClientWrapper

wrap_client_arg

Methods included from ApiItem

#[], #[]=, #initialize, #to_data

Class Method Details

.create(client, data) ⇒ Domain

Create a domain.

Examples:

domain = Domain.create(client, :name => "domain1")

Parameters:

  • client (Client)

    optional client instance to make requests

  • data (Hash)

    data to create a domain

Returns:



26
27
28
29
30
# File 'lib/bandwidth/domain.rb', line 26

def self.create(client, data)
  headers = client.make_request(:post, client.concat_user_path(DOMAIN_PATH), data)[1]
  id = Client.get_id_from_location_header(headers[:location])
  Domain.new(:id => id, :name => data[:name], :description => data[:description])
end

.list(client) ⇒ Array

Get created domains

Examples:

domains = Domain.list(client)

Parameters:

  • client (Client)

    optional client instance to make requests

Returns:

  • (Array)

    list of domains



13
14
15
16
17
# File 'lib/bandwidth/domain.rb', line 13

def self.list(client)
  client.make_request(:get, client.concat_user_path(DOMAIN_PATH))[0].map do |item|
    Domain.new(item, client)
  end
end

Instance Method Details

#create_endpoint(data) ⇒ EndPoint

Add a endpoint to a domain.

Examples:

endpoint = domain.create_endpoint(:name=>"name", :application_id => "id")

Parameters:

  • data (Hash)

    data to add endpoint to a domain

Returns:



47
48
49
50
51
# File 'lib/bandwidth/domain.rb', line 47

def create_endpoint(data)
  headers = @client.make_request(:post, @client.concat_user_path("#{DOMAIN_PATH}/#{id}/endpoints"), data)[1]
  id = Client.get_id_from_location_header(headers[:location])
  get_endpoint(id)
end

#deleteObject Also known as: destroy

Delete a domain

Examples:

domain.delete()


36
37
38
# File 'lib/bandwidth/domain.rb', line 36

def delete()
  @client.make_request(:delete, @client.concat_user_path("#{DOMAIN_PATH}/#{id}"))[0]
end

#delete_endpoint(endpoint_id) ⇒ Object Also known as: destroy_endpoint

Delete an endpoint

Examples:

domain.delete_endpoint("id")


80
81
82
83
84
# File 'lib/bandwidth/domain.rb', line 80

def delete_endpoint(endpoint_id)
  endpoint = EndPoint.new({:id => endpoint_id}, @client)
  endpoint.domain_id = id
  endpoint.delete()
end

#get_endpoint(endpoint_id) ⇒ EndPoint

Retrieve information about an endpoint

Examples:

endpoint = domain.get_endpoint("id")

Parameters:

  • endpoint_id (String)

    id of endpoint

Returns:



58
59
60
61
62
63
# File 'lib/bandwidth/domain.rb', line 58

def get_endpoint(endpoint_id)
  endpoint = EndPoint.new(@client.make_request(:get, @client.concat_user_path("#{DOMAIN_PATH}/#{id}/endpoints/#{endpoint_id}"))[0],
                       @client)
  endpoint.domain_id = id
  endpoint
end

#get_endpointsArray

List all endpoints from a domain

Examples:

endpoints = domain.get_endpoints()

Returns:

  • (Array)

    array of EndPoint instances



69
70
71
72
73
74
75
# File 'lib/bandwidth/domain.rb', line 69

def get_endpoints()
  @client.make_request(:get, @client.concat_user_path("#{DOMAIN_PATH}/#{id}/endpoints"))[0].map do |i|
    endpoint = EndPoint.new(i, @client)
    endpoint.domain_id = id
    endpoint
  end
end