Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starter #41

Open
wants to merge 53 commits into
base: test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5258687
Updating project structure on readme
DrkSephy May 10, 2015
cca94da
remove a line, test request
mk200789 May 11, 2015
8892fac
Merge pull request #2 from mk200789/master
DrkSephy May 11, 2015
3426496
Added facebook login.
lsxliron May 13, 2015
c2a64eb
Adding Tumblr instructions to readme
DrkSephy May 13, 2015
2e30707
Merge remote-tracking branch 'upstream/master'
lsxliron May 13, 2015
9e04686
pulled after update
lsxliron May 13, 2015
e71a95f
Merge pull request #4 from lsxliron/master
DrkSephy May 13, 2015
72479ba
change scope to basic profile
mk200789 May 16, 2015
a3dc1ce
fix tumblr api example url
mk200789 May 16, 2015
67b52b7
fixed tumblr login
mk200789 May 16, 2015
7c63030
include tumblrprofile in djangoadmin
mk200789 May 16, 2015
1447cea
minor fix in readme
mk200789 May 16, 2015
4019edd
Merge pull request #7 from mk200789/master
DrkSephy May 16, 2015
1a17131
Changed facebook app in order to resolve issue #3
lsxliron May 16, 2015
a5290a2
Added a Facebook API example to get the user basic info.
lsxliron May 16, 2015
ec8d07e
Merge pull request #8 from lsxliron/master
DrkSephy May 16, 2015
d0890dd
Updating readme
DrkSephy May 16, 2015
39669b9
Removing old facebook example
DrkSephy May 18, 2015
c9c808c
Fixed Facebook example instructions
lsxliron May 18, 2015
64d9031
Added sign in with google. Also, added an API example to get user bas…
lsxliron May 18, 2015
94b7138
Added Google Login instructions
lsxliron May 18, 2015
9863247
Fixed merge conlicts
lsxliron May 18, 2015
86e1558
Merge pull request #10 from lsxliron/master
DrkSephy May 18, 2015
7a082d6
Added google login script that was forgotten in previous commits
lsxliron May 18, 2015
0ccbde0
Merge pull request #11 from lsxliron/master
DrkSephy May 18, 2015
e3a3402
Added Google+ to README API examples list
lsxliron May 18, 2015
d769b49
Merge pull request #12 from lsxliron/master
DrkSephy May 18, 2015
cbedc96
Adding template that was forgotten on the last commit
lsxliron May 19, 2015
dd52862
Merge pull request #15 from lsxliron/master
DrkSephy May 19, 2015
586399f
Added Dropbox login option.
lsxliron May 19, 2015
ad49951
Updated readme to include instructions for dropbox
lsxliron May 19, 2015
ccd1ba1
Merge pull request #16 from lsxliron/master
DrkSephy May 19, 2015
64fc22f
Adding a basic temporary front-end for api examples
DrkSephy May 19, 2015
013ae9f
Updating readme with new images
DrkSephy May 19, 2015
bdb5fe5
Minor mistake with readme images
DrkSephy May 19, 2015
2bbc726
Updating readme
DrkSephy May 19, 2015
d1516b7
Added foursquare login and API example for getting user basic info
lsxliron May 20, 2015
010eba8
Updated README to include foursquare app creaton instructions
lsxliron May 20, 2015
bb1e011
Merge pull request #20 from lsxliron/master
DrkSephy May 20, 2015
0a9ed7d
Updating readme
DrkSephy May 20, 2015
512fa6a
change keys
mk200789 May 27, 2015
2ec7d91
Merge pull request #22 from mk200789/master
DrkSephy May 27, 2015
9da1d07
Fixing dead images
DrkSephy Aug 7, 2015
6ce84d4
add CRUD test cases for Snippet
decentral1se Sep 30, 2015
eec9f41
replace function based view with class based view
decentral1se Sep 30, 2015
676ebc5
add router for urlconf
decentral1se Sep 30, 2015
69774d7
Merge pull request #25 from lwm/extended-rest-framework-snippet
DrkSephy Sep 30, 2015
ba51132
Updating readme
DrkSephy Sep 30, 2015
c0dbc75
Removing API keys
DrkSephy Oct 11, 2015
12e5d25
Updating readme
DrkSephy Oct 11, 2015
b192914
Code cleanup
DrkSephy Oct 11, 2015
2b8a573
Resolving #32: Making landing page default to starting server url
DrkSephy Jan 29, 2016
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
205 changes: 147 additions & 58 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions hackathon_starter/hackathon/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from hackathon.models import UserProfile, Profile, InstagramProfile, TwitterProfile, MeetupToken, GithubProfile, LinkedinProfile
from hackathon.models import UserProfile, Profile, InstagramProfile, TwitterProfile, MeetupToken, GithubProfile, LinkedinProfile, TumblrProfile

# Register your models here.
class TwitterProfileAdmin(admin.ModelAdmin):
Expand All @@ -12,4 +12,4 @@ class TwitterProfileAdmin(admin.ModelAdmin):
admin.site.register(GithubProfile)
admin.site.register(MeetupToken)
admin.site.register(LinkedinProfile)

admin.site.register(TumblrProfile)
38 changes: 37 additions & 1 deletion hackathon_starter/hackathon/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ class GithubProfile(models.Model):
def __unicode__(self):
return unicode(self.user)

class TumblrProfile(models.Model):
user = models.ForeignKey(User)
tumblr_user = models.CharField(max_length=200)
access_token = models.CharField(max_length=200)
access_token_secret = models.CharField(max_length=200)

def __unicode__(self):
return unicode(self.user)

class InstagramProfile(models.Model):
user = models.ForeignKey(User)
instagram_user = models.CharField(max_length=200)
Expand Down Expand Up @@ -66,4 +75,31 @@ class MeetupToken(models.Model):
access_token = models.CharField(max_length=200)

def __unicode__(self):
return unicode(self.access_token)
return unicode(self.access_token)

class FacebookProfile(models.Model):
user = models.ForeignKey(User)
fb_user_id = models.CharField(max_length=100)
time_created = models.DateTimeField(auto_now_add=True)
profile_url = models.CharField(max_length=50)
access_token = models.CharField(max_length=100)

class GoogleProfile(models.Model):
user = models.ForeignKey(User)
google_user_id = models.CharField(max_length=100)
time_created = models.DateTimeField(auto_now_add=True)
access_token = models.CharField(max_length=100)
profile_url = models.CharField(max_length=100)

class DropboxProfile(models.Model):
user = models.ForeignKey(User)
dropbox_user_id = models.CharField(max_length=100)
time_created = models.DateTimeField(auto_now_add=True)
access_token = models.CharField(max_length=100)


class FoursquareProfile(models.Model):
user = models.ForeignKey(User)
foursquare_id = models.CharField(max_length=100)
time_created = models.DateTimeField(auto_now_add=True)
access_token = models.CharField(max_length=100)
60 changes: 60 additions & 0 deletions hackathon_starter/hackathon/scripts/dropbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import simplejson as json
import urllib
import requests
import string
import pdb
import random


AUTHORIZE_URL = 'https://www.dropbox.com/1/oauth2/authorize'
ACCESS_TOKEN_URL = 'https://api.dropbox.com/1/oauth2/token'


class DropboxOauthClient(object):

access_token = None
session_id = None
def __init__(self, client_id, client_secret):
self.client_id = client_id
self.client_secret = client_secret


def get_authorize_url(self):
self.get_session_id()
authSettings = {'response_type': 'code',
'client_id': self.client_id,
'redirect_uri': 'http://localhost:8000/hackathon',
'state': self.session_id}

params = urllib.urlencode(authSettings)

return AUTHORIZE_URL + '?' + params

def get_session_id(self, length=50):
chars = string.uppercase + string.digits + string.lowercase
self.session_id = ''.join(random.choice(chars) for _ in range(length))

def get_access_token(self, code, state):
if state != self.session_id:
raise(Exception('Danger! Someone is messing up with you connection!'))

authSettings = {'code': code,
'grant_type': 'authorization_code',
'client_id': self.client_id,
'client_secret': self.client_secret,
'redirect_uri': 'http://localhost:8000/hackathon'}

response = requests.post(ACCESS_TOKEN_URL, data=authSettings)

if response.status_code!=200:
raise(Exception('Invalid response, response code {c}'.format(c=response.status_code)))
self.access_token = response.json()['access_token']


def get_user_info(self):
USER_INFO_API = 'https://api.dropbox.com/1/account/info'
params = urllib.urlencode({'access_token': self.access_token})
response = requests.get(USER_INFO_API + '?' + params)
if response.status_code!=200:
raise(Exception('Invalid response, response code {c}'.format(c=response.status_code)))
return response.json()
153 changes: 153 additions & 0 deletions hackathon_starter/hackathon/scripts/facebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import requests
import urllib
import simplejson as json

##########################
# FACEBOOK API CONSTANTS #
##########################

AUTHORIZE_URL = 'https://graph.facebook.com/oauth/authorize'
ACCESS_TOKEN_URL = 'https://graph.facebook.com/oauth/access_token'
API_URL = 'https://graph.facebook.com/v2.3/'
REQUEST_PERMISSIONS_URL = "https://www.facebook.com/dialog/oauth?"

class FacebookOauthClient(object):
'''
Python client for Facebook API
'''

access_token = None
permission_request_url = None

def __init__(self, client_id, client_secret):
'''
Parameters:
client_id: String
- The client id from the registering app on Facebook
client_secret: String
- The client secret from the registering app on Facebook
'''
self.client_id = client_id
self.client_secret = client_secret



def get_authorize_url(self):
'''
Obtains authorize url link with given client_id.

Returns:
authURL: String
- The authorization url.

'''
authSettings = {'redirect_uri': "http://localhost:8000/hackathon/",
'client_id': self.client_id}
params = urllib.urlencode(authSettings)
return AUTHORIZE_URL + '?' + params



def get_access_token(self, code):
'''
Obtains access token.

Parameters:
code: String
- The code is retrieved from the authorization url parameter
to obtain access_token.
'''
authSettings = {'code': code,
'redirect_uri': "http://localhost:8000/hackathon/",
'client_secret': self.client_secret,
'client_id': self.client_id}
params = urllib.urlencode(authSettings)
response = requests.get(ACCESS_TOKEN_URL + '?' + params)

if response.status_code != 200:
raise(Exception('Invalid response,response code: {c}'.format(c=response.status_code)))

response_array = str(response.text).split('&')
self.access_token = str(response_array[0][13:])



def get_user_info(self):
'''
Obtains user information.

Returns:
content: Dictionary
- A dictionary containing user information.
'''
response = requests.get("https://graph.facebook.com/me?access_token={at}".format(at=self.access_token))
if response.status_code != 200:
raise(Exception('Invalid response,response code: {c}'.format(c=response.status_code)))

return response.json()




def get_user_likes(self):
'''
Obtains a list of all the user likes. Require a special permission
via Facebook.

Returns:
content: dictionary
-A dictionary containing user likes.
'''
#Check if permission exists or ask for it
if not self.check_permissions('user_likes'):
requestedPermissionUrl = self.request_permissions('user_likes')

#Get likes
response = requests.get(API_URL + 'me/likes?access_token={at}'.format(at=self.access_token))
return response.json()['data']



def check_permissions(self, perm):
'''
Checks if the app has the specified permission.

Parameters:
perm: String
- The desired permission (such as user_likes)

Returns:
bool
- True if the permission granted or false otherwise.
'''

permDict = {'status': 'granted', 'permission':perm}
response = requests.get(API_URL + 'me/permissions?access_token={at}'.format(at=self.access_token))
if response.status_code != 200:
raise(Exception('Invalid response,response code: {c}'.format(c=response.status_code)))

currentPermissions = response.json()['data']
if permDict in currentPermissions:
return True
return False


def request_permissions(self, perm):
'''
Requests a permission from the user.

Parameters:
perm: String
- The permission we would like to get.

Returns: String
- The URL to redirect the user in order to get the permission.
'''
authSettings = {'client_id' : self.client_id,
'redirect_uri' : 'http://localhost:8000/hackathon/',
'auth_type' : 'rerequest',
'scope' : perm,
'access_token' : access_token}
params = urllib.urlencode(authSettings)
self.permission_request_url = REQUEST_PERMISSIONS_URL + '?' + params

102 changes: 102 additions & 0 deletions hackathon_starter/hackathon/scripts/foursquare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import simplejson as json
import urllib
import requests


############################
# FOURSQUARE API CONSTANTS #
############################
AUTHORIZE_URL = 'https://foursquare.com/oauth2/authenticate'
ACCESS_TOKEN_URL = 'https://foursquare.com/oauth2/access_token'
REDIRECT_URL = 'http://localhost:8000/hackathon'


class FoursquareOauthClient(object):
'''
Pytohn client for Foursquare API
'''

access_token = None

def __init__(self, client_id, client_secret):
'''
Parameters:
client_id: String
- The client id from the registering app on Facebook
client_secret: String
- The client secret from the registering app on Facebook
'''
self.client_id = client_id
self.client_secret = client_secret



def get_authorize_url(self):
'''
Obtains authorize url link with given client_id.

Returns:
authURL: String
- The authorization url.

'''
authSettings = {'client_id': self.client_id,
'response_type': 'code',
'redirect_uri': REDIRECT_URL}

params = urllib.urlencode(authSettings)

return AUTHORIZE_URL + '?' + params



def get_access_token(self, code):
'''
Obtains access token.

Parameters:
code: String
- The code is retrieved from the authorization url parameter
to obtain access_token.
'''

authSettings = {'client_id': self.client_id,
'client_secret': self.client_secret,
'grant_type': 'authorization_code',
'redirect_uri': REDIRECT_URL,
'code': code}

params = urllib.urlencode(authSettings)
response = requests.get(ACCESS_TOKEN_URL + '?' + params)

if response.status_code != 200:
raise(Exception('Invalid response,response code: {c}'.format(c=response.status_code)))

self.access_token = response.json()['access_token']


def get_user_info(self, api_version='20140806'):
'''
Obtains user information.

Parameters:
api_version: string
- The API version you would use. This parameter is mandatory by Foursquare.

Returns:
content: Dictionary
- A dictionary containing user information.
'''
USER_INFO_API_URL = 'https://api.foursquare.com/v2/users/self'

authSettings={'v':api_version,
'oauth_token': self.access_token}

params = urllib.urlencode(authSettings)

response = requests.get(USER_INFO_API_URL + '?' + params)

if response.status_code != 200:
raise(Exception('Invalid response,response code: {c}'.format(c=response.status_code)))

return response.json()['response']['user']
Loading