Skip to content

Commit

Permalink
Merge pull request #4 from /issues/3
Browse files Browse the repository at this point in the history
Issues/3
  • Loading branch information
pferate committed Mar 3, 2016
2 parents b72b133 + 06c4b29 commit 7a10b46
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
Changelog
---------

v0.1.1 2016-03-03
=================

* Adding MeetupObjectList, for handling multiple MeetupObjects

v0.1 2016-02-04
=================

Expand Down
2 changes: 1 addition & 1 deletion meetup/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

__version__ = '0.1'
__version__ = '0.1.1'
26 changes: 25 additions & 1 deletion meetup/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@
DEFAULT_WAIT_TIME = 30


class MeetupObjectList(list):
"""
A custom, iterative list for MeetupObjects.
Items are stored as raw, jsonified API Responses. Items are converted to MeetupObjects on the fly.
"""
def __init__(self, initial_list):
self.items = initial_list

def __len__(self):
return len(self.items)

def __getitem__(self, key):
return MeetupObject(self.items[key])

def __iter__(self):
for item in self.items:
yield MeetupObject(item)


class MeetupObject(object):
"""
Generic Meetup Object generated from dict and keyword arguments.
Expand Down Expand Up @@ -160,4 +180,8 @@ def _call(self, service_name, parameters=None, **kwargs):
else:
raise exceptions.HttpTooManyRequests(response.content)

return MeetupObject(response.json())
jsonified = response.json()
if isinstance(jsonified, list):
return MeetupObjectList(jsonified)
else:
return MeetupObject(jsonified)
15 changes: 15 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from meetup.api import Client, MeetupObject, MeetupObjectList


@pytest.fixture
def api_client():
return Client()


def test_get_find_groups(api_client):
find_group_info = api_client.GetFindGroups()
assert isinstance(find_group_info, MeetupObjectList)
assert isinstance(find_group_info[0], MeetupObject)
assert isinstance(find_group_info[-1], MeetupObject)

0 comments on commit 7a10b46

Please sign in to comment.