From a6b096cec5cc7b49ff7fb13a3df9d170199f5cbe Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 18 Aug 2017 17:16:26 +0100 Subject: [PATCH 1/4] Implementation of public Ads endpoints --- localbitcoins.js | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/localbitcoins.js b/localbitcoins.js index 270d6cb..4268954 100644 --- a/localbitcoins.js +++ b/localbitcoins.js @@ -8,7 +8,7 @@ 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, @@ -24,7 +24,7 @@ function LBCClient(key, secret, otp) { */ function api(method, ad_id, params, callback) { var methods = { - onlineAds: ['buy-bitcoins-online'], + onlineAds: ['buy-bitcoins-online','sell-bitcoins-online'], public: ['countrycodes'], private: ['ad-get', 'ad-get/ad_id', 'myself', 'ads', 'dashboard', 'dashboard/released', 'dashboard/canceled', 'dashboard/closed', @@ -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']; + 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, }; From 94d79d3adf8c3bbed5f088eeb0c1a6e21c57389b Mon Sep 17 00:00:00 2001 From: Ralph Date: Mon, 21 Aug 2017 09:22:48 +0100 Subject: [PATCH 2/4] Setting right endpoints --- localbitcoins.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/localbitcoins.js b/localbitcoins.js index 4268954..ef71b7e 100644 --- a/localbitcoins.js +++ b/localbitcoins.js @@ -25,7 +25,7 @@ function LBCClient(key, secret, otp) { function api(method, ad_id, params, callback) { var methods = { onlineAds: ['buy-bitcoins-online','sell-bitcoins-online'], - public: ['countrycodes'], + 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', @@ -63,7 +63,7 @@ function LBCClient(key, secret, otp) { path = '/' + method; } - var url = config.url + 'api/'+ path; + var url = config.url + 'api'+ path; return rawRequest(url, {}, params, method, callback); } @@ -147,7 +147,7 @@ function LBCClient(key, secret, otp) { 'dashboard/closed', 'dashboard/released/buyer', 'dashboard/canceled/buyer', 'dashboard/closed/buyer', 'dashboard/released/seller', 'dashboard/canceled/seller', 'dashboard/closed/seller', 'wallet', 'contact_info','countrycode', 'buy-bitcoins-online', - 'sell-bitcoins-online']; + 'sell-bitcoins-online','account_info']; var posts = [ 'ad-get/ad_id', 'myself', 'ads', 'wallet-send', 'wallet-balance', 'wallet-addr']; From 7386b685383f58765a1bce14ec32e4e1bf40da2f Mon Sep 17 00:00:00 2001 From: Ralph Date: Mon, 4 Sep 2017 19:16:13 +0100 Subject: [PATCH 3/4] Improvement to support more services --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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" }, From 79297eee5de57ce2fde8aa383ab53a1aea70678e Mon Sep 17 00:00:00 2001 From: Ralph Date: Mon, 4 Sep 2017 19:17:37 +0100 Subject: [PATCH 4/4] Improvement to support more services --- localbitcoins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localbitcoins.js b/localbitcoins.js index ef71b7e..d948af4 100644 --- a/localbitcoins.js +++ b/localbitcoins.js @@ -14,7 +14,7 @@ function LBCClient(key, secret, otp) { otp: otp, timeoutMS: 5000 }; - + /** * This method makes a public or private API request. * @param {String} method The API method (public or private)