def setUp(self): self.ably = RestSetup.get_ably_rest(use_binary_protocol=False) # Mocked responses # without headers responses.add(responses.GET, 'http://rest.ably.io/channels/channel_name/ch1', body='[{"id": 0}, {"id": 1}]', status=200, content_type='application/json') # with headers responses.add_callback( responses.GET, 'http://rest.ably.io/channels/channel_name/ch2', self.get_response_callback( headers={ 'link': '<http://rest.ably.io/channels/channel_name/ch2?page=1>; rel="first",' ' <http://rest.ably.io/channels/channel_name/ch2?page=2>; rel="next"' }, body='[{"id": 0}, {"id": 1}]', status=200), content_type='application/json') # start intercepting requests responses.start() self.paginated_result = PaginatedResult.paginated_query( self.ably.http, url='http://rest.ably.io/channels/channel_name/ch1', response_processor=lambda response: response.to_native()) self.paginated_result_with_headers = PaginatedResult.paginated_query( self.ably.http, url='http://rest.ably.io/channels/channel_name/ch2', response_processor=lambda response: response.to_native())
def history(self, limit=None, direction=None, start=None, end=None): qs = {} if limit: if limit > 1000: raise ValueError("The maximum allowed limit is 1000") qs["limit"] = limit if direction: qs["direction"] = direction if start: if isinstance(start, int): qs["start"] = start else: qs["start"] = _ms_since_epoch(start) if end: if isinstance(end, int): qs["end"] = end else: qs["end"] = _ms_since_epoch(end) if "start" in qs and "end" in qs and qs["start"] > qs["end"]: raise ValueError("'end' parameter has to be greater than or equal to 'start'") path = self._path_with_qs("%s/presence/history" % self.__base_path.rstrip("/"), qs) if self.__cipher: presence_handler = make_encrypted_presence_response_handler(self.__cipher, self.__binary) else: presence_handler = make_presence_response_handler(self.__binary) return PaginatedResult.paginated_query(self.__http, path, {}, presence_handler)
def history(self, limit=None, direction=None, start=None, end=None): qs = {} if limit: if limit > 1000: raise ValueError("The maximum allowed limit is 1000") qs['limit'] = limit if direction: qs['direction'] = direction if start: if isinstance(start, int): qs['start'] = start else: qs['start'] = _ms_since_epoch(start) if end: if isinstance(end, int): qs['end'] = end else: qs['end'] = _ms_since_epoch(end) if 'start' in qs and 'end' in qs and qs['start'] > qs['end']: raise ValueError( "'end' parameter has to be greater than or equal to 'start'") path = self._path_with_qs( '%s/presence/history' % self.__base_path.rstrip('/'), qs) if self.__cipher: presence_handler = make_encrypted_presence_response_handler( self.__cipher, self.__binary) else: presence_handler = make_presence_response_handler(self.__binary) return PaginatedResult.paginated_query( self.__http, url=path, response_processor=presence_handler)
def history(self, direction=None, limit=None, start=None, end=None, timeout=None): """Returns the history for this channel""" params = {} if direction: params['direction'] = '%s' % direction if limit: params['limit'] = '%d' % limit if start: params['start'] = self._format_time_param(start) if end: params['end'] = self._format_time_param(end) path = '/channels/%s/history' % self.__name if params: path = path + '?' + urlencode(params) if self.__cipher: message_handler = make_encrypted_message_response_handler(self.__cipher) else: message_handler = message_response_handler return PaginatedResult.paginated_query( self.ably.http, path, None, message_handler )
def stats( self, direction=None, start=None, end=None, params=None, limit=None, paginated=None, unit=None, timeout=None ): """Returns the stats for this application""" params = params or {} if direction: params["direction"] = direction if start: params["start"] = self._format_time_param(start) if end: params["end"] = self._format_time_param(end) if limit: if limit > 1000: raise ValueError("The maximum allowed limit is 1000") params["limit"] = limit if unit: params["unit"] = unit if "start" in params and "end" in params and params["start"] > params["end"]: raise ValueError("'end' parameter has to be greater than or equal to 'start'") url = "/stats" if params: url += "?" + urlencode(params) stats_response_processor = make_stats_response_processor(self.options.use_binary_protocol) return PaginatedResult.paginated_query(self.http, url, None, stats_response_processor)
def history(self, direction=None, limit=None, start=None, end=None, timeout=None): """Returns the history for this channel""" params = {} if direction: params['direction'] = '%s' % direction if limit: if limit > 1000: raise ValueError("The maximum allowed limit is 1000") params['limit'] = '%d' % limit if start: params['start'] = self._format_time_param(start) if end: params['end'] = self._format_time_param(end) path = '/channels/%s/history' % self.__name if params: path = path + '?' + urlencode(params) if self.__cipher: message_handler = make_encrypted_message_response_handler( self.__cipher, self.ably.options.use_binary_protocol) else: message_handler = make_message_response_handler( self.ably.options.use_binary_protocol) return PaginatedResult.paginated_query(self.ably.http, path, None, message_handler)
def history(self, limit=None, direction=None, start=None, end=None): qs = {} if limit: if limit > 1000: raise ValueError("The maximum allowed limit is 1000") qs['limit'] = limit if direction: qs['direction'] = direction if start: if isinstance(start, int): qs['start'] = start else: qs['start'] = _ms_since_epoch(start) if end: if isinstance(end, int): qs['end'] = end else: qs['end'] = _ms_since_epoch(end) if 'start' in qs and 'end' in qs and qs['start'] > qs['end']: raise ValueError("'end' parameter has to be greater than or equal to 'start'") path = self._path_with_qs(self.__base_path + 'presence/history', qs) presence_handler = make_presence_response_handler(self.__cipher) return PaginatedResult.paginated_query( self.__http, url=path, response_processor=presence_handler)
def stats(self, direction=None, start=None, end=None, params=None, limit=None, paginated=None, unit=None, timeout=None): """Returns the stats for this application""" params = params or {} if direction: params["direction"] = direction if start: params["start"] = self._format_time_param(start) if end: params["end"] = self._format_time_param(end) if limit: if limit > 1000: raise ValueError("The maximum allowed limit is 1000") params["limit"] = limit if unit: params["unit"] = unit if 'start' in params and 'end' in params and params['start'] > params['end']: raise ValueError("'end' parameter has to be greater than or equal to 'start'") url = '/stats' if params: url += '?' + urlencode(params) stats_response_processor = make_stats_response_processor( self.options.use_binary_protocol) return PaginatedResult.paginated_query(self.http, url, None, stats_response_processor)
def history(self, direction=None, limit=None, start=None, end=None, timeout=None): """Returns the history for this channel""" params = format_params({}, direction=direction, start=start, end=end, limit=limit) path = self.__base_path + 'messages' + params message_handler = make_message_response_handler(self.__cipher) return PaginatedResult.paginated_query( self.ably.http, url=path, response_processor=message_handler)
def get(self, limit=None): qs = {} if limit: if limit > 1000: raise ValueError("The maximum allowed limit is 1000") qs['limit'] = limit path = self._path_with_qs(self.__base_path + 'presence', qs) presence_handler = make_presence_response_handler(self.__cipher) return PaginatedResult.paginated_query( self.__http, url=path, response_processor=presence_handler)
def list(self, **params): """Returns a PaginatedResult object with the list of DeviceDetails objects, filtered by the given parameters. :Parameters: - `**params`: the parameters used to filter the list """ path = '/push/deviceRegistrations' + format_params(params) return PaginatedResult.paginated_query( self.ably.http, url=path, response_processor=device_details_response_processor)
def list_channels(self, **params): """Returns a PaginatedResult object with the list of PushChannelSubscription objects, filtered by the given parameters. :Parameters: - `**params`: the parameters used to filter the list """ path = '/push/channels' + format_params(params) return PaginatedResult.paginated_query( self.ably.http, url=path, response_processor=channels_response_processor)
def history(self): url = '/presence/history' headers = HttpUtils.default_get_headers(self.__binary) response = self.__http.get(url, headers=headers) # FIXME: Why response is not used here? return PaginatedResult.paginated_query( self.__http, url, headers, presence_response_handler )
def setUp(self): self.ably = AblyRest(key=test_vars["keys"][0]["key_str"], rest_host=test_vars["host"], port=test_vars["port"], tls_port=test_vars["tls_port"], tls=test_vars["tls"], use_binary_protocol=False) # Mocked responses # without headers responses.add(responses.GET, 'http://rest.ably.io/channels/channel_name/ch1', body='[{"id": 0}, {"id": 1}]', status=200, content_type='application/json') # with headers responses.add_callback( responses.GET, 'http://rest.ably.io/channels/channel_name/ch2', self.get_response_callback( headers={ 'link': '<http://rest.ably.io/channels/channel_name/ch2?page=1>; rel="first",' ' <http://rest.ably.io/channels/channel_name/ch2?page=2>; rel="next"' }, body='[{"id": 0}, {"id": 1}]', status=200), content_type='application/json') # start intercepting requests responses.start() self.paginated_result = PaginatedResult.paginated_query( self.ably.http, 'http://rest.ably.io/channels/channel_name/ch1', {}, lambda response: response.to_native()) self.paginated_result_with_headers = PaginatedResult.paginated_query( self.ably.http, 'http://rest.ably.io/channels/channel_name/ch2', {}, lambda response: response.to_native())
def get(self, limit=None): qs = {} if limit: if limit > 1000: raise ValueError("The maximum allowed limit is 1000") qs["limit"] = limit path = self._path_with_qs("%s/presence" % self.__base_path.rstrip("/"), qs) if self.__cipher: presence_handler = make_encrypted_presence_response_handler(self.__cipher, self.__binary) else: presence_handler = make_presence_response_handler(self.__binary) return PaginatedResult.paginated_query(self.__http, path, {}, presence_handler)
def setUp(self): self.ably = AblyRest(key=test_vars["keys"][0]["key_str"], rest_host=test_vars["host"], port=test_vars["port"], tls_port=test_vars["tls_port"], tls=test_vars["tls"], use_binary_protocol=False) # Mocked responses # without headers responses.add(responses.GET, 'http://rest.ably.io/channels/channel_name/ch1', body='[{"id": 0}, {"id": 1}]', status=200, content_type='application/json') # with headers responses.add_callback( responses.GET, 'http://rest.ably.io/channels/channel_name/ch2', self.get_response_callback(headers={ 'link': '<http://rest.ably.io/channels/channel_name/ch2?page=1>; rel="first",' ' <http://rest.ably.io/channels/channel_name/ch2?page=2>; rel="next"' }, body='[{"id": 0}, {"id": 1}]', status=200), content_type='application/json') # start intercepting requests responses.start() self.paginated_result = PaginatedResult.paginated_query( self.ably.http, 'http://rest.ably.io/channels/channel_name/ch1', {}, lambda response: response.to_native()) self.paginated_result_with_headers = PaginatedResult.paginated_query( self.ably.http, 'http://rest.ably.io/channels/channel_name/ch2', {}, lambda response: response.to_native())
def get(self, limit=None): qs = {} if limit: if limit > 1000: raise ValueError("The maximum allowed limit is 1000") qs['limit'] = limit path = self._path_with_qs('%s/presence' % self.__base_path.rstrip('/'), qs) if self.__cipher: presence_handler = make_encrypted_presence_response_handler( self.__cipher, self.__binary) else: presence_handler = make_presence_response_handler(self.__binary) return PaginatedResult.paginated_query( self.__http, url=path, response_processor=presence_handler)
def stats(self, direction=None, start=None, end=None, params=None, limit=None, paginated=None, unit=None, timeout=None): """Returns the stats for this application""" params = format_params(params, direction=direction, start=start, end=end, limit=limit, unit=unit) url = '/stats' + params return PaginatedResult.paginated_query( self.http, url=url, response_processor=stats_response_processor)
def stats(self, direction=None, start=None, end=None, params=None, limit=None, paginated=None, by=None, timeout=None): """Returns the stats for this application""" params = params or {} if direction: params["direction"] = "%s" % direction if start: params["start"] = self._format_time_param(start) if end: params["end"] = self._format_time_param(end) if limit: params["limit"] = "%d" % limit if by: params["by"] = "%s" % by url = '/stats' if params: url += '?' + urlencode(params) return PaginatedResult.paginated_query(self.http, url, None, stats_response_processor)