<commit_before>var request = require('request'); 
var Geohub = require('geohub'); 

module.exports = {
  
  provider: true,

  notFound: function(req, res){
    res.send('Must specify a user, repo, and file', 404);
  },

  index: function(req, res){
    res.view('github/index');
  },

  getRepo: function(req, res){
    if ( req.params.user && req.params.repo && req.params.file ){
      Geohub.repo( req.params.user, req.params.repo, req.params.file.replace(/::/g, '/'), function( err, data ){
        if ( err ){
          res.json( err, 500 );
        } else if ( data ){
          res.json( data );
        } else {
          res.send('There was a problem accessing this repo', 500);
        }
      });  
    } else {
      res.send('Must specify a user, repo, and file', 404);
    }
  },
  
  featureservice: function(req, res){
    var callback = req.query.callback;
    delete req.query.callback;

    function send( err, data ){
      if ( err ){
        res.json( err, 500 );
      } else if ( data ){
        if ( FeatureServices[ req.params.layer ]){
          FeatureServices[ req.params.layer ]( data, req.query || {}, function( d ){
            if ( callback ){
              res.send( callback + '(' + JSON.stringify( d ) + ')' );
            } else {
              res.json( d );
            }
          });
        } else {
          if ( req.params.method && FeatureServices[ req.params.method ] ){
            FeatureServices[ req.params.method ]( data, req.query || {}, function( d ){
              if ( callback ){
                res.send( callback + '(' + JSON.stringify( d ) + ')' );
              } else {
                res.json( d );
              }
          });
          } else {
            FeatureServices.info( data, req.params.layer, req.query || {}, function( d ){
              if ( callback ){
                res.send( callback + '(' + JSON.stringify( d ) + ')' );
              } else {
                res.json( d );
              }
          });
          }
        }

      } else {
        res.send('There a problem accessing this repo', 500);
      }
    };

    if ( req.params.user && req.params.repo && req.params.file ){
      var key = [ req.params.user, req.params.repo, req.params.file.replace(/::/g, '/')].join('/');
      if (!Cache.gist[ key ]){
        Geohub.repo( req.params.user, req.params.repo, req.params.file.replace(/::/g, '/'), function( err, data ){
          Cache.gist[ key ] = JSON.stringify( data );
          send( err, data );
        });
      } else {
        send( null, JSON.parse( Cache.gist[ key ] ) );
      }
    } else {
      res.send('Must specify a user, repo, and file', 404);
    }<commit_msg>refactor of gist and github to put logic in models, this is handdy cause more logic will come in terms of caching, and the model is better for that<commit_after>
module.exports = {
  
  provider: true,

  notFound: function(req, res){
    res.send('Must specify a user, repo, and file', 404);
  },

  index: function(req, res){
    res.view('github/index');
  },

  getRepo: function(req, res){
    if ( req.params.user && req.params.repo && req.params.file ){
      Github.find(req.params.user, req.params.repo, req.params.file, function( err, data ){
        if ( err ){
          res.json( err, 500 );
        } else if ( data ){
          res.json( data );
        } else {
          res.send('There was a problem accessing this repo', 500);
        }
      });
    } else {
      res.send('Must specify a user, repo, and file', 404);
    }
  },
  
  featureservice: function(req, res){
    var callback = req.query.callback;
    delete req.query.callback;

    function send( err, data ){
      if ( err ){
        res.json( err, 500 );
      } else if ( data ){
        if ( FeatureServices[ req.params.layer ]){
          FeatureServices[ req.params.layer ]( data, req.query || {}, function( d ){
            if ( callback ){
              res.send( callback + '(' + JSON.stringify( d ) + ')' );
            } else {
              res.json( d );
            }
          });
        } else {
          if ( req.params.method && FeatureServices[ req.params.method ] ){
            FeatureServices[ req.params.method ]( data, req.query || {}, function( d ){
              if ( callback ){
                res.send( callback + '(' + JSON.stringify( d ) + ')' );
              } else {
                res.json( d );
              }
          });
          } else {
            FeatureServices.info( data, req.params.layer, req.query || {}, function( d ){
              if ( callback ){
                res.send( callback + '(' + JSON.stringify( d ) + ')' );
              } else {
                res.json( d );
              }
          });
          }
        }

      } else {
        res.send('There a problem accessing this repo', 500);
      }
    };

    if ( req.params.user && req.params.repo && req.params.file ){
      Github.find( req.params.user, req.params.repo, req.params.file, function( err, data){
        send( null, data );
      });
    } else {
      res.send('Must specify a user, repo, and file', 404);
    }
{'fraction_non_alphanumeric': 0.15774042220484755, 'fraction_numerical': 0.008209538702111024, 'mean_word_length': 1.6471805483704087, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3299220', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1499, 'n_words': 383}