dev_orbit 0.0.4 → 0.0.9

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: 44b1844cc0404a82182eb33f1a103b57d2b9be7577c1975e0c2e1755b44357f3
4
- data.tar.gz: b2c48ee968464e77bf86088969fa35075da57239917274940b1112f4c6cf196a
3
+ metadata.gz: b2c4b8c2f8de5eabeff15996ee2d7d03b7ed40710d8f2f604ef0fb832cef0476
4
+ data.tar.gz: a50f6959cc9292b7822b1da81153df7f0d3a6ad397dd9e5211a5ca6900888085
5
5
  SHA512:
6
- metadata.gz: f58e4425e99158a5e35b7aa0b2c3063c3bf12587339b4fd11b7e2ebee93b8d950e93abcb4285f61bd6e3dbddefba822bb0e41819890191c855cffde806cb7c69
7
- data.tar.gz: ac4ddd1cd9e03cb6cab47cac12973f17e48fb8c2245c05679fb14685419041d8e91841243a53255f28b42fc814a7b92928a7b27dbd12e3fa9e1cde254c7f5f3b
6
+ metadata.gz: 95575a8af9172ad28c5c3613510d2f45076c38e9eb726e7a7670acd6a476f2b3b8683ce4c7abf5c7c8dd5d2c9f1c68c8f41287e4c2e52f6d63d2f74eaed34f62
7
+ data.tar.gz: d71011147c850f5bc5b8b4d6467bf7fb723dc5e766127046c9bb854dfd8afdf2f2e3b136e37b60585dbcf6e2e0503f99a07b7a8e7adbe375f03a4d30eebb5fc3
data/.env.sample ADDED
@@ -0,0 +1,4 @@
1
+ ORBIT_API_KEY=
2
+ ORBIT_WORKSPACE_ID=
3
+ DEV_API_KEY=
4
+ DEV_USERNAME=
@@ -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
@@ -12,4 +12,25 @@
12
12
 
13
13
  ## [0.0.4] - 2021-03-10
14
14
 
15
- - Bug fix for stripping the HTML from the DEV blog post comment body
15
+ - Bug fix for stripping the HTML from the DEV blog post comment body
16
+
17
+ ## [0.0.5] - 2021-03-10
18
+
19
+ - Print out Orbit API response
20
+
21
+ ## [0.0.6] - 2021-03-10
22
+
23
+ - Fix misnamed env var in client instantiation
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
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dev_orbit (0.0.3)
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,5 +1,6 @@
1
1
  # DEV.to Interactions to Orbit Workspace
2
2
 
3
+ ![Build Status](https://github.com/bencgreenberg/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
 
@@ -19,6 +20,15 @@ gem 'dev_orbit'
19
20
 
20
21
  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.
21
22
 
23
+ The following are the expected environment variables:
24
+
25
+ ```ruby
26
+ ORBIT_API_KEY
27
+ ORBIT_WORKSPACE_ID
28
+ DEV_API_KEY
29
+ DEV_USERNAME
30
+ ```
31
+
22
32
  With the credentials as environment variables:
23
33
 
24
34
  ```ruby
@@ -46,7 +56,16 @@ client.comments
46
56
 
47
57
  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.
48
58
 
49
- You can run this a daily cron job, for example, to add your newest DEV comments as activities in your Orbit workspace.
59
+
60
+ ### Post New DEV Followers to Orbit Workspace
61
+
62
+ You can use the gem to get new DEV followers by invoking the `#followers` method on your `client` instance:
63
+
64
+ ```ruby
65
+ client.followers
66
+ ```
67
+
68
+ 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.
50
69
 
51
70
  ### CLI
52
71
 
@@ -58,6 +77,12 @@ You can also use the built-in CLI to perform the following operations:
58
77
  $ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...' bundle exec dev_orbit --check-comments
59
78
  ```
60
79
 
80
+ * Check for new DEV followers and post them to Orbit
81
+
82
+ ```bash
83
+ $ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...' bundle exec dev_orbit --check-followers
84
+ ```
85
+
61
86
  ## Contributing
62
87
 
63
88
  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).
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::CheckComments.start(ARGV)
37
+ end
@@ -29,7 +29,7 @@ module DevOrbit
29
29
 
30
30
  def initialize(params = {})
31
31
  @orbit_api_key = params.fetch(:orbit_api_key, ENV["ORBIT_API_KEY"])
32
- @orbit_workspace = params.fetch(:orbit_workspace, ENV["ORBIT_WORKSPACE"])
32
+ @orbit_workspace = params.fetch(:orbit_workspace, ENV["ORBIT_WORKSPACE_ID"])
33
33
  @dev_api_key = params.fetch(:dev_api_key, ENV["DEV_API_KEY"])
34
34
  @dev_username = params.fetch(:dev_username, ENV["DEV_USERNAME"])
35
35
  end
@@ -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,7 +87,10 @@ 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
@@ -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
- 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
@@ -86,7 +87,9 @@ module DevOrbit
86
87
  end
87
88
 
88
89
  def sanitize_comment(comment)
89
- ActionView::Base.full_sanitizer.sanitize(comment)
90
+ comment = ActionView::Base.full_sanitizer.sanitize(comment)
91
+
92
+ comment.gsub("\n", " ")
90
93
  end
91
94
  end
92
95
  end
@@ -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.4"
4
+ VERSION = "0.0.9"
5
5
  end
@@ -10,8 +10,7 @@ module DevOrbit
10
10
  desc "render", "check for new DEV comments and push them to Orbit"
11
11
  def render
12
12
  client = DevOrbit::Client.new
13
- response = client.comments
14
- puts response
13
+ client.comments
15
14
  end
16
15
  end
17
16
  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,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_orbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Greenberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-10 00:00:00.000000000 Z
11
+ date: 2021-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -133,6 +133,8 @@ executables:
133
133
  extensions: []
134
134
  extra_rdoc_files: []
135
135
  files:
136
+ - ".env.sample"
137
+ - ".github/workflows/ci.yml"
136
138
  - ".gitignore"
137
139
  - ".rspec"
138
140
  - ".rubocop.yml"
@@ -151,9 +153,12 @@ files:
151
153
  - lib/dev_orbit/client.rb
152
154
  - lib/dev_orbit/dev.rb
153
155
  - lib/dev_orbit/interactions/comment.rb
156
+ - lib/dev_orbit/interactions/follower.rb
154
157
  - lib/dev_orbit/orbit.rb
158
+ - lib/dev_orbit/utils.rb
155
159
  - lib/dev_orbit/version.rb
156
160
  - scripts/check_comments.rb
161
+ - scripts/check_followers.rb
157
162
  homepage: https://github.com/bencgreenberg/dev_orbit
158
163
  licenses:
159
164
  - MIT