Permalink
Browse files

updating base to start work on vimeo wrapper

  • Loading branch information...
1 parent 6d58ab7 commit ad3233bd2f1ea7be5826c60f0ea85e557c41df82 @paltman paltman committed Apr 22, 2008
View
@@ -0,0 +1,3 @@
+#!/bin/bash
+pylint -f colorized -i y --ignore=tests pyphanfare
+python run_tests.py
View
@@ -0,0 +1,85 @@
+import ConfigParser
+import os
+
+
+SystemConfigPath = '/etc/pyvimeo.cfg'
+UserConfigPath = '~/.pyvimeo'
+
+class Config(ConfigParser.SafeConfigParser):
+ def __init__(self, path=None, fp=None):
+ ConfigParser.SafeConfigParser.__init__(self)
+
+ if path:
+ self.read(path)
+ elif fp:
+ self.readfp(fp)
+ else:
+ self.read([SystemConfigPath, os.path.expanduser(UserConfigPath)])
+
+ def save_option(self, path, section, option, value):
+ """
+ Write the specified Section.Option to the config file specified by path.
+ Replace any previous value. If the path doesn't exist, create it.
+ Also add the option the the in-memory config.
+
+ Borrowed this code from the boto project. :-) Thanks, Mitch.
+ """
+ config = ConfigParser.SafeConfigParser()
+ config.read(path)
+ if not config.has_section(section):
+ config.add_section(section)
+ config.set(section, option, value)
+ fp = open(path, 'w')
+ config.write(fp)
+ fp.close()
+ if not self.has_section(section):
+ self.add_section(section)
+ self.set(section, option, value)
+
+ def save_user_option(self, section, option, value):
+ self.save_option(os.path.expanduser(UserConfigPath), section, option, value)
+
+ def save_system_option(self, section, option, value):
+ self.save_option(SystemConfigPath, section, option, value)
+
+ def get(self, section, name, default=None):
+ try:
+ val = ConfigParser.SafeConfigParser.get(self, section, name)
+ except Exception, e:
+ print str(e)
+ val = default
+ return val
+
+ def getint(self, section, name, default=0):
+ try:
+ val = ConfigParser.SafeConfigParser.getint(self, section, name)
+ except:
+ val = int(default)
+ return val
+
+ def getfloat(self, section, name, default=0.0):
+ try:
+ val = ConfigParser.SafeConfigParser.getfloat(self, section, name)
+ except:
+ val = float(default)
+ return val
+
+ def getbool(self, section, name, default=False):
+ if self.has_option(section, name):
+ val = self.get(section, name)
+ if val.lower() == 'true':
+ val = True
+ else:
+ val = False
+ else:
+ val = default
+ return val
+
+config = Config()
+
+API_KEY = config.get('Credentials', 'api_key')
+SHARED_SECRET = config.get('Credentials', 'shared_secret')
+API_URL = config.get('Urls', 'starndard_api_url', 'http://www.vimeo.com/api/rest/')
+UPLOAD_URL = config.get('Urls', 'upload_url', 'http://www.vimeo.com/services/upload/')
+AUTH_URL = config.get('Urls', 'auth_url', 'http://www.vimeo.com/services/auth/')
+AUTH_TOKEN = config.get('User', 'auth_token', None)
View
No changes.
No changes.
View
@@ -0,0 +1,113 @@
+from pyvimeo.connection import Connection
+
+class User(Connection):
+ """
+ Represents a Vimeo user, either authenticated as the calling user, or
+ an unauthenticated user in the system.
+
+ Supports the following Vimeo API methods:
+ vimeo.people.findByUserName
+ vimeo.people.findByEmail
+ vimeo.people.getInfo
+ vimeo.people.getPortraitUrl
+ vimeo.people.addContact
+ vimeo.people.removeContact
+ vimeo.people.addSubscription
+ vimeo.people.removeSubscription
+ vimeo.contacts.getList
+ """
+ def __init__(self, authenticate_user=False):
+ super(User, self).__init__()
+
+ self.__userdata = None
+ self.__perms = None
+
+ if authenticate_user:
+ if self.authenticated:
+ self.__get_info(self.auth_data['auth']['user']['id'])
+ self.__perms = self.auth_data['auth']['perms']
+ else:
+ raise Exception("Failed to Authenticate.")
+
+ def __get_info(self, user_id):
+ data = self.make_request('vimeo.people.getInfo', user_id=user_id)
+ if 'stat' in data and data['stat'] == 'ok':
+ self.__userdata = data['person']
+
+ def load_user(self, user_id):
+ self.__get_info(user_id)
+
+ @property
+ def location(self):
+ return self.__userdata['location']
+
+ @property
+ def url(self):
+ return self.__userdata['url']
+
+ @property
+ def number_of_contacts(self):
+ return int(self.__userdata['number_of_contacts'])
+
+ @property
+ def number_of_uploads(self):
+ return int(self.__userdata['number_of_uploads'])
+
+ @property
+ def number_of_likes(self):
+ return int(self.__userdata['number_of_likes'])
+
+ @property
+ def number_of_videos(self):
+ return int(self.__userdata['number_of_videos'])
+
+ @property
+ def number_of_video_appearance(self):
+ return int(self.__userdata['number_of_videos_appears_in'])
+
+ @property
+ def profile_url(self):
+ return self.__userdata['profileurl']
+
+ @property
+ def videos_url(self):
+ return self.__userdata['videosurl']
+
+ @property
+ def is_staff(self):
+ return self.__userdata['is_staff'] == '1'
+
+ @property
+ def id(self):
+ return self.__userdata['id']
+
+ @property
+ def username(self):
+ return self.__userdata['username']
+
+ @property
+ def display_name(self):
+ return self.__userdata['display_name']
+
+ @property
+ def perms(self):
+ return self.__perms
+
+ @staticmethod
+ def find_by_username(username):
+ c = Connection()
+ data = c.make_request('vimeo.people.findByUserName', username=username)
+ if 'stat' in data and data['stat'] == 'ok':
+ u = User()
+ u.load_user(data['user']['id'])
+ return u
+
+ @staticmethod
+ def find_by_email(email):
+ c = Connection()
+ data = c.make_request('vimeo.people.findByEmail', find_email=email)
+ if 'stat' in data and data['stat'] == 'ok':
+ u = User()
+ u.load_user(data['user']['id'])
+ return u
+
No changes.
View
No changes.
No changes.
View
@@ -0,0 +1,18 @@
+import unittest
+import doctest
+
+suite = unittest.TestSuite()
+
+import pyvimeo
+import pyvimeo.connection
+import pyvimeo.exceptions
+import pyvimeo.models
+import pyvimeo.config
+
+suite.addTest(doctest.DocTestSuite(pyvimeo))
+suite.addTest(doctest.DocTestSuite(pyvimeo.connection))
+suite.addTest(doctest.DocTestSuite(pyvimeo.exceptions))
+suite.addTest(doctest.DocTestSuite(pyvimeo.models))
+suite.addTest(doctest.DocTestSuite(pyvimeo.config))
+
+unittest.TextTestRunner(verbosity=2).run(suite)

0 comments on commit ad3233b

Please sign in to comment.