Class: Hipmost::Hipchat::PostRepository

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hipmost/hipchat/post_repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(room) ⇒ PostRepository

Returns a new instance of PostRepository.



17
18
19
20
21
# File 'lib/hipmost/hipchat/post_repository.rb', line 17

def initialize(room)
  @room  = room
  @path  = $path.join("rooms", room.id.to_s, "history.json")
  @posts = []
end

Instance Attribute Details

#name_indexObject

Returns the value of attribute name_index.



8
9
10
# File 'lib/hipmost/hipchat/post_repository.rb', line 8

def name_index
  @name_index
end

#postsObject

Returns the value of attribute posts.



8
9
10
# File 'lib/hipmost/hipchat/post_repository.rb', line 8

def posts
  @posts
end

Class Method Details

.for_room(room) ⇒ Object



13
14
15
# File 'lib/hipmost/hipchat/post_repository.rb', line 13

def self.for_room(room)
  new(room).tap(&:load)
end

Instance Method Details

#file_dataObject



37
38
39
40
# File 'lib/hipmost/hipchat/post_repository.rb', line 37

def file_data
  return if !File.exists?(@path)
  File.read(@path)
end

#load(data = file_data) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hipmost/hipchat/post_repository.rb', line 23

def load(data = file_data)
  return if !File.exists?(@path)
  json = JSON.load(data)

  json.each do |post_obj|
    next if post_obj.key?("NotificationMessage")
    next if post_obj.key?("GuestAccessMessage")
    next if post_obj.key?("ArchiveRoomMessage")
    next if post_obj.key?("TopicRoomMessage")          
    post = post_obj["UserMessage"]
    @posts << Post.new(post, @room)
  end
end