<commit_before>/******************** Library Code *************************/
class SparkFunStream {
    _baseUrl = null;
    
    _publicKey = null;
    _privateKey = null;
    
    _deleteKey = null;
    
    constructor(baseUrl, publicKey, privateKey) {
        _baseUrl = baseUrl;
        _privateKey = privateKey;
        _publicKey = publicKey;
    }
    
    function push(data, cb = null) {
        assert(typeof(data == "table"));
        
        // add private key to table
        data["private_key"] <- _privateKey;
        local url = format("https://%s/input/%s?%s", _baseUrl, _publicKey, http.urlencode(data));
        
        // make the request
        local request = http.get(url);
        if (cb == null) {
            return request.sendsync(cb);
        }
        
        request.sendasync(cb);
    }
    
    function get(cb = null) {
        local url = format("https://%s/output/%s.json", _baseUrl, _publicKey);
        
        local request = http.get(url);
        if(cb == null) {
            return request.sendsync();
        }
        return request.sendasync(cb);
    }
    
    function clear(cb = null) {
        local url = format("https://%s/input/%s/clear", _baseUrl, _publicKey);
        local headers = { "phant-private-key": _privateKey };
        
        local request = http.httpdelete(url, headers);
        if (cb == null) {
            return request.sendsync();
        }
        return request.sendasync(cb);
    }
}

/******************** Application Code ********************/
// Create a Sparkfun Data Stream

const SPARKFUN_BASE = "data.sparkfun.com";
const SPARKFUN_PUBLIC_KEY = "";
const SPARKFUN_PRIVATE_KEY = "";

stream <- SparkFunStream(SPARKFUN_BASE, SPARKFUN_PUBLIC_KEY, SPARKFUN_PRIVATE_KEY);

//Syncronous Push:
local resp = stream.push({ temp = 102.5 });
server.log(format("PUSH: %i - %s", resp.statuscode, resp.body));

//Asyncronous Push:
stream.push({ temp = 103}, function(resp) {
    server.log(format("PUSH: %i - %s", resp.statuscode, resp.body));
})

// Syncronous Get:
resp = stream.get();
server.log(resp.body);

// ASyncronous Get:
stream.get(function(resp) {
    server.log(resp.body);
});

// Syncronous Clear:
resp = stream.clear();
server.log(format("CLEAR: %i - %s", resp.statuscode, resp.body));

// Asyncronous Clear:
stream.clear(function(resp) {
    server.log(format("CLEAR: %i - %s", resp.statuscode, resp.body));
});

<commit_msg>Removed delete key - uncertain what it's for<commit_after>/******************** Library Code *************************/
class SparkFunStream {
    _baseUrl = null;
    
    _publicKey = null;
    _privateKey = null;
   
    constructor(baseUrl, publicKey, privateKey) {
        _baseUrl = baseUrl;
        _privateKey = privateKey;
        _publicKey = publicKey;
    }
    
    function push(data, cb = null) {
        assert(typeof(data == "table"));
        
        // add private key to table
        data["private_key"] <- _privateKey;
        local url = format("https://%s/input/%s?%s", _baseUrl, _publicKey, http.urlencode(data));
        
        // make the request
        local request = http.get(url);
        if (cb == null) {
            return request.sendsync(cb);
        }
        
        request.sendasync(cb);
    }
    
    function get(cb = null) {
        local url = format("https://%s/output/%s.json", _baseUrl, _publicKey);
        
        local request = http.get(url);
        if(cb == null) {
            return request.sendsync();
        }
        return request.sendasync(cb);
    }
    
    function clear(cb = null) {
        local url = format("https://%s/input/%s/clear", _baseUrl, _publicKey);
        local headers = { "phant-private-key": _privateKey };
        
        local request = http.httpdelete(url, headers);
        if (cb == null) {
            return request.sendsync();
        }
        return request.sendasync(cb);
    }
}

/******************** Application Code ********************/
// Create a Sparkfun Data Stream

const SPARKFUN_BASE = "data.sparkfun.com";
const SPARKFUN_PUBLIC_KEY = "";
const SPARKFUN_PRIVATE_KEY = "";

stream <- SparkFunStream(SPARKFUN_BASE, SPARKFUN_PUBLIC_KEY, SPARKFUN_PRIVATE_KEY);

//Syncronous Push:
local resp = stream.push({ temp = 102.5 });
server.log(format("PUSH: %i - %s", resp.statuscode, resp.body));

//Asyncronous Push:
stream.push({ temp = 103}, function(resp) {
    server.log(format("PUSH: %i - %s", resp.statuscode, resp.body));
})

// Syncronous Get:
resp = stream.get();
server.log(resp.body);

// ASyncronous Get:
stream.get(function(resp) {
    server.log(resp.body);
});

// Syncronous Clear:
resp = stream.clear();
server.log(format("CLEAR: %i - %s", resp.statuscode, resp.body));

// Asyncronous Clear:
stream.clear(function(resp) {
    server.log(format("CLEAR: %i - %s", resp.statuscode, resp.body));
});


{'fraction_non_alphanumeric': 0.1781727986771393, 'fraction_numerical': 0.0028937577511368336, 'mean_word_length': 2.5897626112759644, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 6, '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': '6714866', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1532, 'n_words': 324}