diff --git a/localbitcoins.js b/localbitcoins.js index 270d6cb..d948af4 100644 --- a/localbitcoins.js +++ b/localbitcoins.js @@ -8,13 +8,13 @@ function LBCClient(key, secret, otp) { var self = this; var config = { - url: 'https://localbitcoins.com/api', + url: 'https://localbitcoins.com/', key: key, secret: secret, otp: otp, timeoutMS: 5000 }; - + /** * This method makes a public or private API request. * @param {String} method The API method (public or private) @@ -24,8 +24,8 @@ function LBCClient(key, secret, otp) { */ function api(method, ad_id, params, callback) { var methods = { - onlineAds: ['buy-bitcoins-online'], - public: ['countrycodes'], + onlineAds: ['buy-bitcoins-online','sell-bitcoins-online'], + public: ['countrycodes','account_info'], private: ['ad-get', 'ad-get/ad_id', 'myself', 'ads', 'dashboard', 'dashboard/released', 'dashboard/canceled', 'dashboard/closed', 'dashboard/released/buyer', 'dashboard/canceled/buyer', 'dashboard/closed/buyer', @@ -39,7 +39,9 @@ function LBCClient(key, secret, otp) { else if(methods.private.indexOf(method) !== -1) { return privateMethod(method, params, ad_id, callback); } - else { + else if(methods.onlineAds.indexOf(method) !== -1) { + return onlineAdsMethod(method, params, ad_id, callback); + }else { throw new Error(method + ' is not a valid API method.'); } } @@ -61,9 +63,9 @@ function LBCClient(key, secret, otp) { path = '/' + method; } - var url = config.url + path; + var url = config.url + 'api'+ path; - return rawRequest(url, {}, params, callback); + return rawRequest(url, {}, params, method, callback); } /** @@ -84,7 +86,7 @@ function LBCClient(key, secret, otp) { path = '/' + method; } - var url = config.url + path; + var url = config.url + 'api/' + path; var signature = getMessageSignature(path, params, nonce); @@ -98,6 +100,24 @@ function LBCClient(key, secret, otp) { return rawRequest(url, headers, params, method, callback); } + function onlineAdsMethod(method, params, ad_id, callback) { + params = params || {}; + + var path; + if (ad_id) { + path = '/' + method + '/' + ad_id; + } else { + path = '/' + method; + } + + path+='.json' + + var url = config.url + path; + + return rawRequest(url, {}, params, method, callback); + } + + /** * This method returns a signature for a request as a Base64-encoded string * @param {String} path The relative URL path for the request @@ -126,7 +146,9 @@ function LBCClient(key, secret, otp) { var gets = ['ad-get', 'dashboard', 'dashboard/released', 'dashboard/canceled', 'dashboard/closed', 'dashboard/released/buyer', 'dashboard/canceled/buyer', 'dashboard/closed/buyer', 'dashboard/released/seller', 'dashboard/canceled/seller', - 'dashboard/closed/seller', 'wallet', 'contact_info']; + 'dashboard/closed/seller', 'wallet', 'contact_info','countrycode', 'buy-bitcoins-online', + 'sell-bitcoins-online','account_info']; + var posts = [ 'ad-get/ad_id', 'myself', 'ads', 'wallet-send', 'wallet-balance', 'wallet-addr']; @@ -169,7 +191,7 @@ function LBCClient(key, secret, otp) { } else { var options = { - url: url + '/', + url: url , headers: headers, }; diff --git a/package.json b/package.json index 0b34fe4..a8ee67d 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,13 @@ "bitcoin" ], "author": "Vlad Nistor (https://github.com/vnistor)", - "contributors": ["Anthony Mayfield (https://github.com/mrmayfield)", "Robert Myers (https://github.com/nothingisdead)"], + "contributors": [ + "Anthony Mayfield (https://github.com/mrmayfield)", + "Robert Myers (https://github.com/nothingisdead)" + ], "license": "MIT", "dependencies": { + "bitcoin-exchange-rates": "0.0.12", "querystring": ">=0.2.0", "request": ">=2.27.0" },