Jump To …

industriesAPI.js

Comments

 

Code

var PersonAPI = require('./peopleAPI');

// THIS IS HARDCODED TO MATCH LINKEDIN BACKEND!
// we can now load this info via:  http://api.linkedin.com/v1/industries?count=100
// key = industry id
var INDUSTRY_CATALOG = {
  47: "Accounting",
  94: "Airlines/Aviation",
  120:"Alternative Dispute Resolution",
  125:"Alternative Medicine",
  127:"Animation",
  19: "Apparel & Fashion",
  50: "Architecture & Planning",
  111:"Arts and Crafts",
  53: "Automotive",
  52: "Aviation & Aerospace",
  41: "Banking",
  12: "Biotechnology",
  36: "Broadcast Media",
  49: "Building Materials",
  138:"Business Supplies and Equipment",
  129:"Capital Markets",
  54: "Chemicals",
  90: "Civic & Social Organization",
  51: "Civil Engineering",
  128:"Commercial Real Estate",
  118:"Computer & Network Security",
  109:"Computer Games",
   3: "Computer Hardware",
   5: "Computer Networking",
   4: "Computer Software",
  48: "Construction",
  24: "Consumer Electronics",
  25: "Consumer Goods",
  91: "Consumer Services",
  18: "Cosmetics",
  65: "Dairy",
   1: "Defense & Space",
  99: "Design",
  69: "Education Management",
  132:"E-Learning",
  112:"Electrical/Electronic Manufacturing",
  28: "Entertainment",
  86: "Environmental Services",
  110:"Events Services",
  76: "Executive Office",
  122:"Facilities Services",
  63: "Farming",
  43: "Financial Services",
  38: "Fine Art",
  66: "Fishery",
  34: "Food & Beverages",
  23: "Food Production",
  101:"Fund-Raising",
  26: "Furniture",
  29: "Gambling & Casinos",
  145:"Glass, Ceramics & Concrete",
  75: "Government Administration",
  148:"Government Relations",
  140:"Graphic Design",
  124:"Health, Wellness and Fitness",
  68: "Higher Education",
  14: "Hospital & Health Care",
  31: "Hospitality",
  137:"Human Resources",
  134:"Import and Export",
  88: "Individual & Family Services",
  147:"Industrial Automation",
  84: "Information Services",
  96: "Information Technology and Services",
  42: "Insurance",
  74: "International Affairs",
  141:"International Trade and Development",
  6:  "Internet",
  45: "Investment Banking",
  46: "Investment Management",
  73: "Judiciary",
  77: "Law Enforcement",
  9:  "Law Practice",
  10: "Legal Services",
  72: "Legislative Office",
  30: "Leisure, Travel & Tourism",
  85: "Libraries",
  116:"Logistics and Supply Chain",
  143:"Luxury Goods & Jewelry",
  55: "Machinery",
  11: "Management Consulting",
  95: "Maritime",
  97: "Market Research",
  80: "Marketing and Advertising",
  135:"Mechanical or Industrial Engineering",
  126:"Media Production",
  17: "Medical Devices",
  13: "Medical Practice",
  139:"Mental Health Care",
  71: "Military",
  56: "Mining & Metals",
  35: "Motion Pictures and Film",
  37: "Museums and Institutions",
  115:"Music",
  114:"Nanotechnology",
  81: "Newspapers",
  100:"Non-Profit Organization Management",
  57: "Oil & Energy",
  113:"Online Media",
  123:"Outsourcing/Offshoring",
  87: "Package/Freight Delivery",
  146:"Packaging and Containers",
  61: "Paper & Forest Products",
  39: "Performing Arts",
  15: "Pharmaceuticals",
  131:"Philanthropy",
  136:"Photography",
  117:"Plastics",
  107:"Political Organization",
  67: "Primary/Secondary Education",
  83: "Printing",
  105:"Professional Training & Coaching",
  102:"Program Development",
  79: "Public Policy",
  98: "Public Relations and Communications",
  78: "Public Safety",
  82: "Publishing",
  62: "Railroad Manufacture",
  64: "Ranching",
  44: "Real Estate",
  40: "Recreational Facilities and Services",
  89: "Religious Institutions",
  144:"Renewables & Environment",
  70: "Research",
  32: "Restaurants",
  27: "Retail",
  121:"Security and Investigations",
  7:  "Semiconductors",
  58: "Shipbuilding",
  20: "Sporting Goods",
  33: "Sports",
  104:"Staffing and Recruiting",
  22: "Supermarkets",
  8:  "Telecommunications",
  60: "Textiles",
  130:"Think Tanks",
  21: "Tobacco",
  108:"Translation and Localization",
  92: "Transportation/Trucking/Railroad",
  59: "Utilities",
  106:"Venture Capital & Private Equity",
  16: "Veterinary",
  93: "Warehousing",
  133:"Wholesale",
  142:"Wine and Spirits",
  119:"Wireless",
  103:"Writing and Editing"
};


var DEFAULT_FIELDS = ":(id,title,description,because-of,topic-stories:(topic-articles:(is-read,relevance-data:(global-share-count,in-topic-share-count),article-content,shared-in-network-count,trending-in-entities:(industries:(id,relation-to-viewer)),shared-by-people:(" + PersonAPI.standardPersonFields() + "))))";

var INDUSTRY_RESOURCE = "industry";

recommended: Get recommended industries

  • options
    • -start
    • -count
function recommended(options) {
  var url = ["people/~/suggestions/to-follow:(industries:(id,relation-to-viewer))"];
  if (options) {
    url.push("?");
    if (options.start) url.push("start=" + options.start);
    if (options.count) url.push("count=" + options.count);
  }
  var headers = (options && options.headers) ? options.headers : {"x-li-format":"json"};
  return {method:'GET', path:url.join(''), headers:headers, resource:INDUSTRY_RESOURCE};
}

Followed:

Get followed industries
  • options
    • start
    • count

Example:

var Lin = require('lin');
var api = Lin.api('v1','industriesAPI','followed',{count:25});
function followed(options) {
  var url = ["people/~/following/industries"];
  if (options) {
    url.push("?");
    if (options.start) url.push("start=" + options.start);
    if (options.count) url.push("count=" + options.count);
  }
  var headers = (options && options.headers) ? options.headers : {"x-li-format":"json"};
  return {method:'GET', path:url.join(''), headers:headers, resource:INDUSTRY_RESOURCE};
}

Follow:

Follow this industry
  • id: industry id

Example:

var Lin = require('lin');
var api = Lin.api('v1','industriesAPI','follow',6);
function follow(id) {
  if (!id) return undefined;
  
  return {method:'POST', 
          path:"people/~/following/industries", 
          body:'<?xml version="1.0" encoding="UTF-8"?><industry><id>'+id+'</id></industry>',
          headers:{"x-li-format":"xml", "Content-Type":"application/xml;charset=UTF-8"},
          resource:INDUSTRY_RESOURCE};
}

Unfollow:

Unfollow this industry
  • id: industry id

Example:

var Lin = require('lin');
var api = Lin.api('v1','industriesAPI','unfollow',6);
function unfollow(id) {
  if (!id) return undefined;
  
  return {method:'DELETE', 
          path:"people/~/following/industries/id=" + id,
          resource:INDUSTRY_RESOURCE};
}

Preview:

Preview articles for this industry (similar to showing articles for topic)
  • id, industryId, eg: 44
  • options
    • fields: LinkedIn-formatted string describing which profile fields to retrieve. see DEFAULTTOPICFIELDS
    • :maxStories, # max stories to return per topic (default 100)
    • :maxArticles, # max articles to return per story (default 1)

Example:

var Lin = require('lin');
var api = Lin.api('v1','industriesAPI','preview',6, {maxStories:10});
function preview(id, options) {
  if (!id) return undefined;
  
  var fields = (options && options.fields) ? options.fields : DEFAULT_FIELDS;
  var url = ["people/~/topics/industry-id=" + id + fields];
  if (options) {
    var params = [];
    params.push("max-articles=" + (options.maxArticles || 0));
    params.push("max-stories=" + (options.maxStories|| 100));
    url.push("?"+ params.join('&'));
  }
  var headers = (options && options.headers) ? options.headers : {"x-li-format":"json"};
  return {method:'GET', path:url.join(''), headers:headers, resource:INDUSTRY_RESOURCE};
}

industryName:

Get industry name for an industry id
  • industryId: eg: 6

Example:

var Lin = require('lin');
var api = Lin.api('v1','industriesAPI','industryName',6);
function industryName(industryId) {
  return INDUSTRY_CATALOG[industryId];
}


// ====== PUBLIC ==============================================================
var interface = {
  industryName: industryName,
  recommended: recommended,
  followed: followed,
  follow: follow,
  unfollow: unfollow,
  preview: preview
};
module.exports = interface;