initial draft

This commit is contained in:
mose 2018-07-07 11:46:11 +08:00
commit fa34e0c422
9 changed files with 85 additions and 0 deletions

2
.bundle/config Normal file
View file

@ -0,0 +1,2 @@
---
BUNDLE_PATH: "vendor"

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
config.yml
vendor

3
Gemfile Normal file
View file

@ -0,0 +1,3 @@
source 'https://rubygems.org'
gem 'rocketchat'

13
Gemfile.lock Normal file
View file

@ -0,0 +1,13 @@
GEM
remote: https://rubygems.org/
specs:
rocketchat (0.1.15)
PLATFORMS
ruby
DEPENDENCIES
rocketchat
BUNDLED WITH
1.16.2

3
config.yml.sample Normal file
View file

@ -0,0 +1,3 @@
server: 'http://your.server.address'
user: 'user'
pass: 'password'

16
lib/rocketchat/channel.rb Normal file
View file

@ -0,0 +1,16 @@
module RocketChat
module Messages
class Channel < Room
def history(room: nil, since: nil, count: 10)
response = session.request_json(
'/api/v1/channels.history',
body: {
roomId: room,
oldest: since,
count: count
})
response['messages'] if response['success']
end
end
end
end

6
lib/rocketweekly.rb Normal file
View file

@ -0,0 +1,6 @@
$:.unshift File.dirname(__FILE__) unless $:.include? File.dirname(__FILE__)
require 'rocketchat'
require 'rocketchat/channel'
require 'rocketweekly/connect'

View file

@ -0,0 +1,19 @@
module RocketWeekly
class Connect
attr_reader :session
def initialize
config = YAML.load_file(File.expand_path('../../../config.yml', __FILE__))
server = RocketChat::Server.new config['server']
@session = server.login(config['user'], config['pass'])
end
def channels_list
@session.channels.list(offset: 0, count: 200)
end
def channel_history(id)
@session.channels.history(room: id)
end
end
end

21
run.rb Normal file
View file

@ -0,0 +1,21 @@
require 'yaml'
require_relative './lib/rocketweekly'
rocket = RocketWeekly::Connect.new
output = {}
rocket.channels_list.each do |channel|
output[channel.name] = {
'id' => channel.id,
'owner' => channel.owner ? channel.owner['username'] : '----'
}
puts '--------------'
puts channel.name
rocket.channel_history(channel.id).each do |m|
printf "%s %-20s\n", m['u']['username'], m['msg']
puts
end
break
end
puts '--------------'