Skip to content

Commit

Permalink
fix: removing dependancy for node-requests
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck committed Sep 19, 2023
1 parent baa3f38 commit 0929b25
Show file tree
Hide file tree
Showing 11 changed files with 1,989 additions and 1,518 deletions.
15 changes: 7 additions & 8 deletions lib/archiving.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var request = require('request');
var request = require('needle');
var errors = require('./errors');
var pkg = require('../package.json');
var _ = require('lodash');
Expand Down Expand Up @@ -191,13 +191,12 @@ function Archive(config, properties) {

api = function (config, method, path, body, callback) {
var rurl = config.apiEndpoint + '/v2/project/' + config.apiKey + path;
request.defaults(_.pick(config, 'proxy', 'timeout'))(
{
url: rurl,
method: method,
headers: generateHeaders(config),
json: body
},
config.headers = generateHeaders(config);
request.defaults(_.pick(config, 'proxy', 'timeout'));
request(
method,
rurl,
body || null,
callback
);
};
Expand Down
30 changes: 17 additions & 13 deletions lib/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
var request = require('request');
var request = require('needle');
var errors = require('./errors');
var pkg = require('../package.json');
var _ = require('lodash');
var generateJwt = require('./generateJwt');

var api = function (config, method, path, body, callback) {
var rurl = config.apiEndpoint + '/v2/project/' + config.apiKey + path;
request.defaults(_.pick(config, 'proxy', 'timeout'))({
url: rurl,
method: method,
headers: {
'X-OPENTOK-AUTH': generateJwt(config),
'User-Agent': 'OpenTok-Node-SDK/' + pkg.version +
(config.uaAddendum ? ' ' + config.uaAddendum : '')
},
json: body
}, callback);
config.headers = {
'X-OPENTOK-AUTH': generateJwt(config),
'User-Agent': 'OpenTok-Node-SDK/' + pkg.version
+ (config.uaAddendum ? ' ' + config.uaAddendum : '')
};
request.defaults(_.pick(config, 'proxy', 'timeout', 'headers'));
request(
method,
rurl,
body || null,
callback
);
};

function Callback(config, properties) {
Expand All @@ -41,7 +43,7 @@ exports.listCallbacks = function (config, options, callback) {
throw (new errors.ArgumentError('No callback given to listCallbacks'));
}
api(config, 'GET', '/callback', null, function (err, response, body) {
if (!err && body) {
if (!err && body && body.constructor === String) {
try {
body = JSON.parse(body);
}
Expand Down Expand Up @@ -107,7 +109,9 @@ exports.unregisterCallback = function (config, callbackId, callback) {
return;
}
api(
config, 'DELETE', '/callback/' + encodeURIComponent(callbackId),
config,
'DELETE',
'/callback/' + encodeURIComponent(callbackId),
null,
function (err, response, body) {
if (err) {
Expand Down
Loading

0 comments on commit 0929b25

Please sign in to comment.