Class: Livefyre::Comment
- Inherits:
-
Object
- Object
- Livefyre::Comment
- Defined in:
- lib/livefyre/comment.rb
Overview
Public: Proxy object for a [Comment] on a [Livefyre::Conversation]
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#conversation ⇒ Object
Returns the value of attribute conversation.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
-
.create(client, user, conversation, body, reply_to = nil) ⇒ Object
Public: create a new comment on a conversation.
Instance Method Summary collapse
-
#content_type ⇒ Object
Public: Get the comment content type as a string.
-
#content_type_id ⇒ Object
Public: Get the comment visibility as an integer.
-
#delete! ⇒ Object
Public: Delete this comment.
-
#flag(reason, notes, email, user = nil) ⇒ Object
Public: Flag a comment.
-
#initialize(id, conversation, options = {}) ⇒ Comment
constructor
A new instance of Comment.
-
#like!(user) ⇒ Object
Public: Likes a comment as the passed user.
-
#source ⇒ Object
Public: Get the comment source as a string.
-
#source_id ⇒ Object
Public: Get the comment source as an integer.
-
#to_s ⇒ Object
Internal: Returns a cleaner string representation of this object.
-
#unlike!(user) ⇒ Object
Public: Unlikes a comment as the passed user.
-
#update(body) ⇒ Object
Public: Update this comment’s content.
-
#visibility ⇒ Object
Public: Get the comment visibility as a string.
-
#visibility_id ⇒ Object
Public: Get the comment visibility as an integer.
Constructor Details
#initialize(id, conversation, options = {}) ⇒ Comment
Returns a new instance of Comment.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/livefyre/comment.rb', line 14 def initialize(id, conversation, = {}) @id = id @body = [:body] @user = [:user] @parent_id = [:parent_id] @ip = [:author_ip] @conversation = conversation @created_at = [:created_at] @client = [:client] || Livefyre.client @options = end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def body @body end |
#conversation ⇒ Object
Returns the value of attribute conversation.
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def conversation @conversation end |
#created_at ⇒ Object
Returns the value of attribute created_at.
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def id @id end |
#ip ⇒ Object
Returns the value of attribute ip.
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def ip @ip end |
#parent_id ⇒ Object
Returns the value of attribute parent_id.
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def parent_id @parent_id end |
#user ⇒ Object
Returns the value of attribute user.
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def user @user end |
Class Method Details
.create(client, user, conversation, body, reply_to = nil) ⇒ Object
Public: create a new comment on a conversation
client - [Client] representing the site to use when creating the conversation user - [User] to create the comment as conversation - [Conversation] to create body - [String] Comment body
Returns [Comment] Raises [APIException] when the API call fails
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/livefyre/comment.rb', line 159 def self.create(client, user, conversation, body, reply_to = nil) response = client.quill.post "/api/v3.0/collection/#{conversation.id}/post/", {:lftoken => user.token, :body => body, :_bi => client.identifier, :parent_id => reply_to} if response.success? puts JSON.parse(response.body).inspect data = JSON.parse(response.body)["data"] data["messages"].map do |entry| c = entry["content"] Comment.new(c["id"], conversation, { :body => c["bodyHtml"], :parent_id => c["parentId"], :user => User.new(c["authorId"], data["authors"].first.last["displayName"], data["authors"].first.last), :created_at => Time.at(c["createdAt"]), :source => entry["source"], :visibility => entry["vis"], :client => client, :type => entry["type"] }) end.first else raise APIException.new(response.body) end end |
Instance Method Details
#content_type ⇒ Object
Public: Get the comment content type as a string.
Currently only populated when created via ::create
Returns [Enum<CONTENT_TYPES>]
112 113 114 |
# File 'lib/livefyre/comment.rb', line 112 def content_type content_type_id ? CONTENT_TYPES[content_type_id] : nil end |
#content_type_id ⇒ Object
Public: Get the comment visibility as an integer.
Currently only populated when created via ::create
Returns [Integer]
120 121 122 |
# File 'lib/livefyre/comment.rb', line 120 def content_type_id @options[:type] end |
#delete! ⇒ Object
Public: Delete this comment
Returns [Boolean] true on success Raises [APIException] on failure
54 55 56 57 58 59 60 61 |
# File 'lib/livefyre/comment.rb', line 54 def delete! response = client.quill.post "/api/v3.0/message/#{id}/delete", {:lftoken => @client.system_token} if response.success? true else raise APIException.new(response.body) end end |
#flag(reason, notes, email, user = nil) ⇒ Object
Public: Flag a comment
reason - one of [disagree, spam, offensive, off-topic] notes - String containing the reason for the flag email - email address of the flagger user - [User] If set, will include the user token for validation of the flag
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/livefyre/comment.rb', line 32 def flag(reason, notes, email, user = nil) raise "invalid reason" unless REASONS.include? reason payload = { :message_id => @id, :collection_id => @conversation.id, :flag => reason, :notes => notes, :email => email } payload[:lftoken] = user.token if user response = client.quill.post "/api/v3.0/message/25818122/flag/#{reason}/", payload.to_json if response.success? true else raise APIException.new(response.body) end end |
#like!(user) ⇒ Object
Public: Likes a comment as the passed user
Returns [Boolean] true on success Raises [APIException] on failure
128 129 130 131 132 133 134 135 |
# File 'lib/livefyre/comment.rb', line 128 def like!(user) response = @client.quill.post "/api/v3.0/message/#{id}/like/", {:collection_id => conversation.id, :lftoken => user.token} if response.success? true else raise APIException.new(response.body) end end |
#source ⇒ Object
Public: Get the comment source as a string.
Currently only populated when created via ::create
Returns [Enum<SOURCES>]
80 81 82 |
# File 'lib/livefyre/comment.rb', line 80 def source source_id ? SOURCES[source_id] : nil end |
#source_id ⇒ Object
Public: Get the comment source as an integer.
Currently only populated when created via ::create
Returns [Integer]
88 89 90 |
# File 'lib/livefyre/comment.rb', line 88 def source_id @options[:source] end |
#to_s ⇒ Object
Internal: Returns a cleaner string representation of this object
Returns [String] representation of this class
186 187 188 |
# File 'lib/livefyre/comment.rb', line 186 def to_s "#<#{self.class.name}:0x#{object_id.to_s(16).rjust(14, "0")} id='#{id}' options=#{@options.inspect}>" end |
#unlike!(user) ⇒ Object
Public: Unlikes a comment as the passed user
Returns [Boolean] true on success Raises [APIException] on failure
141 142 143 144 145 146 147 148 |
# File 'lib/livefyre/comment.rb', line 141 def unlike!(user) response = @client.quill.post "/api/v3.0/message/#{id}/unlike/", {:collection_id => conversation.id, :lftoken => user.token} if response.success? true else raise APIException.new(response.body) end end |
#update(body) ⇒ Object
Public: Update this comment’s content
Returns [Boolean] true on success Raises [APIException] on failure
67 68 69 70 71 72 73 74 |
# File 'lib/livefyre/comment.rb', line 67 def update(body) response = client.quill.post "/api/v3.0/message/#{id}/edit", {:lftoken => @client.system_token, :body => body} if response.success? true else raise APIException.new(response.body) end end |
#visibility ⇒ Object
Public: Get the comment visibility as a string.
Currently only populated when created via ::create
Returns [Enum<VISIBILITIES>]
96 97 98 |
# File 'lib/livefyre/comment.rb', line 96 def visibility visibility_id ? VISIBILITIES[visibility_id] : nil end |
#visibility_id ⇒ Object
Public: Get the comment visibility as an integer.
Currently only populated when created via ::create
Returns [Integer]
104 105 106 |
# File 'lib/livefyre/comment.rb', line 104 def visibility_id @options[:visibility] end |