plugins/lanyrd.js
function getAPIData(userName, options, callback){

			if(process.env.LANYRD_API_URL)
			{
				var url = process.env.LANYRD_API_URL + 'people/' + userName,
					cache = options.cache,
					startedRequest = new Date(),
					requestObj = {
						uri: url,
						headers: options.httpHeaders
					};

				// if url is in the cache use that
				if(cache && cache.has(url)){
					options.logger.info('using cache for lanyrd API data');
			        callback(null, parse(cache.get(url)));
			    }else{
			     	// if not get the json from the api url  
					request(requestObj, function(requestErrors, response, body){
						options.logger.info('getting lanyrd API data from url');
			          	if(!requestErrors && response.statusCode === 200){
			          		var data = JSON.parse(body)
			            	var out = parse(data);

			            	// add to cache store
				            if(cache){
				              cache.set(url, data);
				            }

		            		var endedRequest = new Date();
	            			var requestTime = endedRequest.getTime() - startedRequest.getTime();
	            			options.logger.log('made API call to: '  + requestTime + 'ms - ' + url);

			            	callback(null, out);
			          	}else{
		            		callback('error requesting Lanyrd API', {});
			          	}
			        });
				}
			}else{
				callback('LANYRD_API_URL not found', {});
			}
		}
function getAPIData(userName, options, callback){

			if(process.env.LANYRD_API_URL)
			{
				var url = process.env.LANYRD_API_URL + 'people/' + userName,
					cache = options.cache,
					startedRequest = new Date(),
					requestObj = {
						uri: url,
						headers: options.httpHeaders
					};

				// if url is in the cache use that
				if(cache && cache.has(url)){
					options.logger.info('using cache for lanyrd API data');
			        callback(null, parse(cache.get(url)));
			    }else{
			     	// if not get the json from the api url  
					request(requestObj, function(requestErrors, response, body){
						options.logger.info('getting lanyrd API data from url');
			          	if(!requestErrors && response.statusCode === 200){
			          		var data = JSON.parse(body)
			            	var out = parse(data);

			            	// add to cache store
				            if(cache){
				              cache.set(url, data);
				            }

		            		var endedRequest = new Date();
	            			var requestTime = endedRequest.getTime() - startedRequest.getTime();
	            			options.logger.log('made API call to: '  + requestTime + 'ms - ' + url);

			            	callback(null, out);
			          	}else{
		            		callback('error requesting Lanyrd API', {});
			          	}
			        });
				}
			}else{
				callback('LANYRD_API_URL not found', {});
			}
		}
function getAPIData ( userName , options , callback ) { if ( process . env . LANYRD_API_URL ) { var url = process . env . LANYRD_API_URL + 'people/' + userName , cache = options . cache , startedRequest = new Date ( ) , requestObj = { uri : url , headers : options . httpHeaders } ; // if url is in the cache use that if ( cache && cache . has ( url ) ) { options . logger . info ( 'using cache for lanyrd API data' ) ; callback ( null , parse ( cache . get ( url ) ) ) ; } else { // if not get the json from the api url   request ( requestObj , function ( requestErrors , response , body ) { options . logger . info ( 'getting lanyrd API data from url' ) ; if ( ! requestErrors && response . statusCode === 200 ) { var data = JSON . parse ( body ) var out = parse ( data ) ; // add to cache store if ( cache ) { cache . set ( url , data ) ; } var endedRequest = new Date ( ) ; var requestTime = endedRequest . getTime ( ) - startedRequest . getTime ( ) ; options . logger . log ( 'made API call to: ' + requestTime + 'ms - ' + url ) ; callback ( null , out ) ; } else { callback ( 'error requesting Lanyrd API' , { } ) ; } } ) ; } } else { callback ( 'LANYRD_API_URL not found' , { } ) ; } }
use the lanyrd api to get data
use the lanyrd api to get data