Module: Hipmost::Hipchat
- Defined in:
- lib/hipmost/hipchat.rb,
lib/hipmost/hipchat/post.rb,
lib/hipmost/hipchat/room.rb,
lib/hipmost/hipchat/post_repository.rb,
lib/hipmost/hipchat/room_repository.rb,
lib/hipmost/hipchat/user_repository.rb
Defined Under Namespace
Classes: Post, PostRepository, Room, RoomRepository, UserRepository
Class Method Summary
collapse
Class Method Details
.direct_channels ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/hipmost/hipchat.rb', line 20
def direct_channels
Dir[$path.join("users", "**", "*.json")].flat_map do |file_path|
json = JSON.parse(File.read(file_path))
json.map do |message|
msg = message["PrivateUserMessage"]
sender = users[msg["sender"]["id"]]
receiver = users[msg["receiver"]["id"]]
[sender.username, receiver.username].sort
end
end.uniq
end
|
.direct_posts(file, verbose) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/hipmost/hipchat.rb', line 32
def direct_posts(file, verbose)
i = 1 if verbose
Dir[$path.join("users", "**", "*.json")].each do |file_path|
puts "Opening 1-on-1 room at #{file_path}..." if verbose
json = JSON.parse(File.read(file_path))
puts "Successfully parsed file at #{file_path}" if verbose
puts "Examining messages in this file..." if verbose
json.each do |message|
if verbose
print "On post #{i}\r"
i += 1
end
msg = message["PrivateUserMessage"]
sender = users[msg["sender"]["id"]]
receiver = users[msg["receiver"]["id"]]
message = msg["message"]
create_at = DateTime.strptime(msg["timestamp"]).to_time.to_i*1000
members = [ sender.username, receiver.username ] .sort
Conversion.convert_formatting_to_markdown(message)
file.puts(%[{ "type": "direct_post", "direct_post": { "channel_members": #{members.inspect}, "user": "#{sender.username}", "message": "#{message}", "create_at": #{create_at} } }])
end
if verbose
print "\n"
puts "Successfully wrote data for that 1-on-1 room\n\n"
end
end
end
|
.rooms ⇒ Object
16
17
18
|
# File 'lib/hipmost/hipchat.rb', line 16
def rooms
@rooms ||= RoomRepository.new($path).tap(&:load)
end
|