diff --git a/browser/components/loop/MozLoopAPI.jsm b/browser/components/loop/MozLoopAPI.jsm
index 738b174425e..408d483462e 100644
--- a/browser/components/loop/MozLoopAPI.jsm
+++ b/browser/components/loop/MozLoopAPI.jsm
@@ -42,19 +42,6 @@ function injectLoopAPI(targetWindow) {
}
},
- /**
- * Returns the url for the Loop server from preferences.
- *
- * @return {String} The Loop server url
- */
- serverUrl: {
- enumerable: true,
- configurable: true,
- get: function() {
- return Services.prefs.getCharPref("loop.server");
- }
- },
-
/**
* Returns the current locale of the browser.
*
@@ -214,7 +201,40 @@ function injectLoopAPI(targetWindow) {
ringer = null;
}
}
- }
+ },
+
+ /**
+ * Performs a hawk based request to the loop server.
+ *
+ * Callback parameters:
+ * - {Object|null} null if success. Otherwise an object:
+ * {
+ * code: 401,
+ * errno: 401,
+ * error: "Request failed",
+ * message: "invalid token"
+ * }
+ * - {String} The body of the response.
+ *
+ * @param {String} path The path to make the request to.
+ * @param {String} method The request method, e.g. 'POST', 'GET'.
+ * @param {Object} payloadObj An object which is converted to JSON and
+ * transmitted with the request.
+ * @param {Function} callback Called when the request completes.
+ */
+ hawkRequest: {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: function(path, method, payloadObj, callback) {
+ // XXX Should really return a DOM promise here.
+ return MozLoopService.hawkRequest(path, method, payloadObj).then((response) => {
+ callback(null, response.body);
+ }, (error) => {
+ callback(Cu.cloneInto(error, targetWindow));
+ });
+ }
+ },
};
let contentObj = Cu.createObjectIn(targetWindow);
diff --git a/browser/components/loop/MozLoopService.jsm b/browser/components/loop/MozLoopService.jsm
index a5b91b39ad9..68ad0850f57 100644
--- a/browser/components/loop/MozLoopService.jsm
+++ b/browser/components/loop/MozLoopService.jsm
@@ -147,6 +147,11 @@ let MozLoopServiceInternal = {
* @param {String} method The request method, e.g. 'POST', 'GET'.
* @param {Object} payloadObj An object which is converted to JSON and
* transmitted with the request.
+ * @returns {Promise}
+ * Returns a promise that resolves to the response of the API call,
+ * or is rejected with an error. If the server response can be parsed
+ * as JSON and contains an 'error' property, the promise will be
+ * rejected with this JSON-parsed response.
*/
hawkRequest: function(path, method, payloadObj) {
if (!this._hawkClient) {
@@ -481,5 +486,22 @@ this.MozLoopService = {
"; exception: " + ex);
return null;
}
- }
+ },
+
+ /**
+ * Performs a hawk based request to the loop server.
+ *
+ * @param {String} path The path to make the request to.
+ * @param {String} method The request method, e.g. 'POST', 'GET'.
+ * @param {Object} payloadObj An object which is converted to JSON and
+ * transmitted with the request.
+ * @returns {Promise}
+ * Returns a promise that resolves to the response of the API call,
+ * or is rejected with an error. If the server response can be parsed
+ * as JSON and contains an 'error' property, the promise will be
+ * rejected with this JSON-parsed response.
+ */
+ hawkRequest: function(path, method, payloadObj) {
+ return MozLoopServiceInternal.hawkRequest(path, method, payloadObj);
+ },
};
diff --git a/browser/components/loop/content/conversation.html b/browser/components/loop/content/conversation.html
index a5142036c1e..470817c6a2b 100644
--- a/browser/components/loop/content/conversation.html
+++ b/browser/components/loop/content/conversation.html
@@ -21,14 +21,11 @@
-
-
-
-
+