/**
 * Copyright 2015 Longtail Ad Solutions Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 **/

/**
 * Utility for making XMLHttpRequests.
 *
 * Usage:
 * http(url)
 *  .get(payload)
 *  .then(callback.success)
 *  .catch(callback.error);
 */
 function http(url) {

   return {

     ajax: function(method, url) {
       var promise = new Promise(function(resolve, reject) {
         var client = new XMLHttpRequest();
         client.responseType = "json";
         client.onload = function() {
           if (this.status >= 200 && this.status < 300) {
             resolve(this.response);
           } else {
             reject(this.statusText);
           }
         };
         client.onerror = function() {
           reject(this.statusText);
         };
         client.open(method, url, true);
         client.send();
       });
       return promise;
     },

     get: function(args) {
       // TODO: args
       return this.ajax('GET', url);
     }
   };

 }

@@ -816,20 +816,29 @@
 hod, url
+, options
 ) %7B%0A
-
        v
@@ -947,37 +947,206 @@
     
-client.responseType = %22json%22;
+if (options) %7B%0A           for (property in options) %7B%0A             if (options.hasOwnProperty(property)) %7B%0A               client%5Bproperty%5D = options%5Bproperty%5D;%0A             %7D%0A           %7D%0A         %7D
 %0A   
@@ -1572,19 +1572,22 @@
 unction(
-arg
+option
 s) %7B%0A   
@@ -1594,21 +1594,182 @@
     
-// TODO: args
+if (!options) %7B%0A         // If options are not defined, assume that we want to load a JSON document.%0A         options = %7B%0A           responseType: %22json%22%0A         %7D;%0A       %7D
 %0A   
@@ -1799,16 +1799,25 @@
 ET', url
+, options
 );%0A     

Allow XHR options to be passed in to http.get()