Class: ReplTalk::Post
- Inherits:
-
Object
- Object
- ReplTalk::Post
- Defined in:
- lib/repltalk/structures.rb
Instance Attribute Summary collapse
-
#answer ⇒ Object
readonly
Returns the value of attribute answer.
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#can_vote ⇒ Object
readonly
Returns the value of attribute can_vote.
-
#comment_count ⇒ Object
readonly
Returns the value of attribute comment_count.
-
#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_announcement ⇒ Object
readonly
Returns the value of attribute is_announcement.
-
#is_answerable ⇒ Object
readonly
Returns the value of attribute is_answerable.
-
#is_answered ⇒ Object
readonly
Returns the value of attribute is_answered.
-
#is_hidden ⇒ Object
readonly
Returns the value of attribute is_hidden.
-
#is_locked ⇒ Object
readonly
Returns the value of attribute is_locked.
-
#is_pinned ⇒ Object
readonly
Returns the value of attribute is_pinned.
-
#preview ⇒ Object
readonly
Returns the value of attribute preview.
-
#repl ⇒ Object
readonly
Returns the value of attribute repl.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#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(title: @title, content: @content, repl_id: @repl.id, show_hosted: false) ⇒ Object
- #get_comments(order: "new", count: nil, after: nil) ⇒ Object
- #get_upvotes(count: nil) ⇒ Object
-
#initialize(client, post) ⇒ Post
constructor
A new instance of Post.
- #report(reason) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(client, post) ⇒ Post
Returns a new instance of Post.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/repltalk/structures.rb', line 360 def initialize(client, post) @client = client @id = post["id"] @url = $BASE_URL + post["url"] @title = post["title"] @timestamp = post["timeCreated"] @board = post["board"].nil? ? nil : Board.new(post["board"]) @repl = post["repl"] == nil ? nil : Repl.new(@client, post["repl"]) @author = post["user"] == nil ? nil : User.new(@client, post["user"]) @answer = post["answer"] == nil ? nil : Comment.new(@client, post["answer"]) @content = post["body"] @preview = post["preview"] if @content == "" && @repl != nil # new post type if post["replComment"].nil? # no post attached @url = @repl.url @title = @repl.title @content = @repl.description else # post attached @url = "#{@repl.url}?c=#{post["replComment"]["id"]}" @content = post["replComment"]["body"] end @preview = @content.length > 150 ? @content[0..150] : @content end @vote_count = post["voteCount"] @comment_count = post["commentCount"] @can_vote = post["canVote"] @has_voted = post["hasVoted"] @is_answered = post["isAnswered"] @is_answerable = post["isAnswerable"] @is_hidden = post["isHidden"] @is_pinned = post["isPinned"] @is_locked = post["isLocked"] @is_announcement = post["isAnnouncement"] end |
Instance Attribute Details
#answer ⇒ Object (readonly)
Returns the value of attribute answer.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def answer @answer end |
#author ⇒ Object (readonly)
Returns the value of attribute author.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def @author end |
#board ⇒ Object (readonly)
Returns the value of attribute board.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def board @board end |
#can_vote ⇒ Object (readonly)
Returns the value of attribute can_vote.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def can_vote @can_vote end |
#comment_count ⇒ Object (readonly)
Returns the value of attribute comment_count.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def comment_count @comment_count end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def content @content end |
#has_voted ⇒ Object (readonly)
Returns the value of attribute has_voted.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def has_voted @has_voted end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def id @id end |
#is_announcement ⇒ Object (readonly)
Returns the value of attribute is_announcement.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def is_announcement @is_announcement end |
#is_answerable ⇒ Object (readonly)
Returns the value of attribute is_answerable.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def is_answerable @is_answerable end |
#is_answered ⇒ Object (readonly)
Returns the value of attribute is_answered.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def is_answered @is_answered end |
#is_hidden ⇒ Object (readonly)
Returns the value of attribute is_hidden.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def is_hidden @is_hidden end |
#is_locked ⇒ Object (readonly)
Returns the value of attribute is_locked.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def is_locked @is_locked end |
#is_pinned ⇒ Object (readonly)
Returns the value of attribute is_pinned.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def is_pinned @is_pinned end |
#preview ⇒ Object (readonly)
Returns the value of attribute preview.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def preview @preview end |
#repl ⇒ Object (readonly)
Returns the value of attribute repl.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def repl @repl end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def @timestamp end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def url @url end |
#vote_count ⇒ Object (readonly)
Returns the value of attribute vote_count.
358 359 360 |
# File 'lib/repltalk/structures.rb', line 358 def vote_count @vote_count end |
Instance Method Details
#create_comment(content) ⇒ Object
425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/repltalk/structures.rb', line 425 def create_comment(content) c = @client.graphql( "createComment", GQL::Mutations::CREATE_COMMENT, input: { postId: @id, body: content } ) Comment.new(@client, c["createComment"]["comment"]) end |
#delete ⇒ Object
452 453 454 455 456 457 458 459 |
# File 'lib/repltalk/structures.rb', line 452 def delete @client.graphql( "deletePost", GQL::Mutations::DELETE_POST, id: @id ) nil end |
#edit(title: @title, content: @content, repl_id: @repl.id, show_hosted: false) ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/repltalk/structures.rb', line 437 def edit(title: @title, content: @content, repl_id: @repl.id, show_hosted: false) p = @client.graphql( "updatePost", GQL::Mutations::EDIT_POST, input: { id: @id, title: title, body: content, replId: repl_id, showHosted: show_hosted } ) Post.new(@client, p["updatePost"]["post"]) end |
#get_comments(order: "new", count: nil, after: nil) ⇒ Object
403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/repltalk/structures.rb', line 403 def get_comments(order: "new", count: nil, after: nil) c = @client.graphql( "post", GQL::Queries::GET_POSTS_COMMENTS, postId: @id, order: order, count: count, after: after ) c["post"]["comments"]["items"].map { |comment| Comment.new(@client, comment) } end |
#get_upvotes(count: nil) ⇒ Object
415 416 417 418 419 420 421 422 423 |
# File 'lib/repltalk/structures.rb', line 415 def get_upvotes(count: nil) u = @client.graphql( "post", GQL::Queries::GET_POSTS_UPVOTERS, id: @id, count: count ) u["post"]["votes"]["items"].map { |vote| User.new(@client, vote["user"]) } end |
#report(reason) ⇒ Object
461 462 463 464 465 466 467 468 469 |
# File 'lib/repltalk/structures.rb', line 461 def report(reason) @client.graphql( "createBoardReport", GQL::Mutations::REPORT_POST, id: @id, reason: reason ) nil end |
#to_s ⇒ Object
471 472 473 |
# File 'lib/repltalk/structures.rb', line 471 def to_s @title end |