dev_orbit 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c91ef071ae7615cf957e49580b99d384b842227bdb5f16557115ae8a81449dfc
4
- data.tar.gz: f0d90c3fe043997e7ca812572b3a81b26e261a51b53d64ca98babc0a002e0287
3
+ metadata.gz: add9a71f83902b74177d6f18be9244a6046ddfce66d9bee7faa7441508521e70
4
+ data.tar.gz: dca028c4a584988d396397eb9ce128efe4689d97e8a1ee3cf033b95d4a6c31aa
5
5
  SHA512:
6
- metadata.gz: 621bd01a4bec7709a5a5ec196dd2bb1235c1eb6334bccb2cc7384c090fee3e8ab10419ccd180e1675d5cdf4694db17e6ccc2d0c7a5b50246cc732bd2e438f798
7
- data.tar.gz: 6f988344ad296cfc1ce2e7defcc6534946a511eeb272079689e2fff375ea37824cf0209a59c7ec3879b1ea934bcf43f03b3bc8291be01edbb35df9dada392b74
6
+ metadata.gz: 1e8a1075c03b2210ed34c00b6ca5be13feefd2ca0d6b520b4b5d6a6f9b6279a46c69114b5506c5251f4c7b9e3b7c1e74e286e0ec676da2d26a748d503c0caf6b
7
+ data.tar.gz: 63e19fc5970490fc262b431937afdda818295a1506732b6286b17889b4fac5aac9c158420cd3a5633842c79e82763a5b84353d2b2a89f4c1f83b1bd280f2cf29
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ matrix:
13
+ os: [ubuntu-latest, macos-latest]
14
+ ruby: [2.7, 3.0]
15
+ runs-on: ${{ matrix.os }}
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - name: Install dependencies
23
+ run: bundle install
24
+ - name: Run tests
25
+ run: bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -21,4 +21,24 @@
21
21
  ## [0.0.6] - 2021-03-10
22
22
 
23
23
  - Fix misnamed env var in client instantiation
24
- - Add a sample `.env` file
24
+ - Add a sample `.env` file
25
+
26
+ ## [0.0.7] - 2021-03-12
27
+
28
+ - Check for valid JSON from API response before continuing
29
+
30
+ ## [0.0.8] - 2021-03-16
31
+
32
+ - Early return if there are no new comments
33
+
34
+ ## [0.0.9] - 2021-04-11
35
+
36
+ - Add check for new DEV followers functionality
37
+
38
+ ## [0.0.10] - 2021-04-23
39
+
40
+ - Fix filter for DEV comments
41
+ ## [0.1.0] - 2021-05-06
42
+
43
+ - Correct CLI `CheckFollowers` action
44
+ - Update gem specifications
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dev_orbit (0.0.4)
4
+ dev_orbit (0.0.8)
5
5
  actionview (~> 6.1)
6
6
  activesupport (~> 6.1)
7
7
  http (~> 4.4)
@@ -59,7 +59,7 @@ GEM
59
59
  crass (~> 1.0.2)
60
60
  nokogiri (>= 1.5.9)
61
61
  minitest (5.14.4)
62
- nokogiri (1.11.1-x86_64-darwin)
62
+ nokogiri (1.11.2-x86_64-darwin)
63
63
  racc (~> 1.4)
64
64
  parallel (1.20.1)
65
65
  parser (3.0.0.0)
data/README.md CHANGED
@@ -1,10 +1,14 @@
1
1
  # DEV.to Interactions to Orbit Workspace
2
2
 
3
+ ![Build Status](https://github.com/orbit-love/community-ruby-dev-orbit/workflows/CI/badge.svg)
3
4
  [![Gem Version](https://badge.fury.io/rb/dev_orbit.svg)](https://badge.fury.io/rb/dev_orbit)
4
5
  [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](code_of_conduct.md)
5
6
 
6
7
  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.
7
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
+
8
12
  ## Installation
9
13
 
10
14
  Add this line to your application's Gemfile:
@@ -55,7 +59,16 @@ client.comments
55
59
 
56
60
  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.
57
61
 
58
- You can run this a daily cron job, for example, to add your newest DEV comments as activities in your Orbit workspace.
62
+
63
+ ### Post New DEV Followers to Orbit Workspace
64
+
65
+ You can use the gem to get new DEV followers by invoking the `#followers` method on your `client` instance:
66
+
67
+ ```ruby
68
+ client.followers
69
+ ```
70
+
71
+ You can run this either of those or any one of them as a daily cron job, for example, to add your newest DEV comments and/or followers as activities and members in your Orbit workspace.
59
72
 
60
73
  ### CLI
61
74
 
@@ -67,9 +80,15 @@ You can also use the built-in CLI to perform the following operations:
67
80
  $ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...' bundle exec dev_orbit --check-comments
68
81
  ```
69
82
 
83
+ * Check for new DEV followers and post them to Orbit
84
+
85
+ ```bash
86
+ $ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...' bundle exec dev_orbit --check-followers
87
+ ```
88
+
70
89
  ## Contributing
71
90
 
72
- 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).
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/orbit-love/community-ruby-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/orbit-love/community-ruby-dev-orbit/blob/main/CODE_OF_CONDUCT.md).
73
92
 
74
93
  ## License
75
94
 
@@ -77,4 +96,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
77
96
 
78
97
  ## Code of Conduct
79
98
 
80
- 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).
99
+ 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-love/community-ruby-dev-orbit/blob/main/CODE_OF_CONDUCT.md).
data/bin/dev_orbit CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'optparse'
3
3
 
4
4
  check_comments = false
5
+ check_followers = false
5
6
 
6
7
  options = {}
7
8
  choices = OptionParser.new do |opts|
@@ -13,6 +14,9 @@ choices = OptionParser.new do |opts|
13
14
  opts.on("--check-comments", "Check for new DEV comments") do
14
15
  check_comments = true
15
16
  end
17
+ opts.on("--check-followers", "Check for new DEV followers") do
18
+ check_followers = true
19
+ end
16
20
  end.parse!
17
21
 
18
22
  $LOAD_PATH.unshift(File.expand_path('../lib/dev_orbit', __dir__))
@@ -25,3 +29,9 @@ if check_comments
25
29
  ARGV[0] = 'render'
26
30
  DevOrbit::Scripts::CheckComments.start(ARGV)
27
31
  end
32
+
33
+ if check_followers
34
+ puts "Checking for new DEV followers posting them to your Orbit workspace..."
35
+ ARGV[0] = 'render'
36
+ DevOrbit::Scripts::CheckFollowers.start(ARGV)
37
+ end
data/dev_orbit.gemspec CHANGED
@@ -5,18 +5,18 @@ require_relative "lib/dev_orbit/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "dev_orbit"
7
7
  spec.version = DevOrbit::VERSION
8
- spec.authors = ["Ben Greenberg"]
9
- spec.email = ["ben.greenberg@hey.com"]
8
+ spec.authors = ["Orbit DevRel", "Ben Greenberg"]
9
+ spec.email = ["devrel@orbit.love"]
10
10
 
11
11
  spec.summary = "Integrate DEV interactions into your Orbit workspace"
12
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"
13
+ spec.homepage = "https://github.com/orbit-love/community-ruby-dev-orbit"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
16
16
 
17
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"
18
+ spec.metadata["source_code_uri"] = "https://github.com/orbit-love/community-ruby-dev-orbit"
19
+ spec.metadata["changelog_uri"] = "https://github.com/orbit-love/community-ruby-dev-orbit/blob/main/CHANGELOG.md"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -44,6 +44,15 @@ module DevOrbit
44
44
  ).process_comments
45
45
  end
46
46
 
47
+ def followers
48
+ DevOrbit::Dev.new(
49
+ api_key: @dev_api_key,
50
+ username: @dev_username,
51
+ workspace_id: @orbit_workspace,
52
+ orbit_api_key: @orbit_api_key
53
+ ).process_followers
54
+ end
55
+
47
56
  def orbit
48
57
  DevOrbit::Orbit.new
49
58
  end
data/lib/dev_orbit/dev.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "net/http"
4
4
  require "json"
5
5
  require "active_support/time"
6
+ require_relative "utils"
6
7
 
7
8
  module DevOrbit
8
9
  class Dev
@@ -18,7 +19,8 @@ module DevOrbit
18
19
 
19
20
  articles.each do |article|
20
21
  comments = get_article_comments(article["id"])
21
- next if comments.empty?
22
+
23
+ next if comments.nil? || comments.empty?
22
24
 
23
25
  DevOrbit::Orbit.call(
24
26
  type: "comments",
@@ -33,6 +35,23 @@ module DevOrbit
33
35
  end
34
36
  end
35
37
 
38
+ def process_followers
39
+ followers = get_followers
40
+
41
+ followers.each do |follower|
42
+ next if follower.nil? || follower.empty?
43
+
44
+ DevOrbit::Orbit.call(
45
+ type: "followers",
46
+ data: {
47
+ follower: follower
48
+ },
49
+ workspace_id: @workspace_id,
50
+ api_key: @orbit_api_key
51
+ )
52
+ end
53
+ end
54
+
36
55
  private
37
56
 
38
57
  def get_articles
@@ -44,7 +63,20 @@ module DevOrbit
44
63
 
45
64
  response = https.request(request)
46
65
 
47
- JSON.parse(response.body)
66
+ JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
67
+ end
68
+
69
+ def get_followers
70
+ url = URI("https://dev.to/api/followers/users")
71
+ https = Net::HTTP.new(url.host, url.port)
72
+ https.use_ssl = true
73
+
74
+ request = Net::HTTP::Get.new(url)
75
+ request["api_key"] = @api_key
76
+
77
+ response = https.request(request)
78
+
79
+ JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
48
80
  end
49
81
 
50
82
  def get_article_comments(id)
@@ -55,14 +87,17 @@ module DevOrbit
55
87
  request = Net::HTTP::Get.new(url)
56
88
 
57
89
  response = https.request(request)
58
- comments = JSON.parse(response.body)
90
+
91
+ comments = JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
92
+
93
+ return if comments.nil? || comments.empty?
59
94
 
60
95
  filter_comments(comments)
61
96
  end
62
97
 
63
98
  def filter_comments(comments)
64
99
  comments.select do |comment|
65
- comment["created_at"] >= 1.day.ago
100
+ comment["created_at"] <= 1.day.ago
66
101
  end
67
102
  end
68
103
  end
@@ -3,6 +3,7 @@
3
3
  require "net/http"
4
4
  require "json"
5
5
  require "action_view"
6
+ require_relative "../utils"
6
7
 
7
8
  module DevOrbit
8
9
  module Interactions
@@ -36,7 +37,7 @@ module DevOrbit
36
37
 
37
38
  response = http.request(req)
38
39
 
39
- puts JSON.parse(response.body)
40
+ JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
40
41
  end
41
42
 
42
43
  def construct_body
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "action_view"
6
+ require_relative "../utils"
7
+
8
+ module DevOrbit
9
+ module Interactions
10
+ class Follower
11
+ def initialize(id:, name:, username:, url:, workspace_id:, api_key:)
12
+ @id = id
13
+ @name = name
14
+ @username = username
15
+ @url = url
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}/members")
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 = construct_body
33
+
34
+ req.body = req.body.to_json
35
+
36
+ response = http.request(req)
37
+
38
+ JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
39
+ end
40
+
41
+ def construct_body
42
+ {
43
+ member: {
44
+ name: @name.include?("_") ? @name.split("_").map(&:capitalize).join(" ") : @name,
45
+ devto: @username,
46
+ url: "https://dev.to#{@url}"
47
+ }
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -17,6 +17,17 @@ module DevOrbit
17
17
  )
18
18
  end
19
19
  end
20
+
21
+ if type == "followers"
22
+ DevOrbit::Interactions::Follower.new(
23
+ id: data[:follower]["id"],
24
+ name: data[:follower]["name"],
25
+ username: data[:follower]["username"],
26
+ url: data[:follower]["path"],
27
+ workspace_id: workspace_id,
28
+ api_key: api_key
29
+ )
30
+ end
20
31
  end
21
32
  end
22
33
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevOrbit
4
+ class Utils
5
+ def self.valid_json?(string)
6
+ !JSON.parse(string).nil?
7
+ rescue JSON::ParserError
8
+ false
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DevOrbit
4
- VERSION = "0.0.6"
4
+ VERSION = "0.1.0"
5
5
  end
@@ -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 DevOrbit
8
+ module Scripts
9
+ class CheckFollowers < Thor
10
+ desc "render", "check for new DEV followers and push them to Orbit"
11
+ def render
12
+ client = DevOrbit::Client.new
13
+ client.followers
14
+ end
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_orbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Orbit DevRel
7
8
  - Ben Greenberg
8
- autorequire:
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2021-03-10 00:00:00.000000000 Z
12
+ date: 2021-05-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activesupport
@@ -125,7 +126,7 @@ dependencies:
125
126
  description: This gem integrates DEV blog interactions like comments, etc. into your
126
127
  Orbit workspace
127
128
  email:
128
- - ben.greenberg@hey.com
129
+ - devrel@orbit.love
129
130
  executables:
130
131
  - console
131
132
  - dev_orbit
@@ -134,6 +135,7 @@ extensions: []
134
135
  extra_rdoc_files: []
135
136
  files:
136
137
  - ".env.sample"
138
+ - ".github/workflows/ci.yml"
137
139
  - ".gitignore"
138
140
  - ".rspec"
139
141
  - ".rubocop.yml"
@@ -152,17 +154,20 @@ files:
152
154
  - lib/dev_orbit/client.rb
153
155
  - lib/dev_orbit/dev.rb
154
156
  - lib/dev_orbit/interactions/comment.rb
157
+ - lib/dev_orbit/interactions/follower.rb
155
158
  - lib/dev_orbit/orbit.rb
159
+ - lib/dev_orbit/utils.rb
156
160
  - lib/dev_orbit/version.rb
157
161
  - scripts/check_comments.rb
158
- homepage: https://github.com/bencgreenberg/dev_orbit
162
+ - scripts/check_followers.rb
163
+ homepage: https://github.com/orbit-love/community-ruby-dev-orbit
159
164
  licenses:
160
165
  - MIT
161
166
  metadata:
162
- homepage_uri: https://github.com/bencgreenberg/dev_orbit
163
- source_code_uri: https://github.com/bencgreenberg/dev_orbit
164
- changelog_uri: https://github.com/bencgreenberg/dev_orbit/blob/master/CHANGELOG.md
165
- post_install_message:
167
+ homepage_uri: https://github.com/orbit-love/community-ruby-dev-orbit
168
+ source_code_uri: https://github.com/orbit-love/community-ruby-dev-orbit
169
+ changelog_uri: https://github.com/orbit-love/community-ruby-dev-orbit/blob/main/CHANGELOG.md
170
+ post_install_message:
166
171
  rdoc_options: []
167
172
  require_paths:
168
173
  - lib
@@ -177,8 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
182
  - !ruby/object:Gem::Version
178
183
  version: '0'
179
184
  requirements: []
180
- rubygems_version: 3.1.4
181
- signing_key:
185
+ rubygems_version: 3.2.15
186
+ signing_key:
182
187
  specification_version: 4
183
188
  summary: Integrate DEV interactions into your Orbit workspace
184
189
  test_files: []