Skip to content

Commit

Permalink
Added Object.assign, closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Amareis committed Jun 13, 2016
1 parent 395144a commit 633e89a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 13 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ All the examples given above are based on the default settings. If for some reas
All configuration is done using the object passed to the constructor or method `conf`. Some options are also duplicated by optional methods arguments.
`conf` returns full options. If you call it without parameters (just `conf()`), it gives you current options.
```js
console.log(api.conf());
/* Defaults:
{
trailing: '',
shortcut: true,
contentType: 'application/json',
'application/x-www-form-urlencoded': {encode: encodeUrl},
'application/json': {encode: JSON.stringify, decode: JSON.parse}
}*/
```
If you want change RestClient host (lol why?..), you can just:
```js
api.host = 'http://example2.com';
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "another-rest-client",
"version": "0.3.1",
"version": "0.3.2",
"description": "Simple REST API client that makes your code lesser and more beautiful than without it.",
"main": "rest-client.js",
"scripts": {
Expand All @@ -23,6 +23,7 @@
"devDependencies": {
"babel": "^6.5.2",
"babel-loader": "^6.2.4",
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"chai": "^3.5.0",
"minivents": "^2.0.2",
Expand Down
10 changes: 6 additions & 4 deletions rest-client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rest-client.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rest-client.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rest-client.min.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/rest-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ class RestClient {
}

conf(options={}) {
this._opts = this._opts || {
let currentOptions = this._opts || {
trailing: '',
shortcut: true,
contentType: 'application/json',
'application/x-www-form-urlencoded': {encode: encodeUrl},
'application/json': {encode: JSON.stringify, decode: JSON.parse}
};

for (let k in options) {
this._opts[k] = options[k];
}
this._opts = Object.assign(currentOptions, options);

return Object.assign({}, this._opts);
}

_request(method, url, data=null, contentType=null) {
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ module.exports = {
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['es2015']
presets: ['es2015'],
plugins: ['transform-object-assign']
}
}
]
Expand Down

0 comments on commit 633e89a

Please sign in to comment.