diff --git a/classes/API.js b/classes/API.js index 7dbd1df..5ff26fa 100644 --- a/classes/API.js +++ b/classes/API.js @@ -187,31 +187,40 @@ export default class linkedInAPIClass { */ evade = () => wait(randomIntFromInterval(2, 5) * 1000); - /** + /** * @param {String} keyword i.e. "biotechnology" * @param {Array?} numEmp + * @param {Number?} [limit=1000] the function will use the bound the given number is contained in (see {@link findRangeIndex} for ranges) * @param {Number?} [start=0] * @param {boolean?} [castToClass=true] whether the function should return a list of Company classes or just raw JSON * @param {boolean} [excludeGeneric=false] * @returns {Promise<[SocialActivityCounts | Group | Company | GenericEntity]>} */ - async searchCompanies(keyword, numEmp = undefined, start = 0, castToClass = true, excludeGeneric = false) { - let urlExt = `variables=(start:${start},origin:GLOBAL_SEARCH_HEADER,query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(COMPANIES))${(numEmp) ? `,(key:companySize,value:List(${numsToSizes(...numEmp)}))` : ''}),includeFiltersInResponse:false))`; - const r = await this._makeReq(urlExt); + async searchCompanies(keyword, numEmp = undefined, limit = 1000, start = 0, castToClass = true, excludeGeneric = false) { + const compAll = []; + for (let i = start; i < limit; i += 50) { + let urlExt = `variables=(start:${i},origin:GLOBAL_SEARCH_HEADER,query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(COMPANIES))${(numEmp) ? `,(key:companySize,value:List(${numsToSizes(...numEmp)}))` : ''}),includeFiltersInResponse:false))`; + const r = await this._makeReq(urlExt); - if (!r?.included && r?.data?.errors) { - console.error(JSON.stringify(r.data.errors)) - throw "ERROR!"; + if (!r?.included && r?.data?.errors) { + console.error(JSON.stringify(r.data.errors)) + throw "ERROR!"; + } + + if (!castToClass) compAll.push(r); + else compAll.push(await parseResponse(r, this, excludeGeneric)); + + await this.evade(); } - if (!castToClass) return r; - else return parseResponse(r, this, excludeGeneric); + + return compAll.flat(); } /** * @returns {Promise} * @param {String} keyword the user to search for - * @param {Number?} [limit=1000] the function will find the bound the given number is contained in (see {@link findRangeIndex} for ranges) + * @param {Number?} [limit=1000] the function will use the bound the given number is contained in (see {@link findRangeIndex} for ranges) * @param {boolean?} [castToClass=true] whether the function should return a list of Company classes or just raw JSON * @param {boolean} [filterObfuscated=true] where or not to filter out members with obfuscated profiles ("LinkedIn Member") * @param {Array?} currentCompanies diff --git a/package.json b/package.json index 65de28c..5e3b5f2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ }, "type": "module", "name": "linkedin-api-js", - "version": "1.0.0-7", + "version": "1.0.0-9", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/tests/companyTests.js b/tests/companyTests.js index 3c9b276..5031108 100644 --- a/tests/companyTests.js +++ b/tests/companyTests.js @@ -7,8 +7,7 @@ import fs from 'fs'; const o = JSON.parse(fs.readFileSync('config.json')); await LAPI.login(o.email, o.password); - const c = await LAPI.searchCompanies('microsoft', [10, 500, 5000], 0, true, true); - + const c = await LAPI.searchCompanies('microsoft', [10, 500, 5000], 20, 0, true, true); console.log(c); const managers = await c.find(o => (o.name === 'Microsoft')).searchEmployees('manager', 5);