forked from ozgur/python-linkedin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
__author__ = 'Samuel Marks <[email protected]>' | ||
__version__ = '0.1.0' | ||
|
||
from SocketServer import ThreadingTCPServer | ||
from SimpleHTTPServer import SimpleHTTPRequestHandler | ||
try: | ||
from urllib.parse import urlparse | ||
except ImportError: | ||
from urlparse import urlparse | ||
|
||
from socketserver import ThreadingTCPServer | ||
from http.server import SimpleHTTPRequestHandler | ||
|
||
from webbrowser import open_new_tab | ||
from json import dumps | ||
from urlparse import urlparse | ||
from os import environ | ||
from types import NoneType | ||
|
||
|
||
from linkedin.linkedin import LinkedInAuthentication, LinkedInApplication, PERMISSIONS | ||
|
||
|
@@ -38,35 +43,35 @@ def json_headers(self, status_code=200): | |
|
||
def do_GET(self): | ||
parsedurl = urlparse(self.path) | ||
authed = type(liw.authentication.token) is not NoneType | ||
authed = liw.authentication.token is not None | ||
|
||
if parsedurl.path == '/code': | ||
self.json_headers() | ||
|
||
liw.authentication.authorization_code = params_to_d(self.path).get('code') | ||
self.wfile.write(dumps({'access_token': liw.authentication.get_access_token(), | ||
'routes': filter(lambda d: not d.startswith('_'), dir(liw.application))})) | ||
'routes': list(filter(lambda d: not d.startswith('_'), dir(liw.application)))}).encode('utf8')) | ||
elif parsedurl.path == '/routes': | ||
self.json_headers() | ||
|
||
self.wfile.write(dumps({'routes': filter(lambda d: not d.startswith('_'), dir(liw.application))})) | ||
self.wfile.write(dumps({'routes': list(filter(lambda d: not d.startswith('_'), dir(liw.application)))}).encode('utf8')) | ||
elif not authed: | ||
self.json_headers() | ||
|
||
if not globals()['run_already']: | ||
open_new_tab(liw.authentication.authorization_url) | ||
globals()['run_already'] = True | ||
self.wfile.write(dumps({'path': self.path, 'authed': type(liw.authentication.token) is NoneType})) | ||
self.wfile.write(dumps({'path': self.path, 'authed': type(liw.authentication.token) is None}).encode('utf8')) | ||
elif authed and len(parsedurl.path) and parsedurl.path[1:] in dir(liw.application): | ||
self.json_headers() | ||
self.wfile.write(dumps(getattr(liw.application, parsedurl.path[1:])())) | ||
self.wfile.write(dumps(getattr(liw.application, parsedurl.path[1:])()).encode('utf8')) | ||
else: | ||
self.json_headers(501) | ||
self.wfile.write(dumps({'error': 'NotImplemented'})) | ||
self.wfile.write(dumps({'error': 'NotImplemented'}).encode('utf8')) | ||
|
||
|
||
if __name__ == '__main__': | ||
httpd = ThreadingTCPServer(('localhost', PORT), CustomHandler) | ||
|
||
print 'Server started on port:', PORT | ||
print('Server started on port:{}'.format(PORT)) | ||
httpd.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
future==0.14.3 | ||
requests | ||
requests_oauthlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters