// Generated by CoffeeScript 1.10.0
(function() {
  var fs, generateApiUrl, githubHost, helpers, logger, path, postfix, restler, tl, token, tokenPath;


  restler = require('restler');

  path = require('path');

  fs = require('fs');

  helpers = require('./helpers');

  logger = helpers.logger;

  githubHost = 'https://api.github.com';

  tokenPath = path.resolve("" + __dirname, "../.tokens");

  token = JSON.parse(fs.readFileSync(tokenPath + "/github.json", 'utf8'));

  postfix = "?client_id=" + token.cliendId + "&client_secret=" + token.clientSecret;

  tl = module.exports = {
    getCommitUrls: function(timeline) {
      var i, len, ref, results, sha;
      
      ref = timeline.sha;
      results = [];

        results.push("/repos/" + "codepath" + "/" + "android_snake_game" + "/commits/" + timeline.sha);
      
      return results;
    },
    getCommitInfo: function(url, callback) {
      return restler.get(generateApiUrl(url)).on('success', function(data, res) {
        if (res.headers['x-ratelimit-remaining'] % 50 === 0) {
          logger.info("github api limit: " + res.headers['x-ratelimit-remaining']);
        }
        if (res.headers['x-ratelimit-remaining'] < '10') {
          logger.error("github api limit: " + res.headers['x-ratelimit-remaining']);
        }
        return callback(null, data, res);
      }).on('fail', function(data, res) {
        return callback(data);
      }).on('complete', function(err) {
        if (err instanceof Error) {
          return callback(err);
        }
      });
    },
    checkApiLimit: function(callback) {
      return restler.get(generateApiUrl("/users/whatever")).on('success', function(data, res) {
        logger.debug("API rate ramained " + res.headers['x-ratelimit-remaining']);
        return callback(res.headers['x-ratelimit-remaining']);
      }).on('fail', function(data, res) {
        logger.debug("API rate ramained " + res.headers['x-ratelimit-remaining']);
        return callback(res.headers['x-ratelimit-remaining']);
      });
    }
  };

  generateApiUrl = function(url) {
    return "" + githubHost + url + postfix;
  };

}).call(this);
