lib/page.js
function(callback){
    var options = this.options,
        cache = this.options.cache,
        logger =  this.options.logger;


    if(this.url){
      logger.log('fetch page: ' + this.url);

      // if there is a cache and it holds the url
      if(cache &&cache.has(this.url)){
        // http status - content located elsewhere, retrieve from there
        this.statusCode = 305;
        this.requestTime = 0;
        this.html = cache.get(this.url);
        logger.log('fetched html from cache: ' + this.url);

        this.parse(function(){
          callback(this);
        })

      // if not get the html from the url  
      }else{

        this.startedRequest = new Date();
        var self = this;

        var requestObj = {
          uri: this.url,
          headers: options.httpHeaders
        }

        request(requestObj, function(requestErrors, response, body){
          if(!requestErrors && response.statusCode === 200){

            self.endedRequest = new Date();
            self.requestTime = self.endedRequest.getTime() - self.startedRequest.getTime();
            logger.log('fetched html from page: ' 
              + self.requestTime + 'ms - ' + self.url);
            
            self.statusCode = response.statusCode;
            self.html = body;

            if(cache){
              cache.set(self.url, body);
            }

            self.parse(function(){
              self.status = "fetched";
              callback(self);
            })

          }else{
            logger.warn('error requesting page: ' + self.url);
            self.error = 'error requesting page: ' + self.url;
            self.status = "errored";
            callback();
          }
        });


      }
    }else{
      logger.warn('no url given');
      this.error = 'no url given';
      this.status = "errored";
      callback();
    }
  }
function(callback){
    var options = this.options,
        cache = this.options.cache,
        logger =  this.options.logger;


    if(this.url){
      logger.log('fetch page: ' + this.url);

      // if there is a cache and it holds the url
      if(cache &&cache.has(this.url)){
        // http status - content located elsewhere, retrieve from there
        this.statusCode = 305;
        this.requestTime = 0;
        this.html = cache.get(this.url);
        logger.log('fetched html from cache: ' + this.url);

        this.parse(function(){
          callback(this);
        })

      // if not get the html from the url  
      }else{

        this.startedRequest = new Date();
        var self = this;

        var requestObj = {
          uri: this.url,
          headers: options.httpHeaders
        }

        request(requestObj, function(requestErrors, response, body){
          if(!requestErrors && response.statusCode === 200){

            self.endedRequest = new Date();
            self.requestTime = self.endedRequest.getTime() - self.startedRequest.getTime();
            logger.log('fetched html from page: ' 
              + self.requestTime + 'ms - ' + self.url);
            
            self.statusCode = response.statusCode;
            self.html = body;

            if(cache){
              cache.set(self.url, body);
            }

            self.parse(function(){
              self.status = "fetched";
              callback(self);
            })

          }else{
            logger.warn('error requesting page: ' + self.url);
            self.error = 'error requesting page: ' + self.url;
            self.status = "errored";
            callback();
          }
        });


      }
    }else{
      logger.warn('no url given');
      this.error = 'no url given';
      this.status = "errored";
      callback();
    }
  }
function ( callback ) { var options = this . options , cache = this . options . cache , logger = this . options . logger ; if ( this . url ) { logger . log ( 'fetch page: ' + this . url ) ; // if there is a cache and it holds the url if ( cache && cache . has ( this . url ) ) { // http status - content located elsewhere, retrieve from there this . statusCode = 305 ; this . requestTime = 0 ; this . html = cache . get ( this . url ) ; logger . log ( 'fetched html from cache: ' + this . url ) ; this . parse ( function ( ) { callback ( this ) ; } ) // if not get the html from the url   } else { this . startedRequest = new Date ( ) ; var self = this ; var requestObj = { uri : this . url , headers : options . httpHeaders } request ( requestObj , function ( requestErrors , response , body ) { if ( ! requestErrors && response . statusCode === 200 ) { self . endedRequest = new Date ( ) ; self . requestTime = self . endedRequest . getTime ( ) - self . startedRequest . getTime ( ) ; logger . log ( 'fetched html from page: ' + self . requestTime + 'ms - ' + self . url ) ; self . statusCode = response . statusCode ; self . html = body ; if ( cache ) { cache . set ( self . url , body ) ; } self . parse ( function ( ) { self . status = "fetched" ; callback ( self ) ; } ) } else { logger . warn ( 'error requesting page: ' + self . url ) ; self . error = 'error requesting page: ' + self . url ; self . status = "errored" ; callback ( ) ; } } ) ; } } else { logger . warn ( 'no url given' ) ; this . error = 'no url given' ; this . status = "errored" ; callback ( ) ; } }
fetches page and loads html into object before call parse
fetches page and loads html into object before call parse