From a95face8505445c8c1137ff89ed681bba49643b4 Mon Sep 17 00:00:00 2001 From: Adi Sieker Date: Wed, 9 Mar 2011 11:00:03 +0100 Subject: [PATCH 1/7] implemented topics and messages. groups now know their topics and topics know their messages. the relevant convore apis are: - /groups/:group_id/topics.json - /topics/:topic_id/messages.json --- convore/api.py | 69 +++++++++++++++++++++++++++++++++++++++++------ convore/models.py | 59 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 118 insertions(+), 10 deletions(-) diff --git a/convore/api.py b/convore/api.py index 16c8861..ef49ad5 100644 --- a/convore/api.py +++ b/convore/api.py @@ -41,7 +41,7 @@ def get(*path, **kwargs): """ Accepts optional error parameter, which will be passed in the event of a non-401 HTTP error. - + api.get('groups') api.get('groups', 'id') api.get('accounts', 'verify') @@ -57,7 +57,7 @@ def get(*path, **kwargs): def post(params, *path): - + url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json') r = requests.post(url, params=params, auth=auth) return _safe_response(r) @@ -78,7 +78,7 @@ class APIError(RuntimeError): def login(username, password): """Configured API Credentials""" global auth - + auth = (username, password) # print requests.auth_manager.__dict__ @@ -120,15 +120,68 @@ class Groups(SyncedList): group = models.Group() group.import_from_api(_group) group.joined = True + group.topics = Topics(group) self.data.append(group) class Topics(SyncedList): - __data_keys__ = [] + __data_keys__ = ['id', 'slug'] - def __init__(self): - pass + def __init__(self, group): + super(Topics, self).__init__() + self.group = group + + def list(self): + return self.data + + def get(self, key): + r = get('topics', key) + + topic = models.Topic() + topic.import_from_api(deserialize(r.content)['topic']) + return topic + + def sync(self): + + self.data = [] + + r = get('groups', self.group.id, 'topics') + for _topic in deserialize(r.content)['topics']: + + topic = models.Topic() + topic.import_from_api(_topic) + topic.messages = Messages(topic) + topic.group = self.group + self.data.append(topic) + +class Messages(SyncedList): + + __data_keys__ = ['id', 'slug'] + + def __init__(self, topic): + super(Messages, self).__init__() + self.topic = topic + + def list(self): + return self.data + + def get(self, key): + r = get('topics', key) + + topic = models.Topic() + topic.import_from_api(deserialize(r.content)['topic']) + return topic + + def sync(self): + + self.data = [] + + r = get('topics', self.topic.id, 'messages') + for _message in deserialize(r.content)['messages']: + + message = models.Message() + message.import_from_api(_message) + message.topic = self.topic + self.data.append(message) - def import_from_api(self, d): - print d diff --git a/convore/models.py b/convore/models.py index 8e55347..3ec00df 100644 --- a/convore/models.py +++ b/convore/models.py @@ -3,7 +3,7 @@ convore.models ~~~~~~~~~~~~~~ - This module implements the internal models for + This module implements the internal models for Convore API object storage. :copyright: (c) 2011 by Kenneth Reitz. @@ -54,7 +54,7 @@ class Group(object): self.id = None self.joined = False - + def import_from_api(self, d): """Constructs Group from Deserialized API Response.""" @@ -88,6 +88,61 @@ class Group(object): def __repr__(self): return '' % (self.slug) +class Topic(object): + """Convore topic object""" + + def __init__(self): + self.id = None + self.name = None + self.slug = None + self.url = None + self.message_count = None + self.unread = None + self.date_created = None + self.date_latest_message = None + self.creator = None + + + def import_from_api(self, data): + self.creator = User() + + self.id = data.get('id', None) + self.name = data.get('name', None) + self.slug = data.get('slug', None) + self.url = data.get('url', None) + self.message_count = data.get('message_count', None) + self.unread = data.get('unread', None) + self.date_created = datetime.utcfromtimestamp( + data.get('date_created', None) + ) + self.date_latest_message = datetime.utcfromtimestamp( + data.get('date_latest_message', None) + ) + self.creator.import_from_api(data.get('creator', None)) + + +class Message(object): + """Convore message object""" + + def __init__(self): + self.id = None + self.message = None + self.date_created = None + self.user = None + + + def import_from_api(self, data): + self.user = User() + + self.id = data.get('id', None) + self.message = data.get('message', None) + self.date_created = datetime.utcfromtimestamp( + data.get('date_created', None) + ) + self.user.import_from_api(data.get('user', None)) + + + class Category(object): def __init__(self): From 3fde1d12e7b0679c04863d4b47cc3bc24e60f607 Mon Sep 17 00:00:00 2001 From: Cole Kowalski Date: Fri, 25 Mar 2011 13:05:53 -0400 Subject: [PATCH 2/7] add convore.packages and convore.packages.anyjson to the setup package list --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3eb3538..95d32ca 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( author='Kenneth Reitz', author_email='me@kennethreitz.com', url='https://github.com/kennethreitz/python-convore', - packages= ['convore'], + packages= ['convore', 'convore.packages', 'convore.packages.anyjson'], install_requires=required, license='ISC', classifiers=( From 06cfdec321af44a026e64f66730e27bf84264181 Mon Sep 17 00:00:00 2001 From: Cole Kowalski Date: Fri, 25 Mar 2011 13:21:32 -0400 Subject: [PATCH 3/7] some attributes need to be set prior to calling the base class' __init__() method. --- convore/api.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/convore/api.py b/convore/api.py index ef49ad5..51c8c3e 100644 --- a/convore/api.py +++ b/convore/api.py @@ -92,10 +92,9 @@ class Groups(SyncedList): __data_keys__ = ['id', 'slug'] def __init__(self): - super(Groups, self).__init__() - self.discover = groups.GroupsDiscover() self.discover.parent = self + super(Groups, self).__init__() def joined(self): """Returns list of Joined groups.""" @@ -129,8 +128,8 @@ class Topics(SyncedList): __data_keys__ = ['id', 'slug'] def __init__(self, group): - super(Topics, self).__init__() self.group = group + super(Topics, self).__init__() def list(self): return self.data @@ -160,8 +159,8 @@ class Messages(SyncedList): __data_keys__ = ['id', 'slug'] def __init__(self, topic): - super(Messages, self).__init__() self.topic = topic + super(Messages, self).__init__() def list(self): return self.data From 77f4b3dfd50b710729839d0e9481a1a37b0cbd75 Mon Sep 17 00:00:00 2001 From: Cole Kowalski Date: Tue, 29 Mar 2011 20:38:17 -0400 Subject: [PATCH 4/7] add myself to the authors file --- AUTHORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 0e132ba..b20bee2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,4 +10,5 @@ Development Lead Patches and Suggestions ``````````````````````` -- The Convore Peeps \ No newline at end of file +- The Convore Peeps +- Cole Kowalski From 1707d7ea7bbb0203a9a8cf027b9eaa0d772e31ba Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 2 Apr 2011 02:51:08 -0400 Subject: [PATCH 5/7] that shouldn't be there --- test.py | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 test.py diff --git a/test.py b/test.py deleted file mode 100644 index 70b08b6..0000000 --- a/test.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import os -from convore import Convore - - -CONVORE_NAME = os.environ.get('CONVORE_NAME', 'requeststest') -CONVORE_PASS = os.environ.get('CONVORE_PASS', 'requeststest') - -convore = Convore(CONVORE_NAME, CONVORE_PASS) - -#print convore.groups.discover.category -convore.groups.discover.search('github') From 785103218d1531c5bdd9cec4a55f04c727617ba6 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 14 May 2011 14:34:10 -0400 Subject: [PATCH 6/7] Requests v0.3.4 --- reqs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reqs.txt b/reqs.txt index 31f7773..6f05da3 100644 --- a/reqs.txt +++ b/reqs.txt @@ -1,2 +1,2 @@ -requests=0.3.0 +requests=0.3.4 unittest2 \ No newline at end of file From 8143a6c090c4371ef5be9da44af9fc1ffc1c3874 Mon Sep 17 00:00:00 2001 From: Mahdi Yusuf Date: Mon, 16 May 2011 07:07:02 -0700 Subject: [PATCH 7/7] this is convore not tablib; thought i would get some low hanging fruit. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 8741ff7..47e0f43 100644 --- a/README.rst +++ b/README.rst @@ -61,7 +61,7 @@ Hmm.. :: Installation ------------ -To install tablib, simply: :: +To install convore, simply: :: $ pip install convore