Class: Gitter::API::Message
- Includes:
- Collectable
- Defined in:
- lib/gitter/api/message.rb
Overview
Model representation of the /room/:room_id/chatMessages* REST endpoints in the gitter API
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
ISO formatted date of when the message originally sent.
-
#html ⇒ Object
readonly
HTML formatted message (formatted on the API server).
-
#id ⇒ Object
readonly
Message id (from gitter).
-
#issues ⇒ Object
readonly
List of github issues referened in the message.
-
#mentions ⇒ Object
readonly
List of
Gitter::API::Usermentioned in the message. -
#read_by ⇒ Object
readonly
Number of users that have read the message.
-
#text ⇒ Object
readonly
Original message in plain-text/markdown.
-
#unread ⇒ Object
readonly
Indicates if the message has been read by the client user.
-
#updated_at ⇒ Object
readonly
ISO formatted data of when the message was edited last (if it has been).
-
#urls ⇒ Object
readonly
List of URLs present in the message.
-
#user ⇒ Object
readonly
Gitter::API::Userthat sent the message.
Attributes inherited from Base
Class Method Summary collapse
-
.collectable_args(parent, item_data) ⇒ Object
See Gitter::API::Collectable.
Instance Method Summary collapse
-
#initialize(client, room_id, data) ⇒ Message
constructor
INTERNAL METHOD.
-
#mark_as_read ⇒ Object
Mark the message as read for the client user.
-
#update(text) ⇒ Object
Edit/update a Message’s text.
Methods included from Collectable
Methods inherited from Base
Constructor Details
#initialize(client, room_id, data) ⇒ Message
INTERNAL METHOD
Initialize a new Gitter::API::Message
Used by Gitter::API::Room when fetching messages, so favor using that instead.
Parameters
Note: messages in the Gitter schema don’t have a ‘room_id`, so that is passed in as an additional arg here.
- client (Gitter::API::Client)
-
Configured client object
- room_id (String)
-
Room ID message came from
- data (Hash)
-
Initialization data
Options
(string keys only)
- id (String)
-
Message id
- user (String)
-
Gitter::API::Userthat sent the message - text (String)
-
Original message in plain-text/markdown
- html (String)
-
HTML formatted message
- unread (Boolean)
-
Indicates if current user has read the message
- read_by (Integer)
-
Number of users that have read the message
- created_at (Date)
-
ISO formatted date of the message
- updated_at (Date)
-
ISO formatted date of the message if edited
- mentions (Array<User>)
-
Gitter::API::User(s) mentioned in message - issues (Array<String>)
-
List of #Issues referenced in the message
- urls (Array<String>)
-
List of URLs present in message
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gitter/api/message.rb', line 82 def initialize client, room_id, data super client, data @room_id = room_id @id = data["id"] @user = User.new client, data["fromUser"] @text = data["text"] @html = data["html"] @unread = data["unread"] @read_by = data["readBy"] @created_at = data["sent"] @updated_at = data["editedAt"] @mentions = data["mentions"].map { |user| User.new client, user } @issues = data["issues"] @urls = data["urls"] end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
ISO formatted date of when the message originally sent
36 37 38 |
# File 'lib/gitter/api/message.rb', line 36 def created_at @created_at end |
#html ⇒ Object (readonly)
HTML formatted message (formatted on the API server)
27 28 29 |
# File 'lib/gitter/api/message.rb', line 27 def html @html end |
#id ⇒ Object (readonly)
Message id (from gitter)
18 19 20 |
# File 'lib/gitter/api/message.rb', line 18 def id @id end |
#issues ⇒ Object (readonly)
List of github issues referened in the message
45 46 47 |
# File 'lib/gitter/api/message.rb', line 45 def issues @issues end |
#mentions ⇒ Object (readonly)
List of Gitter::API::User mentioned in the message
42 43 44 |
# File 'lib/gitter/api/message.rb', line 42 def mentions @mentions end |
#read_by ⇒ Object (readonly)
Number of users that have read the message
33 34 35 |
# File 'lib/gitter/api/message.rb', line 33 def read_by @read_by end |
#text ⇒ Object (readonly)
Original message in plain-text/markdown
24 25 26 |
# File 'lib/gitter/api/message.rb', line 24 def text @text end |
#unread ⇒ Object (readonly)
Indicates if the message has been read by the client user
30 31 32 |
# File 'lib/gitter/api/message.rb', line 30 def unread @unread end |
#updated_at ⇒ Object (readonly)
ISO formatted data of when the message was edited last (if it has been)
39 40 41 |
# File 'lib/gitter/api/message.rb', line 39 def updated_at @updated_at end |
#urls ⇒ Object (readonly)
List of URLs present in the message
48 49 50 |
# File 'lib/gitter/api/message.rb', line 48 def urls @urls end |
#user ⇒ Object (readonly)
Gitter::API::User that sent the message
21 22 23 |
# File 'lib/gitter/api/message.rb', line 21 def user @user end |
Class Method Details
.collectable_args(parent, item_data) ⇒ Object
See Gitter::API::Collectable
11 12 13 14 15 |
# File 'lib/gitter/api/message.rb', line 11 def self.collectable_args parent, item_data # :nodoc: room_id = parent.respond_to? :room_id ? parent.room_id : nil [parent.client, room_id, item_data] end |
Instance Method Details
#mark_as_read ⇒ Object
Mark the message as read for the client user
:return: true
126 127 128 129 130 131 132 133 |
# File 'lib/gitter/api/message.rb', line 126 def mark_as_read payload = { "chat" => [id] }.to_json path = "/#{api_prefix}/user/#{client.user.id}/rooms/#{room_id}/unreadItems" client.post path, payload true end |
#update(text) ⇒ Object
Edit/update a Message’s text
The html will be reformated on the server, and returned as part of the data when returned.
A new instance of Gitter::API::Message is the turn value
:return: Gitter::API::Message
Parameters
- text (String)
-
New text to update the message record to
115 116 117 118 119 120 |
# File 'lib/gitter/api/message.rb', line 115 def update text payload = { "text" => }.to_json data = client.post "#{api_prefix}/rooms/#{room_id}/chatMessages/#{id}", payload new client, room_id, data end |