Commit 20da4ac8 authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Implemented friendship endpoints.

parent 9ef0c687
......@@ -2,14 +2,14 @@ import base64
from binder import bind_api
from parsers import *
from models import User, Status, DirectMessage
from models import User, Status, DirectMessage, Friendship
"""Twitter API"""
class API(object):
def __init__(self, username=None, password=None, host='twitter.com', secure=False,
classes={'user': User, 'status': Status,
'direct_message': DirectMessage}):
'direct_message': DirectMessage, 'friendship': Friendship}):
if username and password:
self._b64up = base64.b64encode('%s:%s' % (username, password))
else:
......@@ -138,4 +138,37 @@ class API(object):
require_auth = True
)
"""Create friendship"""
create_friendship = bind_api(
path = '/friendships/create.json',
method = 'POST',
parser = parse_user,
allowed_param = ['id', 'user_id', 'screen_name', 'follow'],
require_auth = True
)
"""Destroy friendship"""
destroy_friendship = bind_api(
path = '/friendships/destroy.json',
method = 'DELETE',
parser = parse_user,
allowed_param = ['id', 'user_id', 'screen_name'],
require_auth = True
)
"""Check if friendship exists"""
exists_friendship = bind_api(
path = '/friendships/exists.json',
parser = parse_bool,
allowed_param = ['user_a', 'user_b']
)
"""Show friendship details"""
show_friendship = bind_api(
path = '/friendships/show.json',
parser = parse_friendship,
allowed_param = ['source_id', 'source_screen_name',
'target_id', 'target_screen_name']
)
api = API('jitterapp', 'josh1987')
......@@ -18,3 +18,7 @@ class DirectMessage(object):
def destroy(self):
return self._api.destroy_direct_message(id=self.id)
class Friendship(object):
pass
......@@ -84,3 +84,23 @@ def parse_directmessages(data, api):
for obj in json.loads(data):
directmessages.append(_parse_dm(obj, api))
return directmessages
def parse_friendship(data, api):
relationship = json.loads(data)['relationship']
# parse source
source = api.classes['friendship']()
for k,v in relationship['source'].items():
setattr(source, k, v)
# parse target
target = api.classes['friendship']()
for k,v in relationship['target'].items():
setattr(target, k, v)
return source, target
def parse_bool(data, api):
return json.loads(data)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment