Example #1
0
    def get_variable(self, variable_name, client=None):
        """API call:  get a variable via a ``GET`` request.

        This will return None if the variable doesn't exist::

          >>> from google.cloud import runtimeconfig
          >>> client = runtimeconfig.Client()
          >>> config = client.get_config('my-config')
          >>> print(config.get_varialbe('variable-name'))
          <Variable: my-config, variable-name>
          >>> print(config.get_variable('does-not-exist'))
          None

        :type variable_name: str
        :param variable_name: The name of the variable to retrieve.

        :type client: :class:`~google.cloud.runtimeconfig.client.Client`
        :param client:
            (Optional) The client to use.  If not passed, falls back to the
            ``client`` stored on the current config.

        :rtype: :class:`google.cloud.runtimeconfig.variable.Variable` or None
        :returns: The variable object if it exists, otherwise None.
        """
        client = self._require_client(client)
        variable = Variable(config=self, name=variable_name)
        try:
            variable.reload(client=client)
            return variable
        except NotFound:
            return None
Example #2
0
    def get_variable(self, variable_name, client=None):
        """API call:  get a variable via a ``GET`` request.

        This will return None if the variable doesn't exist::

          >>> from google.cloud import runtimeconfig
          >>> client = runtimeconfig.Client()
          >>> config = client.get_config('my-config')
          >>> print(config.get_varialbe('variable-name'))
          <Variable: my-config, variable-name>
          >>> print(config.get_variable('does-not-exist'))
          None

        :type variable_name: str
        :param variable_name: The name of the variable to retrieve.

        :type client: :class:`~google.cloud.runtimeconfig.client.Client`
        :param client:
            (Optional) The client to use.  If not passed, falls back to the
            ``client`` stored on the current config.

        :rtype: :class:`google.cloud.runtimeconfig.variable.Variable` or None
        :returns: The variable object if it exists, otherwise None.
        """
        client = self._require_client(client)
        variable = Variable(config=self, name=variable_name)
        try:
            variable.reload(client=client)
            return variable
        except NotFound:
            return None
Example #3
0
def _item_to_variable(iterator, resource):
    """Convert a JSON variable to the native object.

    :type iterator: :class:`~google.cloud.iterator.Iterator`
    :param iterator: The iterator that has retrieved the item.

    :type resource: dict
    :param resource: An item to be converted to a variable.

    :rtype: :class:`.Variable`
    :returns: The next variable in the page.
    """
    return Variable.from_api_repr(resource, iterator.config)
Example #4
0
def _item_to_variable(iterator, resource):
    """Convert a JSON variable to the native object.

    :type iterator: :class:`~google.cloud.iterator.Iterator`
    :param iterator: The iterator that has retrieved the item.

    :type resource: dict
    :param resource: An item to be converted to a variable.

    :rtype: :class:`.Variable`
    :returns: The next variable in the page.
    """
    return Variable.from_api_repr(resource, iterator.config)
Example #5
0
    def variable(self, variable_name):
        """Factory constructor for variable object.

        .. note::
          This will not make an HTTP request; it simply instantiates
          a variable object owned by this config.

        :type variable_name: str
        :param variable_name: The name of the variable to be instantiated.

        :rtype: :class:`google.cloud.runtimeconfig.variable.Variable`
        :returns: The variable object created.
        """
        return Variable(name=variable_name, config=self)