Skip to content

Commit

Permalink
updating base to start work on vimeo wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
paltman committed Apr 22, 2008
1 parent cf5fbe8 commit 6d58ab7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 283 deletions.
106 changes: 0 additions & 106 deletions pyvimeo/__init__.py
@@ -1,108 +1,2 @@
#!/usr/bin/python

# Copyright (c) 2008 Patrick Altman http://paltman.com
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
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()

config.API_KEY = config.get('Credentials', 'api_key')
config.SHARED_SECRET = config.get('Credentials', 'shared_secret')
config.API_URL = config.get('Urls', 'starndard_api_url', 'http://www.vimeo.com/api/rest/')
config.UPLOAD_URL = config.get('Urls', 'upload_url', 'http://www.vimeo.com/services/upload/')
config.AUTH_URL = config.get('Urls', 'auth_url', 'http://www.vimeo.com/services/auth/')
config.AUTH_TOKEN = config.get('User', 'auth_token', None)

56 changes: 15 additions & 41 deletions pyvimeo/connection.py
@@ -1,26 +1,3 @@
#!/usr/bin/python

# Copyright (c) 2008 Patrick Altman http://paltman.com
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

import hashlib
import simplejson
import urllib
Expand All @@ -34,11 +11,11 @@ class Connection(object):
Authentication for a Vimeo app goes as follows:
0. Check configuration for a valid token.
1. Get a Frob to establish an application session
2. Generate an authentication URL for the user using:
a. the frob
b. permissions (read, write, delete)
c. api key
1. Generate an authorization URL for the user using:
a. permissions (read, write, delete)
b. api key
2. Get a Frob to establish an application session after going to the url
from #1 to authorize the application for the user account.
3. Once the user goes to that url and clicks accept, a call to getToken
will work.
4. Once a valid token is received, it should be saved in the user's
Expand All @@ -49,6 +26,8 @@ class Connection(object):
def __init__(self):
self.auth_token = config.AUTH_TOKEN
self.auth_data = None
self.__frob = None
self.__auth_token_data = None

def __generate_sig(self, **kargs):
sig = ''
Expand Down Expand Up @@ -76,20 +55,14 @@ def make_request(self, method, **kargs):

def check_token(self):
if self.auth_token:
self.auth_data = self.make_request(method='vimeo.auth.checkToken', auth_token=self.auth_token)
self.auth_data = self.make_request(
method='vimeo.auth.checkToken', auth_token=self.auth_token)
return 'stat' in self.auth_data and self.auth_data['stat'] == 'ok'
return False

@property
def authenticated(self):
return self.check_token()


class Authentication(Connection):
def __init__(self):
super(Connection, self).__init__()
self.__frob = None
self.__auth_token_data = None

def __get_frob(self):
if self.__frob:
Expand All @@ -99,7 +72,7 @@ def __get_frob(self):
if 'stat' in frob_data and frob_data['stat'] == 'ok':
self.__frob = frob_data['frob']
return self.__frob

def get_token(self):
"""
Get and save to the user configuration file, the auth token.
Expand All @@ -108,8 +81,10 @@ def get_token(self):
return self.auth_token

frob = self.__get_frob()
self.__auth_token_data = self.make_request(method='vimeo.auth.getToken', frob=frob)
if 'stat' in self.__auth_token_data and self.__auth_token_data['stat'] == 'ok':
self.__auth_token_data = self.make_request(
method='vimeo.auth.getToken', frob=frob)
if 'stat' in self.__auth_token_data and \
self.__auth_token_data['stat'] == 'ok':
self.auth_token = self.__auth_token_data['auth']['token']
config.save_user_option('User', 'auth_token', self.auth_token)
return self.auth_token
Expand All @@ -118,11 +93,10 @@ def get_auth_url(self, write_perm=False, delete_perm=False):
"""
Get the authenticate url for the the user to register the app with.
"""
frob = self.__get_frob()
perms = 'read'
if write_perm:
perms = 'write'
if delete_perm:
perms = 'delete'
url = self.generate_url(url_base=config.AUTH_URL, perms=perms, frob=frob)
url = self.generate_url(url_base=config.AUTH_URL, perms=perms)
return url
136 changes: 0 additions & 136 deletions pyvimeo/user.py

This file was deleted.

Empty file removed test.py
Empty file.

0 comments on commit 6d58ab7

Please sign in to comment.