dev_orbit 0.1.4 → 0.4.0
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/Gemfile.lock +17 -27
- data/README.md +38 -8
- 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 +63 -14
- data/lib/dev_orbit/version.rb +1 -1
- data/readme-images/new-comment-screenshot.png +0 -0
- data/readme-images/ways-to-use.png +0 -0
- data/scripts/check_comments.rb +2 -2
- data/scripts/check_org_comments.rb +17 -0
- metadata +7 -8
- data/bin/console +0 -15
- 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: 7774f0f9d702f87b2f33c72a4edf845b93d1731e6c65e582b1b74c47ff2c99f0
|
4
|
+
data.tar.gz: 753462633d15b68957c47febca5e2125734e07b238a1233f69534af92c22aa61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 363e30287c5d67513726b86ec5b0ece72a608031ff17dbe8b53017d85f982ca78a1bb2faf3c0a0f204572fad515ddfcfe9275c5a007c17a5090aa675262ae729
|
7
|
+
data.tar.gz: ae845211fd2fe101fe3444551d26c960bafc46014114c32d6c4337ee0673e7f102628ddeeb788e69084832c0b68b19c96e82a465bb19708349505fcd510e9603
|
data/.env.sample
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.3.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
@@ -4,11 +4,14 @@
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/dev_orbit.svg)](https://badge.fury.io/rb/dev_orbit)
|
5
5
|
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](code_of_conduct.md)
|
6
6
|
|
7
|
-
|
7
|
+
Add your DEV interactions into your Orbit workspace with this community-built integration.
|
8
|
+
|
9
|
+
![New DEV blog post comment in Orbit screenshot](readme-images/new-comment-screenshot.png)
|
8
10
|
|
9
11
|
|<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
12
|
|-----------------------------------------|
|
11
13
|
|
14
|
+
![There are three ways to use this integration. Install package - build and run your own applications. Run the CLI - run on-demand directly from your terminal. Schedule an automation with GitHub - get started in minutes - no coding required](readme-images/ways-to-use.png)
|
12
15
|
## Installation
|
13
16
|
|
14
17
|
Add this line to your application's Gemfile:
|
@@ -23,13 +26,14 @@ gem 'dev_orbit'
|
|
23
26
|
|
24
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.
|
25
28
|
|
26
|
-
The following are the
|
29
|
+
The following are the environment variables, you can provide either or both a `DEV_USERNAME` or a `DEV_ORGANIZATION`:
|
27
30
|
|
28
31
|
```ruby
|
29
32
|
ORBIT_API_KEY
|
30
33
|
ORBIT_WORKSPACE_ID
|
31
34
|
DEV_API_KEY
|
32
35
|
DEV_USERNAME
|
36
|
+
DEV_ORGANIZATION
|
33
37
|
```
|
34
38
|
|
35
39
|
With the credentials as environment variables:
|
@@ -45,20 +49,39 @@ client = DevOrbit::Client.new(
|
|
45
49
|
orbit_api_key: '...',
|
46
50
|
orbit_workspace: '...',
|
47
51
|
dev_api_key: '...',
|
48
|
-
dev_username: '...'
|
52
|
+
dev_username: '...',
|
53
|
+
dev_organization: '...'
|
49
54
|
)
|
50
55
|
```
|
51
56
|
|
52
|
-
###
|
57
|
+
### Performing a Historical Import
|
58
|
+
|
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
|
53
67
|
|
54
|
-
You can use the gem to get new DEV comments on your DEV user
|
68
|
+
You can use the gem to get new DEV comments on your DEV user by invoking the `#comments` method on your `client` instance:
|
55
69
|
|
56
70
|
```ruby
|
57
71
|
client.comments
|
58
72
|
```
|
59
73
|
|
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.
|
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.
|
75
|
+
|
76
|
+
### Post New DEV Comments from a DEV Organization to Orbit Workspace
|
61
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.
|
62
85
|
|
63
86
|
### Post New DEV Followers to Orbit Workspace
|
64
87
|
|
@@ -74,18 +97,25 @@ You can run this either of those or any one of them as a daily cron job, for exa
|
|
74
97
|
|
75
98
|
You can also use the built-in CLI to perform the following operations:
|
76
99
|
|
77
|
-
* Check for new DEV comments and post them to Orbit
|
100
|
+
* Check for new DEV user comments and post them to Orbit
|
78
101
|
|
79
102
|
```bash
|
80
103
|
$ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...' bundle exec dev_orbit --check-comments
|
81
104
|
```
|
82
105
|
|
83
|
-
* Check for new DEV followers and post them to Orbit
|
106
|
+
* Check for new DEV user followers and post them to Orbit
|
84
107
|
|
85
108
|
```bash
|
86
109
|
$ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...' bundle exec dev_orbit --check-followers
|
87
110
|
```
|
88
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
|
+
|
89
119
|
## Contributing
|
90
120
|
|
91
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,81 @@
|
|
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
|
+
puts "inside first condition"
|
25
|
+
next if comment["created_at"] || comment[:created_at] < @last_orbit_activity_timestamp unless @last_orbit_activity_timestamp.nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
if @last_orbit_activity_timestamp && @historical_import == false
|
29
|
+
puts "inside second condition"
|
30
|
+
next if comment["created_at"] || comment[:created_at] < @last_orbit_activity_timestamp
|
31
|
+
end
|
32
|
+
|
33
|
+
times += 1
|
34
|
+
|
11
35
|
DevOrbit::Interactions::Comment.new(
|
12
|
-
article_title: data.transform_keys(&:to_sym)[:title],
|
36
|
+
article_title: @data.transform_keys(&:to_sym)[:title],
|
13
37
|
comment: comment.transform_keys(&:to_sym),
|
14
|
-
url: data[:url],
|
15
|
-
workspace_id: workspace_id,
|
16
|
-
api_key: api_key
|
38
|
+
url: @data[:url],
|
39
|
+
workspace_id: @workspace_id,
|
40
|
+
api_key: @api_key
|
17
41
|
)
|
18
42
|
end
|
43
|
+
|
44
|
+
output = "Sent #{times} new DEV comments to your Orbit workspace"
|
45
|
+
|
46
|
+
puts output
|
47
|
+
return output
|
19
48
|
end
|
20
49
|
|
21
|
-
if type == "followers"
|
50
|
+
if @type == "followers"
|
22
51
|
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
|
52
|
+
id: @data[:follower]["id"],
|
53
|
+
name: @data[:follower]["name"],
|
54
|
+
username: @data[:follower]["username"],
|
55
|
+
url: @data[:follower]["path"],
|
56
|
+
workspace_id: @workspace_id,
|
57
|
+
api_key: @api_key
|
29
58
|
)
|
30
59
|
end
|
31
60
|
end
|
61
|
+
|
62
|
+
def last_orbit_activity_timestamp(type)
|
63
|
+
@last_orbit_activity_timestamp ||= begin
|
64
|
+
if type == "comments"
|
65
|
+
activity_type = "custom:dev:comment"
|
66
|
+
end
|
67
|
+
|
68
|
+
if type == "followers"
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
|
72
|
+
OrbitActivities::Request.new(
|
73
|
+
api_key: @api_key,
|
74
|
+
workspace_id: @workspace_id,
|
75
|
+
user_agent: "community-ruby-dev-orbit/#{DevOrbit::VERSION}",
|
76
|
+
action: "latest_activity_timestamp",
|
77
|
+
filters: { activity_type: activity_type }
|
78
|
+
).response
|
79
|
+
end
|
80
|
+
end
|
32
81
|
end
|
33
82
|
end
|
data/lib/dev_orbit/version.rb
CHANGED
Binary file
|
Binary file
|
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.
|
4
|
+
version: 0.4.0
|
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-06-28 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
|
@@ -142,9 +142,7 @@ description: This gem integrates DEV blog interactions like comments, etc. into
|
|
142
142
|
email:
|
143
143
|
- devrel@orbit.love
|
144
144
|
executables:
|
145
|
-
- console
|
146
145
|
- dev_orbit
|
147
|
-
- setup
|
148
146
|
extensions: []
|
149
147
|
extra_rdoc_files: []
|
150
148
|
files:
|
@@ -160,9 +158,7 @@ files:
|
|
160
158
|
- LICENSE.txt
|
161
159
|
- README.md
|
162
160
|
- Rakefile
|
163
|
-
- bin/console
|
164
161
|
- bin/dev_orbit
|
165
|
-
- bin/setup
|
166
162
|
- dev_orbit.gemspec
|
167
163
|
- lib/dev_orbit.rb
|
168
164
|
- lib/dev_orbit/client.rb
|
@@ -172,8 +168,11 @@ files:
|
|
172
168
|
- lib/dev_orbit/orbit.rb
|
173
169
|
- lib/dev_orbit/utils.rb
|
174
170
|
- lib/dev_orbit/version.rb
|
171
|
+
- readme-images/new-comment-screenshot.png
|
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
|
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
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__)
|