repltalk 1.0.1 → 2.0.1

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 +135 -0
  3. data/lib/repltalk.rb +185 -16
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74d0fb4fc93b281bb6c09286ef8b892019295e7f223861c699fbdc4525a25951
4
- data.tar.gz: 6532d944f19ac0aaaa7f4229fff5a5402b8ec114af6ad09158015e019af5e4f2
3
+ metadata.gz: ada3715121c7d61ea64ba460d56d128540495ad5d0e6e40f7b2b3356449a6928
4
+ data.tar.gz: f514edbaeb4ffe4bfd90b5d9821329349e5c917d70e7cc91f32c9ce4d74d9684
5
5
  SHA512:
6
- metadata.gz: 30fcdd93403ec9802117b93a7fad9fb106e883d30554988f0d67ef1f0edff706a0ae4fd1eb46de785df116bb0fee99ca3814d3b903dd54a337b31350b25d43df
7
- data.tar.gz: 846e42e9b4665420458dc1c97fd028ae95814a09c78d0a26011ad96547b71ade0ee12ae83dd957c51fcb9a53bd3f29c98c57040ddd6596ff892005f721ca9827
6
+ metadata.gz: 32cf8cc7d8d8bbcee551ef1fe73ddc1c54102a655fc26d0ea465e77f576ee297f446b4ec9314a9a7e198b9ad9e0566743491a4a52905c3f4ea4e318901b3243f
7
+ data.tar.gz: a06595ab22910394812a9144bae621a90570a110785c1d5acf1964e8c58737a3d8d0c2b5847817189c410e4c213b483e53e55960821473d1cd6886d55405e37c
data/lib/queries.rb CHANGED
@@ -298,6 +298,25 @@ class Queries
298
298
  }"
299
299
  end
300
300
 
301
+ def Queries.get_repl_comment
302
+ "query ReplViewComment($id: Int!) {
303
+ replComment(id: $id) {
304
+ ... on ReplComment {
305
+ #{@@repl_comment}
306
+ }
307
+ }
308
+ }"
309
+ end
310
+
311
+
312
+ def Queries.get_board
313
+ "query boardBySlug($slug: String!) {
314
+ board: boardBySlug(slug: $slug) {
315
+ #{@@board}
316
+ }
317
+ }"
318
+ end
319
+
301
320
  def Queries.get_posts
302
321
  "query PostsFeed($order: String, $after: String, $searchQuery: String, $languages: [String!], $count: Int, $boardSlugs: [String!], $pinAnnouncements: Boolean, $pinPinned: Boolean) {
303
322
  posts(order: $order, after: $after, searchQuery: $searchQuery, languages: $languages, count: $count, boardSlugs: $boardSlugs, pinAnnouncements: $pinAnnouncements, pinPinned: $pinPinned) {
@@ -318,4 +337,120 @@ class Queries
318
337
  }
319
338
  }"
320
339
  end
340
+ end
341
+
342
+
343
+ class Mutations < Queries
344
+ def Mutations.create_post
345
+ "mutation createPost($input: CreatePostInput!) {
346
+ createPost(input: $input) {
347
+ post {
348
+ #{@@post}
349
+ }
350
+ }
351
+ }"
352
+ end
353
+
354
+ def Mutations.edit_post
355
+ "mutation updatePost($input: UpdatePostInput!) {
356
+ updatePost(input: $input) {
357
+ post {
358
+ #{@@post}
359
+ }
360
+ }
361
+ }
362
+ "
363
+ end
364
+
365
+ def Mutations.delete_post
366
+ "mutation deletePost($id: Int!) {
367
+ deletePost(id: $id) {
368
+ id
369
+ }
370
+ }"
371
+ end
372
+
373
+ def Mutations.create_comment
374
+ "mutation createComment($input: CreateCommentInput!) {
375
+ createComment(input: $input) {
376
+ comment {
377
+ #{@@comment}
378
+ }
379
+ }
380
+ }"
381
+ end
382
+
383
+ def Mutations.edit_comment
384
+ "mutation updateComment($input: UpdateCommentInput!) {
385
+ updateComment(input: $input) {
386
+ comment {
387
+ #{@@comment}
388
+ }
389
+ }
390
+ }"
391
+ end
392
+
393
+ def Mutations.delete_comment
394
+ "mutation deleteComment($id: Int!) {
395
+ deleteComment(id: $id) {
396
+ id
397
+ }
398
+ }"
399
+ end
400
+
401
+ def Mutations.create_repl_comment
402
+ "mutation ReplViewCreateReplComment($input: CreateReplCommentInput!) {
403
+ createReplComment(input: $input) {
404
+ ... on ReplComment {
405
+ #{@@repl_comment}
406
+ }
407
+ }
408
+ }"
409
+ end
410
+
411
+ def Mutations.reply_repl_comment
412
+ "mutation ReplViewCreateReplCommentReply($input: CreateReplCommentReplyInput!) {
413
+ createReplCommentReply(input: $input) {
414
+ ... on ReplComment {
415
+ #{@@repl_comment}
416
+ }
417
+ }
418
+ }"
419
+ end
420
+
421
+ def Mutations.edit_repl_comment
422
+ "mutation ReplViewCommentsUpdateReplComment($input: UpdateReplCommentInput!) {
423
+ updateReplComment(input: $input) {
424
+ ... on ReplComment {
425
+ #{@@repl_comment}
426
+ }
427
+ }
428
+ }"
429
+ end
430
+
431
+ def Mutations.delete_repl_comment
432
+ "mutation ReplViewCommentsDeleteReplComment($id: Int!) {
433
+ deleteReplComment(id: $id) {
434
+ ... on ReplComment {
435
+ id
436
+ }
437
+ }
438
+ }"
439
+ end
440
+
441
+ def Mutations.report_post
442
+ "mutation createBoardReport($id: Int!, $reason: String!) {
443
+ createBoardReport(postId: $id, reason: $reason) {
444
+ id
445
+ }
446
+ }"
447
+ end
448
+
449
+ def Mutations.report_comment
450
+ "mutation createBoardReport($id: Int!, $reason: String!) {
451
+ createBoardReport(commentId: $id, reason: $reason) {
452
+ id
453
+ }
454
+ }"
455
+ end
321
456
  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
 
@@ -89,6 +106,40 @@ class ReplComment
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
+ puts c
131
+ ReplComment.new(@client, c["updateReplComment"])
132
+ end
133
+
134
+ def delete
135
+ @client.graphql(
136
+ "ReplViewCommentsDeleteReplComment",
137
+ Mutations.delete_repl_comment,
138
+ id: @id
139
+ )
140
+ nil
141
+ end
142
+
92
143
  def to_s
93
144
  @content
94
145
  end
@@ -138,25 +189,20 @@ class Repl
138
189
  c["repl"]["comments"]["items"].map { |comment| ReplComment.new(@client, comment) }
139
190
  end
140
191
 
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"]
192
+ def create_comment(content)
193
+ c = @client.graphql(
194
+ "ReplViewCreateReplComment",
195
+ Mutations.create_repl_comment,
196
+ input: {
197
+ replId: @id,
198
+ body: content
199
+ }
200
+ )
201
+ ReplComment.new(@client, c["createReplComment"])
156
202
  end
157
203
 
158
204
  def to_s
159
- @name
205
+ @title
160
206
  end
161
207
  end
162
208
 
@@ -208,6 +254,50 @@ class Comment
208
254
  c["comment"]["parentComment"] == nil ? nil : Comment.new(@client, c["comment"]["parentComment"])
209
255
  end
210
256
 
257
+ def create_comment(content)
258
+ c = @client.graphql(
259
+ "createComment",
260
+ Mutations.create_comment,
261
+ input: {
262
+ postId: @post_id,
263
+ commentId: @id,
264
+ body: content
265
+ }
266
+ )
267
+ Comment.new(@client, c["createComment"]["comment"])
268
+ end
269
+
270
+ def edit(content)
271
+ c = @client.graphql(
272
+ "updateComment",
273
+ Mutations.edit_comment,
274
+ input: {
275
+ id: @id,
276
+ body: content
277
+ }
278
+ )
279
+ Comment.new(@client, c["updateComment"]["comment"])
280
+ end
281
+
282
+ def delete
283
+ @client.graphql(
284
+ "deleteComment",
285
+ Mutations.delete_comment,
286
+ id: @id
287
+ )
288
+ nil
289
+ end
290
+
291
+ def report(reason)
292
+ @client.graphql(
293
+ "createBoardReport",
294
+ Mutations.report_comment,
295
+ id: @id,
296
+ reason: reason
297
+ )
298
+ nil
299
+ end
300
+
211
301
  def to_s
212
302
  @content
213
303
  end
@@ -270,6 +360,52 @@ class Post
270
360
  u["post"]["votes"]["items"].map { |vote| User.new(@client, vote["user"]) }
271
361
  end
272
362
 
363
+ def create_comment(content)
364
+ c = @client.graphql(
365
+ "createComment",
366
+ Mutations.create_comment,
367
+ input: {
368
+ postId: @id,
369
+ body: content
370
+ }
371
+ )
372
+ Comment.new(@client, c["createComment"]["comment"])
373
+ end
374
+
375
+ def edit(title: @title, content: @content, repl_id: @repl.id, show_hosted: false)
376
+ p = @client.graphql(
377
+ "updatePost",
378
+ Mutations.edit_post,
379
+ input: {
380
+ id: @id,
381
+ title: title,
382
+ body: content,
383
+ replId: repl_id,
384
+ showHosted: show_hosted
385
+ }
386
+ )
387
+ Post.new(@client, p["updatePost"]["post"])
388
+ end
389
+
390
+ def delete
391
+ @client.graphql(
392
+ "deletePost",
393
+ Mutations.delete_post,
394
+ id: @id
395
+ )
396
+ nil
397
+ end
398
+
399
+ def report(reason)
400
+ @client.graphql(
401
+ "createBoardReport",
402
+ Mutations.report_post,
403
+ id: @id,
404
+ reason: reason
405
+ )
406
+ nil
407
+ end
408
+
273
409
  def to_s
274
410
  @title
275
411
  end
@@ -438,6 +574,24 @@ class Client
438
574
  Repl.new(self, r["repl"])
439
575
  end
440
576
 
577
+ def get_repl_comment(id)
578
+ c = graphql(
579
+ "ReplViewComment",
580
+ Queries.get_repl_comment,
581
+ id: id
582
+ )
583
+ ReplComment.new(self, c["replComment"])
584
+ end
585
+
586
+ def get_board(name)
587
+ b = graphql(
588
+ "boardBySlug",
589
+ Queries.get_board,
590
+ slug: name
591
+ )
592
+ Board.new(b["board"])
593
+ end
594
+
441
595
  def get_leaderboard(count: nil, since: nil, after: nil)
442
596
  u = graphql(
443
597
  "LeaderboardQuery",
@@ -462,4 +616,19 @@ class Client
462
616
  )
463
617
  p["posts"]["items"].map { |post| Post.new(self, post) }
464
618
  end
619
+
620
+ def create_post(board_name, title, content, repl_id: nil, show_hosted: false)
621
+ p = graphql(
622
+ "createPost",
623
+ Mutations.create_post,
624
+ input: {
625
+ boardId: get_board(board_name).id,
626
+ title: title,
627
+ body: content,
628
+ replId: repl_id,
629
+ showHosted: show_hosted
630
+ }
631
+ )
632
+ Post.new(self, p["createPost"]["post"])
633
+ end
465
634
  end
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.0.1
4
+ version: 2.0.1
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-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http