repltalk 1.4.0 → 2.0.5

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 +56 -2
  3. data/lib/repltalk.rb +84 -21
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65d203ef3528fe101026800562c7f63088f16ce6e92fc90227bb023cb4d7301c
4
- data.tar.gz: a26cbd197e3268b40375a8eb435593792b9cabcbf99f560e06a44b5b25af85f8
3
+ metadata.gz: 021bec9878ab43bc85c7c1ef8fb628c34cece2c8643559b2969b955e13694f1a
4
+ data.tar.gz: 519b81ab0f69d8b8f0289ecb85de62bfb5fb4a674f5574e70b5868d98882ef07
5
5
  SHA512:
6
- metadata.gz: 7d77c7ca647951ca694e23786038c1df339d946b80fe9dee70c3897d2c67a4e85616558e9ce941c107c24b49587d896b28553c211e78bd86d524d81aca335497
7
- data.tar.gz: 85e91cdb4b8f7c72951e03dc6de860ac3179635298db19cb7d263256343b76796e3af03f2831f9c4f329c8a95549bc4750881a8bc99f66013b6c1614f2d3f21b
6
+ metadata.gz: 0ff92dcc8ce300ab5c84c0753f51bb8788b695c4da858ec58f9abbf6d11f92f287589a49a36bf2bb346845ffe3d8f954b4113181718b57c86056ff9cb85eca40
7
+ data.tar.gz: fe44468b7671355bdc1b143e9b032472a6715c2b40ebce9a02fbfb0bc1f4d8fe381cc80c5523f59483683465e5b68081352416b738b75741dbfea834a2c9608d
data/lib/queries.rb CHANGED
@@ -1,4 +1,4 @@
1
- class Queries
1
+ class Fields
2
2
  @@roles = "
3
3
  id
4
4
  name
@@ -67,6 +67,7 @@ class Queries
67
67
  url
68
68
  title
69
69
  description
70
+ timeCreated
70
71
  size
71
72
  imageUrl
72
73
  isPrivate
@@ -141,8 +142,10 @@ class Queries
141
142
  #{@@comment}
142
143
  }
143
144
  "
145
+ end
144
146
 
145
147
 
148
+ class Queries < Fields
146
149
  def Queries.get_user
147
150
  "query userByUsername($username: String!) {
148
151
  user: userByUsername(username: $username) {
@@ -298,6 +301,17 @@ class Queries
298
301
  }"
299
302
  end
300
303
 
304
+ def Queries.get_repl_comment
305
+ "query ReplViewComment($id: Int!) {
306
+ replComment(id: $id) {
307
+ ... on ReplComment {
308
+ #{@@repl_comment}
309
+ }
310
+ }
311
+ }"
312
+ end
313
+
314
+
301
315
  def Queries.get_board
302
316
  "query boardBySlug($slug: String!) {
303
317
  board: boardBySlug(slug: $slug) {
@@ -329,7 +343,7 @@ class Queries
329
343
  end
330
344
 
331
345
 
332
- class Mutations < Queries
346
+ class Mutations < Fields
333
347
  def Mutations.create_post
334
348
  "mutation createPost($input: CreatePostInput!) {
335
349
  createPost(input: $input) {
@@ -387,6 +401,46 @@ class Mutations < Queries
387
401
  }"
388
402
  end
389
403
 
404
+ def Mutations.create_repl_comment
405
+ "mutation ReplViewCreateReplComment($input: CreateReplCommentInput!) {
406
+ createReplComment(input: $input) {
407
+ ... on ReplComment {
408
+ #{@@repl_comment}
409
+ }
410
+ }
411
+ }"
412
+ end
413
+
414
+ def Mutations.reply_repl_comment
415
+ "mutation ReplViewCreateReplCommentReply($input: CreateReplCommentReplyInput!) {
416
+ createReplCommentReply(input: $input) {
417
+ ... on ReplComment {
418
+ #{@@repl_comment}
419
+ }
420
+ }
421
+ }"
422
+ end
423
+
424
+ def Mutations.edit_repl_comment
425
+ "mutation ReplViewCommentsUpdateReplComment($input: UpdateReplCommentInput!) {
426
+ updateReplComment(input: $input) {
427
+ ... on ReplComment {
428
+ #{@@repl_comment}
429
+ }
430
+ }
431
+ }"
432
+ end
433
+
434
+ def Mutations.delete_repl_comment
435
+ "mutation ReplViewCommentsDeleteReplComment($id: Int!) {
436
+ deleteReplComment(id: $id) {
437
+ ... on ReplComment {
438
+ id
439
+ }
440
+ }
441
+ }"
442
+ end
443
+
390
444
  def Mutations.report_post
391
445
  "mutation createBoardReport($id: Int!, $reason: String!) {
392
446
  createBoardReport(postId: $id, reason: $reason) {
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
@@ -97,7 +147,7 @@ end
97
147
 
98
148
 
99
149
  class Repl
100
- attr_reader :id, :url, :title, :author, :description, :size, :language, :img_url, :origin_url, :is_private, :is_always_on
150
+ attr_reader :id, :url, :title, :author, :description, :timestamp, :size, :language, :img_url, :origin_url, :is_private, :is_always_on
101
151
 
102
152
  def initialize(client, repl)
103
153
  @client = client
@@ -107,6 +157,7 @@ class Repl
107
157
  @title = repl["title"]
108
158
  @author = User.new(@client, repl["user"])
109
159
  @description = repl["description"]
160
+ @timestamp = repl["timeCreated"]
110
161
  @size = repl["size"]
111
162
  @language = Language.new(repl["lang"])
112
163
  @image_url = repl["imageUrl"]
@@ -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
 
@@ -274,7 +320,7 @@ class Post
274
320
 
275
321
  @board = Board.new(post["board"])
276
322
  @repl = post["repl"] == nil ? nil : Repl.new(@client, post["repl"])
277
- @author = post["user"] == nil ? "[deleted user]" : User.new(@client, post["user"])
323
+ @author = post["user"] == nil ? nil : User.new(@client, post["user"])
278
324
  @answer = post["answer"] == nil ? nil : Comment.new(@client, post["answer"])
279
325
 
280
326
  @vote_count = post["voteCount"]
@@ -371,6 +417,7 @@ class User
371
417
  attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :timestamp, :subscription, :roles, :organization, :languages
372
418
 
373
419
  def initialize(client, user)
420
+ return nil if user == nil
374
421
  @client = client
375
422
 
376
423
  @id = user["id"]
@@ -489,6 +536,7 @@ class Client
489
536
  Queries.get_user,
490
537
  username: name
491
538
  )
539
+ return nil if u == nil || u["user"] == nil
492
540
  User.new(self, u["user"])
493
541
  end
494
542
 
@@ -498,6 +546,7 @@ class Client
498
546
  Queries.get_user_by_id,
499
547
  user_id: id
500
548
  )
549
+ return nil if u == nil || u["user"] == nil
501
550
  User.new(self, u["user"])
502
551
  end
503
552
 
@@ -507,6 +556,7 @@ class Client
507
556
  Queries.get_post,
508
557
  id: id
509
558
  )
559
+ return nil if p == nil || p["post"] == nil
510
560
  Post.new(self, p["post"])
511
561
  end
512
562
 
@@ -516,6 +566,7 @@ class Client
516
566
  Queries.get_comment,
517
567
  id: id
518
568
  )
569
+ return nil if c == nil || c["comment"] == nil
519
570
  Comment.new(self, c["comment"])
520
571
  end
521
572
 
@@ -525,15 +576,27 @@ class Client
525
576
  Queries.get_repl,
526
577
  url: url
527
578
  )
579
+ return nil if r == nil || r["repl"] == nil
528
580
  Repl.new(self, r["repl"])
529
581
  end
530
582
 
583
+ def get_repl_comment(id)
584
+ c = graphql(
585
+ "ReplViewComment",
586
+ Queries.get_repl_comment,
587
+ id: id
588
+ )
589
+ return nil if c == nil || c["replComment"] == nil
590
+ ReplComment.new(self, c["replComment"])
591
+ end
592
+
531
593
  def get_board(name)
532
594
  b = graphql(
533
595
  "boardBySlug",
534
596
  Queries.get_board,
535
597
  slug: name
536
598
  )
599
+ return nil if b == nil || b["board"] == nil
537
600
  Board.new(b["board"])
538
601
  end
539
602
 
@@ -552,7 +615,7 @@ class Client
552
615
  p = graphql(
553
616
  "PostsFeed",
554
617
  Queries.get_posts,
555
- baordSlugs: [board],
618
+ boardSlugs: [board],
556
619
  order: order,
557
620
  count: count,
558
621
  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.4.0
4
+ version: 2.0.5
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-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http