1 var Class = require('../../mootools/mootools-node.js').Class;
  2 
  3 /**
  4  * @class UrlRequest
  5  * @requires Class
  6  *
  7  * @param {String} url
  8  */
  9 var UrlRequest = function(){
 10 
 11     /**
 12      * @private
 13      * @property {String} _url
 14      */
 15     this._url = '/';
 16 
 17     /**
 18      * @private
 19      * @property {String} _method
 20      */
 21     this._method = 'GET';
 22 
 23     /**
 24      * @private
 25      * @property {Object} _headers
 26      */
 27     this._headers = {};
 28 
 29     /**
 30      * @private
 31      * @property {Object} _data
 32      */
 33     this._data = {};
 34     
 35     /** @ignore */
 36     this.initialize = function(url){
 37         if(url){
 38             this._url = url;
 39         }
 40     };
 41 
 42     /**
 43      * sets url of a service endpoint
 44      *
 45      * @param {String} url
 46      * @returns {UrlRequest}
 47      */
 48     this.setUrl = function(url){
 49         this._url = url;
 50 
 51         return this;
 52     };
 53 
 54     /**
 55      * returns url of a service endpoint
 56      *
 57      * @returns {String}
 58      */
 59     this.getUrl = function(){
 60         return this._url;
 61     };
 62 
 63     /**
 64      * sets method of communicating with a service
 65      *
 66      * @param {String} method
 67      * @returns {UrlRequest}
 68      */
 69     this.setMethod = function(method){
 70         this._method = method;
 71 
 72         return this;
 73     };
 74 
 75     /**
 76      * returns method of communicating with a service
 77      *
 78      * @returns {String}
 79      */
 80     this.getMethod = function(){
 81         return this._method;
 82     };
 83 
 84     /**
 85      * sets request headers
 86      * could be Object with key/value pais or
 87      * two String Objects first with a header name, second with the header value
 88      *
 89      * @param {String} headerName
 90      * @param {String} headerValue
 91      * @param {Object} headers
 92      * @returns {UrlRequest}
 93      */
 94     this.setHeaders = function(){
 95         if(arguments.length == 2){
 96             this._headers[arguments[0]] = arguments[1];                
 97         } else if (typeof arguments[0] == 'object'){
 98             this._headers = arguments[0];
 99         }
100 
101         return this;
102     };
103 
104     /**
105      * returns headers value pair object
106      * @returns {Object}
107      */
108     this.getHeaders = function(){
109         return this._headers;
110     };
111 
112     /**
113      * sets the data or parameters that will be sent to service
114      * @param {Object} data
115      * @returns {Object}
116      */
117     this.setData = function(data){
118         this._data = data;
119 
120         return this;            
121     };
122 
123     /**
124      * returns data or parameters that will be sent to service
125      * @returns {Object}
126      */
127     this.getData = function(){
128         return this._data;
129     };
130 };
131 
132 UrlRequest = new Class(new UrlRequest());
133 UrlRequest.POST = "POST";
134 UrlRequest.GET = "GET";
135 
136 exports.UrlRequest = UrlRequest;