Class: Hipmost::Hipchat::Post
- Inherits:
-
Object
- Object
- Hipmost::Hipchat::Post
- Defined in:
- lib/hipmost/hipchat/post.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#sender ⇒ Object
readonly
Returns the value of attribute sender.
-
#team ⇒ Object
readonly
Returns the value of attribute team.
Instance Method Summary collapse
-
#initialize(attrs, room, is_private_room) ⇒ Post
constructor
A new instance of Post.
- #to_jsonl ⇒ Object
Constructor Details
#initialize(attrs, room, is_private_room) ⇒ Post
Returns a new instance of Post.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hipmost/hipchat/post.rb', line 8 def initialize(attrs, room, is_private_room) @private = is_private_room @attrs = attrs @sender = Hipchat.users[attrs["sender"]["id"]] @message = attrs["message"] @created_at = DateTime.strptime(attrs["timestamp"]) @team = room.team @channel = room.channel if is_private_room @receiver = Hipchat.users[attrs["sender"]["id"]] end end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
20 21 22 |
# File 'lib/hipmost/hipchat/post.rb', line 20 def channel @channel end |
#sender ⇒ Object (readonly)
Returns the value of attribute sender.
20 21 22 |
# File 'lib/hipmost/hipchat/post.rb', line 20 def sender @sender end |
#team ⇒ Object (readonly)
Returns the value of attribute team.
20 21 22 |
# File 'lib/hipmost/hipchat/post.rb', line 20 def team @team end |
Instance Method Details
#to_jsonl ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hipmost/hipchat/post.rb', line 22 def to_jsonl # First, convert Hipchat formatting to markdown... Conversion.convert_formatting_to_markdown(@message) # Then, generate the actual object based on whether the room is private or not. if @private members = [@sender.username, @receiver.username].sort %[{ "type": "direct_post", "direct_post": { "channel_members": #{members.inspect}, "user": "#{@sender.username}", "message": "#{JSON.dump(@message)}", "create_at": #{@created_at.to_time.to_i*1000} } }] else %[{ "type": "post", "post": { "team": "#{team.name}", "channel": "#{channel.name}", "user": "#{sender.username}", "message": #{JSON.dump(@message)}, "create_at": #{@created_at.to_time.to_i*1000} } }] end end |