How to use the ops.OperationQueue function in ops

To help you get started, we’ve selected a few ops examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SwellRT / swellrt / src / python / api / waveservice.py View on Github external
Args:
      json: a json object or string containing at least a key
        wavelet defining the wavelet and a key blips defining the
        blips in the view.

      proxy_for_id: the proxying information that will be set on the wavelet's
        operation queue.

    Returns:
      A new wavelet with its own operation queue. It the
      responsibility of the caller to make sure this wavelet gets
      submited to the server, either by calling robot.submit() or
      by calling .submit_with() on the returned wavelet.
    """
    util.check_is_valid_proxy_for_id(proxy_for_id)
    return self._wavelet_from_json(json, ops.OperationQueue(proxy_for_id))
github chrismdp / pushy / waveapi / robot.py View on Github external
"""Use the REST interface to fetch a wave and return it.

    The returned wavelet contains a snapshot of the state of the
    wavelet at that point. It can be used to modify the wavelet,
    but the wavelet might change in between, so treat carefully.

    Also note that the wavelet returned has its own operation
    queue. It the responsibility of the caller to make sure this
    wavelet gets submited to the server, either by calling
    robot.submit() or by calling .submit_with() on the returned
    wavelet.
    """
    operation_queue = ops.OperationQueue(proxy_for_id)
    operation_queue.robot_fetch_wave(wave_id, wavelet_id)
    result = self._first_rpc_result(self.make_rpc(operation_queue))
    return self._wavelet_from_json(result, ops.OperationQueue(proxy_for_id))
github melmothx / jsonbot / jsb / upload / waveapi / robot.py View on Github external
"""Use the REST interface to fetch a wave and return it.

    The returned wavelet contains a snapshot of the state of the
    wavelet at that point. It can be used to modify the wavelet,
    but the wavelet might change in between, so treat carefully.

    Also note that the wavelet returned has its own operation
    queue. It the responsibility of the caller to make sure this
    wavelet gets submited to the server, either by calling
    robot.submit() or by calling .submit_with() on the returned
    wavelet.
    """
    operation_queue = ops.OperationQueue(proxy_for_id)
    operation_queue.robot_fetch_wave(wave_id, wavelet_id)
    result = self._first_rpc_result(self.make_rpc(operation_queue))
    return self._wavelet_from_json(result, ops.OperationQueue(proxy_for_id))
github SwellRT / swellrt / src / python / api / waveservice.py View on Github external
def make_rpc(self, operations):
    """Make an rpc call, submitting the specified operations."""

    rpc_host = urlparse.urlparse(self._server_rpc_base).netloc

    # We either expect an operationqueue, a single op or a list
    # of ops:
    if (not isinstance(operations, ops.OperationQueue)):
      if not isinstance(operations, list):
        operations = [operations]
      queue = ops.OperationQueue()
      queue.copy_operations(operations)
    else:
      queue = operations


    data = simplejson.dumps(queue.serialize(method_prefix='wave'))

    oauth_request = oauth.OAuthRequest.from_consumer_and_token(self._consumer,
         token=self._access_token, http_method='POST',
         http_url=self._server_rpc_base)
    oauth_request.sign_request(WaveService.SIGNATURE_METHOD,
         self._consumer, self._access_token)

    logging.info('Active URL: %s'  % self._server_rpc_base)
    logging.info('Active Outgoing: %s' % data)
    headers = {'Content-Type': 'application/json'}
github melmothx / jsonbot / jsb / upload / waveapi / robot.py View on Github external
def make_rpc(self, operations):
    """Make an rpc call, submitting the specified operations."""

    if not oauth or not self._oauth_consumer.key:
      raise errors.Error('OAuth has not been configured')
    if (not type(operations) == list and
        not isinstance(operations, ops.OperationQueue)):
      operations = [operations]

    rpcs = [op.serialize(method_prefix='wave') for op in operations]

    post_body = simplejson.dumps(rpcs)
    body_hash = self._hash(post_body)
    params = {
      'oauth_consumer_key': 'google.com:' + self._oauth_consumer.key,
      'oauth_timestamp': oauth.generate_timestamp(),
      'oauth_nonce': oauth.generate_nonce(),
      'oauth_version': oauth.OAuthRequest.version,
      'oauth_body_hash': body_hash,
    }
    oauth_request = oauth.OAuthRequest.from_request('POST',
                                                    self._server_rpc_base,
                                                    parameters=params)
github SwellRT / swellrt / src / python / api / robot.py View on Github external
def process_events(self, json):
    """Process an incoming set of events encoded as json."""
    parsed = simplejson.loads(json)
    pending_ops = ops.OperationQueue()
    event_wavelet = self.get_waveservice()._wavelet_from_json(parsed, pending_ops)

    for event_data in parsed['events']:
      for payload in self._handlers.get(event_data['type'], []):
        handler, event_class, context, filter = payload
        event = event_class(event_data, event_wavelet)
        handler(event, event_wavelet)

    pending_ops.set_capability_hash(self.capabilities_hash())
    return simplejson.dumps(pending_ops.serialize())
github melmothx / jsonbot / jsb / upload / waveapi / robot.py View on Github external
where the robot is calling new_wave outside of an
          event or when the server is handling multiple domains.

      participants: initial participants on the wave. The robot
          as the creator of the wave is always added.

      message: a string that will be passed back to the robot
          when the WAVELET_CREATOR event is fired. This is a
          lightweight way to pass around state.

      submit: if true, use the active gateway to make a round
          trip to the server. This will return immediately an
          actual waveid/waveletid and blipId for the root blip.

    """
    operation_queue = ops.OperationQueue(proxy_for_id)
    if not isinstance(message, basestring):
      message = simplejson.dumps(message)

    blip_data, wavelet_data = operation_queue.robot_create_wavelet(
        domain=domain,
        participants=participants,
        message=message)

    blips = {}
    root_blip = blip.Blip(blip_data, blips, operation_queue)
    blips[root_blip.blip_id] = root_blip
    created = wavelet.Wavelet(wavelet_data,
                              blips=blips,
                              robot=self,
                              operation_queue=operation_queue)
    if submit:
github chrismdp / pushy / waveapi / robot.py View on Github external
def make_rpc(self, operations):
    """Make an rpc call, submitting the specified operations."""

    if not oauth or not self._oauth_consumer.key:
      raise errors.Error('OAuth has not been configured')
    if (not type(operations) == list and
        not isinstance(operations, ops.OperationQueue)):
      operations = [operations]

    rpcs = [op.serialize(method_prefix='wave') for op in operations]

    post_body = simplejson.dumps(rpcs)
    body_hash = self._hash(post_body)
    params = {
      'oauth_consumer_key': 'google.com:' + self._oauth_consumer.key,
      'oauth_timestamp': oauth.generate_timestamp(),
      'oauth_nonce': oauth.generate_nonce(),
      'oauth_version': oauth.OAuthRequest.version,
      'oauth_body_hash': body_hash,
    }
    oauth_request = oauth.OAuthRequest.from_request('POST',
                                                    self._server_rpc_base,
                                                    parameters=params)
github SwellRT / swellrt / src / python / api / waveservice.py View on Github external
event or when the server is handling multiple domains.

      participants: initial participants on the wave. The robot
          as the creator of the wave is always added.

      message: a string that will be passed back to the robot
          when the WAVELET_CREATOR event is fired. This is a
          lightweight way to pass around state.

      submit: if true, use the active gateway to make a round
          trip to the server. This will return immediately an
          actual waveid/waveletid and blipId for the root blip.

    """
    util.check_is_valid_proxy_for_id(proxy_for_id)
    operation_queue = ops.OperationQueue(proxy_for_id)
    if not isinstance(message, basestring):
      message = simplejson.dumps(message)

    # Create temporary wavelet data
    blip_data, wavelet_data = operation_queue.robot_create_wavelet(
        domain=domain,
        participants=participants,
        message=message)

    # Create temporary blips dictionary
    blips = {}
    root_blip = blip.Blip(blip_data, blips, operation_queue)
    blips[root_blip.blip_id] = root_blip

    if submit:
      # Submit operation to server and return actual wave/blip IDs