Skip to content

Commit

Permalink
support for GET parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
hij1nx committed May 29, 2011
1 parent 248d406 commit b6f8b76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ The Porter constructor takes a single object literal containing members grouped
```javascript
porter.users.list(

{ partialname: 'bill' },

{ partialname: 'bill' }, // replaces the ':partialname' token in the 'list' resource's URI.
{ foo: 10, bar: 20 }, // appends '?foobar=10&bar=20' to the URL when the method is a GET, adds as a message body for a POST.
function(error, response) {
// do something...
}
Expand Down Expand Up @@ -86,8 +86,8 @@ var porter = Porter({
The `use` function sets the defaults for all calls that get made. It accepts an object literal containing the following members...

`port` Number - The port of the server that will accept the requests.<br/>
`in` Object - A JSONSchema object that will validate against every incoming request.<br/>
`out` Object - A JSONSchema object that will validate against every outgoing request.<br/>
`inbound` Object - A JSONSchema object that will validate against every incoming request.<br/>
`outbound` Object - A JSONSchema object that will validate against every outgoing request.<br/>
`host` String - An IP address of the host server that will accept the requests.<br/>
`headers` Object - An object literal of HTTP request headers that will be attached to each request.<br/>
`protocol` String - The protocol to be used for all requests, ie 'http', 'https'.<br/>
Expand Down
14 changes: 12 additions & 2 deletions lib/Porter.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@

this.clear = function() {
for(var d in self.cache) {
delete self.cache[d];
if(self.cache.hasOwnProperty(d)) { delete self.cache[d]; }
}
}

Expand Down Expand Up @@ -243,10 +243,20 @@
}
else {

var params = '';

if(method === 'get') {
params = '?';
for(var d in data) {
if(self.cache.hasOwnProperty(d)) { params += encodeURIComponent(d) + "=" encodeURIComponent(data[d]) + "&"; }
}
}

return new self.ajax({


// merege in the options and build the url to request.
url: [self.options.protocol, '://', self.options.ip || self.options.host, ':', self.options.port, url].join(''),
url: [self.options.protocol, '://', self.options.ip || self.options.host, ':', self.options.port, url, params].join(''),
type: method,
data: data || {}

Expand Down

0 comments on commit b6f8b76

Please sign in to comment.