Skip to content

Commit

Permalink
Release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wejendorp committed Apr 12, 2014
1 parent 0996c2e commit f60d3cb
Show file tree
Hide file tree
Showing 7 changed files with 1,579 additions and 40 deletions.
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.2.0 / 2014-04-12
==================

* Complete rewrite for a much cleaner implementation and API.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

BROWSERS= "ie6..11, chrome, safari, firefox"
SRC= $(wildcard index.js lib/*.js)
SRC= $(wildcard index.js)
tests ?= *
BINS= node_modules/.bin
C= $(BINS)/component
Expand All @@ -16,6 +16,9 @@ build: node_modules components $(SRC)
components: component.json
@$(C) install --dev

release: node_modules components
@$(C) build -o release -n angular-superagent

kill:
-@test -e test/pid.txt \
&& kill `cat test/pid.txt` \
Expand Down
34 changes: 15 additions & 19 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# angular-superagent

Angular wrapper for [Superagent](https://github.com/visionmedia/superagent).

Written because the [Restangular](https://github.com/mgonto/restangular) api never made sense to me,
and superagent has a nicer api than [$http](http://docs.angularjs.org/api/ng.$http) or jQuery.

Expand All @@ -14,7 +14,8 @@
$ bower install angular-superagent

## API
The `Request` service works just like [superagent](https://github.com/visionmedia/superagent), except extended with promises and defaults via `RequestProvider`.
The `Request` service works just like [superagent](https://github.com/visionmedia/superagent),
except extended with promises and defaults via `RequestProvider.defaults`.

The request can be written as default superagent, e.g.
```js
Expand All @@ -30,27 +31,22 @@ Like `request#end`, but returns a promise instead of taking a callback.
Returns a [$q](http://docs.angularjs.org/api/ng.$q) promise, that is resolved with the superagent response object.

### request#end(fn)
The classic superagent request end, but applies configured transformations if any.
The classic superagent request end, but with configured defaults


## Configure: RequestProvider
### #baseUrl(url)
Append this url to all requests made with superagent

### #withCredentials()
Sets `withCredentials()` as the default. Usable for CORS.

### #setHeaders(headers)
Takes a header object, extends

### #timeout(n)
Timeout requests after n ms.

### #transform( fn(err, res, next) )
Add a transformation to response object, before making the callback in `request#end`.
Multiple transformations can be applied, and will be run in order of registration.
### defaults
To set new defaults just override the options here:
```js
RequestProvider.defaults = {
baseUrl: '',
headers: {},
credentials: true,
timeout: 10000
};
```

### #then(success, error)
### #addResolver(success, error)
Extends the promise chain returned from `request#promise()`,
useful for conditional transformations.

Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-superagent",
"main": "index.js",
"version": "0.1.0",
"main": "release/angular-superagent.js",
"version": "0.2.0",
"homepage": "https://github.com/wejendorp/angular-superagent",
"authors": [
"Jacob Wejendorp <[email protected]>"
Expand Down
10 changes: 5 additions & 5 deletions component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"name": "angular-superagent",
"repo": "wejendorp/angular-superagent",
"description": "Angular wrapper for Superagent",
"version": "0.0.1",
"version": "0.2.0",
"keywords": [],
"dependencies": {
"visionmedia/superagent": "*",
"component/emitter": "*",
"chaijs/chai": "*"
"component/emitter": "*"
},
"development": {
"visionmedia/debug": "0.7.4",
"ianstormtaylor/assert": "*"
"ianstormtaylor/assert": "*",
"chaijs/chai": "*"
},
"license": "MIT",
"main": "index.js",
"scripts": [
"index.js"
]
}
}
23 changes: 10 additions & 13 deletions examples/RequestConfig.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
angular.module('ng-superagent')
.config(['RequestProvider', function(RequestProvider) {
RequestProvider
.baseUrl('http://localhost:3000')
.withCredentials()
.setHeaders({'Authentication': 'Token cookiemonster'})
.timeout(2500)
.transform(function(err, res, next) {
next(err, res);
})
.then(function(res) {
RequestProvider.defaults = {
baseUrl: '',
timeout: 10000,
headers: {},
credentials: true
};
RequestProvider.addResolver(function(res) {
if(res.body)
})

}, function(err) {

});
}]);
}]);
Loading

0 comments on commit f60d3cb

Please sign in to comment.