repltalk 1.3.0 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/queries.rb +71 -2
  3. data/lib/repltalk.rb +102 -20
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ade4342442037dfec06df6d42dc4fb825aa0ae28020a9a65a8cc6072ff1d5a83
4
- data.tar.gz: eabb22b821d0170bbec6a1cdcf1a9b8ab877d7cf5c746796ed56d098fa07b23f
3
+ metadata.gz: f7698843f4821cfa70c70212835ca464d12aef28d561f918f95d644f3c4656b7
4
+ data.tar.gz: 6386104c0526471dc1501e90e2f9cbfd22efef4a8de53c0490b1942478283815
5
5
  SHA512:
6
- metadata.gz: 8e1d95df4fa09ec118ee4d82115652831fded6cb0b9b55b09045d68f7ff0cc48c975a28de0b6e207de5d786c8ebc3f1482cdf4225b80f06baf407074e10b264c
7
- data.tar.gz: fc16a9bccab5cca65fa7041b9dce1720198d686582a47beb64310c0b6eb3d5e5359685bfbdd5120366d3df797608468e11040b9d5fce1cdaa32d98dd126ad7c7
6
+ metadata.gz: d3803dcf7ec09ecbbb63fd4819f48f4464138264a462e384a923747374525c37764e3f50fcdc796e7d581602179d24e0b9d3e93b5507d4020ebbb13a3846145a
7
+ data.tar.gz: ee2a048806996c587420ca9a6ec33a9ab45de7a357c8e0c61c177b628bfe9796d75396da0d6e3746b3ec9125ac0700757679fb35dc987c73ace13c8ba31ba8e5
data/lib/queries.rb CHANGED
@@ -1,4 +1,4 @@
1
- class Queries
1
+ class Fields
2
2
  @@roles = "
3
3
  id
4
4
  name
@@ -141,8 +141,10 @@ class Queries
141
141
  #{@@comment}
142
142
  }
143
143
  "
144
+ end
144
145
 
145
146
 
147
+ class Queries < Fields
146
148
  def Queries.get_user
147
149
  "query userByUsername($username: String!) {
148
150
  user: userByUsername(username: $username) {
@@ -298,6 +300,17 @@ class Queries
298
300
  }"
299
301
  end
300
302
 
303
+ def Queries.get_repl_comment
304
+ "query ReplViewComment($id: Int!) {
305
+ replComment(id: $id) {
306
+ ... on ReplComment {
307
+ #{@@repl_comment}
308
+ }
309
+ }
310
+ }"
311
+ end
312
+
313
+
301
314
  def Queries.get_board
302
315
  "query boardBySlug($slug: String!) {
303
316
  board: boardBySlug(slug: $slug) {
@@ -329,7 +342,7 @@ class Queries
329
342
  end
330
343
 
331
344
 
332
- class Mutations < Queries
345
+ class Mutations < Fields
333
346
  def Mutations.create_post
334
347
  "mutation createPost($input: CreatePostInput!) {
335
348
  createPost(input: $input) {
@@ -386,4 +399,60 @@ class Mutations < Queries
386
399
  }
387
400
  }"
388
401
  end
402
+
403
+ def Mutations.create_repl_comment
404
+ "mutation ReplViewCreateReplComment($input: CreateReplCommentInput!) {
405
+ createReplComment(input: $input) {
406
+ ... on ReplComment {
407
+ #{@@repl_comment}
408
+ }
409
+ }
410
+ }"
411
+ end
412
+
413
+ def Mutations.reply_repl_comment
414
+ "mutation ReplViewCreateReplCommentReply($input: CreateReplCommentReplyInput!) {
415
+ createReplCommentReply(input: $input) {
416
+ ... on ReplComment {
417
+ #{@@repl_comment}
418
+ }
419
+ }
420
+ }"
421
+ end
422
+
423
+ def Mutations.edit_repl_comment
424
+ "mutation ReplViewCommentsUpdateReplComment($input: UpdateReplCommentInput!) {
425
+ updateReplComment(input: $input) {
426
+ ... on ReplComment {
427
+ #{@@repl_comment}
428
+ }
429
+ }
430
+ }"
431
+ end
432
+
433
+ def Mutations.delete_repl_comment
434
+ "mutation ReplViewCommentsDeleteReplComment($id: Int!) {
435
+ deleteReplComment(id: $id) {
436
+ ... on ReplComment {
437
+ id
438
+ }
439
+ }
440
+ }"
441
+ end
442
+
443
+ def Mutations.report_post
444
+ "mutation createBoardReport($id: Int!, $reason: String!) {
445
+ createBoardReport(postId: $id, reason: $reason) {
446
+ id
447
+ }
448
+ }"
449
+ end
450
+
451
+ def Mutations.report_comment
452
+ "mutation createBoardReport($id: Int!, $reason: String!) {
453
+ createBoardReport(commentId: $id, reason: $reason) {
454
+ id
455
+ }
456
+ }"
457
+ end
389
458
  end
data/lib/repltalk.rb CHANGED
@@ -76,6 +76,23 @@ end
76
76
 
77
77
 
78
78
 
79
+ class Board
80
+ attr_reader :id, :name, :color, :description
81
+
82
+ def initialize(board)
83
+ @id = board["id"]
84
+ @name = board["name"]
85
+ @color = board["color"]
86
+ @description = board["description"]
87
+ end
88
+
89
+ def to_s
90
+ @name
91
+ end
92
+ end
93
+
94
+
95
+
79
96
  class ReplComment
80
97
  attr_reader :id, :content, :author, :repl, :replies
81
98
 
@@ -84,11 +101,44 @@ class ReplComment
84
101
 
85
102
  @id = comment["id"]
86
103
  @content = comment["body"]
87
- @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
88
- @repl = Repl.new(@client, comment["repl"])
104
+ @author = comment["user"] == nil ? nil : User.new(@client, comment["user"])
105
+ @repl = comment["repl"] == nil ? nil : Repl.new(@client, comment["repl"])
89
106
  @replies = comment["replies"] == nil ? nil : comment["replies"].map { |c| ReplComment.new(@client, c) }
90
107
  end
91
108
 
109
+ def create_comment(content)
110
+ c = @client.graphql(
111
+ "ReplViewCreateReplCommentReply",
112
+ Mutations.reply_repl_comment,
113
+ input: {
114
+ replCommentId: @id,
115
+ body: content
116
+ }
117
+ )
118
+ ReplComment.new(@client, c["createReplCommentReply"])
119
+ end
120
+
121
+ def edit(content)
122
+ c = @client.graphql(
123
+ "ReplViewCommentsUpdateReplComment",
124
+ Mutations.edit_repl_comment,
125
+ input: {
126
+ id: @id,
127
+ body: content
128
+ }
129
+ )
130
+ ReplComment.new(@client, c["updateReplComment"])
131
+ end
132
+
133
+ def delete
134
+ @client.graphql(
135
+ "ReplViewCommentsDeleteReplComment",
136
+ Mutations.delete_repl_comment,
137
+ id: @id
138
+ )
139
+ nil
140
+ end
141
+
92
142
  def to_s
93
143
  @content
94
144
  end
@@ -138,25 +188,20 @@ class Repl
138
188
  c["repl"]["comments"]["items"].map { |comment| ReplComment.new(@client, comment) }
139
189
  end
140
190
 
141
- def to_s
142
- @title
143
- end
144
- end
145
-
146
-
147
-
148
- class Board
149
- attr_reader :id, :name, :color, :description
150
-
151
- def initialize(board)
152
- @id = board["id"]
153
- @name = board["name"]
154
- @color = board["color"]
155
- @description = board["description"]
191
+ def create_comment(content)
192
+ c = @client.graphql(
193
+ "ReplViewCreateReplComment",
194
+ Mutations.create_repl_comment,
195
+ input: {
196
+ replId: @id,
197
+ body: content
198
+ }
199
+ )
200
+ ReplComment.new(@client, c["createReplComment"])
156
201
  end
157
202
 
158
203
  def to_s
159
- @name
204
+ @title
160
205
  end
161
206
  end
162
207
 
@@ -242,6 +287,16 @@ class Comment
242
287
  nil
243
288
  end
244
289
 
290
+ def report(reason)
291
+ @client.graphql(
292
+ "createBoardReport",
293
+ Mutations.report_comment,
294
+ id: @id,
295
+ reason: reason
296
+ )
297
+ nil
298
+ end
299
+
245
300
  def to_s
246
301
  @content
247
302
  end
@@ -264,7 +319,7 @@ class Post
264
319
 
265
320
  @board = Board.new(post["board"])
266
321
  @repl = post["repl"] == nil ? nil : Repl.new(@client, post["repl"])
267
- @author = post["user"] == nil ? "[deleted user]" : User.new(@client, post["user"])
322
+ @author = post["user"] == nil ? nil : User.new(@client, post["user"])
268
323
  @answer = post["answer"] == nil ? nil : Comment.new(@client, post["answer"])
269
324
 
270
325
  @vote_count = post["voteCount"]
@@ -340,6 +395,16 @@ class Post
340
395
  nil
341
396
  end
342
397
 
398
+ def report(reason)
399
+ @client.graphql(
400
+ "createBoardReport",
401
+ Mutations.report_post,
402
+ id: @id,
403
+ reason: reason
404
+ )
405
+ nil
406
+ end
407
+
343
408
  def to_s
344
409
  @title
345
410
  end
@@ -351,6 +416,7 @@ class User
351
416
  attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :timestamp, :subscription, :roles, :organization, :languages
352
417
 
353
418
  def initialize(client, user)
419
+ return nil if user == nil
354
420
  @client = client
355
421
 
356
422
  @id = user["id"]
@@ -469,6 +535,7 @@ class Client
469
535
  Queries.get_user,
470
536
  username: name
471
537
  )
538
+ return nil if u == nil || u["user"] == nil
472
539
  User.new(self, u["user"])
473
540
  end
474
541
 
@@ -478,6 +545,7 @@ class Client
478
545
  Queries.get_user_by_id,
479
546
  user_id: id
480
547
  )
548
+ return nil if u == nil || u["user"] == nil
481
549
  User.new(self, u["user"])
482
550
  end
483
551
 
@@ -487,6 +555,7 @@ class Client
487
555
  Queries.get_post,
488
556
  id: id
489
557
  )
558
+ return nil if p == nil || p["post"] == nil
490
559
  Post.new(self, p["post"])
491
560
  end
492
561
 
@@ -496,6 +565,7 @@ class Client
496
565
  Queries.get_comment,
497
566
  id: id
498
567
  )
568
+ return nil if c == nil || c["comment"] == nil
499
569
  Comment.new(self, c["comment"])
500
570
  end
501
571
 
@@ -505,15 +575,27 @@ class Client
505
575
  Queries.get_repl,
506
576
  url: url
507
577
  )
578
+ return nil if r == nil || r["repl"] == nil
508
579
  Repl.new(self, r["repl"])
509
580
  end
510
581
 
582
+ def get_repl_comment(id)
583
+ c = graphql(
584
+ "ReplViewComment",
585
+ Queries.get_repl_comment,
586
+ id: id
587
+ )
588
+ return nil if c == nil || c["replComment"] == nil
589
+ ReplComment.new(self, c["replComment"])
590
+ end
591
+
511
592
  def get_board(name)
512
593
  b = graphql(
513
594
  "boardBySlug",
514
595
  Queries.get_board,
515
596
  slug: name
516
597
  )
598
+ return nil if b == nil || b["board"] == nil
517
599
  Board.new(b["board"])
518
600
  end
519
601
 
@@ -532,7 +614,7 @@ class Client
532
614
  p = graphql(
533
615
  "PostsFeed",
534
616
  Queries.get_posts,
535
- baordSlugs: [board],
617
+ boardSlugs: [board],
536
618
  order: order,
537
619
  count: count,
538
620
  after: after,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repltalk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - CodingCactus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-07 00:00:00.000000000 Z
11
+ date: 2021-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http