now using the Services class everywhere
This commit is contained in:
Родитель
dc21e54b10
Коммит
70c32cc00f
|
@ -57,6 +57,9 @@ oauth.linkedin.com.request = https://api.linkedin.com/uas/oauth/requestToken
|
|||
oauth.linkedin.com.access = https://api.linkedin.com/uas/oauth/accessToken
|
||||
oauth.linkedin.com.authorize = https://api.linkedin.com/uas/oauth/authorize
|
||||
|
||||
sstatus.servers = 127.0.0.1:11211
|
||||
sstatus.domains = google.com,twitter.com,facebook.com,linkedin.com
|
||||
|
||||
[server:main]
|
||||
use = egg:Paste#http
|
||||
host = 127.0.0.1
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is Raindrop.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Mozilla Messaging, Inc..
|
||||
# Portions created by the Initial Developer are Copyright (C) 2009
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): Tarek Ziade <tarek@mozilla.com>
|
||||
#
|
||||
|
||||
# XXX services instance to be moved in the future application
|
||||
# object once Pylons gets removed
|
||||
|
||||
from linkoauth import Services
|
||||
from pylons import config
|
||||
|
||||
servers = config['sstatus.servers'].split(',')
|
||||
domains = config['sstatus.domains'].split(',')
|
||||
ttl = int(config.get('sstatus.ttl', '60'))
|
||||
|
||||
services = Services(domains, servers, ttl)
|
||||
|
|
@ -30,8 +30,9 @@ from pylons.controllers.util import abort, redirect
|
|||
from pylons.decorators import jsonify
|
||||
from pylons.decorators.util import get_pylons
|
||||
|
||||
from linkoauth import get_provider
|
||||
from linkoauth.base import OAuthKeysException, ServiceUnavailableException
|
||||
from linkoauth.errors import DomainNotRegisteredError
|
||||
from linkdrop.controllers import services
|
||||
|
||||
from linkdrop.lib.base import BaseController, render
|
||||
from linkdrop.lib.helpers import json_exception_response, api_response, api_entry, api_arg
|
||||
|
@ -94,15 +95,8 @@ Name of the group to return.
|
|||
startIndex = int(request.POST.get('startindex','0'))
|
||||
maxResults = int(request.POST.get('maxresults','25'))
|
||||
account_data = request.POST.get('account', None)
|
||||
provider = get_provider(domain)
|
||||
if provider is None:
|
||||
error = {
|
||||
'message': "'domain' is invalid",
|
||||
'code': constants.INVALID_PARAMS
|
||||
}
|
||||
return {'result': None, 'error': error}
|
||||
|
||||
acct = None
|
||||
|
||||
if account_data:
|
||||
acct = json.loads(account_data)
|
||||
if not acct:
|
||||
|
@ -114,7 +108,16 @@ Name of the group to return.
|
|||
return {'result': None, 'error': error}
|
||||
|
||||
try:
|
||||
result, error = provider.api(acct).getcontacts(startIndex, maxResults, group)
|
||||
#result, error = provider.api(acct).getcontacts(startIndex, maxResults, group)
|
||||
result, error = services.getcontacts(domain, acct, startIndex,
|
||||
maxResults, group)
|
||||
except DomainNotRegisteredError:
|
||||
error = {
|
||||
'message': "'domain' is invalid",
|
||||
'code': constants.INVALID_PARAMS
|
||||
}
|
||||
return {'result': None, 'error': error}
|
||||
|
||||
except OAuthKeysException, e:
|
||||
# more than likely we're missing oauth tokens for some reason.
|
||||
error = {'provider': domain,
|
||||
|
|
|
@ -36,8 +36,10 @@ from pylons import config, request, response
|
|||
from pylons.controllers.util import abort, redirect
|
||||
from pylons.decorators.util import get_pylons
|
||||
|
||||
from linkoauth import get_provider
|
||||
#from linkoauth import get_provider
|
||||
from linkoauth.base import OAuthKeysException, ServiceUnavailableException
|
||||
from linkdrop.controllers import services
|
||||
from linkoauth.errors import DomainNotRegisteredError
|
||||
|
||||
from linkdrop.lib.base import BaseController
|
||||
from linkdrop.lib.helpers import json_exception_response, api_response, api_entry, api_arg
|
||||
|
@ -129,13 +131,6 @@ Site provided description of the shared item, not supported by all services.
|
|||
'code': constants.INVALID_PARAMS
|
||||
}
|
||||
return {'result': result, 'error': error}
|
||||
provider = get_provider(domain)
|
||||
if provider is None:
|
||||
error = {
|
||||
'message': "'domain' is invalid",
|
||||
'code': constants.INVALID_PARAMS
|
||||
}
|
||||
return {'result': result, 'error': error}
|
||||
|
||||
if account_data:
|
||||
acct = json.loads(account_data)
|
||||
|
@ -160,9 +155,16 @@ Site provided description of the shared item, not supported by all services.
|
|||
acct_hash = hashlib.sha1("%s#%s" % ((username or '').encode('utf-8'), (userid or '').encode('utf-8'))).hexdigest()
|
||||
timer = metrics.start_timer(request, domain=domain, message_len=len(message),
|
||||
long_url=longurl, short_url=shorturl, acct_id=acct_hash)
|
||||
# send the item.
|
||||
|
||||
# send the item
|
||||
try:
|
||||
result, error = provider.api(acct).sendmessage(message, args)
|
||||
result, error = services.sendmessage(domain, acct, message, args)
|
||||
except DomainNotRegisteredError:
|
||||
error = {
|
||||
'message': "'domain' is invalid",
|
||||
'code': constants.INVALID_PARAMS
|
||||
}
|
||||
return {'result': result, 'error': error}
|
||||
except OAuthKeysException, e:
|
||||
# XXX - I doubt we really want a full exception logged here?
|
||||
#log.exception('error providing item to %s: %s', domain, e)
|
||||
|
|
3
test.ini
3
test.ini
|
@ -67,6 +67,9 @@ oauth.yahoo.com.app_id = FILL_ME_IN
|
|||
# set to true if you have completed domain verification with Yahoo
|
||||
oauth.yahoo.com.verified = 0
|
||||
|
||||
sstatus.servers = 127.0.0.1:11211
|
||||
sstatus.domains = google.com,twitter.com,facebook.com,linkedin.com
|
||||
|
||||
[server:main]
|
||||
use = egg:Paste#http
|
||||
host = 127.0.0.1
|
||||
|
|
Загрузка…
Ссылка в новой задаче