class Bandwidth::WebRtc::APIController

APIController

Public Class Methods

new(config, http_call_back: nil) click to toggle source
Calls superclass method Bandwidth::BaseController::new
# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 10
def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Public Instance Methods

add_participant_to_session(account_id, session_id, participant_id, body: nil) click to toggle source

Add a participant to a session Subscriptions can optionally be provided as part of this call @param [String] account_id Required parameter: Account ID @param [String] session_id Required parameter: Session ID @param [String] participant_id Required parameter: Participant ID @param [Subscriptions] body Optional parameter: Subscriptions the participant should be created with @return [void] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 439
def add_participant_to_session(account_id,
                               session_id,
                               participant_id,
                               body: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false },
    'sessionId' => { 'value' => session_id, 'encode' => false },
    'participantId' => { 'value' => participant_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'content-type' => 'application/json; charset=utf-8'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.put(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  elsif _response.status_code == 404
    raise APIException.new(
      'Not Found',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  ApiResponse.new(_response)
end
create_participant(account_id, body: nil) click to toggle source

Create a new participant under this account Participants are idempotent, so relevant parameters must be set in this function if desired @param [String] account_id Required parameter: Account ID @param [Participant] body Optional parameter: Participant parameters @return [AccountsParticipantsResponse] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 20
def create_participant(account_id,
                       body: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/participants'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'content-type' => 'application/json; charset=utf-8'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 400
    raise APIException.new(
      'Bad Request',
      _response
    )
  elsif _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  ApiResponse.new(
    _response,
    data: AccountsParticipantsResponse.from_hash(decoded)
  )
end
create_session(account_id, body: nil) click to toggle source

Create a new session Sessions are idempotent, so relevant parameters must be set in this function if desired @param [String] account_id Required parameter: Account ID @param [Session] body Optional parameter: Session parameters @return [Session] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 198
def create_session(account_id,
                   body: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/sessions'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'content-type' => 'application/json; charset=utf-8'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 400
    raise APIException.new(
      'Bad Request',
      _response
    )
  elsif _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  ApiResponse.new(
    _response, data: Session.from_hash(decoded)
  )
end
delete_participant(account_id, participant_id) click to toggle source

Delete participant by ID @param [String] account_id Required parameter: Account ID @param [String] participant_id Required parameter: Example: @return [void] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 144
def delete_participant(account_id,
                       participant_id)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/participants/{participantId}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false },
    'participantId' => { 'value' => participant_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare and execute HttpRequest.
  _request = config.http_client.delete(
    _query_url
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  elsif _response.status_code == 404
    raise APIException.new(
      'Not Found',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  ApiResponse.new(_response)
end
delete_session(account_id, session_id) click to toggle source

Delete session by ID @param [String] account_id Required parameter: Account ID @param [String] session_id Required parameter: Session ID @return [void] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 321
def delete_session(account_id,
                   session_id)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false },
    'sessionId' => { 'value' => session_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare and execute HttpRequest.
  _request = config.http_client.delete(
    _query_url
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  elsif _response.status_code == 404
    raise APIException.new(
      'Not Found',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  ApiResponse.new(_response)
end
get_participant(account_id, participant_id) click to toggle source

Get participant by ID @param [String] account_id Required parameter: Account ID @param [String] participant_id Required parameter: Participant ID @return [Participant] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 83
def get_participant(account_id,
                    participant_id)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/participants/{participantId}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false },
    'participantId' => { 'value' => participant_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  elsif _response.status_code == 404
    raise APIException.new(
      'Not Found',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  ApiResponse.new(
    _response, data: Participant.from_hash(decoded)
  )
end
get_participant_subscriptions(account_id, session_id, participant_id) click to toggle source

Get a participant's subscriptions @param [String] account_id Required parameter: Account ID @param [String] session_id Required parameter: Session ID @param [String] participant_id Required parameter: Participant ID @return [Subscriptions] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 559
def get_participant_subscriptions(account_id,
                                  session_id,
                                  participant_id)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false },
    'sessionId' => { 'value' => session_id, 'encode' => false },
    'participantId' => { 'value' => participant_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  elsif _response.status_code == 404
    raise APIException.new(
      'Not Found',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  ApiResponse.new(
    _response, data: Subscriptions.from_hash(decoded)
  )
end
get_session(account_id, session_id) click to toggle source

Get session by ID @param [String] account_id Required parameter: Account ID @param [String] session_id Required parameter: Session ID @return [Session] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 260
def get_session(account_id,
                session_id)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false },
    'sessionId' => { 'value' => session_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  elsif _response.status_code == 404
    raise APIException.new(
      'Not Found',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  ApiResponse.new(
    _response, data: Session.from_hash(decoded)
  )
end
list_session_participants(account_id, session_id) click to toggle source

List participants in a session @param [String] account_id Required parameter: Account ID @param [String] session_id Required parameter: Session ID @return [List of Participant] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 373
def list_session_participants(account_id,
                              session_id)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false },
    'sessionId' => { 'value' => session_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  elsif _response.status_code == 404
    raise APIException.new(
      'Not Found',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  ApiResponse.new(
    _response,
    data: decoded.map { |element| Participant.from_hash(element) }
  )
end
remove_participant_from_session(account_id, session_id, participant_id) click to toggle source

Remove a participant from a session This will automatically remove any subscriptions the participant has associated with this session @param [String] account_id Required parameter: Account ID @param [String] session_id Required parameter: Session ID @param [String] participant_id Required parameter: Participant ID @return [void] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 504
def remove_participant_from_session(account_id,
                                    session_id,
                                    participant_id)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false },
    'sessionId' => { 'value' => session_id, 'encode' => false },
    'participantId' => { 'value' => participant_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare and execute HttpRequest.
  _request = config.http_client.delete(
    _query_url
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  elsif _response.status_code == 404
    raise APIException.new(
      'Not Found',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  ApiResponse.new(_response)
end
update_participant_subscriptions(account_id, session_id, participant_id, body: nil) click to toggle source

Update a participant's subscriptions This is a full update that will replace the participant's subscriptions. First call `getParticipantSubscriptions` if you need the current subscriptions. Call this function with no `Subscriptions` object to remove all subscriptions @param [String] account_id Required parameter: Account ID @param [String] session_id Required parameter: Session ID @param [String] participant_id Required parameter: Participant ID @param [Subscriptions] body Optional parameter: Initial state @return [void] response from the API call

# File lib/bandwidth/web_rtc_lib/web_rtc/controllers/api_controller.rb, line 628
def update_participant_subscriptions(account_id,
                                     session_id,
                                     participant_id,
                                     body: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri(Server::WEBRTCDEFAULT)
  _query_builder << '/accounts/{accountId}/sessions/{sessionId}/participants/{participantId}/subscriptions'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'accountId' => { 'value' => account_id, 'encode' => false },
    'sessionId' => { 'value' => session_id, 'encode' => false },
    'participantId' => { 'value' => participant_id, 'encode' => false }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'content-type' => 'application/json; charset=utf-8'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.put(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  WebRtcBasicAuth.apply(config, _request)
  _response = execute_request(_request)

  # Validate response against endpoint and global error codes.
  if _response.status_code == 400
    raise APIException.new(
      'Bad Request',
      _response
    )
  elsif _response.status_code == 401
    raise APIException.new(
      'Unauthorized',
      _response
    )
  elsif _response.status_code == 403
    raise APIException.new(
      'Access Denied',
      _response
    )
  elsif _response.status_code == 404
    raise APIException.new(
      'Not Found',
      _response
    )
  end
  unless _response.status_code.between?(200, 208)
    raise ErrorException.new(
      'Unexpected Error',
      _response
    )
  end
  validate_response(_response)

  # Return appropriate response type.
  ApiResponse.new(_response)
end