xify 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: c33e22276a4a7300eb6173fc59c138ab023273a3f8707228c44f671daf95be0d
4
- data.tar.gz: 54c6954be8ce6ff1ae785155659525ccedfab5172d83bf4e8874feeb2e350bfe
3
+ metadata.gz: 7887a75fe26b23e8914d2c644ab854b43f10962cba6098f6cef821cf1e331e4b
4
+ data.tar.gz: 8e5d734727dbfb96767d1a96376f851c83095c2d6ebcfc0dbb3d932fcf100dbb
5
5
  SHA512:
6
- metadata.gz: 61a2e697065f2156bf1981b27605b4d321d675f1ca56718675c3f023c2b68049bc9aca927131a6307970a25205907c7363960ecd029edd29ae91d81e7cc54c60
7
- data.tar.gz: f3fda430b30f731daa6e52cd357d607a6df4c8c0477c98903125cf8cdeea639565d84bbc6f1c3a98ddda1b477597a15f9d562aabef154e1f807fc794ea7e1efe
6
+ metadata.gz: 51b09d9c1f0aaa42a03347ff6a1d6c7f462d305295719a965ee70f8068cc096ffc7e325dfb84cd1974c0fbc32695ebfcde9533bff0cbf8587d0bfc2bb3802db2
7
+ data.tar.gz: eafcba6853de81298f3ea6d7c1966a79530684efefc4e78474b1c908e50898446feacb007793d3fd4284bd99229ba43829e0e5c805ed75361e864be56997de5a
data/lib/xify/event.rb ADDED
@@ -0,0 +1,8 @@
1
+ class Event
2
+ attr_accessor :author, :message, :args
3
+ def initialize(author, message, **args)
4
+ self.author = author
5
+ self.message = message
6
+ self.args = args
7
+ end
8
+ end
@@ -1,7 +1,8 @@
1
- require 'xify/item'
1
+ require 'xify/event'
2
2
 
3
3
  class Stdin
4
4
  def initialize(config)
5
+ @author = config['author']
5
6
  end
6
7
 
7
8
  def updates
@@ -16,7 +17,7 @@ class Stdin
16
17
  end
17
18
 
18
19
  if input.length != 1
19
- yield Item.new link: 'http://localhost', message: input, source: 'stdin'
20
+ yield Event.new @author, input
20
21
  end
21
22
  rescue Interrupt
22
23
  # Stop on CTRL+C
@@ -56,19 +56,16 @@ class RocketChat
56
56
  req
57
57
  end
58
58
 
59
- def process(item)
59
+ def process(event)
60
60
  res = @http.request(authenticated_request do |req|
61
61
  req.body = {
62
62
  channel: @channel,
63
- alias: item.author,
63
+ alias: event.author,
64
64
  attachments: [
65
65
  {
66
- author_name: item.source,
67
- ts: item.time,
68
- message_link: item.link,
69
- title: item.parent,
70
- title_link: item.parent_link,
71
- text: item.message
66
+ title: event.args[:parent],
67
+ title_link: event.args[:parent_link],
68
+ text: event.args[:link] ? "#{event.message.chomp} ([more](#{event.args[:link]}))" : event.message.chomp
72
69
  }
73
70
  ]
74
71
  }.to_json
@@ -77,7 +74,7 @@ class RocketChat
77
74
  case res
78
75
  when Net::HTTPUnauthorized
79
76
  reset_auth
80
- process(item)
77
+ process event
81
78
  when Net::HTTPSuccess
82
79
  # nothing
83
80
  else
@@ -4,7 +4,7 @@ class Stdout
4
4
  def initialize(config)
5
5
  end
6
6
 
7
- def process(item)
8
- puts "[#{item.time}] #{item.message}"
7
+ def process(event)
8
+ puts "[#{event.args[:time] || Time.now.iso8601}] #{event.author}: #{event.message}"
9
9
  end
10
10
  end
data/lib/xify.rb CHANGED
@@ -17,7 +17,7 @@ class Xify
17
17
  config[c].map! do |handler|
18
18
  next unless handler['enabled']
19
19
  Object.const_get(handler['class']).new(handler)
20
- end
20
+ end.compact!
21
21
  end
22
22
 
23
23
  puts 'Looking for updates'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xify
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
  - Finn Glöe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-10 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Cross-post content from one service to another.
14
14
  email: fgloee@united-internet.de
@@ -19,8 +19,8 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - bin/xify
21
21
  - lib/xify.rb
22
+ - lib/xify/event.rb
22
23
  - lib/xify/input/stdin.rb
23
- - lib/xify/item.rb
24
24
  - lib/xify/output/rocket_chat.rb
25
25
  - lib/xify/output/stdout.rb
26
26
  homepage:
data/lib/xify/item.rb DELETED
@@ -1,12 +0,0 @@
1
- class Item
2
- attr_accessor :link, :message, :source, :author, :parent, :parent_link, :time
3
- def initialize(link:, message:, source:, author: 'Anonymous', parent: nil, parent_link: nil, time: Time.now.iso8601)
4
- self.author = author
5
- self.link = link
6
- self.message = message
7
- self.parent = parent
8
- self.parent_link = parent_link
9
- self.source = source
10
- self.time = time
11
- end
12
- end