circle_orbit 0.0.1 → 0.0.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: cbac5f7ade30e799d21b967182a325147afe4bacd647d15b4da7a1e4b6143376
4
- data.tar.gz: ca554062dff6fc1e3586c9d4f13d548b3aaff5a25ef67b662afbacef1e832670
3
+ metadata.gz: 05150b8b72010db06ed8915304757ae06a885e62130c9911b3de0e770177024d
4
+ data.tar.gz: f89c0f9b61f0aa4719a95e1e10a34e4c4d62519908a6a99aad38804acb9617ea
5
5
  SHA512:
6
- metadata.gz: 2bbffe1dce506e639811fc17565d182cd0a42902f8e58a71cc7d202026ec005494699250104e0875e3fffc7d4a08fa4508d84a95d4a534aa3aa93552dd1d6d7b
7
- data.tar.gz: '026877e0bd8fec53f1ba8d8bcd68bb9de921d92a8a1b8f290df7009dfce48b1d8444ef3f2842db251e19987faa84844322d97281052294d50621d227b15b7166'
6
+ metadata.gz: 3bba116eab82c62e33bdae6abd7b03bf63934b07b892f2eb1bfc8424efb0f1863c9dc5e75df722bf7fbcb0117cd348f966c5858dcb6fa955ef59ad72cfbca5a2
7
+ data.tar.gz: 67d5bdf2f0a18ffdcaae2e29108c40794d01b30dd56268268ffe401809ae363831dfc3b4356c3222855ae86778401783869c842c986c46b8267fe2b09d90062b
data/bin/circle_orbit CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- require 'optparse'
2
+ # frozen_string_literal: true
3
+
4
+ require "optparse"
3
5
 
4
6
  check_comments = false
5
7
  check_posts = false
@@ -19,20 +21,20 @@ choices = OptionParser.new do |opts|
19
21
  end
20
22
  end.parse!
21
23
 
22
- $LOAD_PATH.unshift(File.expand_path('../lib/circle_orbit', __dir__))
24
+ $LOAD_PATH.unshift(File.expand_path("../lib/circle_orbit", __dir__))
23
25
 
24
- require_relative '../lib/circle_orbit'
25
- require_relative '../scripts/check_comments'
26
- require_relative '../scripts/check_posts'
26
+ require_relative "../lib/circle_orbit"
27
+ require_relative "../scripts/check_comments"
28
+ require_relative "../scripts/check_posts"
27
29
 
28
30
  if check_comments
29
31
  puts "Checking for new Circle Spaces post comments within the past day and sending them to your Orbit workspace..."
30
- ARGV[0] = 'render'
32
+ ARGV[0] = "render"
31
33
  CircleOrbit::Scripts::CheckComments.start(ARGV)
32
34
  end
33
35
 
34
36
  if check_posts
35
37
  puts "Checking for new Circle Spaces posts and sending them to your Orbit workspace..."
36
- ARGV[0] = 'render'
38
+ ARGV[0] = "render"
37
39
  CircleOrbit::Scripts::CheckPosts.start(ARGV)
38
- end
40
+ end
@@ -17,6 +17,8 @@ module CircleOrbit
17
17
  posts = get_posts(space["id"])
18
18
 
19
19
  posts.each do |post|
20
+ next if post.nil? || post.empty?
21
+
20
22
  CircleOrbit::Orbit.call(
21
23
  type: "post",
22
24
  data: post,
@@ -28,18 +30,20 @@ module CircleOrbit
28
30
  end
29
31
 
30
32
  def process_comments
31
- comments = get_comments
33
+ comments = get_comments
32
34
 
33
- return if comments.nil? || comments.empty?
35
+ return if comments.nil? || comments.empty?
34
36
 
35
- comments.each do |comment|
36
- CircleOrbit::Orbit.call(
37
- type: "comment",
38
- data: comment,
39
- orbit_api_key: @orbit_api_key,
40
- orbit_workspace: @orbit_workspace
41
- )
42
- end
37
+ comments.each do |comment|
38
+ next if comment.nil? || comment.empty?
39
+
40
+ CircleOrbit::Orbit.call(
41
+ type: "comment",
42
+ data: comment,
43
+ orbit_api_key: @orbit_api_key,
44
+ orbit_workspace: @orbit_workspace
45
+ )
46
+ end
43
47
  end
44
48
 
45
49
  private
@@ -55,7 +59,7 @@ module CircleOrbit
55
59
 
56
60
  response = https.request(request)
57
61
 
58
- response = JSON.parse(response.body)
62
+ JSON.parse(response.body)
59
63
  end
60
64
 
61
65
  def get_posts(id)
@@ -69,21 +73,21 @@ module CircleOrbit
69
73
 
70
74
  response = https.request(request)
71
75
 
72
- response = JSON.parse(response.body)
76
+ JSON.parse(response.body)
73
77
  end
74
78
 
75
79
  def get_comments
76
- url = URI("#{@circle_url}/api/v1/comments?community_id=#{@circle_community_id}")
77
-
78
- https = Net::HTTP.new(url.host, url.port)
79
- https.use_ssl = true
80
-
81
- request = Net::HTTP::Get.new(url)
82
- request["Authorization"] = "Token #{@circle_api_key}"
83
-
84
- response = https.request(request)
85
-
86
- response = JSON.parse(response.body)
80
+ url = URI("#{@circle_url}/api/v1/comments?community_id=#{@circle_community_id}")
81
+
82
+ https = Net::HTTP.new(url.host, url.port)
83
+ https.use_ssl = true
84
+
85
+ request = Net::HTTP::Get.new(url)
86
+ request["Authorization"] = "Token #{@circle_api_key}"
87
+
88
+ response = https.request(request)
89
+
90
+ JSON.parse(response.body)
87
91
  end
88
92
  end
89
93
  end
@@ -2,13 +2,14 @@
2
2
 
3
3
  require "json"
4
4
  require "action_view"
5
+ require_relative "../utils"
5
6
 
6
7
  module CircleOrbit
7
8
  module Interactions
8
9
  class Comment
9
10
  def initialize(post_title:, body:, created_at:, id:, space:, url:, author:, email:, workspace_id:, api_key:)
10
11
  @post_title = post_title
11
- @body = sanitize_body(body)
12
+ @body = CircleOrbit::Utils.sanitize_body(body)
12
13
  @created_at = created_at
13
14
  @id = id
14
15
  @space = space
@@ -62,14 +63,6 @@ module CircleOrbit
62
63
  #{body}
63
64
  HEREDOC
64
65
  end
65
-
66
- private
67
-
68
- def sanitize_body(body)
69
- body = ActionView::Base.full_sanitizer.sanitize(body)
70
-
71
- body.gsub("\n", " ")
72
- end
73
66
  end
74
67
  end
75
68
  end
@@ -2,13 +2,14 @@
2
2
 
3
3
  require "json"
4
4
  require "action_view"
5
+ require_relative "../utils"
5
6
 
6
7
  module CircleOrbit
7
8
  module Interactions
8
9
  class Post
9
10
  def initialize(post_title:, body:, created_at:, id:, space:, url:, author:, email:, workspace_id:, api_key:)
10
11
  @post_title = post_title
11
- @body = sanitize_body(body)
12
+ @body = CircleOrbit::Utils.sanitize_body(body)
12
13
  @created_at = created_at
13
14
  @id = id
14
15
  @space = space
@@ -62,14 +63,6 @@ module CircleOrbit
62
63
  #{body}
63
64
  HEREDOC
64
65
  end
65
-
66
- private
67
-
68
- def sanitize_body(body)
69
- body = ActionView::Base.full_sanitizer.sanitize(body)
70
-
71
- body.gsub("\n", " ")
72
- end
73
66
  end
74
67
  end
75
68
  end
@@ -23,16 +23,16 @@ module CircleOrbit
23
23
 
24
24
  if type == "comment"
25
25
  CircleOrbit::Interactions::Comment.new(
26
- post_title: data["post_name"],
27
- body: data["body"]["body"],
28
- created_at: data["body"]["created_at"],
29
- id: data["body"]["record_id"],
30
- space: data["space_slug"].gsub(/-/, ' ').capitalize,
31
- url: data["url"],
32
- author: data["user_name"],
33
- email: data["user_email"],
34
- workspace_id: orbit_workspace,
35
- api_key: orbit_api_key
26
+ post_title: data["post_name"],
27
+ body: data["body"]["body"],
28
+ created_at: data["body"]["created_at"],
29
+ id: data["body"]["record_id"],
30
+ space: data["space_slug"].gsub(/-/, " ").capitalize,
31
+ url: data["url"],
32
+ author: data["user_name"],
33
+ email: data["user_email"],
34
+ workspace_id: orbit_workspace,
35
+ api_key: orbit_api_key
36
36
  )
37
37
  end
38
38
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CircleOrbit
4
+ class Utils
5
+ def self.sanitize_body(body)
6
+ body = ActionView::Base.full_sanitizer.sanitize(body)
7
+
8
+ body&.gsub!("\n", " ")
9
+
10
+ body
11
+ end
12
+ end
13
+ end
@@ -3,5 +3,5 @@
3
3
  # frozen_string_literal = true
4
4
 
5
5
  module CircleOrbit
6
- VERSION = "0.0.1"
6
+ VERSION = "0.0.2"
7
7
  end
@@ -14,4 +14,4 @@ module CircleOrbit
14
14
  end
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -14,4 +14,4 @@ module CircleOrbit
14
14
  end
15
15
  end
16
16
  end
17
- end
17
+ 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.1
4
+ version: 0.0.2
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-07 00:00:00.000000000 Z
12
+ date: 2021-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionview
@@ -179,6 +179,7 @@ files:
179
179
  - lib/circle_orbit/interactions/comment.rb
180
180
  - lib/circle_orbit/interactions/post.rb
181
181
  - lib/circle_orbit/orbit.rb
182
+ - lib/circle_orbit/utils.rb
182
183
  - lib/circle_orbit/version.rb
183
184
  - readme-images/screenshot_of_activity.png
184
185
  - readme-images/ways-to-use.png