   constructor: ->
     @client_id = '0b093d563346476729fb'
     @client_secret = '8fdsfdsgfdsg98d7'
-    @htoken = ''
+    @htoken = {'id': 0, 'token': ""}
 
   getUserInfo: (params, callback) ->
     #params.user, callback
     #https://developer.github.com/v3/users/
-    if @htoken is ''
-      return
-    opts = {
-      hostname: 'api.github.com',
-      port: 443,
-      path: '/users/',
-      method: 'GET',
-      headers: {
-        'User-Agent': 'aTox Github Binding v0.0.1',
-        'Content-Type': 'application/json; charset=utf-8',
-        'Authorization': "token " + @htoken,
-        'Accept': 'application/vnd.github.v3+json'
-      }
-    }
+    path = '/users/'
     if params.user?
-      opts.path += params.user
-    data = {
-      "note": "aTox github binding"
-    }
-    @sendRequest {opts: opts, data: data}, (data) =>
-      callback(JSON.parse(data))
+      path += params.user
+    @request({'path': path}, callback)
 
   getUserImage: (params, callback) ->
     #params.user, callback
+    if not params.user?
+      params.user = ''
     @getUserInfo {user: params.user}, (info) =>
       callback(info.avatar_url)
 

    if params.otp?
      opts.headers['X-GitHub-OTP'] = params.otp
    data = {
      #"client_secret": @client_secret,
      #"scopes": [
      #  "public_repo" #To fill up
      #],
      "note": "aTox github binding"
    }
    @sendRequest {opts: opts, data: data}, (data) =>
      console.log data
      console.log JSON.parse(data)
      @setToken JSON.parse(data).token
      callback()

  createAppToken: (params, callback) ->

    if params.otp? and params.otp != ""
      opts.headers['X-GitHub-OTP'] = params.otp
    data = {
      "scopes": [], # No scopes: read-only access to public information
      "note": "aTox github binding",
      "note_url": "https://github.com/EEnginE/atox"
    }
    @sendRequest {opts: opts, data: data}, (data) =>
      parsedData = JSON.parse(data)
      console.log parsedData
      @setToken parsedData.id parsedData.token
      callback({id: parsedData.id, token: parsedData.token, data: parsedData})

  checkToken: (params, callback) ->
    #params.id, callback
    if not params.id?
      params.id = @getID()

    path = '/authorizations/' + params.id
    @request {'path': path}, (parsedData) =>
      if parsedData.id? and parsedData.id is params.id
        callback({id: parsedData.id, valid: true, data: parsedData})
      else
        callback({id: params.id, valid: false, data: parsedData})

  getRepoInfo: (params, callback) ->
    #params.owner, params.repo, callback
    if not params.owner? or not params.repo?
      return

    path = '/repos/' + params.owner + '/' + params.repo
    @request({'path': path}, callback)

  getTagInfo: (params, callback) ->
    #params.owner, params.repo, params.id callback
    if not params.owner? or not params.repo?
      return

    path = '/repos/' + params.owner + '/' + params.repo + '/tags'
    @request({'path': path}, callback)
    
  getIssueInfo: (params, callback) ->
    #params.owner, params.repo, params.id callback
    if not params.owner? or not params.repo?
      return

    path = '/repos/' + params.owner + '/' + params.repo + '/issues'
    if params.id?
      path += '/' + params.id
    @request({'path': path}, callback)

  getCommitInfo: (params, callback) ->
    #params.owner, params.repo, params.sha callback
    if not params.owner? or not params.repo?
      return

    path = '/repos/' + params.owner + '/' + params.repo + '/commits'
    if params.sha?
      path += '/' + params.sha
    @request({'path': path}, callback)

  deleteUserToken: (params, callback) ->
    #params.token, params.id, callback
