diff --git a/HISTORY.rst b/HISTORY.rst index 8829781..acecc12 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,10 +3,15 @@ History ------- +3.1.0 (2014-04-24) +------------------ + +* Added control over expansion of response. Documentation at http://www.eventbrite.com/developer/v3/reference/expansions/ + 3.0.5 (2014-04-24) ------------------ -* Removed 'content-type' header from all GET requests +* Removed 'content-type' header from all GET requests. Thank you @xxv for identifying the problem and contributing code. 3.0.4 (2014-03-12) ------------------ diff --git a/eventbrite/__init__.py b/eventbrite/__init__.py index 8d22a2f..e886c4e 100755 --- a/eventbrite/__init__.py +++ b/eventbrite/__init__.py @@ -3,7 +3,7 @@ __author__ = 'Daniel Greenfeld' __email__ = 'danny@eventbrite.com' -__version__ = '3.0.5' +__version__ = '3.1.0' from .client import Eventbrite diff --git a/eventbrite/client.py b/eventbrite/client.py index 8bc7eeb..0037e59 100755 --- a/eventbrite/client.py +++ b/eventbrite/client.py @@ -44,7 +44,7 @@ def headers(self): } return headers - def api(self, method, path, data, expansions=()): + def api(self, method, path, data, expand=()): method = method.strip().lower() if method not in self.allowed_methods: msg = "The '{0}' method is not accepted by the Eventbrite " \ @@ -54,23 +54,37 @@ def api(self, method, path, data, expansions=()): return method(path, data) @objectify - def get(self, path, data=None, expansions=()): + def get(self, path, data=None, expand=()): # Resolves the search result response problem headers = self.headers if headers.has_key('content-type'): headers.pop('content-type') # Get the function path path = format_path(path, self.eventbrite_api_url) + + if data is None: + data = {} + + # Manage expansions + if data.get('expand'): + # Do nothing because expand is already passed in + pass + elif expand: + # Manage expansions + data['expand'] = ','.join(expand) + else: + # Anything else is None + data['expand'] = 'none' return requests.get(path, headers=headers, params=data or {}) @objectify - def post(self, path, data=None, expansions=()): + def post(self, path, data=None): path = format_path(path, self.eventbrite_api_url) json_data = json.dumps(data or {}) return requests.post(path, headers=self.headers, data=json_data) @objectify - def delete(self, path, data=None, expansions=()): + def delete(self, path, data=None): path = format_path(path, self.eventbrite_api_url) json_data = json.dumps(data or {}) return requests.delete(path, headers=self.headers, data=data or {}) diff --git a/eventbrite/models.py b/eventbrite/models.py index be4bca3..4193f98 100644 --- a/eventbrite/models.py +++ b/eventbrite/models.py @@ -16,7 +16,11 @@ class EventbriteObject(dict): def create(cls, response): data = response.json() evbobject = cls(data) - evbobject.resource_uri = response.url + try: + # Strip out URL parameters for resource_uri + evbobject.resource_uri = response.url[:response.url.index('?')] + except ValueError: + evbobject.resource_uri = response.url evbobject.ok = response.ok evbobject.elapsed = response.elapsed evbobject.headers = response.headers diff --git a/setup.py b/setup.py index ab3f04c..583cb5c 100755 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ except ImportError: from distutils.core import setup -__version__ = '3.0.5' +__version__ = '3.1.0' if sys.argv[-1] == 'tag': os.system("git tag -a %s -m 'version %s'" % (__version__, __version__)) diff --git a/tests/integration/test_client.py b/tests/integration/test_client.py index 2f7dea5..00b28db 100644 --- a/tests/integration/test_client.py +++ b/tests/integration/test_client.py @@ -95,6 +95,7 @@ def test_get_user(self): # check that the ID's match self.assertEqual(evbobject.get('id'), USER_ID) + @unittest.skipIf(condition=skip_integration_tests, reason='Needs an OAUTH_TOKEN') def test_webhook_no_internet(self): webhook = { @@ -106,3 +107,15 @@ def test_webhook_no_internet(self): } evbobject = self.eventbrite.webhook_to_object(webhook) self.assertTrue('id' in evbobject) + + + @unittest.skipIf(condition=skip_user_id_tests, reason='Needs a USER_ID') + @unittest.skipIf(condition=skip_integration_tests, reason='Needs an OAUTH_TOKEN') + def test_get_event_expansions(self): + # Get event with no expansions + evbobject = self.eventbrite.get_event('11260994939') + self.assertFalse('ticket_classes' in evbobject) + + # Now get event with ticket_classes expansion + evbobject = self.eventbrite.get_event('11260994939', expand='ticket_classes') + self.assertTrue('ticket_classes' in evbobject) diff --git a/tests/test_client.py b/tests/test_client.py index ddb06a5..77052ea 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -4,11 +4,8 @@ from platform import platform from eventbrite import __version__ -from eventbrite.exceptions import InvalidResourcePath from eventbrite.client import Eventbrite -from .base import unittest, mock - def test_headers(): eventbrite = Eventbrite('12345') @@ -20,4 +17,4 @@ def test_headers(): system=platform(), ) } - assert eventbrite.headers == expected_headers \ No newline at end of file + assert eventbrite.headers == expected_headers