diff --git a/b2blaze/b2lib.py b/b2blaze/b2lib.py index a5eebdd..8b20f76 100644 --- a/b2blaze/b2lib.py +++ b/b2blaze/b2lib.py @@ -34,5 +34,5 @@ def buckets(self): :return: """ - return B2Buckets(connector=self.connector) + return B2Buckets(connector=self.connector, single_bucket=self.connector.bucket_id) diff --git a/b2blaze/connector.py b/b2blaze/connector.py index be4a3e0..f40eb09 100644 --- a/b2blaze/connector.py +++ b/b2blaze/connector.py @@ -29,6 +29,7 @@ def __init__(self, key_id, application_key): self.download_url = None self.recommended_part_size = None self.api_session = None + self.bucket_id = None #TODO: Part Size self._authorize() @@ -63,6 +64,8 @@ def _authorize(self): self.api_url = result_json['apiUrl'] + API_VERSION self.download_url = result_json['downloadUrl'] + API_VERSION + API.download_file_by_id self.recommended_part_size = result_json['recommendedPartSize'] + if result_json.get('allowed'): + self.bucket_id = result_json['allowed'].get('bucketId', None) self.api_session = requests.Session() self.api_session.headers.update({ 'Authorization': self.auth_token diff --git a/b2blaze/models/bucket_list.py b/b2blaze/models/bucket_list.py index 5ea558f..90f516f 100644 --- a/b2blaze/models/bucket_list.py +++ b/b2blaze/models/bucket_list.py @@ -14,12 +14,14 @@ class B2Buckets(object): public = 'allPublic' private = 'allPrivate' - def __init__(self, connector): + def __init__(self, connector, single_bucket=None): """ :param connector: + :param str single_bucket: If any, the ID of the single bucket that we can list. """ self.connector = connector + self._single_bucket = single_bucket self._buckets_by_name = {} self._buckets_by_id = {} @@ -37,7 +39,10 @@ def _update_bucket_list(self, retrieve=False): :return: """ path = API.list_all_buckets - response = self.connector.make_request(path=path, method='post', account_id_required=True) + params = {} + if self._single_bucket: + params['bucketId'] = self._single_bucket + response = self.connector.make_request(path=path, method='post', account_id_required=True, params=params) if response.status_code == 200: response_json = response.json() buckets = []