dev_orbit 0.0.8 → 0.0.9

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: 792e11afeefa69fd18e74185a4032bdbb91f9f61ba1a81c7438f9ce9e4135fbc
4
- data.tar.gz: 43d69304e73007aa485da66a4531e3d0a72897749cec00c6961566c34a7e83be
3
+ metadata.gz: b2c4b8c2f8de5eabeff15996ee2d7d03b7ed40710d8f2f604ef0fb832cef0476
4
+ data.tar.gz: a50f6959cc9292b7822b1da81153df7f0d3a6ad397dd9e5211a5ca6900888085
5
5
  SHA512:
6
- metadata.gz: b3f5520a392e8cd0884650e148dd8e576e2c1a40833ea3d50b00e41b75f4b5d6163c9bf940f4b7bac61bbb10a967a27cbd8a8190d724c1f2b4d039162d00f9bd
7
- data.tar.gz: 3fbefe52bfb1d3c5624216650f604c53481e78e6e234396d820cb903bd3d5048afb23ee485a06cec0456be6ddd0a2b1eb55a8b83b81edd3bae8e0e6504aeab91
6
+ metadata.gz: 95575a8af9172ad28c5c3613510d2f45076c38e9eb726e7a7670acd6a476f2b3b8683ce4c7abf5c7c8dd5d2c9f1c68c8f41287e4c2e52f6d63d2f74eaed34f62
7
+ data.tar.gz: d71011147c850f5bc5b8b4d6467bf7fb723dc5e766127046c9bb854dfd8afdf2f2e3b136e37b60585dbcf6e2e0503f99a07b7a8e7adbe375f03a4d30eebb5fc3
data/CHANGELOG.md CHANGED
@@ -29,4 +29,8 @@
29
29
 
30
30
  ## [0.0.8] - 2021-03-16
31
31
 
32
- - Early return if there are no new comments
32
+ - Early return if there are no new comments
33
+
34
+ ## [0.0.9] - 2021-04-11
35
+
36
+ - Add check for new DEV followers functionality
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dev_orbit (0.0.7)
4
+ dev_orbit (0.0.8)
5
5
  actionview (~> 6.1)
6
6
  activesupport (~> 6.1)
7
7
  http (~> 4.4)
data/README.md CHANGED
@@ -56,7 +56,16 @@ client.comments
56
56
 
57
57
  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.
58
58
 
59
- You can run this a daily cron job, for example, to add your newest DEV comments as activities in your Orbit workspace.
59
+
60
+ ### Post New DEV Followers to Orbit Workspace
61
+
62
+ You can use the gem to get new DEV followers by invoking the `#followers` method on your `client` instance:
63
+
64
+ ```ruby
65
+ client.followers
66
+ ```
67
+
68
+ You can run this either of those or any one of them as a daily cron job, for example, to add your newest DEV comments and/or followers as activities and members in your Orbit workspace.
60
69
 
61
70
  ### CLI
62
71
 
@@ -68,6 +77,12 @@ You can also use the built-in CLI to perform the following operations:
68
77
  $ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...' bundle exec dev_orbit --check-comments
69
78
  ```
70
79
 
80
+ * Check for new DEV followers and post them to Orbit
81
+
82
+ ```bash
83
+ $ ORBIT_API_KEY='...' ORBIT_WORKSPACE='...' DEV_API_KEY='...' DEV_USERNAME='...' bundle exec dev_orbit --check-followers
84
+ ```
85
+
71
86
  ## Contributing
72
87
 
73
88
  Bug reports and pull requests are welcome on GitHub at https://github.com/bencgreenberg/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/bencgreenberg/dev_orbit/blob/master/CODE_OF_CONDUCT.md).
data/bin/dev_orbit CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'optparse'
3
3
 
4
4
  check_comments = false
5
+ check_followers = false
5
6
 
6
7
  options = {}
7
8
  choices = OptionParser.new do |opts|
@@ -13,6 +14,9 @@ choices = OptionParser.new do |opts|
13
14
  opts.on("--check-comments", "Check for new DEV comments") do
14
15
  check_comments = true
15
16
  end
17
+ opts.on("--check-followers", "Check for new DEV followers") do
18
+ check_followers = true
19
+ end
16
20
  end.parse!
17
21
 
18
22
  $LOAD_PATH.unshift(File.expand_path('../lib/dev_orbit', __dir__))
@@ -25,3 +29,9 @@ if check_comments
25
29
  ARGV[0] = 'render'
26
30
  DevOrbit::Scripts::CheckComments.start(ARGV)
27
31
  end
32
+
33
+ if check_followers
34
+ puts "Checking for new DEV followers posting them to your Orbit workspace..."
35
+ ARGV[0] = 'render'
36
+ DevOrbit::Scripts::CheckComments.start(ARGV)
37
+ end
@@ -44,6 +44,15 @@ module DevOrbit
44
44
  ).process_comments
45
45
  end
46
46
 
47
+ def followers
48
+ DevOrbit::Dev.new(
49
+ api_key: @dev_api_key,
50
+ username: @dev_username,
51
+ workspace_id: @orbit_workspace,
52
+ orbit_api_key: @orbit_api_key
53
+ ).process_followers
54
+ end
55
+
47
56
  def orbit
48
57
  DevOrbit::Orbit.new
49
58
  end
data/lib/dev_orbit/dev.rb CHANGED
@@ -35,6 +35,23 @@ module DevOrbit
35
35
  end
36
36
  end
37
37
 
38
+ def process_followers
39
+ followers = get_followers
40
+
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
53
+ end
54
+
38
55
  private
39
56
 
40
57
  def get_articles
@@ -49,6 +66,19 @@ module DevOrbit
49
66
  JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
50
67
  end
51
68
 
69
+ 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
73
+
74
+ request = Net::HTTP::Get.new(url)
75
+ request["api_key"] = @api_key
76
+
77
+ response = https.request(request)
78
+
79
+ JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
80
+ end
81
+
52
82
  def get_article_comments(id)
53
83
  url = URI("https://dev.to/api/comments?a_id=#{id}")
54
84
  https = Net::HTTP.new(url.host, url.port)
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "action_view"
6
+ require_relative "../utils"
7
+
8
+ module DevOrbit
9
+ module Interactions
10
+ class Follower
11
+ def initialize(id:, name:, username:, url:, workspace_id:, api_key:)
12
+ @id = id
13
+ @name = name
14
+ @username = username
15
+ @url = url
16
+ @workspace_id = workspace_id
17
+ @api_key = api_key
18
+
19
+ after_initialize!
20
+ end
21
+
22
+ def after_initialize!
23
+ url = URI("https://app.orbit.love/api/v1/#{@workspace_id}/members")
24
+
25
+ http = Net::HTTP.new(url.host, url.port)
26
+ http.use_ssl = true
27
+ req = Net::HTTP::Post.new(url)
28
+ req["Accept"] = "application/json"
29
+ req["Content-Type"] = "application/json"
30
+ req["Authorization"] = "Bearer #{@api_key}"
31
+
32
+ req.body = construct_body
33
+
34
+ req.body = req.body.to_json
35
+
36
+ response = http.request(req)
37
+
38
+ JSON.parse(response.body) if DevOrbit::Utils.valid_json?(response.body)
39
+ end
40
+
41
+ def construct_body
42
+ {
43
+ member: {
44
+ name: @name.include?("_") ? @name.split("_").map(&:capitalize).join(" ") : @name,
45
+ devto: @username,
46
+ url: "https://dev.to#{@url}"
47
+ }
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -17,6 +17,17 @@ module DevOrbit
17
17
  )
18
18
  end
19
19
  end
20
+
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
+ )
30
+ end
20
31
  end
21
32
  end
22
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DevOrbit
4
- VERSION = "0.0.8"
4
+ VERSION = "0.0.9"
5
5
  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 CheckFollowers < Thor
10
+ desc "render", "check for new DEV followers and push them to Orbit"
11
+ def render
12
+ client = DevOrbit::Client.new
13
+ client.followers
14
+ end
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_orbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Greenberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-16 00:00:00.000000000 Z
11
+ date: 2021-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -153,10 +153,12 @@ files:
153
153
  - lib/dev_orbit/client.rb
154
154
  - lib/dev_orbit/dev.rb
155
155
  - lib/dev_orbit/interactions/comment.rb
156
+ - lib/dev_orbit/interactions/follower.rb
156
157
  - lib/dev_orbit/orbit.rb
157
158
  - lib/dev_orbit/utils.rb
158
159
  - lib/dev_orbit/version.rb
159
160
  - scripts/check_comments.rb
161
+ - scripts/check_followers.rb
160
162
  homepage: https://github.com/bencgreenberg/dev_orbit
161
163
  licenses:
162
164
  - MIT