import urllib
import urlparse
from google.appengine.api import urlfetch
from flask import json
import logging, os

CLIENT_ID = 'YOUR_CLIENT_ID'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
GITHUB_API_URL = 'https://api.github.com'
REPO_NAME = 'watcher'
REPO_DESC = 'gitmark'
REPO_HOMEPAGE = 'http://localhost'

class Helpers(object):

	access_token = ''
	
	def __init__(self, access_token=None):
		self.access_token = access_token
		
	def setAccessToken(self, access_token):
		self.access_token = access_token

	# make default request
	def make_request(self, url='', payload=None, method=urlfetch.GET):
		result = urlfetch.fetch(url=url,
								payload=payload,
		                        method=method,
		                        headers={'Authorization': 'token %s' % self.access_token})
		
		logging.info('token %s' % self.access_token);
		                        
		return result
	
	# request access token after receiving code
	def requestAccessToken(self, code):
		data = dict(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, code=code)
		form_data = urllib.urlencode(data)
		url = 'https://github.com/login/oauth/access_token'