diff --git a/eventbrite/client.py b/eventbrite/client.py index e71434a..5d1e92f 100755 --- a/eventbrite/client.py +++ b/eventbrite/client.py @@ -27,20 +27,24 @@ class Eventbrite(AccessMethodsMixin): allowed_methods = ['post', 'get', 'delete'] eventbrite_api_url = EVENTBRITE_API_URL + content_type_specified = True def __init__(self, oauth_token): self.oauth_token = oauth_token @property def headers(self): - return { + headers = { "Authorization": "Bearer {0}".format(self.oauth_token), - "content-type": "application/json", "User-Agent": "eventbrite-python-sdk {version} ({system})".format( version=__version__, system=platform(), ) } + # Resolves the search result response problem + if self.content_type_specified: + headers["content-type"] = "application/json" + return headers def api(self, method, path, data, expansions=()): method = method.strip().lower() @@ -185,6 +189,10 @@ def post_event(self, data): return self.post("/events/", data=data) + def event_search(self, **data): + # Resolves the search result response problem + self.content_type_specified = False + return self.get("/events/search/", data=data) def webhook_to_object(self, webhook): """ @@ -208,3 +216,5 @@ def webhook_to_object(self, webhook): payload = self.get(webhook['api_url']) return payload + + diff --git a/tests/integration/test_events.py b/tests/integration/test_events.py index 3ebd602..a7bc4e3 100644 --- a/tests/integration/test_events.py +++ b/tests/integration/test_events.py @@ -61,6 +61,17 @@ def test_post_event(self): # Just for access to see the event, not full authentication self.assertEqual(event['password'], "test") + @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_search_events(self): + data = { + 'location.latitude':'40.4313684', + 'start_date.keyword':'today', + 'location.longitude':'-79.9805005', + 'location.within':'10km' + } + events = self.eventbrite.event_search(**data) + self.assertLess(events['pagination'][u'object_count'], 1000) if __name__ == '__main__': unittest.main()