Skip to content
This repository was archived by the owner on Oct 9, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions examples/desktop_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import odesk
from pprint import pprint

Expand All @@ -9,7 +11,7 @@ def desktop_app():
Returns: ``odesk.Client`` instance ready to work.

"""
print "Emulating desktop app"
print("Emulating desktop app")

public_key = raw_input('Please enter public key: > ')
secret_key = raw_input('Please enter secret key: > ')
Expand All @@ -20,9 +22,9 @@ def desktop_app():
'following this link:\n{0}\n\n> '.format(
client.auth.get_authorize_url()))

print 'Retrieving keys.... '
print('Retrieving keys.... ')
access_token, access_token_secret = client.auth.get_access_token(verifier)
print 'OK'
print('OK')

# For further use you can store ``access_toket`` and
# ``access_token_secret`` somewhere
Expand All @@ -36,19 +38,19 @@ def desktop_app():
client = desktop_app()

try:
print "My info"
print("My info")
pprint(client.auth.get_info())
print "Team rooms:"
print("Team rooms:")
pprint(client.team.get_teamrooms())
#HRv2 API
print "HR: companies"
print("HR: companies")
pprint(client.hr.get_companies())
print "HR: teams"
print("HR: teams")
pprint(client.hr.get_teams())
print "HR: userroles"
print("HR: userroles")
pprint(client.hr.get_user_roles())
print "Get jobs"
print("Get jobs")
pprint(client.provider.search_jobs({'q': 'python'}))
except Exception, e:
print "Exception at %s %s" % (client.last_method, client.last_url)
except Exception as e:
print("Exception at %s %s" % (client.last_method, client.last_url))
raise e
34 changes: 18 additions & 16 deletions examples/web_based_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from __future__ import print_function
import odesk
from six import input
from pprint import pprint


Expand All @@ -9,20 +11,20 @@ def web_based_app():
Returns: ``odesk.Client`` instance ready to work.

"""
print "Emulating web-based app"
print("Emulating web-based app")

public_key = raw_input('Please enter public key: > ')
secret_key = raw_input('Please enter secret key: > ')
public_key = input('Please enter public key: > ')
secret_key = input('Please enter secret key: > ')

#Instantiating a client without an auth token
client = odesk.Client(public_key, secret_key)

print "Please to this URL (authorize the app if necessary):"
print client.auth.get_authorize_url()
print "After that you should be redirected back to your app URL with " + \
"additional ?oauth_verifier= parameter"
print("Please to this URL (authorize the app if necessary):")
print(client.auth.get_authorize_url())
print("After that you should be redirected back to your app URL with "
"additional ?oauth_verifier= parameter")

verifier = raw_input('Enter oauth_verifier: ')
verifier = input('Enter oauth_verifier: ')

oauth_access_token, oauth_access_token_secret = \
client.auth.get_access_token(verifier)
Expand All @@ -42,19 +44,19 @@ def web_based_app():
client = web_based_app()

try:
print "My info"
print("My info")
pprint(client.auth.get_info())
print "Team rooms:"
print("Team rooms:")
pprint(client.team.get_teamrooms())
#HRv2 API
print "HR: companies"
print("HR: companies")
pprint(client.hr.get_companies())
print "HR: teams"
print("HR: teams")
pprint(client.hr.get_teams())
print "HR: userroles"
print("HR: userroles")
pprint(client.hr.get_user_roles())
print "Get jobs"
print("Get jobs")
pprint(client.provider.search_jobs({'q': 'python'}))
except Exception, e:
print "Exception at %s %s" % (client.last_method, client.last_url)
except Exception as e:
print("Exception at %s %s" % (client.last_method, client.last_url))
raise e
6 changes: 3 additions & 3 deletions getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Initializing the client::

Now follow the ``authorize_url``::

print client.auth.get_authorize_url()
print(client.auth.get_authorize_url())

After you follow this url you'll be redirected to the callback url that you
entered during API keys creation. The ``oauth_verifier`` parameter is passed to the callback
Expand Down Expand Up @@ -107,11 +107,11 @@ This call will give you information about the currently authorized user.

So now just start playing with the API, for example you can get your teamrooms::

print client.team.get_teamrooms()
print(client.team.get_teamrooms())

or get your companies::

print client.hr.get_companies()
print(client.hr.get_companies())


See the Reference Documentation for the full list of available API calls
Expand Down
14 changes: 7 additions & 7 deletions how_to.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ http://developers.odesk.com/Authentication
To authenticate your web application with the python-odesk, use something similar
to the code below::

public_key = raw_input('Please enter public key: > ')
secret_key = raw_input('Please enter secret key: > ')
public_key = input('Please enter public key: > ')
secret_key = input('Please enter secret key: > ')

#Instantiating a client without an auth token
client = odesk.Client(public_key, secret_key)

print "Please to this URL (authorize the app if necessary):"
print client.auth.get_authorize_url()
print "After that you should be redirected back to your app URL with " + \
"additional ?oauth_verifier= parameter"
print("Please to this URL (authorize the app if necessary):")
print(client.auth.get_authorize_url())
print("After that you should be redirected back to your app URL with "
"additional ?oauth_verifier= parameter")

verifier = raw_input('Enter oauth_verifier: ')
verifier = input('Enter oauth_verifier: ')

oauth_access_token, oauth_access_token_secret = \
client.auth.get_access_token(verifier)
Expand Down
6 changes: 3 additions & 3 deletions odesk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# (C) 2010-2014 oDesk

import logging
import urllib2
from six.moves import urllib


class BaseException(Exception):
Expand All @@ -19,10 +19,10 @@ def odesk_debug(self, *args, **kwargs):
logger = logging.getLogger('python-odesk')
logger.debug('{0}: {1}'.format(
self.__class__.__name__,
', '.join(map(unicode, args))))
', '.join(map(str, args))))


class BaseHttpException(urllib2.HTTPError, BaseException):
class BaseHttpException(urllib.error.HTTPError, BaseException):

def __init__(self, *args, **kwargs):
self.odesk_debug(*args, **kwargs)
Expand Down
19 changes: 9 additions & 10 deletions odesk/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# (C) 2010-2014 oDesk

import logging
import urllib2
import httplib
from six.moves import http_client, urllib

from odesk.exceptions import HTTP400BadRequestError, HTTP401UnauthorizedError,\
HTTP403ForbiddenError, HTTP404NotFoundError
Expand All @@ -17,12 +16,12 @@


def raise_http_error(url, response):
"""Raise custom ``urllib2.HTTPError`` exception.
"""Raise custom ``urllib.error.HTTPError`` exception.

*Parameters:*
:url: Url that caused an error

:response: ``urllib3`` response object
:response: ``urllib`` response object

"""
status_code = response.status
Expand All @@ -34,21 +33,21 @@ def raise_http_error(url, response):
formatted_msg = 'Code {0}: {1}'.format(odesk_error_code,
odesk_error_message)

if status_code == httplib.BAD_REQUEST:
if status_code == http_client.BAD_REQUEST:
raise HTTP400BadRequestError(url, status_code, formatted_msg,
headers, None)
elif status_code == httplib.UNAUTHORIZED:
elif status_code == http_client.UNAUTHORIZED:
raise HTTP401UnauthorizedError(url, status_code, formatted_msg,
headers, None)
elif status_code == httplib.FORBIDDEN:
elif status_code == http_client.FORBIDDEN:
raise HTTP403ForbiddenError(url, status_code, formatted_msg,
headers, None)
elif status_code == httplib.NOT_FOUND:
elif status_code == http_client.NOT_FOUND:
raise HTTP404NotFoundError(url, status_code, formatted_msg,
headers, None)
else:
error = urllib2.HTTPError(url, status_code, formatted_msg,
headers, None)
error = urllib.error.HTTPError(url, status_code, formatted_msg,
headers, None)
logger = logging.getLogger('python-odesk')
logger.debug(str(error))
raise error
19 changes: 9 additions & 10 deletions odesk/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# python-odesk version 0.5
# (C) 2010-2014 oDesk

from six.moves import urllib
import logging
import oauth2 as oauth
import os
import time
import urlparse
import urllib
import oauth2 as oauth
import logging

from .config import BASE_URL

Expand Down Expand Up @@ -91,7 +90,7 @@ def get_request_token(self):
if response.get('status') != '200':
raise Exception(
"Invalid request token response: {0}.".format(content))
request_token = dict(urlparse.parse_qsl(content))
request_token = dict(urllib.parse.parse_qsl(content))
self.request_token = request_token.get('oauth_token')
self.request_token_secret = request_token.get('oauth_token_secret')
return self.request_token, self.request_token_secret
Expand All @@ -103,10 +102,10 @@ def get_authorize_url(self, callback_url=None):
oauth_token = getattr(self, 'request_token', None) or\
self.get_request_token()[0]
if callback_url:
params = urllib.urlencode({'oauth_token': oauth_token,\
'oauth_callback': callback_url})
params = urllib.parse.urlencode({'oauth_token': oauth_token,
'oauth_callback': callback_url})
else:
params = urllib.urlencode({'oauth_token': oauth_token})
params = urllib.parse.urlencode({'oauth_token': oauth_token})
return '{0}?{1}'.format(self.authorize_url, params)

def get_access_token(self, verifier):
Expand All @@ -116,7 +115,7 @@ def get_access_token(self, verifier):
try:
request_token = self.request_token
request_token_secret = self.request_token_secret
except AttributeError, e:
except AttributeError as e:
logger = logging.getLogger('python-odesk')
logger.debug(e)
raise Exception("At first you need to call get_authorize_url")
Expand All @@ -127,7 +126,7 @@ def get_access_token(self, verifier):
if response.get('status') != '200':
raise Exception(
"Invalid access token response: {0}.".format(content))
access_token = dict(urlparse.parse_qsl(content))
access_token = dict(urllib.parse.parse_qsl(content))
self.access_token = access_token.get('oauth_token')
self.access_token_secret = access_token.get('oauth_token_secret')
return self.access_token, self.access_token_secret
Expand Down
6 changes: 4 additions & 2 deletions odesk/routers/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# python-odesk version 0.5
# (C) 2010-2014 oDesk

from six import u

from odesk.namespaces import Namespace


Expand All @@ -26,7 +28,7 @@ def get_job_profile(self, job_key):
max_keys = 20
url = 'jobs/{0}'
# Check job key(s)
if not job_key.__class__ in [str, int, list, tuple]:
if not job_key.__class__ in [str, u, int, list, tuple]:
raise ValueError(
'Invalid job key. Job recno, key or list of keys expected, ' +
'{0} given'.format(job_key.__class__))
Expand All @@ -35,7 +37,7 @@ def get_job_profile(self, job_key):
raise ValueError(
'Number of keys per request is limited by {0}'.format(
max_keys))
elif filter(lambda x: not str(x).startswith('~~'), job_key):
elif list(filter(lambda x: not str(x).startswith('~~'), job_key)):
raise ValueError(
'List should contain only job keys not recno.')
else:
Expand Down
2 changes: 1 addition & 1 deletion odesk/routers/mc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# python-odesk version 0.5
# (C) 2010-2014 oDesk

import urllib
from six.moves import urllib

from odesk.namespaces import Namespace

Expand Down
10 changes: 5 additions & 5 deletions odesk/routers/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# python-odesk version 0.5
# (C) 2010-2014 oDesk

import urllib
from six.moves import urllib


from odesk.namespaces import Namespace
Expand Down Expand Up @@ -78,7 +78,7 @@ def get_team_specific_tasks(self, company_id, team_id, task_codes):
"""
task_codes = self._encode_task_codes(task_codes)
url = 'tasks/companies/{0}/teams/{1}/tasks/{2}'.format(
company_id, team_id, urllib.quote(task_codes))
company_id, team_id, urllib.parse.quote(task_codes))
result = self.get(url)
try:
return result["tasks"] or []
Expand Down Expand Up @@ -227,7 +227,7 @@ def put_team_task(self, company_id, team_id, code, description, url,

"""
put_url = 'tasks/companies/{0}/teams/{1}/tasks/{2}'.format(
company_id, team_id, urllib.quote(str(code)))
company_id, team_id, urllib.parse.quote(str(code)))
data = {'code': code,
'description': description,
'url': url}
Expand Down Expand Up @@ -295,7 +295,7 @@ def archive_team_task(self, company_id, team_id, task_code):

"""
url = 'tasks/companies/{0}/teams/{1}/archive/{2}'.format(
company_id, team_id, urllib.quote(str(task_code)))
company_id, team_id, urllib.parse.quote(str(task_code)))
return self.put(url, data={})

def archive_company_task(self, company_id, task_code):
Expand Down Expand Up @@ -328,7 +328,7 @@ def unarchive_team_task(self, company_id, team_id, task_code):

"""
url = 'tasks/companies/{0}/teams/{1}/unarchive/{2}'.format(
company_id, team_id, urllib.quote(str(task_code)))
company_id, team_id, urllib.parse.quote(str(task_code)))
return self.put(url, data={})

def unarchive_company_task(self, company_id, task_code):
Expand Down
Loading