Class: ReplTalk::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/repltalk/structures.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#authorObject (readonly)

Returns the value of attribute author.



261
262
263
# File 'lib/repltalk/structures.rb', line 261

def author
  @author
end

#can_voteObject (readonly)

Returns the value of attribute can_vote.



261
262
263
# File 'lib/repltalk/structures.rb', line 261

def can_vote
  @can_vote
end

#contentObject (readonly)

Returns the value of attribute content.



261
262
263
# File 'lib/repltalk/structures.rb', line 261

def content
  @content
end

#has_votedObject (readonly)

Returns the value of attribute has_voted.



261
262
263
# File 'lib/repltalk/structures.rb', line 261

def has_voted
  @has_voted
end

#idObject (readonly)

Returns the value of attribute id.



261
262
263
# File 'lib/repltalk/structures.rb', line 261

def id
  @id
end

#is_answerObject (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_idObject (readonly)

Returns the value of attribute post_id.



261
262
263
# File 'lib/repltalk/structures.rb', line 261

def post_id
  @post_id
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



261
262
263
# File 'lib/repltalk/structures.rb', line 261

def timestamp
  @timestamp
end

#urlObject (readonly)

Returns the value of attribute url.



261
262
263
# File 'lib/repltalk/structures.rb', line 261

def url
  @url
end

#vote_countObject (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

#deleteObject



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_commentsObject



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_parentObject



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_postObject



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_sObject



350
351
352
# File 'lib/repltalk/structures.rb', line 350

def to_s
	@content
end