From 90b032cc61ebcb916e14b6fec31dbde27c5714b3 Mon Sep 17 00:00:00 2001 From: Cameron Stanley Date: Tue, 17 Nov 2015 14:54:19 -0600 Subject: [PATCH 01/13] Implement requesting specific fields when retrieving company page --- lib/linked_in/companies.rb | 7 ++++++- spec/linked_in/api/companies_spec.rb | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/linked_in/companies.rb b/lib/linked_in/companies.rb index 424a5bf..517bd9a 100644 --- a/lib/linked_in/companies.rb +++ b/lib/linked_in/companies.rb @@ -23,6 +23,7 @@ class Companies < APIResource # @option options [String] :type # @option options [String] :count # @option options [String] :start + # @option options [String] :profile_fields # @return [LinkedIn::Mash] def company(options = {}) path = company_path(options) @@ -182,7 +183,11 @@ def company_path(options) if domain = options.delete(:domain) path += "?email-domain=#{CGI.escape(domain)}" elsif id = options.delete(:id) - path += "/#{id}" + if profile_fields = options.delete(:profile_fields) + path += "/#{id}:(#{profile_fields})" + else + path += "/#{id}" + end elsif url = options.delete(:url) path += "/url=#{CGI.escape(url)}" elsif name = options.delete(:name) diff --git a/spec/linked_in/api/companies_spec.rb b/spec/linked_in/api/companies_spec.rb index 96b211b..d953ff5 100644 --- a/spec/linked_in/api/companies_spec.rb +++ b/spec/linked_in/api/companies_spec.rb @@ -14,6 +14,11 @@ def stub(url) expect(api.company(id: 1586)).to be_an_instance_of(LinkedIn::Mash) end + it "retrieves a company page with requested profile fields" do + stub("https://api.linkedin.com/v1/companies/1586:(id,name,description,logo-url)?") + expect(api.company(id: 1586, profile_fields: "id,name,description,logo-url")).to be_an_instance_of(LinkedIn::Mash) + end + it "should be able to view a company by universal name" do stub("https://api.linkedin.com/v1/companies/universal-name=acme?") expect(api.company(name: "acme")).to be_an_instance_of(LinkedIn::Mash) From 2c85811196720a6d74d10e5de42613e672fbd1d9 Mon Sep 17 00:00:00 2001 From: cameronstanley Date: Thu, 1 Aug 2019 07:10:49 -0500 Subject: [PATCH 02/13] Set API version to v2 --- lib/linked_in/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linked_in/configuration.rb b/lib/linked_in/configuration.rb index bb4771d..b903ba2 100644 --- a/lib/linked_in/configuration.rb +++ b/lib/linked_in/configuration.rb @@ -32,7 +32,7 @@ class Configuration def initialize @api = "https://api.linkedin.com" - @api_version = "/v1" + @api_version = "/v2" @site = "https://www.linkedin.com" @token_url = "/uas/oauth2/accessToken" @authorize_url = "/uas/oauth2/authorization" From 2a89bbd8656f9ff369c2f0f204a83858a2ec7d9e Mon Sep 17 00:00:00 2001 From: cameronstanley Date: Fri, 2 Aug 2019 07:11:59 -0500 Subject: [PATCH 03/13] Add me method for obtaining current profile info --- lib/linked_in/api_resource.rb | 4 ++++ lib/linked_in/people.rb | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/linked_in/api_resource.rb b/lib/linked_in/api_resource.rb index 83b8984..daf33b6 100644 --- a/lib/linked_in/api_resource.rb +++ b/lib/linked_in/api_resource.rb @@ -114,6 +114,10 @@ def build_fields_params(fields) end end + def me_path + path = "/me" + end + def profile_path(options={}, allow_multiple=true) path = "/people" diff --git a/lib/linked_in/people.rb b/lib/linked_in/people.rb index 850e241..8a6f059 100644 --- a/lib/linked_in/people.rb +++ b/lib/linked_in/people.rb @@ -39,6 +39,11 @@ def profile(id={}, options={}) get(path, options) end + def me(options={}) + path = me_path + get(path, options) + end + # Retrieve a list of 1st degree connections for a user who has # granted access to his/her account # @@ -95,7 +100,7 @@ def skills(id={}, options={}) options = parse_id(id, options) path = "#{profile_path(options, false)}/skills" get(path, options) - end + end protected ############################################################ From 90f44ea2fb117ecd2c63131df6efd1ef29f70e62 Mon Sep 17 00:00:00 2001 From: cameronstanley Date: Fri, 2 Aug 2019 07:31:52 -0500 Subject: [PATCH 04/13] Add delegator for me method --- lib/linked_in/api.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/linked_in/api.rb b/lib/linked_in/api.rb index db90c60..8d8f250 100644 --- a/lib/linked_in/api.rb +++ b/lib/linked_in/api.rb @@ -24,7 +24,8 @@ def initialize(access_token=nil) :skills, :connections, :picture_urls, - :new_connections + :new_connections, + :me def_delegators :@search, :search From 17eedb4deb11597f939773f7f8bd835e1cd26083 Mon Sep 17 00:00:00 2001 From: cameronstanley Date: Sat, 3 Aug 2019 08:20:39 -0500 Subject: [PATCH 05/13] Fixes for authorization headers and eliminating "secure-urls" param for people calls --- lib/linked_in/api.rb | 6 ++---- lib/linked_in/api_resource.rb | 2 +- lib/linked_in/people.rb | 9 --------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/lib/linked_in/api.rb b/lib/linked_in/api.rb index 8d8f250..f83498c 100644 --- a/lib/linked_in/api.rb +++ b/lib/linked_in/api.rb @@ -74,13 +74,11 @@ def initialize_endpoints end def default_params - # https//developer.linkedin.com/documents/authentication - return {oauth2_access_token: @access_token.token} + {} end def default_headers - # https://developer.linkedin.com/documents/api-requests-json - return {"x-li-format" => "json"} + { "Authorization" => "Bearer #{@access_token.token}" } end def verify_access_token!(access_token) diff --git a/lib/linked_in/api_resource.rb b/lib/linked_in/api_resource.rb index daf33b6..9fd8b31 100644 --- a/lib/linked_in/api_resource.rb +++ b/lib/linked_in/api_resource.rb @@ -115,7 +115,7 @@ def build_fields_params(fields) end def me_path - path = "/me" + "/me" end def profile_path(options={}, allow_multiple=true) diff --git a/lib/linked_in/people.rb b/lib/linked_in/people.rb index 8a6f059..51ca832 100644 --- a/lib/linked_in/people.rb +++ b/lib/linked_in/people.rb @@ -103,15 +103,6 @@ def skills(id={}, options={}) end - protected ############################################################ - - - def get(path, options) - options[:"secure-urls"] = true unless options[:secure] == false - super path, options - end - - private ############################################################## From 58dbeb68ad1d84a8965be48483cb7232fed7e204 Mon Sep 17 00:00:00 2001 From: cameronstanley Date: Sun, 4 Aug 2019 08:04:32 -0500 Subject: [PATCH 06/13] Remove v1 share methods and add add_text_share method --- lib/linked_in/api.rb | 10 +- lib/linked_in/share_and_social_stream.rb | 145 ++++------------------- 2 files changed, 24 insertions(+), 131 deletions(-) diff --git a/lib/linked_in/api.rb b/lib/linked_in/api.rb index f83498c..c270ee8 100644 --- a/lib/linked_in/api.rb +++ b/lib/linked_in/api.rb @@ -51,15 +51,7 @@ def initialize(access_token=nil) def_delegators :@communications, :send_message - def_delegators :@share_and_social_stream, :shares, - :share, - :add_share, - :like_share, - :share_likes, - :unlike_share, - :share_comments, - :update_comment, - :network_updates + def_delegators :@share_and_social_stream, :add_text_share private ############################################################## diff --git a/lib/linked_in/share_and_social_stream.rb b/lib/linked_in/share_and_social_stream.rb index c1c1ad7..69ef25b 100644 --- a/lib/linked_in/share_and_social_stream.rb +++ b/lib/linked_in/share_and_social_stream.rb @@ -1,133 +1,34 @@ module LinkedIn - # Share and Social Stream APIs + # Share APIs # - # @see http://developer.linkedin.com/documents/share-and-social-stream - # @see http://developer.linkedin.com/documents/share-api Share API + # @see https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin # - # The following API actions do not have corresponding methods in - # this module - # - # * GET Network Statistics - # * POST Post Network Update - # - # [(contribute here)](https://github.com/emorikawa/linkedin-oauth2) class ShareAndSocialStream < APIResource - # Retrieve the authenticated users network updates - # - # Permissions: rw_nus - # - # @see http://developer.linkedin.com/documents/get-network-updates-and-statistics-api - # @see http://developer.linkedin.com/documents/network-update-types Network Update Types - # - # @macro profile_options - # @option options [String] :scope - # @option options [String] :type - # @option options [String] :count - # @option options [String] :start - # @option options [String] :after - # @option options [String] :before - # @option options [String] :show-hidden-members - # @return [LinkedIn::Mash] - def network_updates(options={}) - path = "#{profile_path(options)}/network/updates" - get(path, options) - end - - # TODO refactor to use #network_updates - def shares(options={}) - path = "#{profile_path(options)}/network/updates" - get(path, {type: "SHAR", scope: "self"}.merge(options)) - end - - def share(update_key, options={}) - path = "#{profile_path(options)}/network/updates/key=#{update_key}" - get(path) - end - - # Retrieve all comments for a particular network update - # - # @note The first 5 comments are included in the response to #network_updates - # - # Permissions: rw_nus - # - # @see http://developer.linkedin.com/documents/commenting-reading-comments-and-likes-network-updates - # - # @param [String] update_key a update/update-key representing a - # particular network update - # @macro profile_options - # @return [LinkedIn::Mash] - def share_comments(update_key, options={}) - path = "#{profile_path(options)}/network/updates/key=#{update_key}/update-comments" - get(path, options) - end - - # Retrieve all likes for a particular network update - # - # @note Some likes are included in the response to #network_updates - # - # Permissions: rw_nus + # Create a text share for the authenticated user # - # @see http://developer.linkedin.com/documents/commenting-reading-comments-and-likes-network-updates - # - # @param [String] update_key a update/update-key representing a - # particular network update - # @macro profile_options - # @return [LinkedIn::Mash] - def share_likes(update_key, options={}) - path = "#{profile_path(options)}/network/updates/key=#{update_key}/likes" - get(path, options) - end - - # Create a share for the authenticated user - # - # Permissions: rw_nus - # - # @see http://developer.linkedin.com/documents/share-api - # - # @macro share_input_fields - # @return [void] - def add_share(share) - path = "/people/~/shares" - defaults = {visibility: {code: "anyone"}} - post(path, MultiJson.dump(defaults.merge(share)), "Content-Type" => "application/json") - end - - # Create a comment on an update from the authenticated user - # - # @see http://developer.linkedin.com/documents/commenting-reading-comments-and-likes-network-updates - # - # @param [String] update_key a update/update-key representing a - # particular network update - # @param [String] comment The text of the comment - # @return [void] - def update_comment(update_key, comment) - path = "/people/~/network/updates/key=#{update_key}/update-comments" - post(path, {comment: comment}) - end - - # (Update) like an update as the authenticated user - # - # @see http://developer.linkedin.com/documents/commenting-reading-comments-and-likes-network-updates - # - # @param [String] update_key a update/update-key representing a - # particular network update - # @return [void] - def like_share(update_key) - path = "/people/~/network/updates/key=#{update_key}/is-liked" - put(path, "true") - end - - # (Destroy) unlike an update the authenticated user previously - # liked + # Permissions: w_member_social # - # @see http://developer.linkedin.com/documents/commenting-reading-comments-and-likes-network-updates + # @see https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin#create-a-text-share # - # @param [String] update_key a update/update-key representing a - # particular network update # @return [void] - def unlike_share(update_key) - path = "/people/~/network/updates/key=#{update_key}/is-liked" - put(path, "false") + def add_text_share(authorId, text) + path = "/ugcPosts" + params = { + "author" => authorId, + "lifecycleState" => "published", + "specificContent" => { + "com.linkedin.ugc.ShareContent" => { + "shareCommentary" => { + "text" => text + }, + "shareMediaCategory" => "NONE" + } + }, + "visibility" => { + "com.linkedin.ugc.MemberNetworkVisibility" => "PUBLIC" + } + } + post(path, params, "Content-Type" => "application/json") end end end From d92bfcf878e846122001ec5035a10aebc3964d5a Mon Sep 17 00:00:00 2001 From: Cameron Stanley Date: Sat, 28 Mar 2020 07:53:41 -0500 Subject: [PATCH 07/13] Adds organizations access control endpoint --- lib/linked_in/api.rb | 2 ++ lib/linked_in/organizations.rb | 11 +++++++++++ lib/linkedin-oauth2.rb | 1 + 3 files changed, 14 insertions(+) create mode 100644 lib/linked_in/organizations.rb diff --git a/lib/linked_in/api.rb b/lib/linked_in/api.rb index c270ee8..d99bcbe 100644 --- a/lib/linked_in/api.rb +++ b/lib/linked_in/api.rb @@ -53,6 +53,8 @@ def initialize(access_token=nil) def_delegators :@share_and_social_stream, :add_text_share + def_delegators :@organizations, :organization_access + private ############################################################## def initialize_endpoints diff --git a/lib/linked_in/organizations.rb b/lib/linked_in/organizations.rb new file mode 100644 index 0000000..7b3d028 --- /dev/null +++ b/lib/linked_in/organizations.rb @@ -0,0 +1,11 @@ +module LinkedIn + + class Organizations < APIResource + # Retrieves a member's organization access control information + def organization_access(options={}) + path = "/organizationAcls?q=roleAssignee" + get(path, options) + end + end + +end diff --git a/lib/linkedin-oauth2.rb b/lib/linkedin-oauth2.rb index 3cf8a39..5637b3f 100644 --- a/lib/linkedin-oauth2.rb +++ b/lib/linkedin-oauth2.rb @@ -33,6 +33,7 @@ require "linked_in/companies" require "linked_in/communications" require "linked_in/share_and_social_stream" +require "linked_in/organizations" # The primary API object that makes requests. # It composes in all of the endpoints From 88ce3972b31f16113161eb7da884cfe24de52d55 Mon Sep 17 00:00:00 2001 From: Cameron Stanley Date: Sat, 28 Mar 2020 08:18:53 -0500 Subject: [PATCH 08/13] Adds retrieve organization endpoint and adds localized description to ACLs response --- lib/linked_in/api.rb | 1 + lib/linked_in/organizations.rb | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/linked_in/api.rb b/lib/linked_in/api.rb index d99bcbe..8e5fe93 100644 --- a/lib/linked_in/api.rb +++ b/lib/linked_in/api.rb @@ -54,6 +54,7 @@ def initialize(access_token=nil) def_delegators :@share_and_social_stream, :add_text_share def_delegators :@organizations, :organization_access + :organization private ############################################################## diff --git a/lib/linked_in/organizations.rb b/lib/linked_in/organizations.rb index 7b3d028..b7e81e8 100644 --- a/lib/linked_in/organizations.rb +++ b/lib/linked_in/organizations.rb @@ -1,11 +1,25 @@ module LinkedIn class Organizations < APIResource + # Retrieves a member's organization access control information def organization_access(options={}) - path = "/organizationAcls?q=roleAssignee" + path = "/organizationAcls?q=roleAssignee&projection=(elements*(*,organization~(localizedName)))" + get(path, options) + end + + # Retrieves an organization + def organization(options={}) + path = organization_path(options) get(path, options) end - end + + def organization_path(options) + path = "/organizations" + + if id = options.delete(:id) + path += "/#{id}" + end + end end From 3de659ac391fcffdd12c8412bc66d765d27e6ebf Mon Sep 17 00:00:00 2001 From: cameronstanley Date: Sat, 28 Mar 2020 09:07:05 -0500 Subject: [PATCH 09/13] Adds fixes for organizations --- lib/linked_in/api.rb | 1 + lib/linked_in/organizations.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/linked_in/api.rb b/lib/linked_in/api.rb index 8e5fe93..af80352 100644 --- a/lib/linked_in/api.rb +++ b/lib/linked_in/api.rb @@ -66,6 +66,7 @@ def initialize_endpoints @companies = LinkedIn::Companies.new(@connection) @communications = LinkedIn::Communications.new(@connection) @share_and_social_stream = LinkedIn::ShareAndSocialStream.new(@connection) + @organizations = LinkedIn::Organizations.new(@connection) end def default_params diff --git a/lib/linked_in/organizations.rb b/lib/linked_in/organizations.rb index b7e81e8..cf185e9 100644 --- a/lib/linked_in/organizations.rb +++ b/lib/linked_in/organizations.rb @@ -22,4 +22,6 @@ def organization_path(options) end end + end + end From 7ce18a638a5b27efa6811c9dc4b02d7602ae33f3 Mon Sep 17 00:00:00 2001 From: cameronstanley Date: Sun, 29 Mar 2020 09:07:09 -0500 Subject: [PATCH 10/13] Fixes bug with organization method in delegator --- lib/linked_in/api.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linked_in/api.rb b/lib/linked_in/api.rb index af80352..cde76cf 100644 --- a/lib/linked_in/api.rb +++ b/lib/linked_in/api.rb @@ -53,7 +53,7 @@ def initialize(access_token=nil) def_delegators :@share_and_social_stream, :add_text_share - def_delegators :@organizations, :organization_access + def_delegators :@organizations, :organization_access, :organization private ############################################################## From 0bf746854878cabbe23cd5f5996a954597446516 Mon Sep 17 00:00:00 2001 From: Cameron Stanley Date: Thu, 1 Apr 2021 00:34:31 -0500 Subject: [PATCH 11/13] Update share_and_social_stream.rb --- lib/linked_in/share_and_social_stream.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linked_in/share_and_social_stream.rb b/lib/linked_in/share_and_social_stream.rb index 69ef25b..9363059 100644 --- a/lib/linked_in/share_and_social_stream.rb +++ b/lib/linked_in/share_and_social_stream.rb @@ -28,7 +28,7 @@ def add_text_share(authorId, text) "com.linkedin.ugc.MemberNetworkVisibility" => "PUBLIC" } } - post(path, params, "Content-Type" => "application/json") + post(path, params.to_json, "Content-Type" => "application/json") end end end From 64caf937e4d2cbe6ebc1565374fa7a9b56685b27 Mon Sep 17 00:00:00 2001 From: Cameron Stanley Date: Sat, 3 Apr 2021 23:57:01 -0500 Subject: [PATCH 12/13] Update share_and_social_stream.rb --- lib/linked_in/share_and_social_stream.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linked_in/share_and_social_stream.rb b/lib/linked_in/share_and_social_stream.rb index 9363059..1378d26 100644 --- a/lib/linked_in/share_and_social_stream.rb +++ b/lib/linked_in/share_and_social_stream.rb @@ -28,7 +28,7 @@ def add_text_share(authorId, text) "com.linkedin.ugc.MemberNetworkVisibility" => "PUBLIC" } } - post(path, params.to_json, "Content-Type" => "application/json") + post(path, params.to_json, { "Content-Type" => "application/json", "X-Restli-Protocol-Version" => "2.0.0" }) end end end From b68f82eaa4522169b7a1875af1c002d2add0ae9b Mon Sep 17 00:00:00 2001 From: Cameron Stanley Date: Sun, 4 Apr 2021 00:18:26 -0500 Subject: [PATCH 13/13] Update share_and_social_stream.rb --- lib/linked_in/share_and_social_stream.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linked_in/share_and_social_stream.rb b/lib/linked_in/share_and_social_stream.rb index 1378d26..708f3e8 100644 --- a/lib/linked_in/share_and_social_stream.rb +++ b/lib/linked_in/share_and_social_stream.rb @@ -15,7 +15,7 @@ def add_text_share(authorId, text) path = "/ugcPosts" params = { "author" => authorId, - "lifecycleState" => "published", + "lifecycleState" => "PUBLISHED", "specificContent" => { "com.linkedin.ugc.ShareContent" => { "shareCommentary" => {