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 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)