Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
dist/
build/
cloudconvert.egg-info/
*.egg
*.egg
**/__pycache__
5 changes: 5 additions & 0 deletions cloudconvert/cloudconvertrestclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ def default_client():

return __client__

def get_existing_client():
"""Gets an already created client if there is one, None otherwise."""
global __client__
return __client__


def set_config(options=None, **config):
"""Create new default api object with given configuration
Expand Down
14 changes: 7 additions & 7 deletions cloudconvert/resource.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
import urllib
import cloudconvert.utils as util
from cloudconvert.cloudconvertrestclient import default_client
from cloudconvert.cloudconvertrestclient import default_client, get_existing_client


class Resource(object):
Expand Down Expand Up @@ -114,7 +114,7 @@ def find(cls, id):
Usage::
>>> job = Job.find("s9fsf9-s9f9sf9s-ggfgf9-fg9fg")
"""
api_client = default_client()
api_client = get_existing_client() or default_client()

url = util.join_url(cls.path, str(id))
res = api_client.get(url)
Expand All @@ -134,7 +134,7 @@ def all(cls, params=None):
Usage::
>>> tasks_list = tasks.all({'status': 'waiting'})
"""
api_client = default_client()
api_client = get_existing_client() or default_client()

if params is None:
url = cls.path
Expand Down Expand Up @@ -165,7 +165,7 @@ def create(cls, operation=None, payload={}):
>>> task.create(name=TASK_NAME) # return newly created task
"""

api_client = default_client()
api_client = get_existing_client() or default_client()
url = util.join_url('v2', operation or '')
res = api_client.post(url, payload, headers={})

Expand All @@ -182,7 +182,7 @@ def wait(cls, id):
Usage::
>>> job = job.wait("s9fsf9-s9f9sf9s-ggfgf9-fg9fg")
"""
api_client = default_client()
api_client = get_existing_client() or default_client()

url = util.join_url(cls.path, str(id))
res = api_client.get_sync(url)
Expand All @@ -199,7 +199,7 @@ def show(cls, id):
Usage::
>>> job = Job.show("s9fsf9-s9f9sf9s-ggfgf9-fg9fg")
"""
api_client = default_client()
api_client = get_existing_client() or default_client()
url = util.join_url(cls.path, str(id))
res = api_client.get(url)
try:
Expand All @@ -215,7 +215,7 @@ def delete(cls, id):
Usage::
>>> Task.delete(TASK_ID)
"""
api_client = default_client()
api_client = get_existing_client() or default_client()
url = util.join_url(cls.path, str(id))
api_resource = Resource()
new_attributes = api_client.delete(url)
Expand Down