Class: Livefyre::Comment
- Inherits:
-
Object
- Object
- Livefyre::Comment
- Defined in:
- lib/livefyre/comment.rb
Overview
Proxy object for a [Comment] on a [Livefyre::Conversation]
Constant Summary
Instance Attribute Summary (collapse)
- - (Object) body
- - (Object) conversation
- - (Object) created_at
- - (Object) id
- - (Object) ip
- - (Object) parent_id
- - (Object) user
Class Method Summary (collapse)
-
+ (Comment) create(client, user, conversation, body, reply_to = nil)
create a new comment on a conversation.
Instance Method Summary (collapse)
-
- (Enum<CONTENT_TYPES>) content_type
Get the comment content type as a string.
-
- (Integer) content_type_id
Get the comment visibility as an integer.
-
- (Boolean) delete!
Delete this comment.
-
- (Object) flag(reason, notes, email, user = nil)
Flag a comment.
-
- (Comment) initialize(id, conversation, options = {})
constructor
A new instance of Comment.
-
- (Boolean) like!(user)
Likes a comment as the passed user.
-
- (Enum<SOURCES>) source
Get the comment source as a string.
-
- (Integer) source_id
Get the comment source as an integer.
-
- (String) to_s
private
Returns a cleaner string representation of this object.
-
- (Boolean) unlike!(user)
Unlikes a comment as the passed user.
-
- (Boolean) update(body)
Update this comment's content.
-
- (Enum<VISIBILITIES>) visibility
Get the comment visibility as a string.
-
- (Integer) visibility_id
Get the comment visibility as an integer.
Constructor Details
- (Comment) initialize(id, conversation, options = {})
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
- (Object) body
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def body @body end |
- (Object) conversation
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def conversation @conversation end |
- (Object) created_at
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def created_at @created_at end |
- (Object) id
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def id @id end |
- (Object) ip
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def ip @ip end |
- (Object) parent_id
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def parent_id @parent_id end |
- (Object) user
13 14 15 |
# File 'lib/livefyre/comment.rb', line 13 def user @user end |
Class Method Details
+ (Comment) create(client, user, conversation, body, reply_to = nil)
create a new comment on a conversation
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
- (Enum<CONTENT_TYPES>) content_type
Get the comment content type as a string.
Currently only populated when created via ::create
112 113 114 |
# File 'lib/livefyre/comment.rb', line 112 def content_type content_type_id ? CONTENT_TYPES[content_type_id] : nil end |
- (Integer) content_type_id
Get the comment visibility as an integer.
Currently only populated when created via ::create
120 121 122 |
# File 'lib/livefyre/comment.rb', line 120 def content_type_id @options[:type] end |
- (Boolean) delete!
Delete this comment
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 |
- (Object) flag(reason, notes, email, user = nil)
Flag a comment
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 |
- (Boolean) like!(user)
Likes a comment as the passed user
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 |
- (Enum<SOURCES>) source
Get the comment source as a string.
Currently only populated when created via ::create
80 81 82 |
# File 'lib/livefyre/comment.rb', line 80 def source source_id ? SOURCES[source_id] : nil end |
- (Integer) source_id
Get the comment source as an integer.
Currently only populated when created via ::create
88 89 90 |
# File 'lib/livefyre/comment.rb', line 88 def source_id @options[:source] end |
- (String) to_s
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a cleaner string representation of this object
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 |
- (Boolean) unlike!(user)
Unlikes a comment as the passed user
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 |
- (Boolean) update(body)
Update this comment's content
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 |
- (Enum<VISIBILITIES>) visibility
Get the comment visibility as a string.
Currently only populated when created via ::create
96 97 98 |
# File 'lib/livefyre/comment.rb', line 96 def visibility visibility_id ? VISIBILITIES[visibility_id] : nil end |
- (Integer) visibility_id
Get the comment visibility as an integer.
Currently only populated when created via ::create
104 105 106 |
# File 'lib/livefyre/comment.rb', line 104 def visibility_id @options[:visibility] end |