Example #1
0
 def _first_rpc_result(self, result):
   """result is returned from make_rpc. Get the first data record
   or throw an exception if it was an error. Ignore responses to
   NOTIFY_OP_ID."""
   result = [record for record in result if record['id'] != ops.NOTIFY_OP_ID]
   if not result:
     raise errors.RpcError('No results found.')
   result = result[0]
   error = result.get('error')
   if error:
     raise errors.RpcError(str(error['code'])
         + ': ' + error['message'])
   data = result.get('data')
   if data is not None:
     return data
   raise errors.Error('RPC Error: No data record.')
Example #2
0
  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'}
    headers.update(oauth_request.to_header());
    status, content = self._http_post(
         url=self._server_rpc_base,
         data=data,
         headers=headers)

    if status != 200:
      raise errors.RpcError('code: %s\n%s' % (status, content))
    return simplejson.loads(content)