Skip to content
Snippets Groups Projects
Commit cd5dd3dc authored by Stéphane Schoorens's avatar Stéphane Schoorens
Browse files

add url function for resource refs #29848

parent 2c7d1b71
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ pod_client.videos.get()
pod_client.videos.get(resource_id=1)
```
Example to send a video
Example to send a video (VIDEO_PATH is the path of the video to upload):
```
pod_client = PodClient(HOST, API_KEY)
......
......@@ -53,9 +53,7 @@ class Resource:
raise Exception('Resource url not supported')
def _request(self, method='GET', resource_id=None, headers={}, params={}, data={}, **request_params):
url = '%s/%s/' % (self.host_url, API_URLS[self.name])
if resource_id:
url = '%s%s/' % (url, resource_id)
url = self.url(resource_id)
headers['Authorization'] = 'Token %s' % self.api_key
try:
response = requests.request(method, url, headers=headers, params=params, data=data, **request_params)
......@@ -67,6 +65,12 @@ class Resource:
return
return response
def url(self, resource_id=None):
url = '%s/%s/' % (self.host_url, API_URLS[self.name])
if resource_id:
url = '%s%s/' % (url, resource_id)
return url
def get(self, resource_id=None, data=None, **request_params):
return self._request('GET', resource_id=resource_id, params=data, **request_params)
......
......@@ -42,6 +42,14 @@ class ResourceTest(TestCase):
success = False
self.assertFalse(success)
def test_url(self):
for resource_name in API_URLS:
resource = Resource(HOST, API_KEY, resource_name)
url = '%s/%s/' % (resource.host_url, API_URLS[resource_name])
url_with_resource = url + '1/'
self.assertEqual(resource.url(), url)
self.assertEqual(resource.url(1), url_with_resource)
def test_get(self):
for resource_name in API_URLS:
resource = Resource(HOST, API_KEY, resource_name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment