Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some missing endpoints and corrected the base API url #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions localbitcoins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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',
Expand All @@ -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.');
}
}
Expand All @@ -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);
}

/**
Expand All @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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'];

Expand Down Expand Up @@ -169,7 +191,7 @@ function LBCClient(key, secret, otp) {
} else {

var options = {
url: url + '/',
url: url ,
headers: headers,
};

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down