dev_orbit 0.0.5 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.sample +4 -0
- data/.github/workflows/ci.yml +25 -0
- data/CHANGELOG.md +22 -1
- data/Gemfile.lock +2 -2
- data/README.md +26 -1
- data/bin/dev_orbit +10 -0
- data/lib/dev_orbit/client.rb +10 -1
- data/lib/dev_orbit/dev.rb +39 -4
- data/lib/dev_orbit/interactions/comment.rb +2 -1
- data/lib/dev_orbit/interactions/follower.rb +52 -0
- data/lib/dev_orbit/orbit.rb +11 -0
- data/lib/dev_orbit/utils.rb +11 -0
- data/lib/dev_orbit/version.rb +1 -1
- data/scripts/check_comments.rb +1 -2
- data/scripts/check_followers.rb +17 -0
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deba9c4bf14d7d8d11906b6b3e2a15f7e0c4dfc8e65ba5b7fa298e35c2a0877c
|
4
|
+
data.tar.gz: ab09ace67d86209779ad99df66997e7f35009035b209dd71fd035e581b825b7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce4ee9e896e5c1f6560e8253230b07456a290016359b5c385d727a520108d3ed8c1e92343687863e00d1b946d233098eeecc794026aa1fe06e24d927b0cb56c7
|
7
|
+
data.tar.gz: a561ddd4cd678637da62a8a91e4436b8e5df63a0891f46b352606eb88578a60189c52dbe00f5ca620014819aa5cbc37b8d03c0faa607ecc63895dd136567aa1b
|
data/.env.sample
ADDED
@@ -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
@@ -16,4 +16,25 @@
|
|
16
16
|
|
17
17
|
## [0.0.5] - 2021-03-10
|
18
18
|
|
19
|
-
- Print out Orbit API response
|
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
|
37
|
+
|
38
|
+
## [0.0.10] - 2021-04-23
|
39
|
+
|
40
|
+
- Fix filter for DEV comments
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dev_orbit (0.0.
|
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.
|
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
|
-
|
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
|
data/lib/dev_orbit/client.rb
CHANGED
@@ -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["
|
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
|
-
|
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
|
-
|
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"]
|
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
|
-
|
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
|
data/lib/dev_orbit/orbit.rb
CHANGED
@@ -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
|
data/lib/dev_orbit/version.rb
CHANGED
data/scripts/check_comments.rb
CHANGED
@@ -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
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Greenberg
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-23 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
|
@@ -161,7 +166,7 @@ metadata:
|
|
161
166
|
homepage_uri: https://github.com/bencgreenberg/dev_orbit
|
162
167
|
source_code_uri: https://github.com/bencgreenberg/dev_orbit
|
163
168
|
changelog_uri: https://github.com/bencgreenberg/dev_orbit/blob/master/CHANGELOG.md
|
164
|
-
post_install_message:
|
169
|
+
post_install_message:
|
165
170
|
rdoc_options: []
|
166
171
|
require_paths:
|
167
172
|
- lib
|
@@ -176,8 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
181
|
- !ruby/object:Gem::Version
|
177
182
|
version: '0'
|
178
183
|
requirements: []
|
179
|
-
rubygems_version: 3.
|
180
|
-
signing_key:
|
184
|
+
rubygems_version: 3.2.15
|
185
|
+
signing_key:
|
181
186
|
specification_version: 4
|
182
187
|
summary: Integrate DEV interactions into your Orbit workspace
|
183
188
|
test_files: []
|