From d7c78a5d2340a8ec83bc0b3467e218b810d84bb2 Mon Sep 17 00:00:00 2001 From: Bobby Johansen Date: Mon, 3 Apr 2017 15:13:43 -0400 Subject: [PATCH 1/2] Get all companies endpoint for CompanyOperations Allows you to retrieve all companies the profile has admin priveleges over. --- .../social/linkedin/api/CompanyOperations.java | 6 ++++++ .../linkedin/api/impl/CompanyTemplate.java | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/CompanyOperations.java b/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/CompanyOperations.java index a64f51d9..1e88fcb9 100644 --- a/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/CompanyOperations.java +++ b/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/CompanyOperations.java @@ -87,4 +87,10 @@ public interface CompanyOperations { */ Products getProducts(int companyId, int start, int count); + /** + * Get a list of all organizational accounts + * @return company list + */ + Companies getCompanies(); + } diff --git a/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/impl/CompanyTemplate.java b/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/impl/CompanyTemplate.java index 9b6887f8..f50b420e 100644 --- a/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/impl/CompanyTemplate.java +++ b/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/impl/CompanyTemplate.java @@ -16,7 +16,9 @@ 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; @@ -105,7 +107,19 @@ 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 params = new HashMap(); + 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 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}"; @@ -113,6 +127,7 @@ public Products getProducts(int companyId, int start, int count) { 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 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}"; From 1225ab86fff4513743266df7c8780aa0b689e68d Mon Sep 17 00:00:00 2001 From: Bobby Johansen Date: Mon, 3 Apr 2017 16:45:16 -0400 Subject: [PATCH 2/2] Post a share to a company and get the base url for meta usage --- .../linkedin/api/CompanyOperations.java | 14 +++++++++++ .../linkedin/api/impl/CompanyTemplate.java | 25 ++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/CompanyOperations.java b/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/CompanyOperations.java index 1e88fcb9..c8e6a01c 100644 --- a/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/CompanyOperations.java +++ b/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/CompanyOperations.java @@ -93,4 +93,18 @@ public interface CompanyOperations { */ 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(); + } diff --git a/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/impl/CompanyTemplate.java b/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/impl/CompanyTemplate.java index f50b420e..9df52dec 100644 --- a/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/impl/CompanyTemplate.java +++ b/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/impl/CompanyTemplate.java @@ -20,10 +20,8 @@ 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; @@ -120,6 +118,24 @@ public Companies getCompanies() { } } + public Share postShareForCompany(NewShare share, String companyId) { + if(StringUtils.isEmpty(companyId)){ + throw new IllegalArgumentException("CompanyId must not be empty"); + } + Map params = new HashMap(); + 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}"; @@ -128,6 +144,7 @@ public Companies getCompanies() { 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}";