Skip to content

Commit 4a832da

Browse files
committed
update dist files ofr 0.3.0
1 parent f46535d commit 4a832da

2 files changed

Lines changed: 47 additions & 11 deletions

File tree

dist/hook.js

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/doubleleft/hook-javascript
44
*
55
* @copyright 2015 Doubleleft
6-
* @build 2/11/2015
6+
* @build 2/19/2015
77
*/
88
(function(window) {
99
//
@@ -9720,20 +9720,22 @@ window.Hook = Hook;
97209720
* @param {Object} options
97219721
* @param {String} options.app_id
97229722
* @param {String} options.key
9723-
* @param {String} options.url default: http://hook.dev
9723+
* @param {String} options.endpoint default: http://hook.dev
97249724
*
97259725
* @constructor
97269726
*/
97279727

97289728
Hook.Client = function(options) {
97299729
if (!options) { options = {}; }
9730-
this.url = options.endpoint || options.url || window.location.origin;
9730+
this.endpoint = options.endpoint || options.url || window.location.origin;
97319731
this.app_id = options.app_id || options.appId || "";
97329732
this.key = options.key || "";
97339733

9734+
this.options = (typeof(options.options) !== "undefined") ? options.options : {};
9735+
97349736
// append last slash if doesn't have it
9735-
if (this.url.lastIndexOf('/') != this.url.length - 1) {
9736-
this.url += "/";
9737+
if (this.endpoint.lastIndexOf('/') != this.endpoint.length - 1) {
9738+
this.endpoint += "/";
97379739
}
97389740

97399741
/**
@@ -9803,6 +9805,29 @@ Hook.Client.prototype.channel = function(name, options) {
98039805
return new Hook.Channel[options.transport](this, collection, options);
98049806
};
98059807

9808+
/**
9809+
* Get remote URL string.
9810+
* @method url
9811+
* @param {String} route
9812+
* @return {String}
9813+
*
9814+
* @example Downloading data from a hook route
9815+
*
9816+
* location.href = client.url('download', { something: "hey" })
9817+
*
9818+
* @example Using custom hook route for image catpcha
9819+
*
9820+
* // Implementing custom route for captcha: https://github.com/doubleleft/hook/wiki/Composer-dependencies
9821+
* var img = new Image();
9822+
* img.src = client.url('captcha');
9823+
*
9824+
*/
9825+
Hook.Client.prototype.url = function(route, params) {
9826+
var serializedParams = "";
9827+
if (params) { serializedParams = "&" + this.serialize(params); }
9828+
return this.endpoint + route + this._getCredentialsParams() + serializedParams;
9829+
};
9830+
98069831
/**
98079832
* Create resource
98089833
* @method post
@@ -9870,14 +9895,18 @@ Hook.Client.prototype.request = function(segments, method, data) {
98709895
request_headers["Content-Type"] = 'application/json'; // exchange data via JSON to keep basic data types
98719896
}
98729897

9898+
// Use method override? (some web servers doesn't respond to DELETE/PUT requests)
9899+
if (method !== "GET" && method !== "POST" && this.options.method_override) {
9900+
request_headers['X-HTTP-Method-Override'] = method;
9901+
method = "POST";
9902+
}
9903+
98739904
if (typeof(XDomainRequest) !== "undefined") {
98749905
// XMLHttpRequest#setRequestHeader isn't implemented on Internet Explorer's XDomainRequest
9875-
segments += "?X-App-Id=" + this.app_id + "&X-App-Key=" + this.key + "&r=" + Math.floor(Math.random()*1000);
9876-
var auth_token = this.auth.getToken();
9877-
if (auth_token) { segments += '&X-Auth-Token=' + auth_token; }
9906+
segments += this._getCredentialsParams() + "&r=" + Math.floor(Math.random()*1000);
98789907
}
98799908

9880-
var xhr = deferred.promise.xhr = uxhr(this.url + segments, payload, {
9909+
var xhr = deferred.promise.xhr = uxhr(this.endpoint + segments, payload, {
98819910
method: method,
98829911
headers: request_headers,
98839912
sync: synchronous,
@@ -10024,6 +10053,13 @@ Hook.Client.prototype.getPayload = function(method, data) {
1002410053
return payload;
1002510054
}
1002610055

10056+
Hook.Client.prototype._getCredentialsParams = function() {
10057+
var params = "?X-App-Id=" + this.app_id + "&X-App-Key=" + this.key;
10058+
var auth_token = this.auth.getToken();
10059+
if (auth_token) { params += '&X-Auth-Token=' + auth_token; }
10060+
return params;
10061+
}
10062+
1002710063
Hook.Client.prototype.serialize = function(obj, prefix) {
1002810064
var str = [];
1002910065
for (var p in obj) {

0 commit comments

Comments
 (0)