Skip to content

Commit e56fd6b

Browse files
committed
feat: add sources
0 parents  commit e56fd6b

13 files changed

+387
-0
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[Makefile]
12+
charset = utf-8
13+
indent_style = tabs
14+
indent_size = 2
15+
end_of_line = lf
16+
trim_trailing_whitespace = true
17+
insert_final_newline = false

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
npm-debug.log
3+
.DS_Store
4+
bower_components
5+
report

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- stable
4+
before_install:
5+
- npm install -g bower
6+
- bower install

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
The MIT License
2+
3+
Copyright (c) Tomas Aparicio
4+
5+
Permission is hereby granted, free of charge, to any person
6+
obtaining a copy of this software and associated documentation
7+
files (the "Software"), to deal in the Software without
8+
restriction, including without limitation the rights to use,
9+
copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following
12+
conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
VERSION = 0.1.0
2+
BROWSERIFY = node ./node_modules/browserify/bin/cmd.js
3+
MOCHA = ./node_modules/.bin/mocha
4+
UGLIFYJS = ./node_modules/.bin/uglifyjs
5+
BANNER = "/*! theon-angular-adapter - v$(VERSION) - MIT License - https://github.com/theonjs/theon-angular-adapter */"
6+
MOCHA_PHANTOM = ./node_modules/.bin/mocha-phantomjs
7+
8+
default: all
9+
all: test
10+
browser: uglify
11+
test: browser mocha
12+
13+
uglify:
14+
$(UGLIFYJS) angular-adapter.js --mangle --preamble $(BANNER) --source-map angular-adapter.min.js.map --source-map-url http://cdn.rawgit.com/theonjs/theon-angular-adapter/$(VERSION)/angular-adapter.min.js.map > angular-adapter.min.js
15+
16+
mocha:
17+
$(MOCHA_PHANTOM) --reporter spec --ui bdd test/runner.html
18+
19+
loc:
20+
wc -l angular-adapter.js
21+
22+
gzip:
23+
gzip -c angular-adapter.min.js | wc -c
24+
25+
publish: browser release
26+
git push --tags origin HEAD:master
27+
npm publish

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# theon-angular-adapter [![Build Status](https://api.travis-ci.org/theonjs/theon-angular-adapter.svg?branch=master)][travis]
2+
3+
AngularJS [$http](https://docs.angularjs.org/api/ng/service/$http) agent adapter for theon based API clients
4+
5+
It works with Angular `+1.0`.
6+
7+
## Installation
8+
9+
Via [npm](http://npmjs.com)
10+
```bash
11+
npm install theon-angular-adapter
12+
```
13+
14+
Via [Bower](http://bower.io)
15+
```bash
16+
bower install theon-angular-adapter
17+
```
18+
19+
Or loading the script remotely
20+
```html
21+
<script src="//cdn.rawgit.com/theonjs/theon-angular-adapter/master/angular-adapter.js"></script>
22+
```
23+
24+
### Environments
25+
26+
- Chrome >= 5
27+
- Firefox >= 3
28+
- Safari >= 5
29+
- Opera >= 10
30+
- IE >= 9
31+
32+
### Setup
33+
34+
Load the module as dependency of your application
35+
```js
36+
var app = angular.module('app', ['theon.adapter'])
37+
```
38+
39+
### Services
40+
41+
#### $resilient
42+
43+
Main service to creating new Resilient HTTP clients
44+
45+
```js
46+
app.config(function ($theonAdapter) {
47+
// Configure theon to use the agent adapter
48+
theon.agents.set($theonAdapter)
49+
})
50+
```
51+
52+
## API
53+
54+
`theon` API [documentation](https://github.com/h2non/theon).
55+
56+
### $theonAdapter(req, res, done)
57+
58+
`theon` HTTP agent adapter.
59+
60+
### Development
61+
62+
Only [node.js](http://nodejs.org) is required for development
63+
64+
Clone the repository
65+
```bash
66+
$ git clone https://github.com/theonjs/theon-angular-adapter.git && cd theon-angular-adapter
67+
```
68+
69+
Install dependencies
70+
```bash
71+
$ npm install
72+
```
73+
```bash
74+
$ bower install
75+
```
76+
77+
Generate browser bundle source
78+
```bash
79+
$ make browser
80+
```
81+
82+
Run tests
83+
```bash
84+
$ make test
85+
```
86+
87+
## License
88+
89+
[MIT](http://opensource.org/licenses/MIT) © Tomas Aparicio
90+
91+
[travis]: http://travis-ci.org/theonjs/theon-angular-adapter

angular-adapter.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*! theon-angular-adapter - v0.1.0 - MIT License - https://github.com/theonjs/theon-angular-adapter */
2+
angular.module('theon.adapter', [])
3+
4+
.factory('$theonAdapter', ['$http', '$theonResponseAdapter', function ($http, adapter) {
5+
var httpAgent = $http
6+
7+
function $httpAdapter (req, res, done) {
8+
var opts = {
9+
url: req.url,
10+
method: req.method,
11+
auth: req.opts.auth,
12+
params: req.query,
13+
headers: req.headers,
14+
data: req.body,
15+
cache: req.agentOpts.cache,
16+
timeout: +req.opts.timeout || +req.agentOpts.timeout,
17+
withCredentials: req.agentOpts.withCredentials,
18+
xsrfHeaderName: req.agentOpts.xsrfHeaderName,
19+
xsrfCookieName: req.agentOpts.xsrfCookieName,
20+
transformRequest: req.agentOpts.transformRequest,
21+
transformResponse: req.agentOpts.transformResponse,
22+
paramSerializer: req.agentOpts.paramSerializer,
23+
responseType: req.agentOpts.responseType
24+
}
25+
26+
httpAgent(opts).then(function (_res) {
27+
done(null, adapter(res, _res))
28+
}, function (err) {
29+
done(adapter(res, err))
30+
})
31+
}
32+
33+
$httpAdapter.setAgent = function (agent) {
34+
httpAgent = agent
35+
}
36+
37+
return $httpAdapter
38+
}])
39+
40+
.factory('$theonResponseAdapter', ['$q', function ($q) {
41+
return function responseAdapter (res, _res) {
42+
if (!_res) return res
43+
44+
// Expose the agent-specific response
45+
res.setOriginalResponse(_res)
46+
47+
// Define recurrent HTTP fields
48+
res.setStatus(_res.status)
49+
res.setStatusText(_res.statusText)
50+
res.setHeaders(_res.headers)
51+
52+
// Define body, if present
53+
if (_res.data) res.setBody(_res.data)
54+
55+
return res
56+
}
57+
}])

angular-adapter.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular-adapter.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bower.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "theon-angular-adapter",
3+
"description": "Angular's $http agent adapter for theon based API clients",
4+
"version": "0.1.0",
5+
"license": "MIT",
6+
"author": "Tomas Aparicio",
7+
"repository": "theonjs/theon-angular-adapter",
8+
"main": "angular-adapter.js",
9+
"keywords": [
10+
"theon",
11+
"adapter",
12+
"http",
13+
"adapter",
14+
"api",
15+
"angular"
16+
],
17+
"ignore": [
18+
"**/.*",
19+
".*",
20+
"*.md",
21+
"src",
22+
"lib",
23+
"test",
24+
"Makefile",
25+
".editorconfig",
26+
".gitignore",
27+
".travis.yml",
28+
".npmignore",
29+
"package.json",
30+
"examples"
31+
],
32+
"devDependencies": {
33+
"theon.js": "~0.1.23"
34+
}
35+
}

0 commit comments

Comments
 (0)