<commit_before>[![Build Status](https://secure.travis-ci.org/fluffybunnies/glados.png)](http://travis-ci.org/fluffybunnies/glados)

# glados
Monitor remote resource for changes
- Use the cli wrapper to send an email notification or POST to a url when the resource has changed
- Supports Gmail and SES for email
- Diffs are calculated using kpdecker's [diff](https://www.npmjs.com/package/diff)
- Will not start polling until client binds to `'change'`


## App
```javascript
var glados = require('glados')

var watcher = glados('http://example.com/sensitive_data.html', 1000*60)
.on('change',function(diff){
	// do something with diff
})
.on('connection',function(data){
	// data = response from first poll
})
.on('error',function(err){
	// we have some problem connecting with resource
})
```


## CLI Wrapper
See api notes below for opts
```bash
node ./bin/cli.js http://example.com/sensitive_data.html -n60000 \
-p http://myapi.example.com/notify_change \
-m <EMAIL>
```


## Forever Wrapper
Make sure this thing never goes down. Wraps cli.js with sturdiness
```
./bin/forever.sh http://example.com/sensitive_data.html -n60000 \
-p http://myapi.example.com/notify_change \
-m <EMAIL>
```
Kill the process, stop the forever, reboot the instance. Baby will still be kickin.


##### Kill Forever
Shut down what you started with `forever.sh`
```
./bin/kill_forever.sh http://example.com/sensitive_data.html
```


## App Api

##### glados( ttl [, pollInterval] )
returns a `watcher` that will monitor changes of `url`<br />
_string_ `url` - remote resource to watch<br />
_int_ `pollInterval` - interval in ms to check resource for changes. defaults to 1 minute

##### watcher.stop()
Stop watching. No further events will be fired after this is called.

##### watcher.on('change', function(diff){})
Fired when a change has been detected in remote resource<br />
_Array_ `diff` - an array of data comprising added, removed, and unchanged chunks

##### watcher.on('connection', function(data){})
Fired on response from initial poll<br />
_Buffer_ `data` - the response data

##### watcher.on('poll', function(){})
Fired immediately prior to each poll. The first `'poll'` event occurs before `'connection'`<br />

##### watcher.on('error', function(err){})
Catch errors in the stream


## CLI Api

##### Arguments
Applies to both `cli.js` and `forever.sh`
- `[target]`
	- url of resource to watch
- `-n` or `--interval`
	- pollInterval
	- optional, defaults to 1 minute
- `-p` or `--post`
	- endpoint to post `diff` on change event
	- optional
	- supports multiple
- `-m` or `--email`
	- email address to send `diff` on change event
	- optional
	- supports multiple


## Email
Copy &nbsp;`config.sh`&nbsp; to &nbsp;`config.local.sh`&nbsp; and add credentials

##### Gmail
Set &nbsp;`mailTransport`&nbsp; to 'gmail'<br />
Use an application password (not your personal account password)

##### SES
Set &nbsp;`mailTransport`&nbsp; to 'ses'<br />
Set your AWS secret and key, along with an approved From address


## To Do
- Forever updates
	- Save data locally in case of reboot to avoid missing a change event



<!--
cd /root
git clone https://github.com/fluffybunnies/glados.git
cd glados
npm install
echo '' > ./config.local.json && vim ./config.local.json

node /root/glados/bin/cli.js http://www.huffingtonpost.<EMAIL> -n5000 \
-m <EMAIL>

node /root/glados/bin/cli.js http://www.huffingtonpost.com -n5000 \<commit_msg>readme reformat for npm website<commit_after>[![Build Status](https://secure.travis-ci.org/fluffybunnies/glados.png)](http://travis-ci.org/fluffybunnies/glados)

# glados
Monitor remote resource for changes
- Use the cli wrapper to send an email notification or POST to a url when the resource has changed
- Supports Gmail and SES for email
- Diffs are calculated using kpdecker's [diff](https://www.npmjs.com/package/diff)
- Will not start polling until client binds to `'change'`


## App
```javascript
var glados = require('glados')

var watcher = glados('http://example.com/sensitive_data.html', 1000*60)
.on('change',function(diff){
	// do something with diff
})
.on('connection',function(data){
	// data = response from first poll
})
.on('error',function(err){
	// we have some problem connecting with resource
})
```


## CLI Wrapper
See api notes below for opts
```bash
node ./bin/cli.js http://example.com/sensitive_data.html -n60000 \
-p http://myapi.example.com/notify_change \
-m <EMAIL>
```


## Forever Wrapper
Make sure this thing never goes down. Wraps cli.js with sturdiness
```
./bin/forever.sh http://example.com/sensitive_data.html -n60000 \
-p http://myapi.example.com/notify_change \
-m <EMAIL>
```
Kill the process, stop the forever, reboot the instance. Baby will still be kickin.


##### Kill Forever
Shut down what you started with `forever.sh`
```
./bin/kill_forever.sh http://example.com/sensitive_data.html
```


## App Api

##### glados( ttl [, pollInterval] )
returns a `watcher` that will monitor changes of `url`<br />
_string_ `url` - remote resource to watch<br />
_int_ `pollInterval` - interval in ms to check resource for changes. defaults to 1 minute

##### watcher.stop()
Stop watching. No further events will be fired after this is called.

##### watcher.on('change', function(diff){})
Fired when a change has been detected in remote resource<br />
_Array_ `diff` - an array of data comprising added, removed, and unchanged chunks

##### watcher.on('connection', function(data){})
Fired on response from initial poll<br />
_Buffer_ `data` - the response data

##### watcher.on('poll', function(){})
Fired immediately prior to each poll. The first `'poll'` event occurs before `'connection'`<br />

##### watcher.on('error', function(err){})
Catch errors in the stream


## CLI Api

##### Arguments
Applies to both `cli.js` and `forever.sh`
- `[target]`
	- url of resource to watch
- `-n` or `--interval`
	- pollInterval
	- optional, defaults to 1 minute
- `-p` or `--post`
	- endpoint to post `diff` on change event
	- optional
	- supports multiple
- `-m` or `--email`
	- email address to send `diff` on change event
	- optional
	- supports multiple


## Email
Copy &nbsp; `config.sh` &nbsp; to &nbsp; `config.local.sh` &nbsp; and add credentials

##### Gmail
Set &nbsp; `mailTransport` &nbsp; to 'gmail'<br />
Use an application password (not your personal account password)

##### SES
Set &nbsp; `mailTransport` &nbsp; to 'ses'<br />
Set your AWS secret and key, along with an approved From address


## To Do
- Forever updates
	- Save data locally in case of reboot to avoid missing a change event



<!--
cd /root
git clone https://github.com/fluffybunnies/glados.git
cd glados
npm install
echo '' > ./config.local.json && vim ./config.local.json

node /root/glados/bin/cli.js http://www.huffingtonpost.com -n5000 \
-m <EMAIL>

node /root/glados/bin/cli.js http://www.huffingtonpost.com -n5000 \
{'fraction_non_alphanumeric': 0.14406532516768739, 'fraction_numerical': 0.00758238553514144, 'mean_word_length': 4.054532056005895, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, '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': '2288800', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2167, 'n_words': 760}