linkedin_orbit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ea542477b38b242198309bfab98334aa41f4cb7c2e99998c38830e53bad0780d
4
+ data.tar.gz: aa504baf8b553d0540ad0f813e74fff47166aa08d208838e53a5dedba7234764
5
+ SHA512:
6
+ metadata.gz: 8495d7435f85b66d68e2016fdf243afe45edf432d048d503c41ef2d7a179ce336f9915c0863ef1ced1b7847376ca62e8abd871b1f6c39f739c36cc8eaf325c7e
7
+ data.tar.gz: e99b0a4d2e1b52067306151671108b50819d7bd3f27aa70ad6867c1a3760d1f97c3f1dc9a01122b2f5a4981ac861213ca1305d0cf44b73c49f3a84a60dfd39a0
data/.env.sample ADDED
@@ -0,0 +1,5 @@
1
+ LINKEDIN_ORGANIZATION=
2
+ LINKEDIN_CODE=
3
+ LINKEDIN_TOKEN=
4
+ ORBIT_API_KEY=
5
+ ORBIT_WORKSPACE_ID=
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .env
2
+ .byebug_history
3
+ .DS_Store
4
+ readme_images/.DS_Store
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ Exclude:
4
+ - 'spec/**/*'
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 120
16
+
17
+ Metrics/MethodLength:
18
+ Enabled: false
19
+
20
+ Style/GuardClause:
21
+ Enabled: false
22
+
23
+ Style/Documentation:
24
+ Enabled: false
25
+
26
+ Metrics/AbcSize:
27
+ Enabled: false
28
+
29
+ Naming/AccessorMethodName:
30
+ Enabled: false
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at bengreenberg@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
@@ -0,0 +1,92 @@
1
+ # Instructions for First Time Set Up
2
+
3
+ These instructions will walk you through authenticating to LinkedIn, and receiving your LinkedIn code, which is needed to use this integration. You will only need to do this one time.
4
+
5
+ ## Creating a LinkedIn Developers App
6
+
7
+ The first thing you must do is create a LinkedIn Developers app.
8
+
9
+ Navigate to the [LinkedIn Developers](https://www.linkedin.com/developers/) website and click the "Create App" button.
10
+
11
+ ![Create LinkedIn App Button](readme_images/create_app_button.png)
12
+
13
+ This will direct you to a short form where LinkedIn will ask you for a few pieces of information:
14
+
15
+ * **App name**: Feel free to put anything you would like, perhaps `orbit-workspace-integration`
16
+ * **LinkedIn page**: Enter the LinkedIn page web address this integration is for. An admin *must* verify the app.
17
+ * **App logo**: Upload an image representing your company or organization
18
+ * **Legal agreement**: Click the checkbox to agree to the terms
19
+
20
+ Once you submit the form, it usually takes 3-4 days for LinkedIn to confirm the application and grant it credentials. During that time, an admin of the LinkedIn company or organization page, needs to verify the application's request for access by going to the LinkedIn page admin dashboard and doing so.
21
+
22
+ While you wait for verification, you can do the next step, which is to request the right API scope from LinkedIn.
23
+
24
+ ## Requesting the LinkedIn Marketing Developer Platform API Access
25
+
26
+ LinkedIn has many different types of APIs and many different types of access levels to those APIs. The API your app needs access to is the **Marketing Developer Platform**.
27
+
28
+ From within your LinkedIn Developers dashboard, navigate to the "Products" page and submit the access request form.
29
+
30
+ ![Marketing Developer Platform Request](readme_images/marketing_platform_request_access.png)
31
+
32
+ This will take another few days for LinkedIn to verify and confirm this request. Once it is done, you will see the Marketing Developer Platform in your list of "Added Products" like shown in the next screenshot.
33
+
34
+ ![LinkedIn Developer Products List](readme_images/products_list.png)
35
+
36
+ ## LinkedIn API Credentials
37
+
38
+ You will need your LinkedIn API credentials to move forward. You can copy your LinkedIn credentials, which are your Client ID and Client Secret from the "Auth" section in the LinkedIn Developers dashboard.
39
+
40
+ ![LinkedIn Client Credentials](readme_images/client_credentials.png)
41
+
42
+ Make sure to save those somewhere safe and where you can access them as we will need them again shortly.
43
+
44
+ You will also see on the "Auth" page a section called "OAuth 2.0 Settings". We will return here later in order to enter a URL in the "Authorized redirect URLs for your app" section.
45
+
46
+ After you have finished all of the above steps, you are ready to move on to the last step in this first time setup instructions.
47
+
48
+ ## LinkedIn Browser Code
49
+
50
+ LinkedIn uses OAuth 2.0 as its authentication format, and as such, you need to authenticate *one-time* with your browser to obtain a code that will be used for the integration from then on.
51
+
52
+ The `linkedin_orbit` integration includes an authentication application to facilitate this process for you. It requires that you have a [Heroku](https://www.heroku.com/) account. It is free to set up a Heroku account, and the one-time authentication app, is fine to run inside the free tier of the platform.
53
+
54
+ Click on the _Deploy to Heroku_ button below to begin deploying the authentication app to Heroku:
55
+
56
+ [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/orbit-love/linkedin-auth-app)
57
+
58
+ You will need to supply your LinkedIn Client ID and LinkedIn Client Secret as part of the deployment process. These are not stored by Orbit or inside this repository. They are only stored by Heroku as part of your Heroku account.
59
+
60
+ Once the app has been deployed on Heroku, click on the "View" button as shown below.
61
+
62
+ ![Heroku View Button](readme_images/heroku_view_app_button.png)
63
+
64
+ This will load a new browser window with the app rendered.
65
+
66
+ Copy the URL of the Heroku app in your browser address bar and return to the LinkedIn Developers dashboard. In the LinkedIn Developers dashboard click on "Auth" from the navigation menu" and then click on the pencil icon in the "Authorized redirect URLs for your app" section of the page, as shown below.
67
+
68
+ ![LinkedIn OAuth Redirect URLS](readme_images/linkedin_oauth_redirects.png)
69
+
70
+ You will see a link appear called "+ Add redirect URL". Click on that link. In the text box that appears above it enter your Heroku app URL with "/auth/linkedin/callback" appended at the end. For example, if your Heroku URL was "https://example-heroku-app-url.herokuapp.com" then the full address you need to enter would be: "https://example-heroku-app-url.herokuapp.com/auth/linkedin/callback". When you are finished, click on the "Update" button.
71
+
72
+ Now, return back to your browser window with your Heroku app running. Click on the "LinkedIn" link on the app. Follow the prompts by LinkedIn to authorize your LinkedIn Developer application. When you are finished, you will be redirected back to your Heroku app and you will see a LinkedIn code. This code is very important. The code you see will be the credential used to authenticate to LinkedIn for the duration of your use of the LinkedIn Orbit community integration.
73
+
74
+ The last step you need to complete in this first time setup is to add the LinkedIn code you created into the LinkedIn Orbit community integration credentials, either in the context of a standalone app or in the context of running it as a GitHub Action.
75
+
76
+ ## Add the LinkedIn Code to the LinkedIn Orbit Community Integration
77
+ ### Within GitHub Actions
78
+
79
+ *(This step assumes you have a GitHub repository created already to run the LinkedIn Orbit community integration. If you do not, please follow [this guide](https://docs.github.com/en/github/getting-started-with-github/create-a-repo) first.)*
80
+
81
+ The LinkedIn code you created in the last step needs to be added to the GitHub repository that you are running the LinkedIn Orbit community integration from. To do so, follow the step-by-step guide in the [README](https://github.com/orbit-love/github-actions-templates/blob/main/README.md#adding-your-credentials-to-github) in the GitHub Actions instructions. The name for this secret **must** be: `LINKEDIN_CODE`.
82
+
83
+ ### Within a Standalone App
84
+
85
+ If you are running the community integration as a standalone app, you can add the LinkedIn code as an environment variable inside the `.env` file in the root directory of the codebase.
86
+
87
+ Open up the `.env` file and add a new line starting with `LINKEDIN_CODE=` and add the LinkedIn Code after the equal sign.
88
+ ## Wrapping Up
89
+
90
+ You have now successfully finished the first time setup for your LinkedIn Orbit community integration. This is a one-time process, and you can safely delete the Heroku authentication app you deployed.
91
+
92
+ From within the Heroku dashboard, navigate to the "Settings" for the app and at the very bottom of the page is a button called "Delete app". Once you click on that button, Heroku will confirm you wish to delete the app. Upon confirmation, the app will be deleted and the deployment on the web will be removed.
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "byebug"
6
+
7
+ gem "dotenv", "~> 2.7.6"
8
+
9
+ gem "http", "~> 4.4"
10
+
11
+ gem "json", "~> 2.5"
12
+
13
+ gem "rake", "~> 13.0"
14
+
15
+ gem "rubocop", "~> 1.7"
16
+
17
+ gem "linkedin", "~> 1.1"
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.7.0)
5
+ public_suffix (>= 2.0.2, < 5.0)
6
+ ast (2.4.2)
7
+ byebug (11.1.3)
8
+ domain_name (0.5.20190701)
9
+ unf (>= 0.0.5, < 1.0.0)
10
+ dotenv (2.7.6)
11
+ faraday (1.4.1)
12
+ faraday-excon (~> 1.1)
13
+ faraday-net_http (~> 1.0)
14
+ faraday-net_http_persistent (~> 1.1)
15
+ multipart-post (>= 1.2, < 3)
16
+ ruby2_keywords (>= 0.0.4)
17
+ faraday-excon (1.1.0)
18
+ faraday-net_http (1.0.1)
19
+ faraday-net_http_persistent (1.1.0)
20
+ ffi (1.15.0)
21
+ ffi-compiler (1.0.1)
22
+ ffi (>= 1.0.0)
23
+ rake
24
+ hashie (3.6.0)
25
+ http (4.4.1)
26
+ addressable (~> 2.3)
27
+ http-cookie (~> 1.0)
28
+ http-form_data (~> 2.2)
29
+ http-parser (~> 1.2.0)
30
+ http-cookie (1.0.3)
31
+ domain_name (~> 0.5)
32
+ http-form_data (2.3.0)
33
+ http-parser (1.2.3)
34
+ ffi-compiler (>= 1.0, < 2.0)
35
+ json (2.5.1)
36
+ jwt (2.2.3)
37
+ linkedin (1.1.1)
38
+ hashie (~> 3.0)
39
+ multi_json (~> 1.0)
40
+ oauth2 (~> 1.0)
41
+ multi_json (1.15.0)
42
+ multi_xml (0.6.0)
43
+ multipart-post (2.1.1)
44
+ oauth2 (1.4.7)
45
+ faraday (>= 0.8, < 2.0)
46
+ jwt (>= 1.0, < 3.0)
47
+ multi_json (~> 1.3)
48
+ multi_xml (~> 0.5)
49
+ rack (>= 1.2, < 3)
50
+ parallel (1.20.1)
51
+ parser (3.0.1.1)
52
+ ast (~> 2.4.1)
53
+ public_suffix (4.0.6)
54
+ rack (2.2.3)
55
+ rainbow (3.0.0)
56
+ rake (13.0.3)
57
+ regexp_parser (2.1.1)
58
+ rexml (3.2.5)
59
+ rubocop (1.14.0)
60
+ parallel (~> 1.10)
61
+ parser (>= 3.0.0.0)
62
+ rainbow (>= 2.2.2, < 4.0)
63
+ regexp_parser (>= 1.8, < 3.0)
64
+ rexml
65
+ rubocop-ast (>= 1.5.0, < 2.0)
66
+ ruby-progressbar (~> 1.7)
67
+ unicode-display_width (>= 1.4.0, < 3.0)
68
+ rubocop-ast (1.5.0)
69
+ parser (>= 3.0.1.1)
70
+ ruby-progressbar (1.11.0)
71
+ ruby2_keywords (0.0.4)
72
+ unf (0.1.4)
73
+ unf_ext
74
+ unf_ext (0.0.7.7)
75
+ unicode-display_width (2.0.0)
76
+
77
+ PLATFORMS
78
+ arm64-darwin-20
79
+ x86_64-linux
80
+
81
+ DEPENDENCIES
82
+ byebug
83
+ dotenv (~> 2.7.6)
84
+ http (~> 4.4)
85
+ json (~> 2.5)
86
+ linkedin (~> 1.1)
87
+ rake (~> 13.0)
88
+ rubocop (~> 1.7)
89
+
90
+ BUNDLED WITH
91
+ 2.2.16
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Ben Greenberg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # LinkedIn to Orbit Workspace Ruby App
2
+
3
+ ![Build Status](https://github.com/orbit-love/community-ruby-linkedin-orbit/workflows/CI/badge.svg)
4
+ [![Gem Version](https://badge.fury.io/rb/linkedin_orbit.svg)](https://badge.fury.io/rb/dev_orbit)
5
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](code_of_conduct.md)
6
+
7
+ This is a Ruby app that can be used to integrate LinkedIn post comments into your organization's Orbit workspace.
8
+
9
+ |<p align="left">:sparkles:</p> This is a *community project*. The Orbit team does its best to maintain it and keep it up to date with any recent API changes.<br/><br/>We welcome community contributions to make sure that it stays current. <p align="right">:sparkles:</p>|
10
+ |-----------------------------------------|
11
+
12
+ <hr />
13
+
14
+ ## Installation
15
+
16
+ | **Are you setting up this integration for the first time? Please read the [first time setup](https://github.com/orbit-love/community-ruby-linkedin-orbit/blob/main/FIRST_TIME_INSTRUCTIONS.md) guide before proceeding. LinkedIn requires a very specific authentication procedure, and it is required, to successfully use this integration.**
17
+
18
+ ### As a Standalone App
19
+
20
+ To install this integration in a standalone app, add the gem to your `Gemfile`:
21
+
22
+ ```ruby
23
+ gem "linkedin_orbit"
24
+ ```
25
+
26
+ Then, run `bundle install` from your terminal.
27
+
28
+ ### With GitHub Actions
29
+
30
+ This integration can be run as a daily scheduled activity within GitHub Actions! To install this integration with your GitHub account, follow the instructions in the [Orbit GitHub Actions Guide](https://github.com/orbit-love/github-actions-templates).
31
+ ## Usage
32
+
33
+ ### CLI
34
+
35
+ ### Standalone Client
36
+
37
+ ### GitHub Actions
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/orbit-love/community-ruby-linkedin-orbit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/orbit-love/community-ruby-linkedin-orbit/blob/main/CODE_OF_CONDUCT.md).
42
+
43
+ ## License
44
+
45
+ This is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+
47
+ ## Code of Conduct
48
+
49
+ Everyone interacting in the project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/orbit-live/community-ruby-linkedin-orbit/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
4
+ check_comments = false
5
+
6
+ options = {}
7
+ choices = OptionParser.new do |opts|
8
+ opts.banner = "Usage: linkedin_orbit --check-comments"
9
+ opts.on("-h", "--help", "Prints help instructions") do
10
+ puts opts
11
+ exit
12
+ end
13
+ opts.on("--check-comments", "Check for new LinkedIn comments") do
14
+ check_comments = true
15
+ end
16
+ end.parse!
17
+
18
+ $LOAD_PATH.unshift(File.expand_path('../lib/dev_orbit', __dir__))
19
+
20
+ require_relative '../lib/linkedin_orbit'
21
+ require_relative '../scripts/check_comments'
22
+
23
+ if check_comments
24
+ puts "Checking for new LinkedIn comments and posting them to your Orbit workspace..."
25
+ ARGV[0] = 'render'
26
+ LinkedinOrbit::Scripts::CheckComments.start(ARGV)
27
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zeitwerk"
4
+
5
+ module LinkedinOrbit
6
+ loader = Zeitwerk::Loader.new
7
+ loader.tag = File.basename(__FILE__, ".rb")
8
+ loader.push_dir(__dir__)
9
+ loader.setup
10
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "linkedin"
4
+ require "dotenv/load"
5
+
6
+ # Create a client to log LinkedIn interactions in your Orbit workspace
7
+ # Credentials can either be passed in to the instance or be loaded
8
+ # from environment variables
9
+ #
10
+ # @example
11
+ # client = LinkedinOrbit::Client.new
12
+ #
13
+ # @option params [String] :orbit_api_key
14
+ # The API key for the Orbit API
15
+ #
16
+ # @option params [String] :orbit_workspace
17
+ # The workspace ID for the Orbit workspace
18
+ #
19
+ # @option params [String] :linkedin_client_id
20
+ # The Client ID for your LinkedIn Developers Access
21
+ # More details on obtaining it at https://www.linkedin.com/developers/
22
+ #
23
+ # @option params [String] :linkedin_client_secret
24
+ # The Client Secret for your LinkedIn Developers Access
25
+ # More details on obtaining it at https://www.linkedin.com/developers/
26
+ #
27
+ # @option params [String] :linkedin_organization
28
+ # The LinkedIn schema for the LinkedIn organization to log interactions from
29
+ # For example, a company on LinkedIn with the web address of:
30
+ # "https://www.linkedin.com/company/28866695"
31
+ # The LinkedIn organization would use the last component of that web address and would be:
32
+ # urn:li:organization:28866695
33
+ #
34
+ # @param [Hash] params
35
+ #
36
+ # @return [DevOrbit::Client]
37
+ #
38
+ module LinkedinOrbit
39
+ class Client
40
+ attr_accessor :orbit_api_key, :orbit_workspace, :linkedin_organization
41
+ attr_reader :linkedin_token
42
+
43
+ def initialize(params = {})
44
+ @orbit_api_key = params.fetch(:orbit_api_key, ENV["ORBIT_API_KEY"])
45
+ @orbit_workspace = params.fetch(:orbit_workspace, ENV["ORBIT_WORKSPACE_ID"])
46
+ @linkedin_token = token
47
+ @linkedin_organization = params.fetch(:linkedin_organization, ENV["LINKEDIN_ORGANIZATION"])
48
+ end
49
+
50
+ def token
51
+ @token ||= begin
52
+ return ENV["LINKEDIN_TOKEN"] if ENV["LINKEDIN_TOKEN"]
53
+
54
+ linkedin = LinkedIn::Client.new(@linkedin_client_id, @linkedin_client_secret)
55
+ linkedin.authorize_from_access(ENV["LINKEDIN_CODE"])
56
+ end
57
+ end
58
+
59
+ def comments
60
+ LinkedinOrbit::Linkedin.new(
61
+ linkedin_token: @linkedin_token,
62
+ linkedin_organization: @linkedin_organization,
63
+ orbit_api_key: @orbit_api_key,
64
+ orbit_workspace: @orbit_workspace
65
+ ).process_comments
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+
6
+ module LinkedinOrbit
7
+ module Interactions
8
+ class Comment
9
+ def initialize(title:, comment:, orbit_workspace:, orbit_api_key:)
10
+ @title = title
11
+ @comment = comment
12
+ @orbit_workspace = orbit_workspace
13
+ @orbit_api_key = orbit_api_key
14
+
15
+ after_initialize!
16
+ end
17
+
18
+ def after_initialize!
19
+ url = URI("https://app.orbit.love/api/v1/#{@orbit_workspace}/activities")
20
+
21
+ http = Net::HTTP.new(url.host, url.port)
22
+ http.use_ssl = true
23
+
24
+ request = Net::HTTP::Post.new(url)
25
+ request["Accept"] = "application/json"
26
+ request["Content-Type"] = "application/json"
27
+ request["Authorization"] = "Bearer #{@orbit_api_key}"
28
+
29
+ request.body = construct_body.to_json
30
+
31
+ response = http.request(request)
32
+
33
+ JSON.parse(response.body)
34
+ end
35
+
36
+ def construct_body
37
+ {
38
+ activity: {
39
+ activity_type: "linkedin:comment",
40
+ title: "Commented on LinkedIn Post",
41
+ description: construct_description,
42
+ occurred_at: Time.at(@comment["created"]["time"] / 1000),
43
+ key: @comment["id"],
44
+ member: {
45
+ name: name
46
+ }
47
+ },
48
+ identity: {
49
+ source: "linkedin",
50
+ name: name,
51
+ uid: @comment["actor"]
52
+ }
53
+ }
54
+ end
55
+
56
+ def name
57
+ @name ||= begin
58
+ return @comment["actor~"]["localizedName"] if @comment["actor~"]["localizedName"]
59
+
60
+ "#{@comment["actor~"]["localizedFirstName"]} #{@comment["actor~"]["localizedLastName"]}"
61
+ end
62
+ end
63
+
64
+ def construct_description
65
+ <<~HEREDOC
66
+ LinkedIn post: "#{@title}..."
67
+ \n
68
+ Comment:
69
+ \n
70
+ "#{@comment["message"]["text"]}"
71
+ HEREDOC
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LinkedinOrbit
4
+ class Linkedin
5
+ def initialize(params = {})
6
+ @linkedin_organization = params.fetch(:linkedin_organization)
7
+ @linkedin_token = params.fetch(:linkedin_token)
8
+ @orbit_api_key = params.fetch(:orbit_api_key)
9
+ @orbit_workspace = params.fetch(:orbit_workspace)
10
+ end
11
+
12
+ def process_comments
13
+ posts = get_posts
14
+
15
+ posts.each do |post|
16
+ comments = get_post_comments(post["id"])
17
+
18
+ comments.reject! { |comment| comment["actor~"]["id"] == "private" }
19
+
20
+ next if comments.nil? || comments.empty?
21
+
22
+ comments.each do |comment|
23
+ LinkedinOrbit::Orbit.call(
24
+ type: "comments",
25
+ data: {
26
+ comment: comment,
27
+ title: post["message_highlight"]
28
+ },
29
+ orbit_workspace: @orbit_workspace,
30
+ orbit_api_key: @orbit_api_key
31
+ )
32
+ end
33
+ end
34
+ end
35
+
36
+ def get_posts
37
+ posts = []
38
+ url = URI("https://api.linkedin.com/v2/shares?q=owners&owners=#{@linkedin_organization}")
39
+ https = Net::HTTP.new(url.host, url.port)
40
+ https.use_ssl = true
41
+
42
+ request = Net::HTTP::Get.new(url)
43
+ request["Accept"] = "application/json"
44
+ request["Content-Type"] = "application/json"
45
+ request["Authorization"] = "Bearer #{@linkedin_token}"
46
+
47
+ response = https.request(request)
48
+
49
+ response = JSON.parse(response.body)
50
+
51
+ response["elements"].each do |element|
52
+ posts << {
53
+ "id" => element["activity"],
54
+ "message_highlight" => element["text"]["text"][0, 40]
55
+ }
56
+ end
57
+
58
+ posts
59
+ end
60
+
61
+ def get_post_comments(id)
62
+ url = URI("https://api.linkedin.com/v2/socialActions/#{id}/comments?projection=(elements(*(*,actor~(*,profilePicture(displayImage~:playableStreams)))))")
63
+ https = Net::HTTP.new(url.host, url.port)
64
+ https.use_ssl = true
65
+
66
+ request = Net::HTTP::Get.new(url)
67
+ request["Accept"] = "application/json"
68
+ request["Content-Type"] = "application/json"
69
+ request["Authorization"] = "Bearer #{@linkedin_token}"
70
+
71
+ response = https.request(request)
72
+
73
+ response = JSON.parse(response.body)
74
+
75
+ response["elements"]
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LinkedinOrbit
4
+ class Orbit
5
+ def self.call(type:, data:, orbit_workspace:, orbit_api_key:)
6
+ if type == "comments"
7
+ LinkedinOrbit::Interactions::Comment.new(
8
+ title: data[:title].gsub("\n", " "),
9
+ comment: data[:comment],
10
+ orbit_workspace: orbit_workspace,
11
+ orbit_api_key: orbit_api_key
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LinkedinOrbit
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/linkedin_orbit/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "linkedin_orbit"
7
+ spec.version = LinkedinOrbit::VERSION
8
+ spec.authors = ["Orbit DevRel", "Ben Greenberg"]
9
+ spec.email = ["devrel@orbit.love"]
10
+
11
+ spec.summary = "Integrate LinkedIn interactions into Orbit"
12
+ spec.description = "This gem brings in LinkedIn comments to your Orbit workspace"
13
+ spec.homepage = "https://github.com/orbit-love/community-ruby-linkedin-orbit"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.2")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "https://github.com/orbit-love/community-ruby-linkedin-orbit/blob/main/CHANGELOG.md"
20
+
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+
25
+ spec.bindir = "bin"
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "http", "~> 4.4"
30
+ spec.add_dependency "json", "~> 2.5"
31
+ spec.add_dependency "zeitwerk", "~> 2.4"
32
+ spec.add_dependency "thor", "~> 1.1"
33
+ spec.add_dependency "linkedin", "~> 1.1"
34
+ spec.add_development_dependency "rspec", "~> 3.4"
35
+ spec.add_development_dependency "webmock", "~> 3.12"
36
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "dev_orbit"
5
+ require "thor"
6
+
7
+ module LinkedinOrbit
8
+ module Scripts
9
+ class CheckComments < Thor
10
+ desc "render", "check for new LinkedIn post comments and push them to Orbit"
11
+ def render
12
+ client = LinkedinOrbit::Client.new
13
+ client.comments
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linkedin_orbit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Orbit DevRel
8
+ - Ben Greenberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-05-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: http
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '4.4'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '4.4'
28
+ - !ruby/object:Gem::Dependency
29
+ name: json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.5'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.5'
42
+ - !ruby/object:Gem::Dependency
43
+ name: zeitwerk
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.4'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.4'
56
+ - !ruby/object:Gem::Dependency
57
+ name: thor
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.1'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.1'
70
+ - !ruby/object:Gem::Dependency
71
+ name: linkedin
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.1'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.1'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.4'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.4'
98
+ - !ruby/object:Gem::Dependency
99
+ name: webmock
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '3.12'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '3.12'
112
+ description: This gem brings in LinkedIn comments to your Orbit workspace
113
+ email:
114
+ - devrel@orbit.love
115
+ executables:
116
+ - linkedin_orbit
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".env.sample"
121
+ - ".gitignore"
122
+ - ".rubocop.yml"
123
+ - CODE_OF_CONDUCT.md
124
+ - FIRST_TIME_INSTRUCTIONS.md
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - LICENSE
128
+ - README.md
129
+ - bin/linkedin_orbit
130
+ - lib/linkedin_orbit.rb
131
+ - lib/linkedin_orbit/client.rb
132
+ - lib/linkedin_orbit/interactions/comment.rb
133
+ - lib/linkedin_orbit/linkedin.rb
134
+ - lib/linkedin_orbit/orbit.rb
135
+ - lib/linkedin_orbit/version.rb
136
+ - linkedin_orbit.gemspec
137
+ - readme_images/.DS_Store
138
+ - readme_images/client_credentials.png
139
+ - readme_images/create_app_button.png
140
+ - readme_images/heroku_view_app_button.png
141
+ - readme_images/linkedin_oauth_redirects.png
142
+ - readme_images/logo.png
143
+ - readme_images/marketing_platform_request_access.png
144
+ - readme_images/products_list.png
145
+ - scripts/check_comments.rb
146
+ homepage: https://github.com/orbit-love/community-ruby-linkedin-orbit
147
+ licenses:
148
+ - MIT
149
+ metadata:
150
+ homepage_uri: https://github.com/orbit-love/community-ruby-linkedin-orbit
151
+ source_code_uri: https://github.com/orbit-love/community-ruby-linkedin-orbit
152
+ changelog_uri: https://github.com/orbit-love/community-ruby-linkedin-orbit/blob/main/CHANGELOG.md
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: 2.7.2
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubygems_version: 3.2.15
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Integrate LinkedIn interactions into Orbit
172
+ test_files: []