Class: ReplTalk::Comment
- Inherits:
-
Object
- Object
- ReplTalk::Comment
- Defined in:
- lib/repltalk/structures.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#can_vote ⇒ Object
readonly
Returns the value of attribute can_vote.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#has_voted ⇒ Object
readonly
Returns the value of attribute has_voted.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#is_answer ⇒ Object
readonly
Returns the value of attribute is_answer.
-
#post_id ⇒ Object
readonly
Returns the value of attribute post_id.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#vote_count ⇒ Object
readonly
Returns the value of attribute vote_count.
Instance Method Summary collapse
- #create_comment(content) ⇒ Object
- #delete ⇒ Object
- #edit(content) ⇒ Object
- #get_comments ⇒ Object
- #get_parent ⇒ Object
- #get_post ⇒ Object
-
#initialize(client, comment) ⇒ Comment
constructor
A new instance of Comment.
- #report(reason) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(client, comment) ⇒ Comment
Returns a new instance of Comment.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/repltalk/structures.rb', line 263 def initialize(client, comment) @client = client @id = comment["id"] @url = $BASE_URL + comment["url"] @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"]) @content = comment["body"] @post_id = comment["post"]["id"] @is_answer = comment["isAnswer"] @vote_count = comment["voteCount"] @timestamp = comment["timeCreated"] @can_vote = comment["canVote"] @has_voted = comment["hasVoted"] end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
261 262 263 |
# File 'lib/repltalk/structures.rb', line 261 def @author end |
#can_vote ⇒ Object (readonly)
Returns the value of attribute can_vote.
261 262 263 |
# File 'lib/repltalk/structures.rb', line 261 def can_vote @can_vote end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
261 262 263 |
# File 'lib/repltalk/structures.rb', line 261 def content @content end |
#has_voted ⇒ Object (readonly)
Returns the value of attribute has_voted.
261 262 263 |
# File 'lib/repltalk/structures.rb', line 261 def has_voted @has_voted end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
261 262 263 |
# File 'lib/repltalk/structures.rb', line 261 def id @id end |
#is_answer ⇒ Object (readonly)
Returns the value of attribute is_answer.
261 262 263 |
# File 'lib/repltalk/structures.rb', line 261 def is_answer @is_answer end |
#post_id ⇒ Object (readonly)
Returns the value of attribute post_id.
261 262 263 |
# File 'lib/repltalk/structures.rb', line 261 def post_id @post_id end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
261 262 263 |
# File 'lib/repltalk/structures.rb', line 261 def @timestamp end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
261 262 263 |
# File 'lib/repltalk/structures.rb', line 261 def url @url end |
#vote_count ⇒ Object (readonly)
Returns the value of attribute vote_count.
261 262 263 |
# File 'lib/repltalk/structures.rb', line 261 def vote_count @vote_count end |
Instance Method Details
#create_comment(content) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/repltalk/structures.rb', line 306 def create_comment(content) c = @client.graphql( "createComment", GQL::Mutations::CREATE_COMMENT, input: { postId: @post_id, commentId: @id, body: content } ) Comment.new(@client, c["createComment"]["comment"]) end |
#delete ⇒ Object
331 332 333 334 335 336 337 338 |
# File 'lib/repltalk/structures.rb', line 331 def delete @client.graphql( "deleteComment", GQL::Mutations::DELETE_COMMENT, id: @id ) nil end |
#edit(content) ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/repltalk/structures.rb', line 319 def edit(content) c = @client.graphql( "updateComment", GQL::Mutations::EDIT_COMMENT, input: { id: @id, body: content } ) Comment.new(@client, c["updateComment"]["comment"]) end |
#get_comments ⇒ Object
288 289 290 291 292 293 294 295 |
# File 'lib/repltalk/structures.rb', line 288 def get_comments c = @client.graphql( "comment", GQL::Queries::GET_COMMENTS_COMMENTS, id: @id ) c["comment"]["comments"].map { |comment| Comment.new(@client, comment) } end |
#get_parent ⇒ Object
297 298 299 300 301 302 303 304 |
# File 'lib/repltalk/structures.rb', line 297 def get_parent c = @client.graphql( "comment", GQL::Queries::GET_PARENT_COMMENT, id: @id ) c["comment"]["parentComment"] == nil ? nil : Comment.new(@client, c["comment"]["parentComment"]) end |
#get_post ⇒ Object
279 280 281 282 283 284 285 286 |
# File 'lib/repltalk/structures.rb', line 279 def get_post p = @client.graphql( "post", GQL::Queries::GET_POST, id: @post_id ) Post.new(@client, p["post"]) end |
#report(reason) ⇒ Object
340 341 342 343 344 345 346 347 348 |
# File 'lib/repltalk/structures.rb', line 340 def report(reason) @client.graphql( "createBoardReport", GQL::Mutations::REPORT_COMMENT, id: @id, reason: reason ) nil end |
#to_s ⇒ Object
350 351 352 |
# File 'lib/repltalk/structures.rb', line 350 def to_s @content end |