dev_orbit 0.3.0 → 0.4.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: 35e2ad6dd881b1e7265572680d9de389105da258ec72f875d34dfa309f16ee79
4
- data.tar.gz: 10c46af45bd4b450d751fba17ba401525b5cb0d5cf407262f79942ac922d6fe6
3
+ metadata.gz: 7774f0f9d702f87b2f33c72a4edf845b93d1731e6c65e582b1b74c47ff2c99f0
4
+ data.tar.gz: 753462633d15b68957c47febca5e2125734e07b238a1233f69534af92c22aa61
5
5
  SHA512:
6
- metadata.gz: 137fccb332ab557dfc2eb0f7f0b61a44fa2cb2e4afeb1821119dbbcb6c8743c5169d88d0fe9ffcfdfdfffd5dc458ebce54f2c367af5b493919a78891d77a0694
7
- data.tar.gz: 5a1972186147056fe7c3b06e50fe113c5d7ec578690218a4babefd44d9a5b9f6458460d6fb2adf7eb7591288a74138ae8ce4b598d9361ff11f083d3f3fb90f22
6
+ metadata.gz: 363e30287c5d67513726b86ec5b0ece72a608031ff17dbe8b53017d85f982ca78a1bb2faf3c0a0f204572fad515ddfcfe9275c5a007c17a5090aa675262ae729
7
+ data.tar.gz: ae845211fd2fe101fe3444551d26c960bafc46014114c32d6c4337ee0673e7f102628ddeeb788e69084832c0b68b19c96e82a465bb19708349505fcd510e9603
data/Gemfile.lock CHANGED
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dev_orbit (0.2.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.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)
@@ -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.1)
41
+ ffi (1.15.3)
42
42
  ffi-compiler (1.0.1)
43
43
  ffi (>= 1.0.0)
44
44
  rake
@@ -62,7 +62,7 @@ GEM
62
62
  minitest (5.14.4)
63
63
  nokogiri (1.11.7-arm64-darwin)
64
64
  racc (~> 1.4)
65
- orbit_activities (0.1.0)
65
+ orbit_activities (0.2.2)
66
66
  http (~> 4.4)
67
67
  json (~> 2.5)
68
68
  rake (~> 13.0)
@@ -94,7 +94,7 @@ GEM
94
94
  diff-lcs (>= 1.2.0, < 2.0)
95
95
  rspec-support (~> 3.10.0)
96
96
  rspec-support (3.10.2)
97
- rubocop (1.16.0)
97
+ rubocop (1.17.0)
98
98
  parallel (~> 1.10)
99
99
  parser (>= 3.0.0.0)
100
100
  rainbow (>= 2.2.2, < 4.0)
data/README.md CHANGED
@@ -54,6 +54,15 @@ client = DevOrbit::Client.new(
54
54
  )
55
55
  ```
56
56
 
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
+ ```
57
66
  ### Post New DEV Comments from a DEV User to Orbit Workspace
58
67
 
59
68
  You can use the gem to get new DEV comments on your DEV user by invoking the `#comments` method on your `client` instance:
@@ -74,7 +83,6 @@ client.organization_comments
74
83
 
75
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.
76
85
 
77
-
78
86
  ### Post New DEV Followers to Orbit Workspace
79
87
 
80
88
  You can use the gem to get new DEV followers by invoking the `#followers` method on your `client` instance:
@@ -106,6 +114,7 @@ $ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...'
106
114
  ```bash
107
115
  $ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_ORGANIZATION='...' bundle exec dev_orbit --check-organization-comments
108
116
  ```
117
+ **Add the `--historical-import` flag to your CLI command to perform a historical import of all your DEV comments using the CLI.**
109
118
 
110
119
  ## Contributing
111
120
 
data/bin/dev_orbit CHANGED
@@ -4,6 +4,7 @@ require 'optparse'
4
4
  check_comments = false
5
5
  check_followers = false
6
6
  check_org_comments = false
7
+ historical_import = false
7
8
 
8
9
  options = {}
9
10
  choices = OptionParser.new do |opts|
@@ -21,6 +22,9 @@ choices = OptionParser.new do |opts|
21
22
  opts.on("--check-organization-comments", "Check for new DEV comments for an organization") do
22
23
  check_org_comments = true
23
24
  end
25
+ opts.on("--historical-import", "Performa historical import of all new DEV comments") do
26
+ historical_import = true
27
+ end
24
28
  end.parse!
25
29
 
26
30
  $LOAD_PATH.unshift(File.expand_path('../lib/dev_orbit', __dir__))
@@ -33,6 +37,7 @@ require_relative '../scripts/check_org_comments'
33
37
  if check_comments
34
38
  puts "Checking for new DEV comments within the past day and posting them to your Orbit workspace..."
35
39
  ARGV[0] = 'render'
40
+ ARGV[1] = historical_import
36
41
  DevOrbit::Scripts::CheckComments.start(ARGV)
37
42
  end
38
43
 
@@ -45,5 +50,6 @@ end
45
50
  if check_org_comments
46
51
  puts "Checking for new DEV organization comments and posting them to your Orbit workspace..."
47
52
  ARGV[0] = 'render'
53
+ ARGV[1] = historical_import
48
54
  DevOrbit::Scripts::CheckOrgComments.start(ARGV)
49
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
 
@@ -22,13 +22,17 @@
22
22
  # @option params [String] :orbit_api_key
23
23
  # The API key for the Orbit API
24
24
  #
25
+ # @option params [Boolean] :historical_import
26
+ # Perform a historical import on all DEV comments
27
+ # Boolean, default to false
28
+ #
25
29
  # @param [Hash] params
26
30
  #
27
31
  # @return [DevOrbit::Client]
28
32
  #
29
33
  module DevOrbit
30
34
  class Client
31
- attr_accessor :dev_username, :dev_api_key, :dev_organization, :orbit_workspace, :orbit_api_key
35
+ attr_accessor :dev_username, :dev_api_key, :dev_organization, :orbit_workspace, :orbit_api_key, :historical_import
32
36
 
33
37
  def initialize(params = {})
34
38
  @orbit_api_key = params.fetch(:orbit_api_key, ENV["ORBIT_API_KEY"])
@@ -36,6 +40,7 @@ module DevOrbit
36
40
  @dev_api_key = params.fetch(:dev_api_key, ENV["DEV_API_KEY"])
37
41
  @dev_username = params.fetch(:dev_username, ENV["DEV_USERNAME"])
38
42
  @dev_organization = params.fetch(:dev_organization, ENV["DEV_ORGANIZATION"])
43
+ @historical_import = params.fetch(:historical_import, false)
39
44
  end
40
45
 
41
46
  # Fetch new comments from DEV and post them to the Orbit workspace
@@ -44,7 +49,8 @@ module DevOrbit
44
49
  api_key: @dev_api_key,
45
50
  username: @dev_username,
46
51
  workspace_id: @orbit_workspace,
47
- orbit_api_key: @orbit_api_key
52
+ orbit_api_key: @orbit_api_key,
53
+ historical_import: @historical_import
48
54
  ).process_comments(type: type)
49
55
  end
50
56
 
data/lib/dev_orbit/dev.rb CHANGED
@@ -13,6 +13,7 @@ module DevOrbit
13
13
  @api_key = params.fetch(:api_key, ENV["DEV_API_KEY"])
14
14
  @workspace_id = params.fetch(:workspace_id, ENV["ORBIT_WORKSPACE_ID"])
15
15
  @orbit_api_key = params.fetch(:orbit_api_key, ENV["ORBIT_API_KEY"])
16
+ @historical_import = params.fetch(:historical_import, false)
16
17
  end
17
18
 
18
19
  def process_comments(type:)
@@ -23,7 +24,7 @@ module DevOrbit
23
24
 
24
25
  next if comments.nil? || comments.empty?
25
26
 
26
- DevOrbit::Orbit.call(
27
+ return DevOrbit::Orbit.new(
27
28
  type: "comments",
28
29
  data: {
29
30
  comments: comments,
@@ -31,8 +32,9 @@ module DevOrbit
31
32
  url: article["url"]
32
33
  },
33
34
  workspace_id: @workspace_id,
34
- api_key: @orbit_api_key
35
- )
35
+ api_key: @orbit_api_key,
36
+ historical_import: @historical_import
37
+ ).call
36
38
  end
37
39
  end
38
40
 
@@ -42,14 +44,15 @@ module DevOrbit
42
44
  followers.each do |follower|
43
45
  next if follower.nil? || follower.empty?
44
46
 
45
- DevOrbit::Orbit.call(
47
+ DevOrbit::Orbit.new(
46
48
  type: "followers",
47
49
  data: {
48
50
  follower: follower
49
51
  },
50
52
  workspace_id: @workspace_id,
51
- api_key: @orbit_api_key
52
- )
53
+ api_key: @orbit_api_key,
54
+ historical_import: @historical_import
55
+ ).call
53
56
  end
54
57
  end
55
58
 
@@ -100,13 +103,7 @@ module DevOrbit
100
103
 
101
104
  return if comments.nil? || comments.empty?
102
105
 
103
- filter_comments(comments)
104
- end
105
-
106
- def filter_comments(comments)
107
- comments.select do |comment|
108
- comment["created_at"] <= 1.day.ago
109
- end
106
+ comments
110
107
  end
111
108
  end
112
109
  end
@@ -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 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)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DevOrbit
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.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
@@ -8,8 +8,8 @@ module DevOrbit
8
8
  module Scripts
9
9
  class CheckOrgComments < Thor
10
10
  desc "render", "check for new DEV comments on an organization 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.organization_comments
14
14
  end
15
15
  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.3.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-06-09 00:00:00.000000000 Z
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.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