dev_orbit 0.4.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7774f0f9d702f87b2f33c72a4edf845b93d1731e6c65e582b1b74c47ff2c99f0
4
- data.tar.gz: 753462633d15b68957c47febca5e2125734e07b238a1233f69534af92c22aa61
3
+ metadata.gz: 198c77f0fa496da26f71f8fa4328a38fec80522b439599756236d8eaf35023a4
4
+ data.tar.gz: d318cb75b421a63af7d18afa30264c99362e97ac81169b05fd944af8c31407a2
5
5
  SHA512:
6
- metadata.gz: 363e30287c5d67513726b86ec5b0ece72a608031ff17dbe8b53017d85f982ca78a1bb2faf3c0a0f204572fad515ddfcfe9275c5a007c17a5090aa675262ae729
7
- data.tar.gz: ae845211fd2fe101fe3444551d26c960bafc46014114c32d6c4337ee0673e7f102628ddeeb788e69084832c0b68b19c96e82a465bb19708349505fcd510e9603
6
+ metadata.gz: d3091757d9601923ff1ca557081e5bd667b051e8ea300952352dff07e6fcd914cdf19fb878b319ec12f48892dcdb3ecc700d3f518a23c862e06a8a1566e034e9
7
+ data.tar.gz: 2bf38be63bdce7b968bd767ceeaea6ea813c654712a8ac9008b5ffec247d50d7452817c76316a292200a4257b1725647d82c3a57e7cd5ed61dbb316562230ba8
data/CHANGELOG.md CHANGED
@@ -41,4 +41,14 @@
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
52
+ ## [0.5.1] - 2021-07-11
53
+
54
+ - Fix URL query params path for organization comments
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dev_orbit (0.3.0)
4
+ dev_orbit (0.5.1)
5
5
  actionview (~> 6.1)
6
6
  activesupport (~> 6.1)
7
7
  http (~> 4.4)
@@ -25,7 +25,7 @@ GEM
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)
@@ -60,7 +60,9 @@ GEM
60
60
  crass (~> 1.0.2)
61
61
  nokogiri (>= 1.5.9)
62
62
  minitest (5.14.4)
63
- nokogiri (1.11.7-arm64-darwin)
63
+ nokogiri (1.12.5-arm64-darwin)
64
+ racc (~> 1.4)
65
+ nokogiri (1.12.5-x86_64-linux)
64
66
  racc (~> 1.4)
65
67
  orbit_activities (0.2.2)
66
68
  http (~> 4.4)
@@ -68,7 +70,7 @@ GEM
68
70
  rake (~> 13.0)
69
71
  zeitwerk (~> 2.4)
70
72
  parallel (1.20.1)
71
- parser (3.0.1.1)
73
+ parser (3.0.2.0)
72
74
  ast (~> 2.4.1)
73
75
  public_suffix (4.0.6)
74
76
  racc (1.5.2)
@@ -78,7 +80,7 @@ GEM
78
80
  rails-html-sanitizer (1.3.0)
79
81
  loofah (~> 2.3)
80
82
  rainbow (3.0.0)
81
- rake (13.0.3)
83
+ rake (13.0.6)
82
84
  regexp_parser (2.1.1)
83
85
  rexml (3.2.5)
84
86
  rspec (3.10.0)
@@ -94,7 +96,7 @@ GEM
94
96
  diff-lcs (>= 1.2.0, < 2.0)
95
97
  rspec-support (~> 3.10.0)
96
98
  rspec-support (3.10.2)
97
- rubocop (1.17.0)
99
+ rubocop (1.18.3)
98
100
  parallel (~> 1.10)
99
101
  parser (>= 3.0.0.0)
100
102
  rainbow (>= 2.2.2, < 4.0)
@@ -121,6 +123,7 @@ GEM
121
123
 
122
124
  PLATFORMS
123
125
  arm64-darwin-20
126
+ x86_64-linux
124
127
 
125
128
  DEPENDENCIES
126
129
  byebug
data/README.md CHANGED
@@ -116,6 +116,12 @@ $ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_ORGANIZATION='
116
116
  ```
117
117
  **Add the `--historical-import` flag to your CLI command to perform a historical import of all your DEV comments using the CLI.**
118
118
 
119
+ ## GitHub Actions Automation Setup
120
+
121
+ ⚡ You can set up this integration in a matter of minutes using our GitHub Actions template. It will run regularly to add new activities to your Orbit workspace. All you need is a GitHub account.
122
+
123
+ [See our guide for setting up this automation](https://github.com/orbit-love/github-actions-templates/blob/main/DEV/README.md).
124
+
119
125
  ## Contributing
120
126
 
121
127
  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/lib/dev_orbit/dev.rb CHANGED
@@ -19,6 +19,8 @@ module DevOrbit
19
19
  def process_comments(type:)
20
20
  articles = get_articles(type: type)
21
21
 
22
+ return if articles.empty? || articles.nil?
23
+
22
24
  articles.each do |article|
23
25
  comments = get_article_comments(article["id"])
24
26
 
@@ -41,53 +43,84 @@ module DevOrbit
41
43
  def process_followers
42
44
  followers = get_followers
43
45
 
44
- followers.each do |follower|
45
- next if follower.nil? || follower.empty?
46
-
47
- DevOrbit::Orbit.new(
48
- type: "followers",
49
- data: {
50
- follower: follower
51
- },
52
- workspace_id: @workspace_id,
53
- api_key: @orbit_api_key,
54
- historical_import: @historical_import
55
- ).call
56
- 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
57
58
  end
58
59
 
59
60
  private
60
61
 
61
62
  def get_articles(type:)
62
- if type == "user"
63
- url = URI("https://dev.to/api/articles?username=#{@username}&top=1")
64
- end
63
+ page = 1
64
+ articles = []
65
+ looped_at_least_once = false
65
66
 
66
- if type == "organization"
67
- url = URI("https://dev.to/api/organizations/#{@organization}/articles")
68
- end
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"
69
70
 
70
- https = Net::HTTP.new(url.host, url.port)
71
- https.use_ssl = true
71
+ if type == "organization"
72
+ url = URI("https://dev.to/api/organizations/#{@organization}/articles?page=#{page}&per_page=1000")
73
+ end
72
74
 
73
- request = Net::HTTP::Get.new(url)
75
+ https = Net::HTTP.new(url.host, url.port)
76
+ https.use_ssl = true
74
77
 
75
- response = https.request(request)
78
+ request = Net::HTTP::Get.new(url)
79
+ request["User-Agent"] = "community-ruby-dev-orbit/#{DevOrbit::VERSION}"
76
80
 
77
- JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
81
+ response = https.request(request)
82
+
83
+ break if response.code == "404"
84
+
85
+ response = JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
86
+
87
+ articles << response unless response.empty? || response.nil?
88
+ looped_at_least_once = true
89
+
90
+ break if response.empty? || response.nil?
91
+ end
92
+
93
+ articles.flatten!
78
94
  end
79
95
 
80
96
  def get_followers
81
- url = URI("https://dev.to/api/followers/users")
82
- https = Net::HTTP.new(url.host, url.port)
83
- https.use_ssl = true
97
+ page = 1
98
+ followers = []
99
+ looped_at_least_once = false
84
100
 
85
- request = Net::HTTP::Get.new(url)
86
- request["api_key"] = @api_key
101
+ while page >= 1
102
+ page += 1 if looped_at_least_once
103
+ url = URI("https://dev.to/api/followers/users?page=#{page}&per_page=1000")
104
+ https = Net::HTTP.new(url.host, url.port)
105
+ https.use_ssl = true
87
106
 
88
- response = https.request(request)
107
+ request = Net::HTTP::Get.new(url)
108
+ request["api_key"] = @api_key
109
+ request["User-Agent"] = "community-ruby-dev-orbit/#{DevOrbit::VERSION}"
89
110
 
90
- JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
111
+ response = https.request(request)
112
+
113
+ break if response.code == "404"
114
+
115
+ response = JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
116
+
117
+ followers << response unless response.empty? || response.nil?
118
+ looped_at_least_once = true
119
+
120
+ break if response.empty? || response.nil?
121
+ end
122
+
123
+ followers.flatten!
91
124
  end
92
125
 
93
126
  def get_article_comments(id)
@@ -96,6 +129,7 @@ module DevOrbit
96
129
  https.use_ssl = true
97
130
 
98
131
  request = Net::HTTP::Get.new(url)
132
+ request["User-Agent"] = "community-ruby-dev-orbit/#{DevOrbit::VERSION}"
99
133
 
100
134
  response = https.request(request)
101
135
 
@@ -105,5 +139,26 @@ module DevOrbit
105
139
 
106
140
  comments
107
141
  end
142
+
143
+ def last_orbit_member_timestamp
144
+ @last_orbit_member_timestamp ||= begin
145
+ url = URI("https://app.orbit.love/api/v1/#{@workspace_id}/members?direction=DESC&items=10&identity=devto&sort=created_at")
146
+
147
+ http = Net::HTTP.new(url.host, url.port)
148
+ http.use_ssl = true
149
+
150
+ request = Net::HTTP::Get.new(url)
151
+ request["Accept"] = "application/json"
152
+ request["Authorization"] = "Bearer #{@orbit_api_key}"
153
+ request["User-Agent"] = "community-ruby-dev-orbit/#{DevOrbit::VERSION}"
154
+
155
+ response = http.request(request)
156
+ response = JSON.parse(response.body)
157
+
158
+ return nil if response["data"].nil? || response["data"].empty?
159
+
160
+ response["data"][0]["attributes"]["created_at"]
161
+ end
162
+ end
108
163
  end
109
164
  end
@@ -6,13 +6,14 @@ require "active_support/time"
6
6
 
7
7
  module DevOrbit
8
8
  class Orbit
9
- def initialize(type:, data:, workspace_id:, api_key:, historical_import: false)
9
+ def initialize(type:, data:, workspace_id:, api_key:, historical_import: false, last_orbit_member_timestamp: nil)
10
10
  @type = type
11
11
  @data = data
12
12
  @workspace_id = workspace_id
13
13
  @api_key = api_key
14
14
  @historical_import = historical_import
15
15
  @last_orbit_activity_timestamp = last_orbit_activity_timestamp(type)
16
+ @last_orbit_member_timestamp = last_orbit_member_timestamp
16
17
  end
17
18
 
18
19
  def call
@@ -21,13 +22,11 @@ module DevOrbit
21
22
 
22
23
  @data[:comments].each do |comment|
23
24
  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?
25
+ next if (comment["created_at"] || comment[:created_at]) < @last_orbit_activity_timestamp unless @last_orbit_activity_timestamp.nil?
26
26
  end
27
27
 
28
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
29
+ next if (comment["created_at"] || comment[:created_at]) < @last_orbit_activity_timestamp
31
30
  end
32
31
 
33
32
  times += 1
@@ -48,17 +47,39 @@ module DevOrbit
48
47
  end
49
48
 
50
49
  if @type == "followers"
51
- DevOrbit::Interactions::Follower.new(
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
58
- )
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
59
78
  end
60
79
  end
61
80
 
81
+ private
82
+
62
83
  def last_orbit_activity_timestamp(type)
63
84
  @last_orbit_activity_timestamp ||= begin
64
85
  if type == "comments"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DevOrbit
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.2"
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_orbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orbit DevRel
8
8
  - Ben Greenberg
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-06-28 00:00:00.000000000 Z
12
+ date: 2021-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -180,7 +180,7 @@ metadata:
180
180
  homepage_uri: https://github.com/orbit-love/community-ruby-dev-orbit
181
181
  source_code_uri: https://github.com/orbit-love/community-ruby-dev-orbit
182
182
  changelog_uri: https://github.com/orbit-love/community-ruby-dev-orbit/blob/main/CHANGELOG.md
183
- post_install_message:
183
+ post_install_message:
184
184
  rdoc_options: []
185
185
  require_paths:
186
186
  - lib
@@ -195,8 +195,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0'
197
197
  requirements: []
198
- rubygems_version: 3.2.15
199
- signing_key:
198
+ rubygems_version: 3.1.4
199
+ signing_key:
200
200
  specification_version: 4
201
201
  summary: Integrate DEV interactions into your Orbit workspace
202
202
  test_files: []