circle_orbit 0.0.2 → 0.1.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: 05150b8b72010db06ed8915304757ae06a885e62130c9911b3de0e770177024d
4
- data.tar.gz: f89c0f9b61f0aa4719a95e1e10a34e4c4d62519908a6a99aad38804acb9617ea
3
+ metadata.gz: fb34d0a49d0faedec68de8090ca49b128254bb362e2ac3dd5766dd81f77078ee
4
+ data.tar.gz: 3559155b79bdcfc9d0acdfad1d015afc9671defe748a2f1abbf2da41d126b8bb
5
5
  SHA512:
6
- metadata.gz: 3bba116eab82c62e33bdae6abd7b03bf63934b07b892f2eb1bfc8424efb0f1863c9dc5e75df722bf7fbcb0117cd348f966c5858dcb6fa955ef59ad72cfbca5a2
7
- data.tar.gz: 67d5bdf2f0a18ffdcaae2e29108c40794d01b30dd56268268ffe401809ae363831dfc3b4356c3222855ae86778401783869c842c986c46b8267fe2b09d90062b
6
+ metadata.gz: f8b7577ddd24e448ac577f9adfa4033749d7407ae72246de36db5ee90ffea1863d7adeb1dd8da444ac5178b728639cfb3a6b2a346446f326420847721c20637a
7
+ data.tar.gz: 02ff348d42763b30afe08044b83c48d57784f5da42324f6556f99e105bcd176c5115aef722d7e0e319967d2671e5c0448aca76fec417aa3b273fa5ce55058d47
data/Gemfile.lock CHANGED
@@ -1,26 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- circle_orbit (0.0.1)
4
+ circle_orbit (0.0.2)
5
5
  actionview (~> 6.1)
6
6
  activesupport (~> 6.1)
7
7
  dotenv (~> 2.7)
8
8
  http (~> 4.4)
9
9
  json (~> 2.5)
10
- orbit_activities (~> 0.1)
10
+ orbit_activities (~> 0.2)
11
11
  thor (~> 1.1)
12
12
  zeitwerk (~> 2.4)
13
13
 
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- actionview (6.1.3.2)
18
- activesupport (= 6.1.3.2)
17
+ actionview (6.1.4)
18
+ activesupport (= 6.1.4)
19
19
  builder (~> 3.1)
20
20
  erubi (~> 1.4)
21
21
  rails-dom-testing (~> 2.0)
22
22
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
- activesupport (6.1.3.2)
23
+ activesupport (6.1.4)
24
24
  concurrent-ruby (~> 1.0, >= 1.0.2)
25
25
  i18n (>= 1.6, < 2)
26
26
  minitest (>= 5.1)
@@ -31,7 +31,7 @@ GEM
31
31
  ast (2.4.2)
32
32
  builder (3.2.4)
33
33
  byebug (11.1.3)
34
- concurrent-ruby (1.1.8)
34
+ concurrent-ruby (1.1.9)
35
35
  crack (0.4.5)
36
36
  rexml
37
37
  crass (1.0.6)
@@ -40,7 +40,7 @@ GEM
40
40
  unf (>= 0.0.5, < 1.0.0)
41
41
  dotenv (2.7.6)
42
42
  erubi (1.10.0)
43
- ffi (1.15.1)
43
+ ffi (1.15.3)
44
44
  ffi-compiler (1.0.1)
45
45
  ffi (>= 1.0.0)
46
46
  rake
@@ -50,7 +50,7 @@ GEM
50
50
  http-cookie (~> 1.0)
51
51
  http-form_data (~> 2.2)
52
52
  http-parser (~> 1.2.0)
53
- http-cookie (1.0.3)
53
+ http-cookie (1.0.4)
54
54
  domain_name (~> 0.5)
55
55
  http-form_data (2.3.0)
56
56
  http-parser (1.2.3)
@@ -58,13 +58,15 @@ GEM
58
58
  i18n (1.8.10)
59
59
  concurrent-ruby (~> 1.0)
60
60
  json (2.5.1)
61
- loofah (2.9.1)
61
+ loofah (2.10.0)
62
62
  crass (~> 1.0.2)
63
63
  nokogiri (>= 1.5.9)
64
64
  minitest (5.14.4)
65
- nokogiri (1.11.3-arm64-darwin)
65
+ nokogiri (1.11.7-arm64-darwin)
66
66
  racc (~> 1.4)
67
- orbit_activities (0.1.0)
67
+ nokogiri (1.11.7-x86_64-linux)
68
+ racc (~> 1.4)
69
+ orbit_activities (0.2.2)
68
70
  http (~> 4.4)
69
71
  json (~> 2.5)
70
72
  rake (~> 13.0)
@@ -96,13 +98,13 @@ GEM
96
98
  diff-lcs (>= 1.2.0, < 2.0)
97
99
  rspec-support (~> 3.10.0)
98
100
  rspec-support (3.10.2)
99
- rubocop (1.15.0)
101
+ rubocop (1.18.0)
100
102
  parallel (~> 1.10)
101
103
  parser (>= 3.0.0.0)
102
104
  rainbow (>= 2.2.2, < 4.0)
103
105
  regexp_parser (>= 1.8, < 3.0)
104
106
  rexml
105
- rubocop-ast (>= 1.5.0, < 2.0)
107
+ rubocop-ast (>= 1.7.0, < 2.0)
106
108
  ruby-progressbar (~> 1.7)
107
109
  unicode-display_width (>= 1.4.0, < 3.0)
108
110
  rubocop-ast (1.7.0)
@@ -123,6 +125,7 @@ GEM
123
125
 
124
126
  PLATFORMS
125
127
  arm64-darwin-20
128
+ x86_64-linux
126
129
 
127
130
  DEPENDENCIES
128
131
  byebug
data/README.md CHANGED
@@ -49,12 +49,20 @@ client = CircleOrbit::Client.new(
49
49
  circle_url: YOUR_CIRCLE_URL
50
50
  )
51
51
  ```
52
-
53
52
  ### Instantiation with credentials in dotenv file:
54
53
 
55
54
  ```ruby
56
55
  client = CircleOrbit::Client.new
57
56
  ```
57
+ ### Performing a Historical Import
58
+
59
+ You may want to perform a one-time historical import to fetch all your previous Circle interactions and bring them into your Orbit workspace. To do so, instantiate your `client` with the `historical_import` flag:
60
+
61
+ ```ruby
62
+ client = CircleOrbit::Client.new(
63
+ historical_import: true
64
+ )
65
+ ```
58
66
  ### Post New Spaces Posts to Orbit Workspace
59
67
 
60
68
  You can use the gem to get new posts in your Circle Spaces and share them as custom activities to your Orbit workspace by using the `#posts` method on your `client instance`:
@@ -86,6 +94,8 @@ To check for new comments on posts:
86
94
  $ ORBIT_API_KEY=... ORBIT_WORKSPACE_ID=... CIRCLE_API_KEY=... CIRCLE_URL=... bundle exec circle_orbit --check-comments
87
95
  ```
88
96
 
97
+ **Add the `--historical-import` flag to your CLI command to perform a historical import of all your Circle interactions using the CLI.**
98
+
89
99
  ## GitHub Actions Automation Setup
90
100
 
91
101
  ⚡ 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.
data/bin/circle_orbit CHANGED
@@ -5,6 +5,7 @@ require "optparse"
5
5
 
6
6
  check_comments = false
7
7
  check_posts = false
8
+ historical_import = false
8
9
 
9
10
  options = {}
10
11
  choices = OptionParser.new do |opts|
@@ -19,6 +20,9 @@ choices = OptionParser.new do |opts|
19
20
  opts.on("--check-posts", "Check for new posts in your Circle Spaces") do
20
21
  check_posts = true
21
22
  end
23
+ opts.on("--historical-import", "Performa historical import of all new Circle interactions") do
24
+ historical_import = true
25
+ end
22
26
  end.parse!
23
27
 
24
28
  $LOAD_PATH.unshift(File.expand_path("../lib/circle_orbit", __dir__))
@@ -30,11 +34,13 @@ require_relative "../scripts/check_posts"
30
34
  if check_comments
31
35
  puts "Checking for new Circle Spaces post comments within the past day and sending them to your Orbit workspace..."
32
36
  ARGV[0] = "render"
37
+ ARGV[1] = historical_import
33
38
  CircleOrbit::Scripts::CheckComments.start(ARGV)
34
39
  end
35
40
 
36
41
  if check_posts
37
42
  puts "Checking for new Circle Spaces posts and sending them to your Orbit workspace..."
38
43
  ARGV[0] = "render"
44
+ ARGV[1] = historical_import
39
45
  CircleOrbit::Scripts::CheckPosts.start(ARGV)
40
46
  end
data/circle_orbit.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency "dotenv", "~> 2.7"
32
32
  spec.add_dependency "http", "~> 4.4"
33
33
  spec.add_dependency "json", "~> 2.5"
34
- spec.add_dependency "orbit_activities", "~> 0.1"
34
+ spec.add_dependency "orbit_activities", "~> 0.2"
35
35
  spec.add_dependency "thor", "~> 1.1"
36
36
  spec.add_dependency "zeitwerk", "~> 2.4"
37
37
  spec.add_development_dependency "rspec", "~> 3.4"
@@ -8,6 +8,7 @@ module CircleOrbit
8
8
  @circle_url = params.fetch(:circle_url)
9
9
  @orbit_api_key = params.fetch(:orbit_api_key)
10
10
  @orbit_workspace = params.fetch(:orbit_workspace)
11
+ @historical_import = params.fetch(:historical_import, false)
11
12
  end
12
13
 
13
14
  def process_posts
@@ -16,9 +17,21 @@ module CircleOrbit
16
17
  spaces.each do |space|
17
18
  posts = get_posts(space["id"])
18
19
 
20
+ times = 0
21
+ orbit_timestamp = last_orbit_activity_timestamp(type: "post")
19
22
  posts.each do |post|
20
23
  next if post.nil? || post.empty?
21
24
 
25
+ unless @historical_import && orbit_timestamp
26
+ next if post["created_at"] < orbit_timestamp unless orbit_timestamp.nil?
27
+ end
28
+
29
+ if orbit_timestamp && @historical_import == false
30
+ next if post["created_at"] < orbit_timestamp
31
+ end
32
+
33
+ times += 1
34
+
22
35
  CircleOrbit::Orbit.call(
23
36
  type: "post",
24
37
  data: post,
@@ -26,6 +39,11 @@ module CircleOrbit
26
39
  orbit_workspace: @orbit_workspace
27
40
  )
28
41
  end
42
+
43
+ output = "Sent #{times} new posts to your Orbit workspace"
44
+
45
+ puts output
46
+ return output
29
47
  end
30
48
  end
31
49
 
@@ -34,9 +52,21 @@ module CircleOrbit
34
52
 
35
53
  return if comments.nil? || comments.empty?
36
54
 
55
+ times = 0
56
+ orbit_timestamp = last_orbit_activity_timestamp(type: "comment")
37
57
  comments.each do |comment|
38
58
  next if comment.nil? || comment.empty?
39
59
 
60
+ unless @historical_import && orbit_timestamp
61
+ next if comment["body"]["created_at"] < orbit_timestamp unless orbit_timestamp.nil?
62
+ end
63
+
64
+ if orbit_timestamp && @historical_import == false
65
+ next if comment["body"]["created_at"] < orbit_timestamp
66
+ end
67
+
68
+ times += 1
69
+
40
70
  CircleOrbit::Orbit.call(
41
71
  type: "comment",
42
72
  data: comment,
@@ -44,6 +74,10 @@ module CircleOrbit
44
74
  orbit_workspace: @orbit_workspace
45
75
  )
46
76
  end
77
+ output = "Sent #{times} new comments to your Orbit workspace"
78
+
79
+ puts output
80
+ return output
47
81
  end
48
82
 
49
83
  private
@@ -89,5 +123,25 @@ module CircleOrbit
89
123
 
90
124
  JSON.parse(response.body)
91
125
  end
126
+
127
+ def last_orbit_activity_timestamp(type: )
128
+ @last_orbit_activity_timestamp ||= begin
129
+ if type == "post"
130
+ activity_type = "custom:circle:post"
131
+ end
132
+
133
+ if type == "comment"
134
+ activity_type = "custom:circle:comment"
135
+ end
136
+
137
+ OrbitActivities::Request.new(
138
+ api_key: @orbit_api_key,
139
+ workspace_id: @orbit_workspace,
140
+ user_agent: "community-ruby-circle-orbit/#{CircleOrbit::VERSION}",
141
+ action: "latest_activity_timestamp",
142
+ filters: { activity_type: activity_type }
143
+ ).response
144
+ end
145
+ end
92
146
  end
93
147
  end
@@ -23,13 +23,17 @@ require "json"
23
23
  # @option params [String] :circle_url
24
24
  # The URL of the Circle community
25
25
  #
26
+ # @option params [Boolean] :historical_import
27
+ # Flag on whether to import all Circle historical data
28
+ # Default to false
29
+ #
26
30
  # @param [Hash] params
27
31
  #
28
32
  # @return [CircleOrbit::Client]
29
33
  #
30
34
  module CircleOrbit
31
35
  class Client
32
- attr_accessor :orbit_api_key, :orbit_workspace, :circle_api_key, :circle_url, :circle_community_id
36
+ attr_accessor :orbit_api_key, :orbit_workspace, :circle_api_key, :circle_url, :circle_community_id, :historical_import
33
37
 
34
38
  def initialize(params = {})
35
39
  @orbit_api_key = params.fetch(:orbit_api_key, ENV["ORBIT_API_KEY"])
@@ -37,6 +41,7 @@ module CircleOrbit
37
41
  @circle_api_key = params.fetch(:circle_api_key, ENV["CIRCLE_API_KEY"])
38
42
  @circle_url = sanitize_url(params.fetch(:circle_url, ENV["CIRCLE_URL"]))
39
43
  @circle_community_id = circle_community_id
44
+ @historical_import = params.fetch(:historical_import, false)
40
45
  end
41
46
 
42
47
  def posts
@@ -45,7 +50,8 @@ module CircleOrbit
45
50
  circle_url: @circle_url,
46
51
  circle_community_id: @circle_community_id,
47
52
  orbit_api_key: @orbit_api_key,
48
- orbit_workspace: @orbit_workspace
53
+ orbit_workspace: @orbit_workspace,
54
+ historical_import: @historical_import
49
55
  ).process_posts
50
56
  end
51
57
 
@@ -55,7 +61,8 @@ module CircleOrbit
55
61
  circle_url: @circle_url,
56
62
  circle_community_id: @circle_community_id,
57
63
  orbit_api_key: @orbit_api_key,
58
- orbit_workspace: @orbit_workspace
64
+ orbit_workspace: @orbit_workspace,
65
+ historical_import: @historical_import
59
66
  ).process_comments
60
67
  end
61
68
 
@@ -3,5 +3,5 @@
3
3
  # frozen_string_literal = true
4
4
 
5
5
  module CircleOrbit
6
- VERSION = "0.0.2"
6
+ VERSION = "0.1.0"
7
7
  end
@@ -8,8 +8,8 @@ module CircleOrbit
8
8
  module Scripts
9
9
  class CheckComments < Thor
10
10
  desc "render", "check for new comments in Spaces posts and push them to Orbit"
11
- def render
12
- client = CircleOrbit::Client.new
11
+ def render(*params)
12
+ client = CircleOrbit::Client.new(historical_import: params[0])
13
13
  client.comments
14
14
  end
15
15
  end
@@ -8,8 +8,8 @@ module CircleOrbit
8
8
  module Scripts
9
9
  class CheckPosts < Thor
10
10
  desc "render", "check for new posts in Circle Spaces and push them to Orbit"
11
- def render
12
- client = CircleOrbit::Client.new
11
+ def render(*params)
12
+ client = CircleOrbit::Client.new(historical_import: params[0])
13
13
  client.posts
14
14
  end
15
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circle_orbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.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-08 00:00:00.000000000 Z
12
+ date: 2021-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionview
@@ -87,14 +87,14 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '0.1'
90
+ version: '0.2'
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '0.1'
97
+ version: '0.2'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: thor
100
100
  requirement: !ruby/object:Gem::Requirement