コード例 #1
0
def create_channel(client_id, duration_minutes=None):
  """Create a channel.

  Args:
    client_id: A string to identify this channel on the server side.
    duration_minutes: A string, the maximum number of minutes the channel 
      should be open.
  Returns:
    A token that the client can use to connect to the channel.

  Raises:
    InvalidChannelClientIdError: if clientid is not an instance of str or
        unicode, or if the (utf-8 encoded) string is longer than 64 characters.
    Other errors returned by _ToChannelError
  """


  client_id = _ValidateClientId(client_id)

  request = channel_service_pb.CreateChannelRequest()
  response = channel_service_pb.CreateChannelResponse()

  request.set_application_key(client_id)

  try:
    apiproxy_stub_map.MakeSyncCall(_GetService(),
                                   'CreateChannel',
                                   request,
                                   response)
  except apiproxy_errors.ApplicationError, e:
    raise _ToChannelError(e)
コード例 #2
0
def create_channel(application_key):
  """Create a channel.

  Args:
    application_key: A key to identify this channel on the server side.

  Returns:
    A string id that the client can use to connect to the channel.

  Raises:
    InvalidChannelTimeoutError: if the specified timeout is invalid.
    Other errors returned by _ToChannelError
  """

  request = channel_service_pb.CreateChannelRequest()
  response = channel_service_pb.CreateChannelResponse()

  request.set_application_key(application_key)

  try:
    apiproxy_stub_map.MakeSyncCall(_GetService(),
                                   'CreateChannel',
                                   request,
                                   response)
  except apiproxy_errors.ApplicationError, e:
    raise _ToChannelError(e)
コード例 #3
0
def create_channel(client_id, duration_minutes=None):
    """Create a channel.

  Args:
    client_id: A string to identify this channel on the server side.
    duration_minutes: An int specifying the number of minutes for which the
        returned token should be valid.

  Returns:
    A token that the client can use to connect to the channel.

  Raises:
    InvalidChannelClientIdError: if clientid is not an instance of str or
        unicode, or if the (utf-8 encoded) string is longer than 64 characters.
    InvalidChannelTokenDurationError: if duration_minutes is not a number, less
        than 1, or greater than 1440 (the number of minutes in a day).
    Other errors returned by _ToChannelError
  """

    client_id = _ValidateClientId(client_id)

    if not duration_minutes is None:
        if not isinstance(duration_minutes, (int, long)):
            raise InvalidChannelTokenDurationError(
                'Argument duration_minutes must be integral')
        elif duration_minutes < 1:
            raise InvalidChannelTokenDurationError(
                'Argument duration_minutes must not be less than 1')
        elif duration_minutes > MAXIMUM_TOKEN_DURATION_MINUTES:
            msg = ('Argument duration_minutes must be less than %d' %
                   (MAXIMUM_TOKEN_DURATION_MINUTES + 1))
            raise InvalidChannelTokenDurationError(msg)

    request = channel_service_pb.CreateChannelRequest()
    response = channel_service_pb.CreateChannelResponse()

    request.set_application_key(client_id)
    if not duration_minutes is None:
        request.set_duration_minutes(duration_minutes)

    try:
        apiproxy_stub_map.MakeSyncCall(_GetService(), 'CreateChannel', request,
                                       response)
    except apiproxy_errors.ApplicationError as e:
        raise _ToChannelError(e)

    return response.token()