Commit 49074965 authored by Ty Abonil's avatar Ty Abonil
Browse files

initial commit

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+16 −0
Original line number Diff line number Diff line
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules
 No newline at end of file

lib/rp.js

0 → 100644
+40 −0
Original line number Diff line number Diff line
var Promise = require('bluebird'),
    request = require('request');

function rp(options) {
    var statusCodes = {
        'GET' : [200],
        'HEAD' : [200],
        'PUT' : [200, 201],
        'POST' : [200, 201]
    }, c = {}, i;
    if (typeof options === 'string') {
        c.uri = options;
        c.method = 'GET';
    }
    if (typeof options === 'object') {
        for (i in options) {
            if (options.hasOwnProperty(i)) {
                c[i] = options[i];
            }
        }
    }
    c.method = c.method || 'GET';
    return new Promise(function (resolve, reject) {
        request(c, function (error, response, body) {
            if (error) {
                reject(error);
            } else if (c.simple && (statusCodes[c.method].indexOf(response.statusCode) > -1)) {
                reject(response.statusCode);
            } else {
                if (c.transform && typeof c.transform === 'function') {
                    resolve(c.transform(body));
                } else {
                    resolve(body);
                }
            }
        });
    });
}

module.exports = rp;

package.json

0 → 100644
+19 −0
Original line number Diff line number Diff line
{
  "name": "request-promise",
  "version": "0.0.1",
  "description": "Promise-based Wrapper for Request using Bluebird",
  "main": "lib/tp.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "xhr",
    "promise",
    "request"
  ],
  "author": "Ty Abonil",
  "license": "MIT",
  "dependencies": {
    "bluebird": "~0.7.9-1"
  }
}