<commit_before>// xivelyJS
// version 1.0.3
// (c) 2013 Xively Ltd, a LogMeIn company [<EMAIL>]
// http://xively.github.com/xively-js/
// released under the MIT license

var xively = (function ( $ ) {
  "use strict";

  /*
  *
  *   PRIVATE VARS & METHODS
  *
  */
	
  var APIkey,                                         // THIS SHOULD BE CHANGED WITH SETKEY()
      APIendpoint = "http://api.xively.com/v2/",
      WSendpoint = "ws://api.xively.com:8080/",
      methods,
      cacheRequest = false,

      // ---------------------
      // HELPERS 
      //
      
      execute = function ( arr ) {
        if ( typeof arr === "function" ) {
          arr.apply( this, Array.prototype.slice.call( arguments, 1 ));
        }
        else if ( Object.prototype.toString.apply(arr) === '[object Array]' ) {
          var x = arr.length; 
          while (x--) {
            arr[x].apply( this, Array.prototype.slice.call( arguments, 1 ));
          }
        }
      },
      
      log = function ( msg ) {
        if ( window.console && window.console.log ) {
          window.console.log( msg );
        }
      },
  
      // ---------------------
      // REQUEST (PRIVATE)
      //

      request = function( options ) {
        
        var settings = $.extend({
              type      : 'get'
            }, options);
        
        if ( !APIkey ) { 
          return log( "(xivelyJS) ::: No API key ::: Set your API key first with xively.setKey( YOUR_API_KEY ) before using any methods. Check docs for more info." );
        }
        
        if ( !settings.url ) { return; }
        settings.type = settings.type.toUpperCase();
            
        if ( settings.type === "PUT" || settings.type === "POST" ) {
          if ( !settings.data || typeof settings.data !== 'object' ) {
            return;
          }
          else {
            settings.data = JSON.stringify(settings.data);
          }
        }

        $.ajax({
          url         : settings.url,
          type        : settings.type,
          headers     : {
            "X-ApiKey" : APIkey
          },
          data        : settings.data,
          crossDomain : true,
          dataType    : 'json',
          cache       : cacheRequest
        })
        .done(settings.done)
        .fail(settings.fail)
        .always(settings.always);
      },

      // ---------------------
      // WEBSOCKET
      //
      
      ws = {
        socket      : false,
        socketReady : false,
        queue       : [],
        resources   : []
      };
  
  // CONNECT 
  
  ws.connect   = function ( callback ) {
    if ( window.MozWebSocket ) {
      window.WebSocket = window.MozWebSocket;
    } 
    
    if ( !ws.socket && window.WebSocket ) { 
      ws.socket = new WebSocket(WSendpoint);
    
      ws.socket.onerror = function( e ) {
        if ( ws.error ) { ws.error( e, this ); }
        ws.connect();
      };
    
      ws.socket.onclose = function( e ) {
        if ( ws.close ) { ws.close( e, this ); }
        ws.connect();
      };
    
      ws.socket.onopen = function( e ) {
        ws.socketReady = true;
        if ( ws.open )         { ws.open( e, this ); }
        if ( ws.queue.length )  { execute( ws.queue ); }
        if ( callback )         { callback( this ); }
      };
    
      ws.socket.onmessage = function( e ) {
        var data      = e.data,
            response  = JSON.parse( data );
        if ( response.body ) {
          $('body').trigger( "xively."+ response.resource, response.body );
        }
      };
    }
  };
  
  // SUBSCRIBE 
  
  ws.subscribe = function ( resource, callback ) {
    var request  = '{"headers":{"X-ApiKey":"' + APIkey + '"}, "method":"subscribe", "resource":"'+ resource +'"}';
        
    if ( !APIkey ) { 
      return log( "(xivelyJS) ::: No API key ::: Set your API key first with xively.setKey( YOUR_API_KEY ) before using any methods. Check docs for more info." );
    }
    
    if ( !ws.resources[resource] ) {
      ws.resources.push( resource );
      
      if ( !ws.socketReady ) {
        ws.connect();
        ws.queue.push(function() {
          ws.socket.send( request ); 
        });
      }
      else {
        ws.socket.send( request );
      }      
    }
    
    if ( callback && typeof callback === "function" ) {
      $( document ).on( "xively."+ resource, callback );
    }
  };
  
  // SUBSCRIBE 
  
  ws.unsubscribe = function ( resource ) {
    var request  = '{"headers":{"X-ApiKey":"' + APIkey + '"}, "method":"unsubscribe", "resource":"'+ resource +'"}';
        <commit_msg>Corrected typo<commit_after>// xivelyJS
// version 1.0.3
// (c) 2013 Xively Ltd, a LogMeIn company [<EMAIL>]
// http://xively.github.com/xively-js/
// released under the MIT license

var xively = (function ( $ ) {
  "use strict";

  /*
  *
  *   PRIVATE VARS & METHODS
  *
  */
	
  var APIkey,                                         // THIS SHOULD BE CHANGED WITH SETKEY()
      APIendpoint = "http://api.xively.com/v2/",
      WSendpoint = "ws://api.xively.com:8080/",
      methods,
      cacheRequest = false,

      // ---------------------
      // HELPERS 
      //
      
      execute = function ( arr ) {
        if ( typeof arr === "function" ) {
          arr.apply( this, Array.prototype.slice.call( arguments, 1 ));
        }
        else if ( Object.prototype.toString.apply(arr) === '[object Array]' ) {
          var x = arr.length; 
          while (x--) {
            arr[x].apply( this, Array.prototype.slice.call( arguments, 1 ));
          }
        }
      },
      
      log = function ( msg ) {
        if ( window.console && window.console.log ) {
          window.console.log( msg );
        }
      },
  
      // ---------------------
      // REQUEST (PRIVATE)
      //

      request = function( options ) {
        
        var settings = $.extend({
              type      : 'get'
            }, options);
        
        if ( !APIkey ) { 
          return log( "(xivelyJS) ::: No API key ::: Set your API key first with xively.setKey( YOUR_API_KEY ) before using any methods. Check docs for more info." );
        }
        
        if ( !settings.url ) { return; }
        settings.type = settings.type.toUpperCase();
            
        if ( settings.type === "PUT" || settings.type === "POST" ) {
          if ( !settings.data || typeof settings.data !== 'object' ) {
            return;
          }
          else {
            settings.data = JSON.stringify(settings.data);
          }
        }

        $.ajax({
          url         : settings.url,
          type        : settings.type,
          headers     : {
            "X-ApiKey" : APIkey
          },
          data        : settings.data,
          crossDomain : true,
          dataType    : 'json',
          cache       : cacheRequest
        })
        .done(settings.done)
        .fail(settings.fail)
        .always(settings.always);
      },

      // ---------------------
      // WEBSOCKET
      //
      
      ws = {
        socket      : false,
        socketReady : false,
        queue       : [],
        resources   : []
      };
  
  // CONNECT 
  
  ws.connect   = function ( callback ) {
    if ( window.MozWebSocket ) {
      window.WebSocket = window.MozWebSocket;
    } 
    
    if ( !ws.socket && window.WebSocket ) { 
      ws.socket = new WebSocket(WSendpoint);
    
      ws.socket.onerror = function( e ) {
        if ( ws.error ) { ws.error( e, this ); }
        ws.connect();
      };
    
      ws.socket.onclose = function( e ) {
        if ( ws.close ) { ws.close( e, this ); }
        ws.connect();
      };
    
      ws.socket.onopen = function( e ) {
        ws.socketReady = true;
        if ( ws.open )         { ws.open( e, this ); }
        if ( ws.queue.length )  { execute( ws.queue ); }
        if ( callback )         { callback( this ); }
      };
    
      ws.socket.onmessage = function( e ) {
        var data      = e.data,
            response  = JSON.parse( data );
        if ( response.body ) {
          $('body').trigger( "xively."+ response.resource, response.body );
        }
      };
    }
  };
  
  // SUBSCRIBE 
  
  ws.subscribe = function ( resource, callback ) {
    var request  = '{"headers":{"X-ApiKey":"' + APIkey + '"}, "method":"subscribe", "resource":"'+ resource +'"}';
        
    if ( !APIkey ) { 
      return log( "(xivelyJS) ::: No API key ::: Set your API key first with xively.setKey( YOUR_API_KEY ) before using any methods. Check docs for more info." );
    }
    
    if ( !ws.resources[resource] ) {
      ws.resources.push( resource );
      
      if ( !ws.socketReady ) {
        ws.connect();
        ws.queue.push(function() {
          ws.socket.send( request ); 
        });
      }
      else {
        ws.socket.send( request );
      }      
    }
    
    if ( callback && typeof callback === "function" ) {
      $( document ).on( "xively."+ resource, callback );
    }
  };
  
  // UNSUBSCRIBE 
  
  ws.unsubscribe = function ( resource ) {
    var request  = '{"headers":{"X-ApiKey":"' + APIkey + '"}, "method":"unsubscribe", "resource":"'+ resource +'"}';
        
{'fraction_non_alphanumeric': 0.15997373892110733, 'fraction_numerical': 0.003063792537476748, 'mean_word_length': 1.370331950207469, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5241646', 'n_tokens_mistral': 2844, 'n_tokens_neox': 2707, 'n_words': 591}