This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

misc updates:

- finish paging refactoring (startIndex/count)
- fix wrong link in XRDS file
- TODOs due to facebook's TOS
  • Loading branch information...
snarfed committed Mar 12, 2012
1 parent f78d1ba commit 2841628e54607a55ab2011e40568f6921d1ddc35
Showing with 14 additions and 78 deletions.
  1. +11 −0 README
  2. +1 −6 facebook.py
  3. +1 −32 facebook_test.py
  4. +1 −1 templates/host-meta.xrds
  5. +0 −39 twitter_test.py
View
11 README
@@ -44,3 +44,14 @@ rm -f app.yaml && ln -s app.yaml.twitter app.yaml && \
~/google_appengine/appcfg.py update . && \
rm -f app.yaml && ln -s app.yaml.facebook app.yaml && \
~/google_appengine/appcfg.py update .
+
+
+TODO: tweaks to comply with Facebook's TOS:
+
+- can't use user ids; switch to User.third_party_id
+https://developers.facebook.com/policy/#data
+https://developers.facebook.com/docs/reference/api/user/
+
+- can only use friend connections if *both* users have opted into app:
+https://developers.facebook.com/policy/#data
+
View
@@ -69,7 +69,6 @@ class Facebook(source.Source):
"""
DOMAIN = 'facebook.com'
- ITEMS_PER_PAGE = 100
FRONT_PAGE_TEMPLATE = 'templates/facebook_index.html'
AUTH_URL = '&'.join((
('http://localhost:8000/dialog/oauth/?'
@@ -100,12 +99,8 @@ def get_contacts(self, user_id=None, start_index=0, count=0):
resp = self.urlfetch(API_USER_URL % user_id)
friends = [json.loads(resp)]
else:
- if count == 0:
- limit = self.ITEMS_PER_PAGE - start_index
- else:
- limit = min(count, self.ITEMS_PER_PAGE)
batch = urllib.urlencode({'batch': API_FRIENDS_BATCH_REQUESTS %
- {'offset': start_index, 'limit': limit}})
+ {'offset': start_index, 'limit': count}})
resp = self.urlfetch(API_URL, payload=batch, method='POST')
# the batch response is a list of responses to the individual batch
# requests, e.g.
View
@@ -17,7 +17,7 @@
import testutil
DEFAULT_BATCH_REQUEST = urllib.urlencode(
- {'batch': facebook.API_FRIENDS_BATCH_REQUESTS % {'offset': 0, 'limit': 100}})
+ {'batch': facebook.API_FRIENDS_BATCH_REQUESTS % {'offset': 0, 'limit': 0}})
class FacebookTest(testutil.HandlerTest):
@@ -244,34 +244,3 @@ def test_to_poco_work_projects_without_start_and_end_date(self):
org = contact['organizations'][0]
self.assertEqual(None, org['startDate'])
self.assertEqual('2010-01', org['endDate'])
-
- def _test_paging(self, start_index, count, expected_offset, expected_limit):
- batch = facebook.API_FRIENDS_BATCH_REQUESTS % {
- 'offset': expected_offset,
- 'limit': expected_limit}
- def comp(actual):
- """Mox comparator that compares expected string batch request to actual
- url-encoded POST payload."""
- self.assert_equals(json.loads(batch),
- json.loads(urlparse.parse_qs(actual)['batch'][0]))
- return True
-
- self.expect_urlfetch('https://graph.facebook.com/',
- '[null, {"body": "{}"}]',
- payload=mox.Func(comp),
- method='POST')
- self.mox.ReplayAll()
- self.facebook.get_contacts(start_index=start_index, count=count)
-
- def test_paging_defaults(self):
- self._test_paging(0, 0, 0, facebook.Facebook.ITEMS_PER_PAGE)
-
- def test_paging_count_too_big(self):
- self._test_paging(0, facebook.Facebook.ITEMS_PER_PAGE + 1,
- 0, facebook.Facebook.ITEMS_PER_PAGE)
-
- def test_paging_start_index_subtracts_from_limit(self):
- self._test_paging(3, 0, 3, facebook.Facebook.ITEMS_PER_PAGE - 3)
-
- def test_paging_start_index_with_count(self):
- self._test_paging(2, 4, 2, 4)
View
@@ -4,7 +4,7 @@
<Type>xri://$xrds*simple</Type>
<Service>
<Type>http://portablecontacts.net/spec/1.0</Type>
- <URI>https://{{ host }}/.well-known/host-meta.xrds</URI>
+ <URI>https://{{ host }}/</URI>
</Service>
</XRD>
</XRDS>
View
@@ -140,42 +140,3 @@ def test_to_poco_full(self):
'url': 'http://snarfed.org/',
'utc_offset': -28800,
}))
-
- # def _test_paging(self, ids, **get_contacts_kwargs):
- # self.expect_urlfetch(
- # 'https://api.twitter.com/1/account/verify_credentials.json',
- # '{"id": 0, "friends_count": 5}')
- # self.expect_urlfetch(
- # 'https://api.twitter.com/1/friends/ids.json?user_id=0',
- # '{"ids": [1, 2, 3]} ')
- # if ids:
- # ids_str = ','.join(str(id) for id in ids)
- # self.expect_urlfetch(
- # 'https://api.twitter.com/1/users/lookup.json?user_id=%s' % ids_str,
- # json.dumps([{'id': id} for id in ids]))
- # self.mox.ReplayAll()
-
- # self.assert_equals(
- # [{'id': str(id), 'accounts': [{'domain': 'twitter.com', 'userid': str(id)}]}
- # for id in ids],
- # self.twitter.get_contacts(**get_contacts_kwargs)[1])
-
- # def test_start_index(self):
- # self._test_paging([2, 3], start_index=1)
-
- # def test_start_index_at_end(self):
- # self._test_paging([], start_index=3)
-
- # def test_count(self):
- # self._test_paging([1, 2], count=2)
-
- # def test_count_too_big(self):
- # try:
- # orig_items_per_page = twitter.Twitter.ITEMS_PER_PAGE
- # twitter.Twitter.ITEMS_PER_PAGE = 2
- # self._test_paging([1, 2], count=4)
- # finally:
- # twitter.Twitter.ITEMS_PER_PAGE = orig_items_per_page
-
- # def test_start_index_and_count(self):
- # self._test_paging([2], start_index=1, count=1)

0 comments on commit 2841628

Please sign in to comment.