dev_orbit 0.1.6 → 0.5.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: face683978f5efcfc0e63902fc6acfb0f3b60d016344acc950aa049645d8585c
4
- data.tar.gz: 0d620594f0a1b64c7e00605204139fea78fa493f91f4c7e2fdb87587ab1f03fe
3
+ metadata.gz: 81c671aa577a917ca0147e98e71227375b2f6bdb7d3191d64d4d8eded5c7d34e
4
+ data.tar.gz: 7327d11e7ebe8a546d5cc54b15516337801ba435daad4c8124eb55b9571225a9
5
5
  SHA512:
6
- metadata.gz: 527049e721b0248e7e57d13c8ffbd64fc25656493a8e25aa77865b18cc4f97a33e65c41084f8f9238157e3ff2f106b08eb10588761a1a56e9dcbff77e9d42173
7
- data.tar.gz: 1dac710ead8d771ccf4092bc3fa83343c989311a4e53121165f8e57b601ba46c098268e69912cf3c76f36450d75c67c30676c77800c44860eebf3ab0cc2547c9
6
+ metadata.gz: 1efb625e90bbe73b44efcbb6fe0e4fcbe279f7ec2908c30d1b71e9e58e888155e81daffcf8dae5857c4c9ebdc2dae8516c74bfb77db83f56f3867a537e06cac1
7
+ data.tar.gz: a146a6dbb68bbc27ed224d44aab866ac25957d730c00400ba5671ac575982cff637113c125ec331bffaf2efd822d5bc638a70a2817c80431c072d00284204ee8
data/.env.sample CHANGED
@@ -1,4 +1,5 @@
1
1
  ORBIT_API_KEY=
2
2
  ORBIT_WORKSPACE_ID=
3
3
  DEV_API_KEY=
4
- DEV_USERNAME=
4
+ DEV_USERNAME=
5
+ DEV_ORGANIZATION=
data/CHANGELOG.md CHANGED
@@ -41,4 +41,11 @@
41
41
  ## [0.1.0] - 2021-05-06
42
42
 
43
43
  - Correct CLI `CheckFollowers` action
44
- - Update gem specifications
44
+ - Update gem specifications
45
+ ## [0.4.1] - 2021-07-01
46
+
47
+ - Remove debugging output from processing DEV comments
48
+ ## [0.5.0] - 2021-07-08
49
+
50
+ - Add pagination for all DEV interactions
51
+ - Dynamically filter what to send to Orbit based on last item of that type in the Orbit workspace
data/Gemfile.lock CHANGED
@@ -1,36 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dev_orbit (0.1.3)
4
+ dev_orbit (0.4.1)
5
5
  actionview (~> 6.1)
6
6
  activesupport (~> 6.1)
7
7
  http (~> 4.4)
8
8
  json (~> 2.5)
9
- orbit_activities (~> 0.1)
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.3.2)
17
- activesupport (= 6.1.3.2)
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.3.2)
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)
26
26
  tzinfo (~> 2.0)
27
27
  zeitwerk (~> 2.3)
28
- addressable (2.7.0)
28
+ addressable (2.8.0)
29
29
  public_suffix (>= 2.0.2, < 5.0)
30
30
  ast (2.4.2)
31
31
  builder (3.2.4)
32
32
  byebug (11.1.3)
33
- concurrent-ruby (1.1.8)
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.0)
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.3)
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.9.1)
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.5-arm64-darwin)
63
+ nokogiri (1.11.7-arm64-darwin)
64
64
  racc (~> 1.4)
65
- nokogiri (1.11.5-x86_64-darwin)
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.0.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)
@@ -86,7 +78,7 @@ GEM
86
78
  rails-html-sanitizer (1.3.0)
87
79
  loofah (~> 2.3)
88
80
  rainbow (3.0.0)
89
- rake (13.0.3)
81
+ rake (13.0.5)
90
82
  regexp_parser (2.1.1)
91
83
  rexml (3.2.5)
92
84
  rspec (3.10.0)
@@ -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.11.0)
97
+ rubocop (1.18.3)
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.2.0, < 2.0)
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.4.1)
115
- parser (>= 2.7.1.5)
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.12.1)
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 expected environment variables:
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
- ### Post New DEV Comments to Orbit Workspace
57
+ ### Performing a Historical Import
56
58
 
57
- You can use the gem to get new DEV comments on your DEV user or organization by invoking the `#comments` method on your `client` instance:
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.1"
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
 
@@ -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
- ).process_comments
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,24 @@ 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)
21
+
22
+ return if articles.empty? || articles.nil?
19
23
 
20
24
  articles.each do |article|
21
25
  comments = get_article_comments(article["id"])
22
26
 
23
27
  next if comments.nil? || comments.empty?
24
28
 
25
- DevOrbit::Orbit.call(
29
+ return DevOrbit::Orbit.new(
26
30
  type: "comments",
27
31
  data: {
28
32
  comments: comments,
@@ -30,53 +34,87 @@ module DevOrbit
30
34
  url: article["url"]
31
35
  },
32
36
  workspace_id: @workspace_id,
33
- api_key: @orbit_api_key
34
- )
37
+ api_key: @orbit_api_key,
38
+ historical_import: @historical_import
39
+ ).call
35
40
  end
36
41
  end
37
42
 
38
43
  def process_followers
39
44
  followers = get_followers
40
45
 
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
46
+ return if followers.empty? || followers.nil?
47
+
48
+ DevOrbit::Orbit.new(
49
+ type: "followers",
50
+ data: {
51
+ followers: followers
52
+ },
53
+ workspace_id: @workspace_id,
54
+ api_key: @orbit_api_key,
55
+ historical_import: @historical_import,
56
+ last_orbit_member_timestamp: last_orbit_member_timestamp
57
+ ).call
53
58
  end
54
59
 
55
60
  private
56
61
 
57
- def get_articles
58
- url = URI("https://dev.to/api/articles?username=#{@username}&top=1")
59
- https = Net::HTTP.new(url.host, url.port)
60
- https.use_ssl = true
62
+ def get_articles(type:)
63
+ page = 1
64
+ articles = []
65
+ looped_at_least_once = false
61
66
 
62
- request = Net::HTTP::Get.new(url)
67
+ while page >= 1
68
+ page += 1 if looped_at_least_once
69
+ url = URI("https://dev.to/api/articles?username=#{@username}&page=#{page}&per_page=1000") if type == "user"
63
70
 
64
- response = https.request(request)
71
+ if type == "organization"
72
+ url = URI("https://dev.to/api/organizations/#{@organization}/articles&page=#{page}&per_page=1000")
73
+ end
74
+
75
+ https = Net::HTTP.new(url.host, url.port)
76
+ https.use_ssl = true
77
+
78
+ request = Net::HTTP::Get.new(url)
65
79
 
66
- JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
80
+ response = https.request(request)
81
+
82
+ response = JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
83
+
84
+ articles << response unless response.empty? || response.nil?
85
+ looped_at_least_once = true
86
+
87
+ break if response.empty? || response.nil?
88
+ end
89
+
90
+ articles.flatten!
67
91
  end
68
92
 
69
93
  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
94
+ page = 1
95
+ followers = []
96
+ looped_at_least_once = false
73
97
 
74
- request = Net::HTTP::Get.new(url)
75
- request["api_key"] = @api_key
98
+ while page >= 1
99
+ page += 1 if looped_at_least_once
100
+ url = URI("https://dev.to/api/followers/users?page=#{page}&per_page=1000")
101
+ https = Net::HTTP.new(url.host, url.port)
102
+ https.use_ssl = true
76
103
 
77
- response = https.request(request)
104
+ request = Net::HTTP::Get.new(url)
105
+ request["api_key"] = @api_key
106
+
107
+ response = https.request(request)
108
+
109
+ response = JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
110
+
111
+ followers << response unless response.empty? || response.nil?
112
+ looped_at_least_once = true
78
113
 
79
- JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
114
+ break if response.empty? || response.nil?
115
+ end
116
+
117
+ followers.flatten!
80
118
  end
81
119
 
82
120
  def get_article_comments(id)
@@ -92,12 +130,27 @@ module DevOrbit
92
130
 
93
131
  return if comments.nil? || comments.empty?
94
132
 
95
- filter_comments(comments)
133
+ comments
96
134
  end
97
135
 
98
- def filter_comments(comments)
99
- comments.select do |comment|
100
- comment["created_at"] <= 1.day.ago
136
+ def last_orbit_member_timestamp
137
+ @last_orbit_member_timestamp ||= begin
138
+ url = URI("https://app.orbit.love/api/v1/#{@workspace_id}/members?direction=DESC&items=10&identity=devto&sort=created_at")
139
+
140
+ http = Net::HTTP.new(url.host, url.port)
141
+ http.use_ssl = true
142
+
143
+ request = Net::HTTP::Get.new(url)
144
+ request["Accept"] = "application/json"
145
+ request["Authorization"] = "Bearer #{@orbit_api_key}"
146
+ request["User-Agent"] = "community-ruby-dev-orbit/#{DevOrbit::VERSION}"
147
+
148
+ response = http.request(request)
149
+ response = JSON.parse(response.body)
150
+
151
+ return nil if response["data"].nil? || response["data"].empty?
152
+
153
+ response["data"][0]["attributes"]["created_at"]
101
154
  end
102
155
  end
103
156
  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
 
@@ -43,8 +43,7 @@ module DevOrbit
43
43
  {
44
44
  member: {
45
45
  name: @name.include?("_") ? @name.split("_").map(&:capitalize).join(" ") : @name,
46
- devto: @username,
47
- url: "https://dev.to#{@url}"
46
+ devto: @username
48
47
  }
49
48
  }
50
49
  end
@@ -2,31 +2,101 @@
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 self.call(type:, data:, workspace_id:, api_key:)
9
- if type == "comments"
10
- data[:comments].each do |comment|
9
+ def initialize(type:, data:, workspace_id:, api_key:, historical_import: false, last_orbit_member_timestamp: nil)
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
+ @last_orbit_member_timestamp = last_orbit_member_timestamp
17
+ end
18
+
19
+ def call
20
+ if @type == "comments"
21
+ times = 0
22
+
23
+ @data[:comments].each do |comment|
24
+ unless @historical_import && @last_orbit_activity_timestamp
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
+ next if (comment["created_at"] || comment[:created_at]) < @last_orbit_activity_timestamp
30
+ end
31
+
32
+ times += 1
33
+
11
34
  DevOrbit::Interactions::Comment.new(
12
- article_title: data.transform_keys(&:to_sym)[:title],
35
+ article_title: @data.transform_keys(&:to_sym)[:title],
13
36
  comment: comment.transform_keys(&:to_sym),
14
- url: data[:url],
15
- workspace_id: workspace_id,
16
- api_key: api_key
37
+ url: @data[:url],
38
+ workspace_id: @workspace_id,
39
+ api_key: @api_key
17
40
  )
18
41
  end
42
+
43
+ output = "Sent #{times} new DEV comments to your Orbit workspace"
44
+
45
+ puts output
46
+ return output
19
47
  end
20
48
 
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
- )
49
+ if @type == "followers"
50
+ counter = 0
51
+ @data[:followers].each do |follower|
52
+ next if follower.nil? || follower.empty?
53
+
54
+ unless @historical_import && @last_orbit_member_timestamp
55
+ next if follower["created_at"] < @last_orbit_member_timestamp unless @last_orbit_member_timestamp.nil?
56
+ end
57
+
58
+ if @last_orbit_member_timestamp && @historical_import == false
59
+ next if follower["created_at"] < @last_orbit_member_timestamp
60
+ end
61
+
62
+ sleep(20) if counter % 100 == 0 && counter != 0 # API rate limiting
63
+
64
+ DevOrbit::Interactions::Follower.new(
65
+ id: follower["id"],
66
+ name: follower["name"],
67
+ username: follower["username"],
68
+ url: follower["path"],
69
+ workspace_id: @workspace_id,
70
+ api_key: @api_key
71
+ )
72
+ counter += 1
73
+ end
74
+ output = "Sent #{counter} new followers to Orbit"
75
+
76
+ puts output
77
+ return output
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def last_orbit_activity_timestamp(type)
84
+ @last_orbit_activity_timestamp ||= begin
85
+ if type == "comments"
86
+ activity_type = "custom:dev:comment"
87
+ end
88
+
89
+ if type == "followers"
90
+ return nil
91
+ end
92
+
93
+ OrbitActivities::Request.new(
94
+ api_key: @api_key,
95
+ workspace_id: @workspace_id,
96
+ user_agent: "community-ruby-dev-orbit/#{DevOrbit::VERSION}",
97
+ action: "latest_activity_timestamp",
98
+ filters: { activity_type: activity_type }
99
+ ).response
30
100
  end
31
101
  end
32
102
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DevOrbit
4
- VERSION = "0.1.6"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -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.6
4
+ version: 0.5.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-05-27 00:00:00.000000000 Z
12
+ date: 2021-07-08 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.1'
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.1'
111
+ version: '0.2'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: rspec
114
114
  requirement: !ruby/object:Gem::Requirement
@@ -172,6 +172,7 @@ files:
172
172
  - readme-images/ways-to-use.png
173
173
  - scripts/check_comments.rb
174
174
  - scripts/check_followers.rb
175
+ - scripts/check_org_comments.rb
175
176
  homepage: https://github.com/orbit-love/community-ruby-dev-orbit
176
177
  licenses:
177
178
  - MIT