Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Get all companies endpoint for CompanyOperations, Post Shares to the company org, expose base uri for metadata #68

Open
wants to merge 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,24 @@ public interface CompanyOperations {
*/
Products getProducts(int companyId, int start, int count);

/**
* Get a list of all organizational accounts
* @return company list
*/
Companies getCompanies();

/**
* Post a share to organizational account
* @param share The Share to post
* @param companyId The organizational account for the company to post under
* @return The shared post
*/
Share postShareForCompany(NewShare share, String companyId);

/**
* Get the base url with api version that the API uses
* @return base url string
*/
String getBaseUrl();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package org.springframework.social.linkedin.api.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.social.linkedin.api.Companies;
import org.springframework.social.linkedin.api.Company;
import org.springframework.social.linkedin.api.CompanyOperations;
import org.springframework.social.linkedin.api.Products;
import org.springframework.social.linkedin.api.*;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestOperations;

import com.fasterxml.jackson.core.type.TypeReference;
Expand Down Expand Up @@ -105,14 +105,46 @@ public void stopFollowingCompany(int id) {
public Products getProducts(int companyId, int start, int count) {
return restOperations.getForObject(PRODUCTS_URL, Products.class, companyId, start, count);
}


public Companies getCompanies() {
Map<String, String> params = new HashMap<String, String>();
params.put("format", "json");
params.put("is-company-admin", "true");

try {
return restOperations.getForObject(COMPANIES_URL, Companies.class, params);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public Share postShareForCompany(NewShare share, String companyId) {
if(StringUtils.isEmpty(companyId)){
throw new IllegalArgumentException("CompanyId must not be empty");
}
Map<String, String> params = new HashMap<String, String>();
params.put("id", companyId);
params.put("format", "json");
try {
return restOperations.postForObject(COMPANY_SHARE_POST_URL, share, Share.class, params);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public String getBaseUrl() {
return BASE_URL;
}

public static final String BASE_URL = "https://api.linkedin.com/v1/";
public static final String COMPANY_FIELDS = "(id,name,universal-name,email-domains,company-type,ticker,website-url,industry,status,logo-url,square-logo-url,blog-rss-url,twitter-id,employee-count-range,specialties,locations,description,stock-exchange,founded-year,end-year,num-followers)";
public static final String COMPANY_URL = BASE_URL + "companies{id}:" + COMPANY_FIELDS + "?{filter}";
public static final String COMPANY_SEARCH_URL = BASE_URL + "company-search:(companies:" + COMPANY_FIELDS + ")?keywords={keywords}";
public static final String COMPANY_FOLLOW_URL = BASE_URL + "people/~/following/companies:" + COMPANY_FIELDS;
public static final String COMPANY_FOLLOW_START_STOP_URL = BASE_URL + "people/~/following/companies/id={id}";
public static final String COMPANY_SUGGESTIONS_TO_FOLLOW = BASE_URL + "people/~/suggestions/to-follow/companies:" + COMPANY_FIELDS;
public static final String COMPANIES_URL = BASE_URL + "companies"+"?format={format}&is-company-admin={is-company-admin}";
public static final String COMPANY_SHARE_POST_URL = BASE_URL + "companies/{id}/shares?format{format}";

public static final String PRODUCT_FIELDS="(id,name,type,creation-timestamp,logo-url,description,features,video:(title,url),product-deal:(title,url,text),sales-persons,num-recommendations,recommendations:(recommender,id,product-id,text,reply,timestamp,likes:(timestamp,person)),product-category,website-url,disclaimer)";
public static final String PRODUCTS_URL = BASE_URL + "companies/{id}/products:" + PRODUCT_FIELDS +"?start={start}&count={count}";
Expand Down