dev_orbit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 80bcc5826d4088f33048db1adc6cc22029b8739e5affd5154f1af496b7f63e04
4
+ data.tar.gz: 714dc5857e7c11820068f67e004a203cc905c1fcb28c154ebc9f3065a5340561
5
+ SHA512:
6
+ metadata.gz: ae17e17441b221b7a2b9cbf104517c8a3fc36d568549764ffb6670318cb5187be0e9460bf4e59ae6e3d653f40ff27ccf0bdce1deeb2b6d71e3ca6a6edbc44ee3
7
+ data.tar.gz: 85d4c3d19eb02499608dd140c36f2190ca94470086cd17a881c3c51626665c36eb6d013543f705a6a651673c74ce1879d5d430debbf8a7cf8e5fd595d2e6ce28
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
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
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [0.0.1] - 2021-03-06
2
+
3
+ - Initial release
@@ -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.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in dev_orbit.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.7"
11
+
12
+ gem "byebug"
data/Gemfile.lock ADDED
@@ -0,0 +1,105 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dev_orbit (0.0.1)
5
+ activesupport (~> 6.1)
6
+ http (~> 4.4)
7
+ json (~> 2.5)
8
+ zeitwerk (~> 2.4)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (6.1.3)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ i18n (>= 1.6, < 2)
16
+ minitest (>= 5.1)
17
+ tzinfo (~> 2.0)
18
+ zeitwerk (~> 2.3)
19
+ addressable (2.7.0)
20
+ public_suffix (>= 2.0.2, < 5.0)
21
+ ast (2.4.2)
22
+ byebug (11.1.3)
23
+ concurrent-ruby (1.1.8)
24
+ crack (0.4.5)
25
+ rexml
26
+ diff-lcs (1.4.4)
27
+ domain_name (0.5.20190701)
28
+ unf (>= 0.0.5, < 1.0.0)
29
+ ffi (1.15.0)
30
+ ffi-compiler (1.0.1)
31
+ ffi (>= 1.0.0)
32
+ rake
33
+ hashdiff (1.0.1)
34
+ http (4.4.1)
35
+ addressable (~> 2.3)
36
+ http-cookie (~> 1.0)
37
+ http-form_data (~> 2.2)
38
+ http-parser (~> 1.2.0)
39
+ http-cookie (1.0.3)
40
+ domain_name (~> 0.5)
41
+ http-form_data (2.3.0)
42
+ http-parser (1.2.3)
43
+ ffi-compiler (>= 1.0, < 2.0)
44
+ i18n (1.8.9)
45
+ concurrent-ruby (~> 1.0)
46
+ json (2.5.1)
47
+ minitest (5.14.4)
48
+ parallel (1.20.1)
49
+ parser (3.0.0.0)
50
+ ast (~> 2.4.1)
51
+ public_suffix (4.0.6)
52
+ rainbow (3.0.0)
53
+ rake (13.0.3)
54
+ regexp_parser (2.1.1)
55
+ rexml (3.2.4)
56
+ rspec (3.10.0)
57
+ rspec-core (~> 3.10.0)
58
+ rspec-expectations (~> 3.10.0)
59
+ rspec-mocks (~> 3.10.0)
60
+ rspec-core (3.10.1)
61
+ rspec-support (~> 3.10.0)
62
+ rspec-expectations (3.10.1)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.10.0)
65
+ rspec-mocks (3.10.2)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.10.0)
68
+ rspec-support (3.10.2)
69
+ rubocop (1.11.0)
70
+ parallel (~> 1.10)
71
+ parser (>= 3.0.0.0)
72
+ rainbow (>= 2.2.2, < 4.0)
73
+ regexp_parser (>= 1.8, < 3.0)
74
+ rexml
75
+ rubocop-ast (>= 1.2.0, < 2.0)
76
+ ruby-progressbar (~> 1.7)
77
+ unicode-display_width (>= 1.4.0, < 3.0)
78
+ rubocop-ast (1.4.1)
79
+ parser (>= 2.7.1.5)
80
+ ruby-progressbar (1.11.0)
81
+ tzinfo (2.0.4)
82
+ concurrent-ruby (~> 1.0)
83
+ unf (0.1.4)
84
+ unf_ext
85
+ unf_ext (0.0.7.7)
86
+ unicode-display_width (2.0.0)
87
+ webmock (3.12.1)
88
+ addressable (>= 2.3.6)
89
+ crack (>= 0.3.2)
90
+ hashdiff (>= 0.4.0, < 2.0.0)
91
+ zeitwerk (2.4.2)
92
+
93
+ PLATFORMS
94
+ x86_64-darwin-19
95
+
96
+ DEPENDENCIES
97
+ byebug
98
+ dev_orbit!
99
+ rake (~> 13.0)
100
+ rspec (~> 3.4)
101
+ rubocop (~> 1.7)
102
+ webmock (~> 3.12)
103
+
104
+ BUNDLED WITH
105
+ 2.2.13
data/LICENSE.txt 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,58 @@
1
+ # DEV.to Interactions to Orbit Workspace
2
+
3
+ This is a Ruby gem that can be used to integrate your DEV interactions, like DEV comments on blog posts, into your organization's Orbit workspace.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dev_orbit'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Instantiation of the Client
16
+
17
+ To instantiate a DevOrbit client, you can either pass along your credentials for DEV and Orbit directly to the instantiation or retain them in your environment variables.
18
+
19
+ With the credentials as environment variables:
20
+
21
+ ```ruby
22
+ client = DevOrbit::Client.new
23
+ ```
24
+
25
+ Passing in the credentials directly into the instantiation:
26
+
27
+ ```ruby
28
+ client = DevOrbit::Client.new(
29
+ orbit_api_key: '...',
30
+ orbit_workspace: '...',
31
+ dev_api_key: '...',
32
+ dev_username: '...'
33
+ )
34
+ ```
35
+
36
+ ### Post New DEV Comments to Orbit Workspace
37
+
38
+ You can use the gem to get new DEV comments on your DEV user or organization by invoking the `#comments` method on your `client` instance:
39
+
40
+ ```ruby
41
+ client.comments
42
+ ```
43
+
44
+ This method will fetch all your articles from DEV, gather their respective comments, filter them for anything within the past day, and then send them to your Orbit workspace via the Orbit API.
45
+
46
+ You can run this a daily cron job, for example, to add your newest DEV comments as activities in your Orbit workspace.
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bencgreenberg/dev_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/bencgreenberg/dev_orbit/blob/master/CODE_OF_CONDUCT.md).
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
55
+
56
+ ## Code of Conduct
57
+
58
+ 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/bencgreenberg/dev_orbit/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "dev_orbit"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dev_orbit.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/dev_orbit/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "dev_orbit"
7
+ spec.version = DevOrbit::VERSION
8
+ spec.authors = ["Ben Greenberg"]
9
+ spec.email = ["ben.greenberg@hey.com"]
10
+
11
+ spec.summary = "Integrate DEV interactions into your Orbit workspace"
12
+ spec.description = "This gem integrates DEV blog interactions like comments, etc. into your Orbit workspace"
13
+ spec.homepage = "https://github.com/bencgreenberg/dev_orbit"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/bencgreenberg/dev_orbit"
19
+ spec.metadata["changelog_uri"] = "https://github.com/bencgreenberg/dev_orbit/blob/master/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ # Uncomment to register a new dependency of your gem
31
+ # spec.add_dependency "example-gem", "~> 1.0"
32
+ spec.add_dependency "activesupport", "~> 6.1"
33
+ spec.add_dependency "http", "~> 4.4"
34
+ spec.add_dependency "json", "~> 2.5"
35
+ spec.add_dependency "zeitwerk", "~> 2.4"
36
+ spec.add_development_dependency "rspec", "~> 3.4"
37
+ spec.add_development_dependency "webmock", "~> 3.12"
38
+
39
+ # For more information and examples about making a new gem, checkout our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
data/lib/dev_orbit.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zeitwerk"
4
+
5
+ module DevOrbit
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,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Create a client to log DEV interactions in your Orbit workspace
4
+ # Credentials can either be passed in to the instance or be loaded
5
+ # from environment variables
6
+ #
7
+ # @example
8
+ # client = DevOrbit::Client.new
9
+ #
10
+ # @option params [String] :dev_username
11
+ # The username of the person or organization to fetch DEV interactions for
12
+ #
13
+ # @option params [String] :dev_api_key
14
+ # The API key for the DEV API
15
+ #
16
+ # @option params [String] :orbit_workspace
17
+ # The workspace ID for the Orbit workspace
18
+ #
19
+ # @option params [String] :orbit_api_key
20
+ # The API key for the Orbit API
21
+ #
22
+ # @param [Hash] params
23
+ #
24
+ # @return [DevOrbit::Client]
25
+ #
26
+ module DevOrbit
27
+ class Client
28
+ attr_accessor :dev_username, :dev_api_key, :orbit_workspace, :orbit_api_key
29
+
30
+ def initialize(params = {})
31
+ @orbit_api_key = params.fetch(:orbit_api_key, ENV["ORBIT_API_KEY"])
32
+ @orbit_workspace = params.fetch(:orbit_workspace, ENV["ORBIT_WORKSPACE"])
33
+ @dev_api_key = params.fetch(:dev_api_key, ENV["DEV_API_KEY"])
34
+ @dev_username = params.fetch(:dev_username, ENV["DEV_USERNAME"])
35
+ end
36
+
37
+ # Fetch new comments from DEV and post them to the Orbit workspace
38
+ def comments
39
+ DevOrbit::Dev.new(
40
+ api_key: @dev_api_key,
41
+ username: @dev_username,
42
+ workspace_id: @orbit_workspace,
43
+ orbit_api_key: @orbit_api_key
44
+ ).process_comments
45
+ end
46
+
47
+ def orbit
48
+ DevOrbit::Orbit.new
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "active_support/time"
6
+
7
+ module DevOrbit
8
+ class Dev
9
+ def initialize(params = {})
10
+ @username = params.fetch(:username, ENV["DEV_USERNAME"])
11
+ @api_key = params.fetch(:api_key, ENV["DEV_API_KEY"])
12
+ @workspace_id = params.fetch(:workspace_id, ENV["ORBIT_WORKSPACE_ID"])
13
+ @orbit_api_key = params.fetch(:orbit_api_key, ENV["ORBIT_API_KEY"])
14
+ end
15
+
16
+ def process_comments
17
+ articles = get_articles
18
+
19
+ articles.each do |article|
20
+ comments = get_article_comments(article["id"])
21
+ next if comments.empty?
22
+
23
+ DevOrbit::Orbit.call(
24
+ type: "comments",
25
+ data: {
26
+ comments: comments,
27
+ title: article["title"],
28
+ url: article["url"]
29
+ },
30
+ workspace_id: @workspace_id,
31
+ api_key: @orbit_api_key
32
+ )
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def get_articles
39
+ url = URI("https://dev.to/api/articles?username=#{@username}&top=1")
40
+ https = Net::HTTP.new(url.host, url.port)
41
+ https.use_ssl = true
42
+
43
+ request = Net::HTTP::Get.new(url)
44
+
45
+ response = https.request(request)
46
+
47
+ JSON.parse(response.body)
48
+ end
49
+
50
+ def get_article_comments(id)
51
+ url = URI("https://dev.to/api/comments?a_id=#{id}")
52
+ https = Net::HTTP.new(url.host, url.port)
53
+ https.use_ssl = true
54
+
55
+ request = Net::HTTP::Get.new(url)
56
+
57
+ response = https.request(request)
58
+ comments = JSON.parse(response.body)
59
+
60
+ filter_comments(comments)
61
+ end
62
+
63
+ def filter_comments(comments)
64
+ comments.select do |comment|
65
+ comment["created_at"] >= 1.day.ago
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+
6
+ module DevOrbit
7
+ module Interactions
8
+ class Comment
9
+ def initialize(article_title:, url:, comment:, workspace_id:, api_key:)
10
+ @article_title = article_title
11
+ @url = url
12
+ @id = comment[:id_code]
13
+ @created_at = comment[:created_at]
14
+ @body = sanitize_comment(comment[:body_html])
15
+ @commenter = construct_commenter(comment[:user].transform_keys(&:to_sym))
16
+ @workspace_id = workspace_id
17
+ @api_key = api_key
18
+
19
+ after_initialize!
20
+ end
21
+
22
+ def after_initialize!
23
+ url = URI("https://app.orbit.love/api/v1/#{@workspace_id}/activities")
24
+
25
+ http = Net::HTTP.new(url.host, url.port)
26
+ http.use_ssl = true
27
+ req = Net::HTTP::Post.new(url)
28
+ req["Accept"] = "application/json"
29
+ req["Content-Type"] = "application/json"
30
+ req["Authorization"] = "Bearer #{@api_key}"
31
+
32
+ req.body = {
33
+ activity: {
34
+ activity_type: "dev:comment",
35
+ key: "dev-comment-#{@id}",
36
+ title: "Commented on the DEV blog post: #{@article_title}",
37
+ description: @body,
38
+ occurred_at: @created_at,
39
+ link: @url,
40
+ member: {
41
+ name: @commenter[:name],
42
+ devto: @commenter[:username]
43
+ }
44
+ },
45
+ identity: {
46
+ source: "devto",
47
+ username: @commenter[:username]
48
+ }
49
+ }
50
+
51
+ req.body[:activity][:member].merge!(twitter: @commenter[:twitter]) if @commenter[:twitter]
52
+
53
+ req.body[:activity][:member].merge!(github: @commenter[:github]) if @commenter[:github]
54
+
55
+ req.body = req.body.to_json
56
+
57
+ response = http.request(req)
58
+
59
+ JSON.parse(response.body)
60
+ end
61
+
62
+ def construct_commenter(commenter)
63
+ hash = {
64
+ 'name': commenter[:name],
65
+ 'username': commenter[:username]
66
+ }
67
+
68
+ unless commenter[:twitter_username].nil? || commenter[:twitter_username] == ""
69
+ hash.merge!('twitter': commenter[:twitter_username])
70
+ end
71
+
72
+ unless commenter[:github_username].nil? || commenter[:github_username] == ""
73
+ hash.merge!('github': commenter[:github_username])
74
+ end
75
+
76
+ hash
77
+ end
78
+
79
+ def sanitize_comment(comment)
80
+ comment.gsub!(/(<[^>]*>)|\n|\t/s) { " " }
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+
6
+ module DevOrbit
7
+ class Orbit
8
+ def self.call(type:, data:, workspace_id:, api_key:)
9
+ if type == "comments"
10
+ data[:comments].each do |comment|
11
+ DevOrbit::Interactions::Comment.new(
12
+ article_title: data.transform_keys(&:to_sym)[:title],
13
+ comment: comment.transform_keys(&:to_sym),
14
+ url: data[:url],
15
+ workspace_id: workspace_id,
16
+ api_key: api_key
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevOrbit
4
+ VERSION = "0.0.1"
5
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dev_orbit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Greenberg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: zeitwerk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.12'
97
+ description: This gem integrates DEV blog interactions like comments, etc. into your
98
+ Orbit workspace
99
+ email:
100
+ - ben.greenberg@hey.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - CHANGELOG.md
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bin/console
116
+ - bin/setup
117
+ - dev_orbit.gemspec
118
+ - lib/dev_orbit.rb
119
+ - lib/dev_orbit/client.rb
120
+ - lib/dev_orbit/dev.rb
121
+ - lib/dev_orbit/interactions/comment.rb
122
+ - lib/dev_orbit/orbit.rb
123
+ - lib/dev_orbit/version.rb
124
+ homepage: https://github.com/bencgreenberg/dev_orbit
125
+ licenses:
126
+ - MIT
127
+ metadata:
128
+ homepage_uri: https://github.com/bencgreenberg/dev_orbit
129
+ source_code_uri: https://github.com/bencgreenberg/dev_orbit
130
+ changelog_uri: https://github.com/bencgreenberg/dev_orbit/blob/master/CHANGELOG.md
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 2.7.0
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubygems_version: 3.1.4
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Integrate DEV interactions into your Orbit workspace
150
+ test_files: []