Skip to content
Open
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Depending on your setup, you may need to run the above commands with `sudo`.
Simply create a client using your API key. Most of the methods return the JSON response from OneSky as a dictionary:

```python
import onesky.client
from onesky import Client

client = onesky.client.Client(api_key='<your API key>',
api_secret='<your API secret>')
client = Client(api_key='<your API key>',
api_secret='<your API secret>')

status, json_response = client.project_group_list()
# {
Expand Down
2 changes: 2 additions & 0 deletions onesky/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
__version_info__ = ('1', '0', '2')
__version__ = '.'.join(__version_info__)

from onesky.client import Client
10 changes: 5 additions & 5 deletions onesky/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

# python wrapper for OneSky's REST API, see
# https://github.com/onesky/api-documentation-platform
class Client:
class Client(object):

def __init__(self, api_key, api_secret,
api_url=DEFAULT_API_URL,
chunk_size=1,
download_dir='.',
request_callback=None):
self.api_url = api_url
self.api_key = api_key
self.api_secret = api_secret
self.chunk_size = chunk_size
self.download_dir = download_dir
self.request_callback = request_callback

Expand Down Expand Up @@ -77,7 +80,7 @@ def do_http_request(self, relative_url, parameters=None, method='GET',

absolute_filename = os.path.join(self.download_dir, short_filename)
with open(absolute_filename, 'wb') as f:
for chunk in response.iter_content():
for chunk in response.iter_content(chunk_size=self.chunk_size):
f.write(chunk)

response_dict = {'downloaded_filename': absolute_filename}
Expand Down Expand Up @@ -181,9 +184,6 @@ def file_delete(self, project_id, file_name):

################################################################
# translation

# TODO: this doesn't actually work; we need to get the file out of the
# payload that's returned.
def translation_export(self, project_id, locale,
source_file_name, export_file_name=None):
relative_url = 'projects/{}/translations'.format(project_id)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests
import unittest

import onesky.client
from onesky import Client


TEST_API_KEY = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
Expand All @@ -27,6 +27,7 @@ def mock_requests_function(*args, **kwargs):


class ClientTestCase(unittest.TestCase):

def setUp(self):
# we mock out all of the http requests and just make sure the correct
# urls and parameters and such are being passed.
Expand All @@ -38,7 +39,7 @@ def setUp(self):
delete=mock_requests_function)
self.patcher.start()

self.client = onesky.client.Client(TEST_API_KEY, TEST_API_SECRET)
self.client = Client(TEST_API_KEY, TEST_API_SECRET)

def tearDown(self):
del self.client
Expand Down