xify 0.3.1 → 0.4.0
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 +5 -5
- data/lib/xify.rb +6 -10
- data/lib/xify/event.rb +8 -6
- metadata +8 -10
- data/lib/xify/base/rocket_chat.rb +0 -75
- data/lib/xify/input/rocket_chat.rb +0 -39
- data/lib/xify/output/rocket_chat.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 669c526eb23f8e02664a1571d7f134ee0ae6b5c1b600e0ec29d7baf6bf7eb890
|
4
|
+
data.tar.gz: 5b78e9f02dfa562651050ed80964b7ea869e4bdaff9da800f9bb4231ea76342b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ff2de8fec7f64fc37f77aececbe1d546319a131f12bc96450911b71ca92bea939b54c313372dbaf1b53a1310c019fe0dbb3316fd4fbda6dbc95ecf5dd426863
|
7
|
+
data.tar.gz: 9b0907393ae19ecceb921e1fe4f5ff489da79ba7684432516e31bc5ea025dfe25ee7379069387c33d9997cbc017c375e84e9114b96462d60d324b90bff27e3bd
|
data/lib/xify.rb
CHANGED
@@ -1,14 +1,9 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/string/inflections'
|
1
3
|
require 'rufus-scheduler'
|
2
4
|
require 'yaml'
|
3
5
|
|
4
|
-
|
5
|
-
require 'xify/input/prompt'
|
6
|
-
require 'xify/input/rocket_chat'
|
7
|
-
require 'xify/input/shell'
|
8
|
-
require 'xify/output/stdout'
|
9
|
-
require 'xify/output/rocket_chat'
|
10
|
-
|
11
|
-
class Xify
|
6
|
+
module Xify
|
12
7
|
@verbose = false
|
13
8
|
|
14
9
|
def self.run
|
@@ -38,7 +33,8 @@ class Xify
|
|
38
33
|
config[section].map! do |handler|
|
39
34
|
next unless handler['enabled']
|
40
35
|
debug "Setting up #{handler['class']} as #{type}"
|
41
|
-
|
36
|
+
require "xify/#{type}/#{handler['class'].underscore}"
|
37
|
+
Object.const_get("Xify::#{type.capitalize}::#{handler['class']}").new handler
|
42
38
|
end.compact!
|
43
39
|
end
|
44
40
|
|
@@ -60,7 +56,7 @@ class Xify
|
|
60
56
|
end
|
61
57
|
|
62
58
|
Rufus::Scheduler.singleton.join
|
63
|
-
rescue Interrupt
|
59
|
+
rescue Interrupt
|
64
60
|
$stderr.puts "\nExiting."
|
65
61
|
end
|
66
62
|
end
|
data/lib/xify/event.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Xify
|
2
|
+
class Event
|
3
|
+
attr_accessor :author, :message, :args
|
4
|
+
def initialize(author, message, **args)
|
5
|
+
self.author = author
|
6
|
+
self.message = message
|
7
|
+
self.args = args
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Finn Glöe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rufus-scheduler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -47,16 +47,14 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- bin/xify
|
49
49
|
- lib/xify.rb
|
50
|
-
- lib/xify/base/rocket_chat.rb
|
51
50
|
- lib/xify/event.rb
|
52
51
|
- lib/xify/input/pipe.rb
|
53
52
|
- lib/xify/input/prompt.rb
|
54
|
-
- lib/xify/input/rocket_chat.rb
|
55
53
|
- lib/xify/input/shell.rb
|
56
|
-
- lib/xify/output/rocket_chat.rb
|
57
54
|
- lib/xify/output/stdout.rb
|
58
55
|
homepage:
|
59
|
-
licenses:
|
56
|
+
licenses:
|
57
|
+
- MIT
|
60
58
|
metadata: {}
|
61
59
|
post_install_message:
|
62
60
|
rdoc_options: []
|
@@ -74,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
72
|
version: '0'
|
75
73
|
requirements: []
|
76
74
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.6
|
75
|
+
rubygems_version: 2.7.6
|
78
76
|
signing_key:
|
79
77
|
specification_version: 4
|
80
78
|
summary: Cross-post content from one service to another.
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'net/https'
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
module Base
|
6
|
-
class RocketChat
|
7
|
-
def initialize(config)
|
8
|
-
@config = config
|
9
|
-
|
10
|
-
uri = URI.parse config['uri']
|
11
|
-
@http = Net::HTTP.new uri.host, uri.port
|
12
|
-
@http.use_ssl = true
|
13
|
-
|
14
|
-
working_dir = "#{ENV['HOME']}/.xify/RocketChat"
|
15
|
-
Dir.mkdir working_dir rescue Errno::EEXIST
|
16
|
-
@auth_file = "#{working_dir}/#{@config['user']}.json"
|
17
|
-
end
|
18
|
-
|
19
|
-
def request(method, path, &block)
|
20
|
-
login unless @auth_data
|
21
|
-
|
22
|
-
req = Object.const_get("Net::HTTP::#{method.capitalize}").new path,
|
23
|
-
'X-User-Id' => @auth_data['userId'],
|
24
|
-
'X-Auth-Token' => @auth_data['authToken']
|
25
|
-
|
26
|
-
yield req if block_given?
|
27
|
-
|
28
|
-
res = @http.request req
|
29
|
-
|
30
|
-
case res
|
31
|
-
when Net::HTTPUnauthorized
|
32
|
-
relogin
|
33
|
-
request method, path, &block
|
34
|
-
when Net::HTTPSuccess
|
35
|
-
# nothing
|
36
|
-
else
|
37
|
-
$stderr.puts res.body
|
38
|
-
raise "Error on #{method.upcase} #{@config['uri']}#{path}: #{res.code} #{res.message}"
|
39
|
-
end
|
40
|
-
|
41
|
-
res
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def login
|
47
|
-
if File.exists? @auth_file
|
48
|
-
@auth_data = JSON.parse File.read @auth_file
|
49
|
-
return
|
50
|
-
end
|
51
|
-
|
52
|
-
req = Net::HTTP::Post.new '/api/v1/login',
|
53
|
-
'Content-Type' => 'application/json'
|
54
|
-
req.body = {
|
55
|
-
username: @config['user'],
|
56
|
-
password: @config['pass']
|
57
|
-
}.to_json
|
58
|
-
|
59
|
-
res = @http.request req
|
60
|
-
|
61
|
-
unless res.is_a? Net::HTTPSuccess
|
62
|
-
$stderr.puts res.body
|
63
|
-
raise "Error while authenticating to #{@config['uri']}: #{res.code} #{res.message}"
|
64
|
-
end
|
65
|
-
|
66
|
-
@auth_data = JSON.parse(res.body)['data']
|
67
|
-
File.write @auth_file, @auth_data.to_json
|
68
|
-
end
|
69
|
-
|
70
|
-
def relogin
|
71
|
-
File.delete @auth_file
|
72
|
-
login
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'eventmachine'
|
2
|
-
require 'json'
|
3
|
-
require 'metybur'
|
4
|
-
require 'net/https'
|
5
|
-
require 'time'
|
6
|
-
|
7
|
-
require 'xify/base/rocket_chat'
|
8
|
-
|
9
|
-
module Input
|
10
|
-
class RocketChat < Base::RocketChat
|
11
|
-
def updates
|
12
|
-
login
|
13
|
-
|
14
|
-
EM.run do
|
15
|
-
config = @config
|
16
|
-
uri = URI.parse config['uri']
|
17
|
-
meteor = Metybur.connect "wss://#{uri.host}:#{uri.port}/websocket"
|
18
|
-
meteor.login resume: @auth_data['authToken'] do
|
19
|
-
meteor.subscribe 'stream-notify-user', "#{result[:id]}/rooms-changed", false
|
20
|
-
messages = meteor.collection 'stream-notify-user'
|
21
|
-
messages.on(:changed) do |id, attributes|
|
22
|
-
event = attributes[:args].last
|
23
|
-
room = event[:name]
|
24
|
-
message = event[:lastMessage]
|
25
|
-
|
26
|
-
next if message[:editedAt] || room != config['channel'][1..-1]
|
27
|
-
|
28
|
-
author = message[:u][:name]
|
29
|
-
text = message[:msg]
|
30
|
-
time = message[:ts][:'$date']
|
31
|
-
type = event[:t] == 'p' ? 'group' : 'channel'
|
32
|
-
|
33
|
-
yield Event.new author, text, parent: "##{room}", parent_link: "#{config['uri']}/#{type}/#{room}", time: Time.at(time / 1000)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'net/https'
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
require 'xify/base/rocket_chat'
|
6
|
-
|
7
|
-
module Output
|
8
|
-
class RocketChat < Base::RocketChat
|
9
|
-
def process(event)
|
10
|
-
request :post, '/api/v1/chat.postMessage' do |req|
|
11
|
-
req['Content-Type'] = 'application/json'
|
12
|
-
req.body = {
|
13
|
-
channel: @config['channel'],
|
14
|
-
alias: event.author,
|
15
|
-
attachments: [
|
16
|
-
{
|
17
|
-
title: event.args[:parent],
|
18
|
-
title_link: event.args[:parent_link],
|
19
|
-
text: event.args[:link] ? "#{event.message.chomp} ([more](#{event.args[:link]}))" : event.message.chomp
|
20
|
-
}
|
21
|
-
]
|
22
|
-
}.to_json
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|