Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "ask", | ||
"main": "dist/ask.js", | ||
"version": "1.0.0", | ||
"version": "1.2.0", | ||
"homepage": "https://github.com/divshot/ask", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -19,3 +19,3 @@ #!/usr/bin/env node | ||
browserify(ENTRY_FILE, { | ||
standalone: 'RequestBuilder' | ||
standalone: 'Ask' | ||
}) | ||
@@ -22,0 +22,0 @@ .bundle() |
31
index.js
@@ -23,2 +23,4 @@ var asArray = require('as-array'); | ||
this.resources = {}; | ||
// Set up http method mocks | ||
@@ -62,9 +64,7 @@ this.mocks = {}; | ||
Ask.prototype.http = function (method) { | ||
var self = this; | ||
var rawHttp = this._rawHttp; | ||
var uri = rest(asArray(arguments)).join('/'); | ||
// Handle mocking requests | ||
var mock = this.mock(method, uri); | ||
if (mock) return mock.fn(); | ||
// New resource object | ||
@@ -79,9 +79,12 @@ var resource = function (params) { | ||
extend(resourceObject, resource.xhrOptions || {}); | ||
return rawHttp(resourceObject); | ||
// Should this resource be mocked, or real? | ||
// It is ensured that you can define the mock before | ||
// or after the resource is defined | ||
var mock = self.mock(method, uri); | ||
return mock | ||
? mock.fn()() | ||
: rawHttp(extend(resourceObject, resource.xhrOptions || {})); | ||
}; | ||
resource._uri = uri; | ||
resource._builderInstance = this; | ||
resource.attributes = clone(this.attributes); | ||
@@ -91,4 +94,16 @@ resource.headers = clone(this.headers); | ||
resource.queries = clone(this.queries); | ||
resource.extend = function () { | ||
var extended = clone(resource); | ||
extended._uri = join(resource._uri + '/' + asArray(arguments).join('/')); | ||
return extended; | ||
}; | ||
proto.mixInto(resource); | ||
// Store resources | ||
this.resources[resource.url()] = resource; | ||
return resource; | ||
@@ -95,0 +110,0 @@ }; |
{ | ||
"name": "ask", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A simple, chainable way to construct HTTP requests in Node or the browser", | ||
@@ -10,9 +10,7 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "npm run lint && npm run build && npm run test-server && npm run test-browser", | ||
"test": "npm run lint && npm run build && npm run test-server", | ||
"test-server": "echo '\nTesting Server:\n' && mocha test/server/**/*.js --reporter spec", | ||
"test-browser": "echo '\nTesting Angular:\n\n' && ./node_modules/karma/bin/karma start karma.conf.js", | ||
"lint": "jshint index.js lib/", | ||
"build": "npm run bundle-standalone && npm run bundle-angular", | ||
"bundle-standalone": "build/standalone.js", | ||
"bundle-angular": "build/angular.js" | ||
"build": "build/standalone.js" | ||
}, | ||
@@ -40,11 +38,6 @@ "repository": { | ||
"jshint": "^2.5.6", | ||
"karma": "^0.12.24", | ||
"karma-expect": "^1.1.0", | ||
"karma-mocha": "^0.1.9", | ||
"karma-phantomjs-launcher": "^0.1.4", | ||
"minify": "^1.0.3", | ||
"mkdirp": "^0.5.0", | ||
"mocha": "^1.21.4", | ||
"mocha": "^2.0.1", | ||
"mocksy": "^0.1.7", | ||
"ngmin": "^0.5.0", | ||
"testling": "^1.7.1" | ||
@@ -59,4 +52,4 @@ }, | ||
"promise": "^6.0.0", | ||
"slasher": "^0.1.5" | ||
"slasher": "^1.1.0" | ||
} | ||
} |
# ask | ||
A simple, chainable way to construct HTTP requests in Node or the browser (Angular or Standalone); | ||
A simple, chainable way to construct HTTP requests in Node or the browser. | ||
@@ -8,3 +8,2 @@ **Usage Environments:** | ||
* [Node]() | ||
* [Angular]() | ||
* [Browser Standalone]() | ||
@@ -36,31 +35,2 @@ | ||
Angular | ||
```html | ||
<script src="/bower_components/ask/dist/ask.angular.js"></script> | ||
``` | ||
```js | ||
var myApp = angular.module('myApp', ['ask']); | ||
myApp.config(function (askProvider) { | ||
/* This is optional */ | ||
askProvider.configure({ | ||
origin: 'http://api.example.com', | ||
headers: {/* optional default headers */}, | ||
xhrOptions: {/* optional xhr options */} | ||
}); | ||
}); | ||
myApp.controller('SomeController', function (ask /* instance of Ask */) { | ||
}); | ||
myApp.controller('AnotherController', function (Ask /* ready to instantiate */) { | ||
}) | ||
``` | ||
Nodejs/Browserify | ||
@@ -180,3 +150,3 @@ | ||
Builds standalone and Angular version of the module | ||
Builds standalone version | ||
@@ -183,0 +153,0 @@ ``` |
@@ -127,2 +127,20 @@ var expect = require('chai').expect; | ||
it('extends a resource', function () { | ||
request | ||
.origin(ORIGIN); | ||
var tests = request | ||
.get('tests') | ||
.header('custom', 'header') | ||
.query('test', 'ing'); | ||
var oneTest = tests | ||
.extend('123') | ||
.header('extended', 'header'); | ||
expect(oneTest.url()).to.equal(ORIGIN + '/tests/123?test=ing'); | ||
expect(oneTest.headers.custom).to.equal('header'); | ||
expect(oneTest.headers.extended).to.equal('header'); | ||
}); | ||
}); | ||
@@ -129,0 +147,0 @@ |
@@ -29,2 +29,16 @@ var expect = require('chai').expect; | ||
it('works in any order', function () { | ||
var tester = request.get('test'); | ||
request | ||
.when('GET', '/test') | ||
.respond('testing'); | ||
return tester().then(function (res) { | ||
}); | ||
}); | ||
it('sets a custom status code', function () { | ||
@@ -31,0 +45,0 @@ request |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
8
4
4
308284
14
8688
160
+ Addedlodash@4.17.21(transitive)
+ Addedslasher@1.1.0(transitive)
+ Addedtoxic@1.0.1(transitive)
- Removedslasher@0.1.5(transitive)
Updatedslasher@^1.1.0