Skip to content
Closed

wip #70

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kbcstorage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""

from kbcstorage.buckets import Buckets
from kbcstorage.components import Components
from kbcstorage.configurations import Configurations
from kbcstorage.workspaces import Workspaces
from kbcstorage.jobs import Jobs
from kbcstorage.tables import Tables
Expand Down Expand Up @@ -31,6 +33,8 @@ def __init__(self, api_domain, token):
self.jobs = Jobs(self.root_url, self.token)
self.tables = Tables(self.root_url, self.token)
self.workspaces = Workspaces(self.root_url, self.token)
self.components = Components(self.root_url, self.token)
self.configurations = Configurations(self.root_url, self.token)

@property
def token(self):
Expand Down
46 changes: 46 additions & 0 deletions kbcstorage/components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
Manages calls to the Storage API relating to configurations

Full documentation `here`.

.. _here:
http://docs.keboola.apiary.io/#reference/tables/
"""
import tempfile
import os
from kbcstorage.base import Endpoint
from kbcstorage.files import Files
from kbcstorage.jobs import Jobs


class Components(Endpoint):
"""
Components Endpoint
"""
def __init__(self, root_url, token):
"""
Create a Component endpoint.

Args:
root_url (:obj:`str`): The base url for the API.
token (:obj:`str`): A storage API key.
"""
super().__init__(root_url, 'branch/default/components', token)

def detail(self, component_id, configuration_id):
"""
Retrieves information about a given configuration.

Args:
component_id (str): The id of the component.
configuration_id (str): The id of the configuration.

Raises:
requests.HTTPError: If the API request fails.
"""
if not isinstance(component_id, str) or component_id == '':
raise ValueError("Invalid component_id '{}'.".format(component_id))
if not isinstance(configuration_id, str) or configuration_id == '':
raise ValueError("Invalid component_id '{}'.".format(configuration_id))
url = '{}/{}/configs/{}'.format(self.base_url, component_id, configuration_id)
return self._get(url)
43 changes: 43 additions & 0 deletions kbcstorage/configurations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Manages calls to the Storage API relating to configurations

Full documentation `here`.

.. _here:
http://docs.keboola.apiary.io/#reference/tables/
"""
import tempfile
import os
from kbcstorage.base import Endpoint
from kbcstorage.files import Files
from kbcstorage.jobs import Jobs


class Configurations(Endpoint):
"""
Configurations Endpoint
"""
def __init__(self, root_url, token):
"""
Create a Configuration endpoint.

Args:
root_url (:obj:`str`): The base url for the API.
token (:obj:`str`): A storage API key.
"""
super().__init__(root_url, 'branch/default/components', token)

def list(self, include=None):
"""
List all components (and optionally configurations) in a project.

Args:
include (list): Properties to list (configuration, rows, state)
Returns:
response_body: The parsed json from the HTTP response.

Raises:
requests.HTTPError: If the API request fails.
"""
params = {'include': ','.join(include)} if include else {}
return self._get(self.base_url, params=params)
2 changes: 1 addition & 1 deletion kbcstorage/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class Tables(Endpoint):
"""
Buckets Endpoint
Tables Endpoint
"""
def __init__(self, root_url, token):
"""
Expand Down