<commit_before># angular-http-polling
An AngularJS service that allows for continuously polling a remote server.

## Requirements

* **AngularJS v1.5.8+** is currently required.

## Installation

Install this plugin with:
```bash
$ bower install angular-http-polling
```

## Usage

### Injection

Add `ngHTTPPoll` as a dependency to your module and inject `$httpoll`:

```javascript
angular.module('YourModule',['ngHTTPPoll'])
    .controller('YourController', ['$httpoll'], function ($httpoll){
        // ...
    })
```

### Config Options

`$httpoll` wraps Angular's [`$http`](https://docs.angularjs.org/api/ng/service/$http) methods, polling the endpoint multiple times, based on the kind of behavior you configure. The API is the same for `$http`, except that it accepts additional keys in the config object:

- `delay` [integer] Time (in milliseconds) to delay the next retry after a response is received _(default: 100)_
- `errorRange` [array]: A range of HTTP status codes that the poller should interpret as errors _(default: [400, 599])_
- `followRedirect`: If a `Location` header is returned in the HTTP response, subsequent polling will target the address in that header using the `GET` method. (default: false)
- `retries` [integer] The maximum number of retries that the poller will attempt until it receives a status code in either the `successRange` or `errorRange` _(default: 50)_
- `retryOnError` [boolean] Polling continues if an error response is received _(default: true)_
- `successRange` [array]: A range of HTTP status codes that the poller should interpret as a success _(default: [200, 201])_
- `timeout` [integer] Timeout for polling - no further retries will be attempted. A false-y value means that the poller will never timeout. _(default: false)_
- `until` [function(response, config, state, actions)]: Until fires after every request. Polling will stop when this function returns a truth-y value (or unless polling time exceeds the set `timeout`). An error thrown from within the`until` function will stop polling, and the error's message will be sent to a `catch` function, if defined.

### Until Parameters

- `response`: The last response from the HTTP provider
- `config`: The current config values
- `state`: Gives access to the current state of polling
    - `retryCount`: The number of retries that have already been performed
- `actions`:
    - `default` [function()]: Calls the default `until` logic
    - `reConfig` [function(config)]: Overrides the config values for future requests



#### Examples

```javascript

// A GET request with only 10 retries
$httpoll({
    url: '/some_resource/123',
    method: 'GET',
    data: {resource: {...}},
    retries: 10
})

// A GET request that retries 50 times, with 200ms between each response/request<commit_msg>updates readme to clarify overriding the default status code behavior<commit_after># angular-http-polling
An AngularJS service that allows for continuously polling a remote server.

## Requirements

* **AngularJS v1.5.8+** is currently required.

## Installation

Install this plugin with:
```bash
$ bower install angular-http-polling
```

## Usage

### Injection

Add `ngHTTPPoll` as a dependency to your module and inject `$httpoll`:

```javascript
angular.module('YourModule',['ngHTTPPoll'])
    .controller('YourController', ['$httpoll'], function ($httpoll){
        // ...
    })
```

### Config Options

`$httpoll` wraps Angular's [`$http`](https://docs.angularjs.org/api/ng/service/$http) methods, polling the endpoint multiple times, based on the kind of behavior you configure. The API is the same for `$http`, except that it accepts additional keys in the config object:

- `delay` [integer] Time (in milliseconds) to delay the next retry after a response is received _(default: 100)_
- `errorRange` [array]: A range of HTTP status codes that the poller should interpret as errors _(default: [400, 599])_
- `followRedirect`: If a `Location` header is returned in the HTTP response, subsequent polling will target the address in that header using the `GET` method. Polling will continue regardless of whether the HTTP status code of the original response is within the `successRange` or `errorRange` (default: false)
- `retries` [integer] The maximum number of retries that the poller will attempt until it receives a status code in either the `successRange` or `errorRange` _(default: 50)_
- `retryOnError` [boolean] Polling continues if an error response is received _(default: true)_
- `successRange` [array]: A range of HTTP status codes that the poller should interpret as a success _(default: [200, 201])_
- `timeout` [integer] Timeout for polling - no further retries will be attempted. A false-y value means that the poller will never timeout. _(default: false)_
- `until` [function(response, config, state, actions)]: Until fires after every request. Polling will stop when this function returns a truth-y value (or unless polling time exceeds the set `timeout`). An error thrown from within the`until` function will stop polling, and the error's message will be sent to a `catch` function, if defined.

### Until Parameters

- `response`: The last response from the HTTP provider
- `config`: The current config values
- `state`: Gives access to the current state of polling
    - `retryCount`: The number of retries that have already been performed
- `actions`:
    - `default` [function()]: Calls the default `until` logic
    - `reConfig` [function(config)]: Overrides the config values for future requests



#### Examples

```javascript

// A GET request with only 10 retries
$httpoll({
    url: '/some_resource/123',
    method: 'GET',
    data: {resource: {...}},
    retries: 10
})

// A GET request that retries 50 times, with 200ms between each response/request
{'fraction_non_alphanumeric': 0.10295387804456728, 'fraction_numerical': 0.01105544999136293, 'mean_word_length': 4.503802281368821, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '433156', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1520, 'n_words': 742}