dev_orbit 0.1.5 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.sample +2 -1
- data/CHANGELOG.md +4 -1
- data/Gemfile.lock +17 -27
- data/README.md +34 -7
- data/bin/dev_orbit +17 -0
- data/dev_orbit.gemspec +1 -1
- data/lib/dev_orbit/client.rb +23 -4
- data/lib/dev_orbit/dev.rb +22 -17
- data/lib/dev_orbit/interactions/comment.rb +6 -0
- data/lib/dev_orbit/interactions/follower.rb +1 -2
- data/lib/dev_orbit/orbit.rb +61 -14
- data/lib/dev_orbit/version.rb +1 -1
- data/scripts/check_comments.rb +2 -2
- data/scripts/check_org_comments.rb +17 -0
- metadata +5 -6
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce1f0009ec93dd8200f5c31fa63e016780d46aa4214a212990c17192c4da0df6
|
4
|
+
data.tar.gz: 1c7d8b16887c52840016944fc0a0498187e41ccd39e357967109ba48421473b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b2a168a89eea4fad802491d4a686d466f178f62b432c7b2c47ad6f5c20fe7cb17743f4ac6687c94a3a027c214809dde556c64d6bafa3c34fd4d7dfbad2ebcc4
|
7
|
+
data.tar.gz: d820ef63efd2246cc560227c57a26cf332819d30745db76740d8106b888c6e73cc41e706f7e98a844b39ccf726252f402f44d5113dd53a9de3d35fa477634efb
|
data/.env.sample
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dev_orbit (0.
|
4
|
+
dev_orbit (0.4.0)
|
5
5
|
actionview (~> 6.1)
|
6
6
|
activesupport (~> 6.1)
|
7
7
|
http (~> 4.4)
|
8
8
|
json (~> 2.5)
|
9
|
-
orbit_activities (~> 0.
|
9
|
+
orbit_activities (~> 0.2)
|
10
10
|
thor (~> 1.1)
|
11
11
|
zeitwerk (~> 2.4)
|
12
12
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
actionview (6.1.
|
17
|
-
activesupport (= 6.1.
|
16
|
+
actionview (6.1.4)
|
17
|
+
activesupport (= 6.1.4)
|
18
18
|
builder (~> 3.1)
|
19
19
|
erubi (~> 1.4)
|
20
20
|
rails-dom-testing (~> 2.0)
|
21
21
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
22
|
-
activesupport (6.1.
|
22
|
+
activesupport (6.1.4)
|
23
23
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
24
24
|
i18n (>= 1.6, < 2)
|
25
25
|
minitest (>= 5.1)
|
@@ -30,7 +30,7 @@ GEM
|
|
30
30
|
ast (2.4.2)
|
31
31
|
builder (3.2.4)
|
32
32
|
byebug (11.1.3)
|
33
|
-
concurrent-ruby (1.1.
|
33
|
+
concurrent-ruby (1.1.9)
|
34
34
|
crack (0.4.5)
|
35
35
|
rexml
|
36
36
|
crass (1.0.6)
|
@@ -38,7 +38,7 @@ GEM
|
|
38
38
|
domain_name (0.5.20190701)
|
39
39
|
unf (>= 0.0.5, < 1.0.0)
|
40
40
|
erubi (1.10.0)
|
41
|
-
ffi (1.15.
|
41
|
+
ffi (1.15.3)
|
42
42
|
ffi-compiler (1.0.1)
|
43
43
|
ffi (>= 1.0.0)
|
44
44
|
rake
|
@@ -48,7 +48,7 @@ GEM
|
|
48
48
|
http-cookie (~> 1.0)
|
49
49
|
http-form_data (~> 2.2)
|
50
50
|
http-parser (~> 1.2.0)
|
51
|
-
http-cookie (1.0.
|
51
|
+
http-cookie (1.0.4)
|
52
52
|
domain_name (~> 0.5)
|
53
53
|
http-form_data (2.3.0)
|
54
54
|
http-parser (1.2.3)
|
@@ -56,27 +56,19 @@ GEM
|
|
56
56
|
i18n (1.8.10)
|
57
57
|
concurrent-ruby (~> 1.0)
|
58
58
|
json (2.5.1)
|
59
|
-
loofah (2.
|
59
|
+
loofah (2.10.0)
|
60
60
|
crass (~> 1.0.2)
|
61
61
|
nokogiri (>= 1.5.9)
|
62
62
|
minitest (5.14.4)
|
63
|
-
nokogiri (1.11.
|
63
|
+
nokogiri (1.11.7-arm64-darwin)
|
64
64
|
racc (~> 1.4)
|
65
|
-
|
66
|
-
racc (~> 1.4)
|
67
|
-
nokogiri (1.11.5-x86_64-linux)
|
68
|
-
racc (~> 1.4)
|
69
|
-
nokogiri (1.11.3-x86_64-darwin)
|
70
|
-
racc (~> 1.4)
|
71
|
-
nokogiri (1.11.3-x86_64-linux)
|
72
|
-
racc (~> 1.4)
|
73
|
-
orbit_activities (0.1.0)
|
65
|
+
orbit_activities (0.2.2)
|
74
66
|
http (~> 4.4)
|
75
67
|
json (~> 2.5)
|
76
68
|
rake (~> 13.0)
|
77
69
|
zeitwerk (~> 2.4)
|
78
70
|
parallel (1.20.1)
|
79
|
-
parser (3.0.
|
71
|
+
parser (3.0.1.1)
|
80
72
|
ast (~> 2.4.1)
|
81
73
|
public_suffix (4.0.6)
|
82
74
|
racc (1.5.2)
|
@@ -102,17 +94,17 @@ GEM
|
|
102
94
|
diff-lcs (>= 1.2.0, < 2.0)
|
103
95
|
rspec-support (~> 3.10.0)
|
104
96
|
rspec-support (3.10.2)
|
105
|
-
rubocop (1.
|
97
|
+
rubocop (1.17.0)
|
106
98
|
parallel (~> 1.10)
|
107
99
|
parser (>= 3.0.0.0)
|
108
100
|
rainbow (>= 2.2.2, < 4.0)
|
109
101
|
regexp_parser (>= 1.8, < 3.0)
|
110
102
|
rexml
|
111
|
-
rubocop-ast (>= 1.
|
103
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
112
104
|
ruby-progressbar (~> 1.7)
|
113
105
|
unicode-display_width (>= 1.4.0, < 3.0)
|
114
|
-
rubocop-ast (1.
|
115
|
-
parser (>=
|
106
|
+
rubocop-ast (1.7.0)
|
107
|
+
parser (>= 3.0.1.1)
|
116
108
|
ruby-progressbar (1.11.0)
|
117
109
|
thor (1.1.0)
|
118
110
|
tzinfo (2.0.4)
|
@@ -121,7 +113,7 @@ GEM
|
|
121
113
|
unf_ext
|
122
114
|
unf_ext (0.0.7.7)
|
123
115
|
unicode-display_width (2.0.0)
|
124
|
-
webmock (3.
|
116
|
+
webmock (3.13.0)
|
125
117
|
addressable (>= 2.3.6)
|
126
118
|
crack (>= 0.3.2)
|
127
119
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -129,8 +121,6 @@ GEM
|
|
129
121
|
|
130
122
|
PLATFORMS
|
131
123
|
arm64-darwin-20
|
132
|
-
x86_64-darwin-19
|
133
|
-
x86_64-linux
|
134
124
|
|
135
125
|
DEPENDENCIES
|
136
126
|
byebug
|
data/README.md
CHANGED
@@ -26,13 +26,14 @@ gem 'dev_orbit'
|
|
26
26
|
|
27
27
|
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.
|
28
28
|
|
29
|
-
The following are the
|
29
|
+
The following are the environment variables, you can provide either or both a `DEV_USERNAME` or a `DEV_ORGANIZATION`:
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
ORBIT_API_KEY
|
33
33
|
ORBIT_WORKSPACE_ID
|
34
34
|
DEV_API_KEY
|
35
35
|
DEV_USERNAME
|
36
|
+
DEV_ORGANIZATION
|
36
37
|
```
|
37
38
|
|
38
39
|
With the credentials as environment variables:
|
@@ -48,20 +49,39 @@ client = DevOrbit::Client.new(
|
|
48
49
|
orbit_api_key: '...',
|
49
50
|
orbit_workspace: '...',
|
50
51
|
dev_api_key: '...',
|
51
|
-
dev_username: '...'
|
52
|
+
dev_username: '...',
|
53
|
+
dev_organization: '...'
|
52
54
|
)
|
53
55
|
```
|
54
56
|
|
55
|
-
###
|
57
|
+
### Performing a Historical Import
|
56
58
|
|
57
|
-
|
59
|
+
By default, the integration will only import comments that are newer than the newest DEV comment in your Orbit workspace. You may want to perform a one-time historical import to fetch all your previous DEV comments and bring them into your Orbit workspace. To do so, instantiate your `client` with the `historical_import` flag:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
client = DevOrbit::Client.new(
|
63
|
+
historical_import: true
|
64
|
+
)
|
65
|
+
```
|
66
|
+
### Post New DEV Comments from a DEV User to Orbit Workspace
|
67
|
+
|
68
|
+
You can use the gem to get new DEV comments on your DEV user by invoking the `#comments` method on your `client` instance:
|
58
69
|
|
59
70
|
```ruby
|
60
71
|
client.comments
|
61
72
|
```
|
62
73
|
|
63
|
-
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.
|
74
|
+
This method will fetch all your user 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.
|
64
75
|
|
76
|
+
### Post New DEV Comments from a DEV Organization to Orbit Workspace
|
77
|
+
|
78
|
+
You can use the gem to get new DEV comments on your DEV organization by invoking the `#comments` method on your `client` instance:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
client.organization_comments
|
82
|
+
```
|
83
|
+
|
84
|
+
This method will fetch all your organization 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.
|
65
85
|
|
66
86
|
### Post New DEV Followers to Orbit Workspace
|
67
87
|
|
@@ -77,18 +97,25 @@ You can run this either of those or any one of them as a daily cron job, for exa
|
|
77
97
|
|
78
98
|
You can also use the built-in CLI to perform the following operations:
|
79
99
|
|
80
|
-
* Check for new DEV comments and post them to Orbit
|
100
|
+
* Check for new DEV user comments and post them to Orbit
|
81
101
|
|
82
102
|
```bash
|
83
103
|
$ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...' bundle exec dev_orbit --check-comments
|
84
104
|
```
|
85
105
|
|
86
|
-
* Check for new DEV followers and post them to Orbit
|
106
|
+
* Check for new DEV user followers and post them to Orbit
|
87
107
|
|
88
108
|
```bash
|
89
109
|
$ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...' bundle exec dev_orbit --check-followers
|
90
110
|
```
|
91
111
|
|
112
|
+
* Check for new DEV organization comments and post them to Orbit
|
113
|
+
|
114
|
+
```bash
|
115
|
+
$ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_ORGANIZATION='...' bundle exec dev_orbit --check-organization-comments
|
116
|
+
```
|
117
|
+
**Add the `--historical-import` flag to your CLI command to perform a historical import of all your DEV comments using the CLI.**
|
118
|
+
|
92
119
|
## Contributing
|
93
120
|
|
94
121
|
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).
|
data/bin/dev_orbit
CHANGED
@@ -3,6 +3,8 @@ require 'optparse'
|
|
3
3
|
|
4
4
|
check_comments = false
|
5
5
|
check_followers = false
|
6
|
+
check_org_comments = false
|
7
|
+
historical_import = false
|
6
8
|
|
7
9
|
options = {}
|
8
10
|
choices = OptionParser.new do |opts|
|
@@ -17,6 +19,12 @@ choices = OptionParser.new do |opts|
|
|
17
19
|
opts.on("--check-followers", "Check for new DEV followers") do
|
18
20
|
check_followers = true
|
19
21
|
end
|
22
|
+
opts.on("--check-organization-comments", "Check for new DEV comments for an organization") do
|
23
|
+
check_org_comments = true
|
24
|
+
end
|
25
|
+
opts.on("--historical-import", "Performa historical import of all new DEV comments") do
|
26
|
+
historical_import = true
|
27
|
+
end
|
20
28
|
end.parse!
|
21
29
|
|
22
30
|
$LOAD_PATH.unshift(File.expand_path('../lib/dev_orbit', __dir__))
|
@@ -24,10 +32,12 @@ $LOAD_PATH.unshift(File.expand_path('../lib/dev_orbit', __dir__))
|
|
24
32
|
require_relative '../lib/dev_orbit'
|
25
33
|
require_relative '../scripts/check_comments'
|
26
34
|
require_relative '../scripts/check_followers'
|
35
|
+
require_relative '../scripts/check_org_comments'
|
27
36
|
|
28
37
|
if check_comments
|
29
38
|
puts "Checking for new DEV comments within the past day and posting them to your Orbit workspace..."
|
30
39
|
ARGV[0] = 'render'
|
40
|
+
ARGV[1] = historical_import
|
31
41
|
DevOrbit::Scripts::CheckComments.start(ARGV)
|
32
42
|
end
|
33
43
|
|
@@ -36,3 +46,10 @@ if check_followers
|
|
36
46
|
ARGV[0] = 'render'
|
37
47
|
DevOrbit::Scripts::CheckFollowers.start(ARGV)
|
38
48
|
end
|
49
|
+
|
50
|
+
if check_org_comments
|
51
|
+
puts "Checking for new DEV organization comments and posting them to your Orbit workspace..."
|
52
|
+
ARGV[0] = 'render'
|
53
|
+
ARGV[1] = historical_import
|
54
|
+
DevOrbit::Scripts::CheckOrgComments.start(ARGV)
|
55
|
+
end
|
data/dev_orbit.gemspec
CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_dependency "json", "~> 2.5"
|
36
36
|
spec.add_dependency "zeitwerk", "~> 2.4"
|
37
37
|
spec.add_dependency "thor", "~> 1.1"
|
38
|
-
spec.add_dependency "orbit_activities", "~> 0.
|
38
|
+
spec.add_dependency "orbit_activities", "~> 0.2"
|
39
39
|
spec.add_development_dependency "rspec", "~> 3.4"
|
40
40
|
spec.add_development_dependency "webmock", "~> 3.12"
|
41
41
|
|
data/lib/dev_orbit/client.rb
CHANGED
@@ -13,35 +13,45 @@
|
|
13
13
|
# @option params [String] :dev_api_key
|
14
14
|
# The API key for the DEV API
|
15
15
|
#
|
16
|
+
# @option params [String] :dev_organization
|
17
|
+
# The name of the organization in DEV to fetch interactions for
|
18
|
+
#
|
16
19
|
# @option params [String] :orbit_workspace
|
17
20
|
# The workspace ID for the Orbit workspace
|
18
21
|
#
|
19
22
|
# @option params [String] :orbit_api_key
|
20
23
|
# The API key for the Orbit API
|
21
24
|
#
|
25
|
+
# @option params [Boolean] :historical_import
|
26
|
+
# Perform a historical import on all DEV comments
|
27
|
+
# Boolean, default to false
|
28
|
+
#
|
22
29
|
# @param [Hash] params
|
23
30
|
#
|
24
31
|
# @return [DevOrbit::Client]
|
25
32
|
#
|
26
33
|
module DevOrbit
|
27
34
|
class Client
|
28
|
-
attr_accessor :dev_username, :dev_api_key, :orbit_workspace, :orbit_api_key
|
35
|
+
attr_accessor :dev_username, :dev_api_key, :dev_organization, :orbit_workspace, :orbit_api_key, :historical_import
|
29
36
|
|
30
37
|
def initialize(params = {})
|
31
38
|
@orbit_api_key = params.fetch(:orbit_api_key, ENV["ORBIT_API_KEY"])
|
32
39
|
@orbit_workspace = params.fetch(:orbit_workspace, ENV["ORBIT_WORKSPACE_ID"])
|
33
40
|
@dev_api_key = params.fetch(:dev_api_key, ENV["DEV_API_KEY"])
|
34
41
|
@dev_username = params.fetch(:dev_username, ENV["DEV_USERNAME"])
|
42
|
+
@dev_organization = params.fetch(:dev_organization, ENV["DEV_ORGANIZATION"])
|
43
|
+
@historical_import = params.fetch(:historical_import, false)
|
35
44
|
end
|
36
45
|
|
37
46
|
# Fetch new comments from DEV and post them to the Orbit workspace
|
38
|
-
def comments
|
47
|
+
def comments(type: "user")
|
39
48
|
DevOrbit::Dev.new(
|
40
49
|
api_key: @dev_api_key,
|
41
50
|
username: @dev_username,
|
42
51
|
workspace_id: @orbit_workspace,
|
43
|
-
orbit_api_key: @orbit_api_key
|
44
|
-
|
52
|
+
orbit_api_key: @orbit_api_key,
|
53
|
+
historical_import: @historical_import
|
54
|
+
).process_comments(type: type)
|
45
55
|
end
|
46
56
|
|
47
57
|
def followers
|
@@ -53,6 +63,15 @@ module DevOrbit
|
|
53
63
|
).process_followers
|
54
64
|
end
|
55
65
|
|
66
|
+
def organization_comments(type: "organization")
|
67
|
+
DevOrbit::Dev.new(
|
68
|
+
api_key: @dev_api_key,
|
69
|
+
organization: @dev_organization,
|
70
|
+
workspace_id: @orbit_workspace,
|
71
|
+
orbit_api_key: @orbit_api_key
|
72
|
+
).process_comments(type: type)
|
73
|
+
end
|
74
|
+
|
56
75
|
def orbit
|
57
76
|
DevOrbit::Orbit.new
|
58
77
|
end
|
data/lib/dev_orbit/dev.rb
CHANGED
@@ -9,20 +9,22 @@ module DevOrbit
|
|
9
9
|
class Dev
|
10
10
|
def initialize(params = {})
|
11
11
|
@username = params.fetch(:username, ENV["DEV_USERNAME"])
|
12
|
+
@organization = params.fetch(:organization, ENV["DEV_ORGANIZATION"])
|
12
13
|
@api_key = params.fetch(:api_key, ENV["DEV_API_KEY"])
|
13
14
|
@workspace_id = params.fetch(:workspace_id, ENV["ORBIT_WORKSPACE_ID"])
|
14
15
|
@orbit_api_key = params.fetch(:orbit_api_key, ENV["ORBIT_API_KEY"])
|
16
|
+
@historical_import = params.fetch(:historical_import, false)
|
15
17
|
end
|
16
18
|
|
17
|
-
def process_comments
|
18
|
-
articles = get_articles
|
19
|
+
def process_comments(type:)
|
20
|
+
articles = get_articles(type: type)
|
19
21
|
|
20
22
|
articles.each do |article|
|
21
23
|
comments = get_article_comments(article["id"])
|
22
24
|
|
23
25
|
next if comments.nil? || comments.empty?
|
24
26
|
|
25
|
-
DevOrbit::Orbit.
|
27
|
+
return DevOrbit::Orbit.new(
|
26
28
|
type: "comments",
|
27
29
|
data: {
|
28
30
|
comments: comments,
|
@@ -30,8 +32,9 @@ module DevOrbit
|
|
30
32
|
url: article["url"]
|
31
33
|
},
|
32
34
|
workspace_id: @workspace_id,
|
33
|
-
api_key: @orbit_api_key
|
34
|
-
|
35
|
+
api_key: @orbit_api_key,
|
36
|
+
historical_import: @historical_import
|
37
|
+
).call
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
@@ -41,21 +44,29 @@ module DevOrbit
|
|
41
44
|
followers.each do |follower|
|
42
45
|
next if follower.nil? || follower.empty?
|
43
46
|
|
44
|
-
DevOrbit::Orbit.
|
47
|
+
DevOrbit::Orbit.new(
|
45
48
|
type: "followers",
|
46
49
|
data: {
|
47
50
|
follower: follower
|
48
51
|
},
|
49
52
|
workspace_id: @workspace_id,
|
50
|
-
api_key: @orbit_api_key
|
51
|
-
|
53
|
+
api_key: @orbit_api_key,
|
54
|
+
historical_import: @historical_import
|
55
|
+
).call
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
59
|
private
|
56
60
|
|
57
|
-
def get_articles
|
58
|
-
|
61
|
+
def get_articles(type:)
|
62
|
+
if type == "user"
|
63
|
+
url = URI("https://dev.to/api/articles?username=#{@username}&top=1")
|
64
|
+
end
|
65
|
+
|
66
|
+
if type == "organization"
|
67
|
+
url = URI("https://dev.to/api/organizations/#{@organization}/articles")
|
68
|
+
end
|
69
|
+
|
59
70
|
https = Net::HTTP.new(url.host, url.port)
|
60
71
|
https.use_ssl = true
|
61
72
|
|
@@ -92,13 +103,7 @@ module DevOrbit
|
|
92
103
|
|
93
104
|
return if comments.nil? || comments.empty?
|
94
105
|
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
def filter_comments(comments)
|
99
|
-
comments.select do |comment|
|
100
|
-
comment["created_at"] <= 1.day.ago
|
101
|
-
end
|
106
|
+
comments
|
102
107
|
end
|
103
108
|
end
|
104
109
|
end
|
@@ -55,6 +55,8 @@ module DevOrbit
|
|
55
55
|
|
56
56
|
hash[:activity][:member].merge!(github: @commenter[:github]) if @commenter[:github]
|
57
57
|
|
58
|
+
hash[:activity][:member].merge(url: @commenter[:url]) if @commenter[:url]
|
59
|
+
|
58
60
|
hash
|
59
61
|
end
|
60
62
|
|
@@ -74,6 +76,10 @@ module DevOrbit
|
|
74
76
|
hash.merge!('github': commenter[:github_username])
|
75
77
|
end
|
76
78
|
|
79
|
+
unless commenter[:website_url].nil? || commenter[:website_url] == ""
|
80
|
+
hash.merge('url': commenter[:website_url])
|
81
|
+
end
|
82
|
+
|
77
83
|
hash
|
78
84
|
end
|
79
85
|
|
data/lib/dev_orbit/orbit.rb
CHANGED
@@ -2,32 +2,79 @@
|
|
2
2
|
|
3
3
|
require "net/http"
|
4
4
|
require "json"
|
5
|
+
require "active_support/time"
|
5
6
|
|
6
7
|
module DevOrbit
|
7
8
|
class Orbit
|
8
|
-
def
|
9
|
-
|
10
|
-
|
9
|
+
def initialize(type:, data:, workspace_id:, api_key:, historical_import: false)
|
10
|
+
@type = type
|
11
|
+
@data = data
|
12
|
+
@workspace_id = workspace_id
|
13
|
+
@api_key = api_key
|
14
|
+
@historical_import = historical_import
|
15
|
+
@last_orbit_activity_timestamp = last_orbit_activity_timestamp(type)
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
if @type == "comments"
|
20
|
+
times = 0
|
21
|
+
|
22
|
+
@data[:comments].each do |comment|
|
23
|
+
unless @historical_import && @last_orbit_activity_timestamp
|
24
|
+
next if comment["created_at"] || comment[:created_at] < @last_orbit_activity_timestamp unless @last_orbit_activity_timestamp.nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
if @last_orbit_activity_timestamp && @historical_import == false
|
28
|
+
next if comment["created_at"] || comment[:created_at] < @last_orbit_activity_timestamp
|
29
|
+
end
|
30
|
+
|
31
|
+
times += 1
|
32
|
+
|
11
33
|
DevOrbit::Interactions::Comment.new(
|
12
|
-
article_title: data.transform_keys(&:to_sym)[:title],
|
34
|
+
article_title: @data.transform_keys(&:to_sym)[:title],
|
13
35
|
comment: comment.transform_keys(&:to_sym),
|
14
|
-
url: data[:url],
|
15
|
-
workspace_id: workspace_id,
|
16
|
-
api_key: api_key
|
36
|
+
url: @data[:url],
|
37
|
+
workspace_id: @workspace_id,
|
38
|
+
api_key: @api_key
|
17
39
|
)
|
18
40
|
end
|
41
|
+
|
42
|
+
output = "Sent #{times} new DEV comments to your Orbit workspace"
|
43
|
+
|
44
|
+
puts output
|
45
|
+
return output
|
19
46
|
end
|
20
47
|
|
21
|
-
if type == "followers"
|
48
|
+
if @type == "followers"
|
22
49
|
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
|
50
|
+
id: @data[:follower]["id"],
|
51
|
+
name: @data[:follower]["name"],
|
52
|
+
username: @data[:follower]["username"],
|
53
|
+
url: @data[:follower]["path"],
|
54
|
+
workspace_id: @workspace_id,
|
55
|
+
api_key: @api_key
|
29
56
|
)
|
30
57
|
end
|
31
58
|
end
|
59
|
+
|
60
|
+
def last_orbit_activity_timestamp(type)
|
61
|
+
@last_orbit_activity_timestamp ||= begin
|
62
|
+
if type == "comments"
|
63
|
+
activity_type = "custom:dev:comment"
|
64
|
+
end
|
65
|
+
|
66
|
+
if type == "followers"
|
67
|
+
return nil
|
68
|
+
end
|
69
|
+
|
70
|
+
OrbitActivities::Request.new(
|
71
|
+
api_key: @api_key,
|
72
|
+
workspace_id: @workspace_id,
|
73
|
+
user_agent: "community-ruby-dev-orbit/#{DevOrbit::VERSION}",
|
74
|
+
action: "latest_activity_timestamp",
|
75
|
+
filters: { activity_type: activity_type }
|
76
|
+
).response
|
77
|
+
end
|
78
|
+
end
|
32
79
|
end
|
33
80
|
end
|
data/lib/dev_orbit/version.rb
CHANGED
data/scripts/check_comments.rb
CHANGED
@@ -8,8 +8,8 @@ module DevOrbit
|
|
8
8
|
module Scripts
|
9
9
|
class CheckComments < Thor
|
10
10
|
desc "render", "check for new DEV comments and push them to Orbit"
|
11
|
-
def render
|
12
|
-
client = DevOrbit::Client.new
|
11
|
+
def render(*params)
|
12
|
+
client = DevOrbit::Client.new(historical_import: params[0])
|
13
13
|
client.comments
|
14
14
|
end
|
15
15
|
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 CheckOrgComments < Thor
|
10
|
+
desc "render", "check for new DEV comments on an organization and push them to Orbit"
|
11
|
+
def render(*params)
|
12
|
+
client = DevOrbit::Client.new(historical_import: params[0])
|
13
|
+
client.organization_comments
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev_orbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Orbit DevRel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-07-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -101,14 +101,14 @@ dependencies:
|
|
101
101
|
requirements:
|
102
102
|
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '0.
|
104
|
+
version: '0.2'
|
105
105
|
type: :runtime
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: '0.
|
111
|
+
version: '0.2'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: rspec
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,7 +143,6 @@ email:
|
|
143
143
|
- devrel@orbit.love
|
144
144
|
executables:
|
145
145
|
- dev_orbit
|
146
|
-
- setup
|
147
146
|
extensions: []
|
148
147
|
extra_rdoc_files: []
|
149
148
|
files:
|
@@ -160,7 +159,6 @@ files:
|
|
160
159
|
- README.md
|
161
160
|
- Rakefile
|
162
161
|
- bin/dev_orbit
|
163
|
-
- bin/setup
|
164
162
|
- dev_orbit.gemspec
|
165
163
|
- lib/dev_orbit.rb
|
166
164
|
- lib/dev_orbit/client.rb
|
@@ -174,6 +172,7 @@ files:
|
|
174
172
|
- readme-images/ways-to-use.png
|
175
173
|
- scripts/check_comments.rb
|
176
174
|
- scripts/check_followers.rb
|
175
|
+
- scripts/check_org_comments.rb
|
177
176
|
homepage: https://github.com/orbit-love/community-ruby-dev-orbit
|
178
177
|
licenses:
|
179
178
|
- MIT
|