0.3.1 • Published 6 years ago

leboncoin-client v0.3.1

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

Leboncoin.fr HTTP client

This package allows to perform requests on the french e-commerce website "leboncoin.fr". At the moment, it contains 3 simple methods for retrieve items data from the website : search(), get() and watch().

Installation

npm install leboncoin-client

Usage examples

Perform a search :

const lbc = require('leboncoin-client');

const req = {
    category: 'informatique',
    type: 'offres',
    region_or_department: 'cantal',
    sellers: 'particuliers',
    query: 'ordinateur',
    sort: 'date',
    titles_only: false,
    urgent_only: false
};

lbc.search(req, 1, 5) // browse pages 1 to 5
.then(function(items) {
    console.log(items);
}, function(error) {
    console.error(error);
});

Second search example :

const lbc = require('leboncoin-client');

const req = {
   category: 'informatique',
   city_or_postal_code: '75001'
   filters: {
       'Prix min': 400,
       'Prix max': 'Plus de 1000'
   }
};

lbc.search(req) // only the first page
.then(function(items) {
    console.log(items);
}, function(error) {
    console.error(error);
});

Get data from a specific advertisement :

const lbc = require('leboncoin-client');

lbc.get(1159809960)
.then(function(item) {
    console.log(item);
}, function(error) {
    console.error(error);
});

Watch new objects from a specific category and location :

const lbc = require('leboncoin-client');

const req = {
    category: 'informatique',
    region_or_department: 'gers'
};

lbc.watch(req, 60, function(item) { // the request is performed every 60 seconds
    console.log(item);
});

Methods

search(request, minPage, maxPage)

Query a research of items specified by various criterias. Return a promise with an array of items in parameter.

ParameterTypeDescriptionDefault value
requestobjectobject containing the query parameters (see request spec for more info){}
minPageintegerfirst page to browse1
maxPageintegerlast page to browse1

get(id)

Get specific item data by its id. Return a promise with the item data in parameter.

ParameterTypeDescriptionDefault value
idinteger10-digit item idrequired

watch(request, interval, action)

Watching loop for detect new objects added specified by various criterias. Each time a new object is spotted, the function "action" is called with its data in parameter.

ParameterTypeDescriptionDefault value
requestobjectobject containing the query parameters (see request spec for more info){}
intervalintegernumber of seconds between each request60
actionfunctionaction to execute for process the new object datarequired

Request spec

FieldTypeDescriptionDefault value
categorystringcategory to look in (check out the parameters.json for the complete list of categories)"tous"
typestringtype of advertisement ("offres" or "demandes")"offres"
region_or_departmentstringregion or department of items (check out the parameters.json for the complete list of locations)"toute la France"
city_or_postal_codestringcity or postal code of items (return empty array if it does not exist)none
sellersstringtype of sellers ("tous" or "particuliers" or "professionnels""tous"
querystringmatching keywordsnone
sortstringsort criteria ("date" or "prix")"date"
titles_onlybooleansearch only in ad titlesfalse
urgent_onlybooleansearch only for urgent adsfalse
filters:objectobject containing some filters depending on the category (check out the parameters.json for the complete list of filters){}

Filters not implemented yet :

  • Car models (depending on the brand)
  • Dates ("holidays" categories)
  • Clothes sizes (depending on the gender)

Feel free to contact me for any suggestion, issue, improvement...

0.3.1

6 years ago

0.3.0

6 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago