repltalk 0.3.0 → 0.5.0

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 +223 -480
  3. data/lib/repltalk.rb +145 -14
  4. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85e8d796ec5d9532272e6ffb20cfa6881e49a38990c13ec58b0f6126974c7d2b
4
- data.tar.gz: 2a9f9217d0af746f6dcec692e498c248480d68a8f8e1c2851eefa50a07933326
3
+ metadata.gz: 4becb6db34fded69130f61fe1c0bee4eadd9d9aa2e1e832c48f84a51e48f013d
4
+ data.tar.gz: 348eb30ee7f72b57de14f7a3edcd6b99d0c4b48bee827e29e540e30aaafbb4c9
5
5
  SHA512:
6
- metadata.gz: 449d1a9f1f3a0af88d2d4ab6c316f73f437db0f6fca7d521fdc46b66ad783a2f305fc62ea5f72e2b9624a8a0529e026a8ca590f2ca39a161dc0e8ae41daa0aeb
7
- data.tar.gz: b37f383cb86062cf2f1a9788e4f2c6456d0f155fb9eb49932fbcbb7c5e55f8caa319549dcff10cf25dad845ddc0b06ade7f760c558995aa2c72492e52dad2daa
6
+ metadata.gz: 62fc89da26c4217cdddc3f6c7f472197480f32173d83137189219566b27fe9bdf1559ae77f32df43e43dffd46741cd1a02d582f3f487ab68520f729f0a396536
7
+ data.tar.gz: 899726ce8b541957128993cff59183a8945d4173b5daf02e18fbdb07d38b888d6dbe3132f463471a9793b7a99fe9b63dd611fb3b3c112f776c08ef22fbbd3319
data/lib/queries.rb CHANGED
@@ -1,546 +1,289 @@
1
1
  class Queries
2
- def Queries.get_user
3
- "query userByUsername($username: String!) {
4
- user: userByUsername(username: $username) {
5
- id
6
- username
7
- fullName
8
- image
9
- url
10
- ...ProfileHeaderUser
11
- __typename
12
- }
2
+ @@roles = "
3
+ id
4
+ name
5
+ key
6
+ tagline
7
+ "
8
+
9
+ @@organization = "
10
+ id
11
+ name
12
+ "
13
+
14
+ @@language = "
15
+ id
16
+ key
17
+ displayName
18
+ tagline
19
+ icon
20
+ "
21
+
22
+ @@board = "
23
+ id
24
+ name
25
+ color
26
+ "
27
+
28
+ @@user = "
29
+ id
30
+ fullName
31
+ username
32
+ image
33
+ bio
34
+ karma
35
+ isHacker
36
+ timeCreated
37
+ roles {
38
+ #{@@roles}
39
+ }
40
+ organization {
41
+ #{@@organization}
42
+ }
43
+ languages {
44
+ #{@@language}
13
45
  }
46
+ "
14
47
 
15
- fragment ProfileHeaderUser on User {
48
+ @@repl = "
49
+ id
50
+ url
51
+ title
52
+ description
53
+ imageUrl
54
+ isPrivate
55
+ isAlwaysOn
56
+ lang {
57
+ #{@@language}
58
+ }
59
+ user {
60
+ #{@@user}
61
+ }
62
+ "
63
+
64
+ @@comment = "
65
+ id
66
+ body
67
+ timeCreated
68
+ url
69
+ isAnswer
70
+ voteCount
71
+ canVote
72
+ hasVoted
73
+ user {
74
+ #{@@user}
75
+ }
76
+ post {
16
77
  id
17
- fullName
18
- username
19
- image
20
- bio
21
- karma
22
- isHacker
23
- timeCreated
24
- roles {
25
- id
26
- name
27
- key
28
- tagline
29
- __typename
30
- }
31
- organization {
32
- id
33
- name
34
- __typename
35
- }
36
- languages {
37
- id
38
- key
39
- displayName
40
- tagline
41
- icon
42
- __typename
78
+ }
79
+ "
80
+
81
+ @@repl_comment = "
82
+ id
83
+ body
84
+ timeCreated
85
+ user {
86
+ #{@@user}
87
+ }
88
+ repl {
89
+ #{@@repl}
90
+ }
91
+ "
92
+
93
+ @@post = "
94
+ id
95
+ title
96
+ body
97
+ preview(removeMarkdown: true, length: 150)
98
+ url
99
+ commentCount
100
+ isHidden
101
+ isPinned
102
+ isLocked
103
+ isAnnouncement
104
+ timeCreated
105
+ isAnswered
106
+ isAnswerable
107
+ voteCount
108
+ canVote
109
+ hasVoted
110
+ user {
111
+ #{@@user}
112
+ }
113
+ repl {
114
+ #{@@repl}
115
+ }
116
+ board {
117
+ #{@@board}
118
+ }
119
+ answer {
120
+ #{@@comment}
121
+ }
122
+ "
123
+
124
+
125
+ def Queries.get_user
126
+ "query userByUsername($username: String!) {
127
+ user: userByUsername(username: $username) {
128
+ #{@@user}
43
129
  }
44
- __typename
45
130
  }"
46
131
  end
47
132
 
48
133
  def Queries.get_user_by_id
49
134
  "query user($user_id: Int!) {
50
135
  user: user(id: $user_id) {
51
- id
52
- username
53
- fullName
54
- image
55
- url
56
- ...ProfileHeaderUser
57
- __typename
136
+ #{@@user}
58
137
  }
59
- }
60
-
61
- fragment ProfileHeaderUser on User {
62
- id
63
- fullName
64
- username
65
- image
66
- bio
67
- karma
68
- isHacker
69
- timeCreated
70
- roles {
71
- id
72
- name
73
- key
74
- tagline
75
- __typename
76
- }
77
- organization {
78
- id
79
- name
80
- __typename
81
- }
82
- languages {
83
- id
84
- key
85
- displayName
86
- tagline
87
- icon
88
- __typename
89
- }
90
- __typename
91
138
  }"
92
139
  end
93
140
 
94
141
  def Queries.get_user_posts
95
- "query ProfilePosts($username: String!, $after: String, $order: String, $count: Int) {
142
+ "query user($username: String!, $after: String, $order: String, $count: Int) {
96
143
  user: userByUsername(username: $username) {
97
- id
98
- displayName
99
144
  posts(after: $after, order: $order, count: $count) {
100
145
  items {
101
- id
102
- isHidden
103
- ...PostsFeedItemPost
104
- board {
105
- id
106
- name
107
- url
108
- color
109
- __typename
110
- }
111
- __typename
146
+ #{@@post}
112
147
  }
113
- pageInfo {
114
- nextCursor
115
- __typename
116
- }
117
- __typename
118
148
  }
119
- __typename
120
149
  }
121
- }
122
-
123
- fragment PostsFeedItemPost on Post {
124
- id
125
- title
126
- body
127
- preview(removeMarkdown: true, length: 150)
128
- url
129
- commentCount
130
- isPinned
131
- isLocked
132
- isAnnouncement
133
- timeCreated
134
- isAnswered
135
- isAnswerable
136
- ...PostVoteControlPost
137
- ...PostLinkPost
138
- user {
139
- id
140
- username
141
- isHacker
142
- image
143
- ...UserLabelUser
144
- ...UserLinkUser
145
- __typename
146
- }
147
- repl {
148
- id
149
- url
150
- title
151
- description
152
- isPrivate
153
- isAlwaysOn
154
- lang {
155
- id
156
- icon
157
- key
158
- displayName
159
- tagline
160
- __typename
161
- }
162
- __typename
163
- }
164
- board {
165
- id
166
- name
167
- color
168
- __typename
169
- }
170
- }
171
-
172
- fragment PostVoteControlPost on Post {
173
- id
174
- voteCount
175
- canVote
176
- hasVoted
177
- __typename
178
- }
179
-
180
- fragment PostLinkPost on Post {
181
- id
182
- url
183
- __typename
184
- }
185
-
186
- fragment UserLabelUser on User {
187
- id
188
- username
189
- karma
190
- ...UserLinkUser
191
- __typename
192
- }
193
-
194
- fragment UserLinkUser on User {
195
- id
196
- url
197
- username
198
- timeCreated
199
- roles {
200
- id
201
- name
202
- key
203
- tagline
204
- __typename
205
- }
206
- organization {
207
- id
208
- name
209
- __typename
210
- }
211
- languages {
212
- id
213
- key
214
- displayName
215
- tagline
216
- icon
217
- __typename
218
- }
219
- __typename
220
150
  }"
221
151
  end
222
152
 
223
153
  def Queries.get_user_comments
224
- "query ProfileComments($username: String!, $after: String, $order: String, $count: Int) {
154
+ "query user($username: String!, $after: String, $order: String, $count: Int) {
225
155
  user: userByUsername(username: $username) {
226
- id
227
- displayName
228
156
  comments(after: $after, order: $order, count: $count) {
229
157
  items {
230
- id
231
- ...ProfileCommentsComment
232
- __typename
233
- }
234
- pageInfo {
235
- nextCursor
236
- __typename
158
+ #{@@comment}
237
159
  }
238
- __typename
239
160
  }
240
- __typename
241
161
  }
242
- }
162
+ }"
163
+ end
243
164
 
244
- fragment ProfileCommentsComment on Comment {
245
- id
246
- body
247
- timeCreated
248
- url
249
- isAnswer
250
- ...CommentVoteControlComment
251
- user {
252
- id
253
- fullName
254
- username
255
- image
256
- bio
257
- karma
258
- isHacker
259
- timeCreated
260
- roles {
261
- id
262
- name
263
- key
264
- tagline
265
- __typename
266
- }
267
- organization {
268
- id
269
- name
270
- __typename
271
- }
272
- languages {
273
- id
274
- key
275
- displayName
276
- tagline
277
- icon
278
- __typename
279
- }
280
- }
281
- post {
282
- id
283
- title
284
- url
285
- user {
286
- id
287
- username
288
- url
289
- __typename
290
- }
291
- board {
292
- id
293
- name
294
- url
295
- slug
296
- __typename
165
+ def Queries.get_user_repls
166
+ "query user($username: String!, $count: Int, $order: String, $direction: String, $before: String, $after: String, $pinnedReplsFirst: Boolean, $showUnnamed: Boolean) {
167
+ user: userByUsername(username: $username) {
168
+ publicRepls(count: $count, order: $order, direction: $direction, before: $before, after: $after, pinnedReplsFirst: $pinnedReplsFirst, showUnnamed: $showUnnamed) {
169
+ items {
170
+ #{@@repl}
171
+ }
297
172
  }
298
- __typename
299
173
  }
300
- __typename
301
- }
302
-
303
- fragment CommentVoteControlComment on Comment {
304
- id
305
- voteCount
306
- canVote
307
- hasVoted
308
- __typename
309
174
  }"
310
175
  end
311
176
 
312
177
  def Queries.get_post
313
178
  "query post($id: Int!) {
314
179
  post(id: $id) {
315
- id
316
- title
317
- preview(removeMarkdown: true, length: 150)
318
- body
319
- isAnnouncement
320
- url
321
- isAnswerable
322
- isHidden
323
- answeredBy {
324
- id
325
- ...PostAnsweredCardUser
326
- __typename
327
- }
328
- answer {
329
- id
330
- ...PostAnsweredCardComment
331
- __typename
332
- }
333
- board {
334
- id
335
- url
336
- description
337
- slug
338
- __typename
339
- }
340
- ...PostDetailPost
341
- __typename
180
+ #{@@post}
342
181
  }
343
- }
182
+ }"
183
+ end
344
184
 
345
- fragment PostDetailPost on Post {
346
- id
347
- title
348
- body
349
- timeCreated
350
- canReport
351
- hasReported
352
- isAnnouncement
353
- isPinned
354
- isLocked
355
- isHidden
356
- commentCount
357
- isAnswered
358
- isAnswerable
359
- ...PostVoteControlPost
360
- user {
361
- id
362
- timeCreated
363
- roles {
364
- id
365
- name
366
- key
367
- tagline
368
- __typename
369
- }
370
- organization {
371
- id
372
- name
373
- __typename
374
- }
375
- languages {
376
- id
377
- key
378
- displayName
379
- tagline
380
- icon
381
- __typename
185
+ def Queries.get_posts_comments
186
+ "query post($postId: Int!, $order: String, $count: Int, $after: String) {
187
+ post(id: $postId) {
188
+ comments(order: $order, count: $count, after: $after) {
189
+ items {
190
+ #{@@comment}
191
+ }
382
192
  }
383
- ...UserPostHeaderUser
384
- __typename
385
193
  }
386
- repl {
387
- id
388
- url
389
- title
390
- description
391
- isPrivate
392
- isAlwaysOn
393
- lang {
394
- id
395
- icon
396
- key
397
- displayName
398
- tagline
399
- __typename
194
+ }"
195
+ end
196
+
197
+ def Queries.get_posts_upvoters
198
+ "query post($id: Int!, $count: Int) {
199
+ post(id: $id) {
200
+ votes(count: $count) {
201
+ items {
202
+ user {
203
+ #{@@user}
204
+ }
205
+ }
400
206
  }
401
- __typename
402
207
  }
403
- board {
404
- id
405
- name
406
- color
407
- __typename
408
- }
409
- __typename
410
- }
411
-
412
- fragment PostVoteControlPost on Post {
413
- id
414
- voteCount
415
- canVote
416
- hasVoted
417
- __typename
418
- }
419
-
420
- fragment UserPostHeaderUser on User {
421
- id
422
- image
423
- isHacker
424
- isModerator: hasRole(role: MODERATOR)
425
- isAdmin: hasRole(role: ADMIN)
426
- ...DepreciatedUserLabelUser
427
- ...UserLinkUser
428
- __typename
429
- }
430
-
431
- fragment UserLinkUser on User {
432
- id
433
- url
434
- username
435
- __typename
436
- }
437
-
438
- fragment DepreciatedUserLabelUser on User {
439
- id
440
- image
441
- username
442
- url
443
- karma
444
- __typename
445
- }
446
-
447
- fragment PostAnsweredCardUser on User {
448
- id
449
- username
450
- ...DepreciatedUserLabelUser
451
- __typename
452
- }
453
-
454
- fragment PostAnsweredCardComment on Comment {
455
- id
456
- url
457
- __typename
458
208
  }"
459
209
  end
460
210
 
461
211
  def Queries.get_comment
462
212
  "query comment ($id: Int!) {
463
213
  comment(id: $id) {
464
- id
465
- url
466
- isAnswer
467
- ...CommentDetailComment
214
+ #{@@comment}
215
+ }
216
+ }"
217
+ end
218
+
219
+ def Queries.get_comments_comments
220
+ "query comment ($id: Int!) {
221
+ comment(id: $id) {
468
222
  comments {
469
- id
470
- url
471
- isAnswer
472
- ...CommentDetailComment
473
- __typename
223
+ #{@@comment}
474
224
  }
475
- __typename
476
225
  }
477
- }
226
+ }"
227
+ end
478
228
 
479
- fragment DepreciatedUserLabelUser on User {
480
- id
481
- fullName
482
- username
483
- image
484
- bio
485
- karma
486
- isHacker
487
- timeCreated
488
- roles {
489
- id
490
- name
491
- key
492
- tagline
493
- __typename
494
- }
495
- organization {
496
- id
497
- name
498
- __typename
499
- }
500
- languages {
501
- id
502
- key
503
- displayName
504
- tagline
505
- icon
506
- __typename
229
+ def Queries.get_parent_comment
230
+ "query comment ($id: Int!) {
231
+ comment(id: $id) {
232
+ parentComment {
233
+ #{@@comment}
234
+ }
507
235
  }
508
- __typename
509
- }
236
+ }"
237
+ end
510
238
 
511
- fragment CommentDetailComment on Comment {
512
- id
513
- body
514
- timeCreated
515
- url
516
- isAnswer
517
- ...CommentVoteControlComment
518
- user {
519
- id
520
- username
521
- ...DepreciatedUserLabelWithImageUser
522
- __typename
239
+ def Queries.get_repl
240
+ "query ReplView($url: String!) {
241
+ repl(url: $url) {
242
+ ... on Repl {
243
+ #{@@repl}
244
+ }
523
245
  }
524
- post {
525
- id
526
- __typename
246
+ }"
247
+ end
248
+
249
+ def Queries.get_repl_forks
250
+ "query ReplViewForks($url: String!, $count: Int!, $after: String) {
251
+ repl(url: $url) {
252
+ ... on Repl {
253
+ publicForks(count: $count, after: $after) {
254
+ items {
255
+ #{@@repl}
256
+ }
257
+ }
258
+ }
527
259
  }
528
- __typename
529
- }
260
+ }"
261
+ end
530
262
 
531
- fragment DepreciatedUserLabelWithImageUser on User {
532
- id
533
- image
534
- ...DepreciatedUserLabelUser
535
- __typename
536
- }
263
+ def Queries.get_repl_comments
264
+ "query ReplViewComments($url: String!, $count: Int, $after: String) {
265
+ repl(url: $url) {
266
+ ... on Repl {
267
+ comments(count: $count, after: $after) {
268
+ items {
269
+ #{@@repl_comment}
270
+ replies {
271
+ #{@@repl_comment}
272
+ }
273
+ }
274
+ }
275
+ }
276
+ }
277
+ }"
278
+ end
537
279
 
538
- fragment CommentVoteControlComment on Comment {
539
- id
540
- voteCount
541
- canVote
542
- hasVoted
543
- __typename
280
+ def Queries.get_posts
281
+ "query PostsFeed($order: String, $after: String, $searchQuery: String, $languages: [String!], $count: Int, $boardSlugs: [String!], $pinAnnouncements: Boolean, $pinPinned: Boolean) {
282
+ posts(order: $order, after: $after, searchQuery: $searchQuery, languages: $languages, count: $count, boardSlugs: $boardSlugs, pinAnnouncements: $pinAnnouncements, pinPinned: $pinPinned) {
283
+ items {
284
+ #{@@post}
285
+ }
286
+ }
544
287
  }"
545
288
  end
546
289
  end
data/lib/repltalk.rb CHANGED
@@ -2,6 +2,8 @@ require "http"
2
2
  require "json"
3
3
  require_relative "queries"
4
4
 
5
+ $BASE_URL = "https://repl.it"
6
+
5
7
  class Role
6
8
  attr_reader :name, :key, :tagline
7
9
 
@@ -51,20 +53,66 @@ end
51
53
 
52
54
 
53
55
 
56
+ class ReplComment
57
+ attr_reader :id, :content, :author, :repl, :replies
58
+
59
+ def initialize(client, comment)
60
+ @client = client
61
+
62
+ @id = comment["id"]
63
+ @content = comment["body"]
64
+ @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
65
+ @repl = Repl.new(@client, comment["repl"])
66
+ @replies = comment["replies"] == nil ? nil : comment["replies"].map { |c| ReplComment.new(@client, c) }
67
+ end
68
+
69
+ def to_s
70
+ @content
71
+ end
72
+ end
73
+
74
+
75
+
54
76
  class Repl
55
- attr_reader :id, :url, :title, :description, :language, :is_private, :is_always_on
77
+ attr_reader :id, :url, :title, :author, :description, :language, :img_url, :is_private, :is_always_on
78
+
79
+ def initialize(client, repl)
80
+ @client = client
56
81
 
57
- def initialize(repl)
58
82
  @id = repl["id"]
59
- @url = repl["url"]
83
+ @url = $BASE_URL + repl["url"]
60
84
  @title = repl["title"]
85
+ @author = User.new(@client, repl["user"])
61
86
  @description = repl["description"]
62
87
  @language = Language.new(repl["lang"])
88
+ @image_url = repl["imageUrl"]
63
89
 
64
90
  @is_private = repl["isPrivate"]
65
91
  @is_always_on = repl["isAlwaysOn"]
66
92
  end
67
93
 
94
+ def get_forks(count: 100, after: nil)
95
+ f = @client.graphql(
96
+ "ReplViewForks",
97
+ Queries.get_repl_forks,
98
+ url: @url,
99
+ count: count,
100
+ after: after
101
+ )
102
+ f["repl"]["publicForks"]["items"].map { |repl| Repl.new(@client, repl) }
103
+ end
104
+
105
+ def get_comments(count: nil, after: nil)
106
+ c = @client.graphql(
107
+ "ReplViewComments",
108
+ Queries.get_repl_comments,
109
+ url: @url,
110
+ count: count,
111
+ after: after
112
+ )
113
+ c["repl"]["comments"]["items"].map { |comment| ReplComment.new(@client, comment) }
114
+ end
115
+
68
116
  def to_s
69
117
  @title
70
118
  end
@@ -89,20 +137,19 @@ end
89
137
 
90
138
 
91
139
  class Comment
92
- attr_reader :id, :url, :author, :content, :post_id, :is_answer, :vote_count, :timestamp, :comments, :can_vote, :has_voted
140
+ attr_reader :id, :url, :author, :content, :post_id, :is_answer, :vote_count, :timestamp, :can_vote, :has_voted
93
141
 
94
142
  def initialize(client, comment)
95
143
  @client = client
96
144
 
97
145
  @id = comment["id"]
98
- @url = comment["url"]
146
+ @url = $BASE_URL + comment["url"]
99
147
  @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
100
148
  @content = comment["body"]
101
149
  @post_id = comment["post"]["id"]
102
150
  @is_answer = comment["isAnswer"]
103
151
  @vote_count = comment["voteCount"]
104
152
  @timestamp = comment["timeCreated"]
105
- @comments = comment.include?("comments") ? comment["comments"].map { |c| Comment.new(@client, c)} : Array.new
106
153
 
107
154
  @can_vote = comment["canVote"]
108
155
  @has_voted = comment["hasVoted"]
@@ -114,7 +161,25 @@ class Comment
114
161
  Queries.get_post,
115
162
  id: @post_id
116
163
  )
117
- Post.new(self, p["post"])
164
+ Post.new(@client, p["post"])
165
+ end
166
+
167
+ def get_comments
168
+ c = @client.graphql(
169
+ "comment",
170
+ Queries.get_comments_comments,
171
+ id: @id
172
+ )
173
+ c["comment"]["comments"].map { |comment| Comment.new(@client, comment) }
174
+ end
175
+
176
+ def get_parent
177
+ c = @client.graphql(
178
+ "comment",
179
+ Queries.get_parent_comment,
180
+ id: @id
181
+ )
182
+ c["comment"]["parentComment"] == nil ? nil : Comment.new(@client, c["comment"]["parentComment"])
118
183
  end
119
184
 
120
185
  def to_s
@@ -125,21 +190,22 @@ end
125
190
 
126
191
 
127
192
  class Post
128
- attr_reader :id, :url, :repl, :board, :title, :author, :content, :preview, :timestamp, :vote_count, :comment_count, :can_vote, :has_voted, :is_answered, :is_answerable, :is_hidden, :is_pinned, :is_locked, :is_announcement
193
+ attr_reader :id, :url, :repl, :board, :title, :author, :answer, :content, :preview, :timestamp, :vote_count, :comment_count, :can_vote, :has_voted, :is_answered, :is_answerable, :is_hidden, :is_pinned, :is_locked, :is_announcement
129
194
 
130
195
  def initialize(client, post)
131
196
  @client = client
132
197
 
133
198
  @id = post["id"]
134
- @url = post["url"]
199
+ @url = $BASE_URL + post["url"]
135
200
  @title = post["title"]
136
201
  @content = post["body"]
137
202
  @preview = post["preview"]
138
203
  @timestamp = post["timeCreated"]
139
204
 
140
205
  @board = Board.new(post["board"])
141
- @repl = post["repl"] == nil ? nil : Repl.new(post["repl"])
206
+ @repl = post["repl"] == nil ? nil : Repl.new(@client, post["repl"])
142
207
  @author = post["user"] == nil ? "[deleted user]" : User.new(@client, post["user"])
208
+ @answer = post["answer"] == nil ? nil : Comment.new(@client, post["answer"])
143
209
 
144
210
  @vote_count = post["voteCount"]
145
211
  @comment_count = post["commentCount"]
@@ -156,6 +222,28 @@ class Post
156
222
  @is_announcement = post["isAnnouncement"]
157
223
  end
158
224
 
225
+ def get_comments(order: "new", count: nil, after: nil)
226
+ c = @client.graphql(
227
+ "post",
228
+ Queries.get_posts_comments,
229
+ postId: @id,
230
+ order: order,
231
+ count: count,
232
+ after: after
233
+ )
234
+ c["post"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
235
+ end
236
+
237
+ def get_upvotes(count: nil)
238
+ u = @client.graphql(
239
+ "post",
240
+ Queries.get_posts_upvoters,
241
+ id: @id,
242
+ count: count
243
+ )
244
+ u["post"]["votes"]["items"].map { |vote| User.new(@client, vote["user"]) }
245
+ end
246
+
159
247
  def to_s
160
248
  @title
161
249
  end
@@ -184,7 +272,7 @@ class User
184
272
 
185
273
  def get_posts(order: "new", count: nil, after: nil)
186
274
  p = @client.graphql(
187
- "ProfilePosts",
275
+ "user",
188
276
  Queries.get_user_posts,
189
277
  username: @username,
190
278
  order: order,
@@ -196,7 +284,7 @@ class User
196
284
 
197
285
  def get_comments(order: "new", count: nil, after: nil)
198
286
  c = @client.graphql(
199
- "ProfileComments",
287
+ "user",
200
288
  Queries.get_user_comments,
201
289
  username: @username,
202
290
  order: order,
@@ -206,6 +294,22 @@ class User
206
294
  c["user"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
207
295
  end
208
296
 
297
+ def get_repls(count: nil, order: nil, direction: nil, before: nil, after: nil, pinnedReplsFirst: nil, showUnnamed: nil)
298
+ r = @client.graphql(
299
+ "user",
300
+ Queries.get_user_repls,
301
+ username: @username,
302
+ order: order,
303
+ count: count,
304
+ direction: direction,
305
+ before: before,
306
+ after: after,
307
+ pinnedReplsFirst: pinnedReplsFirst,
308
+ showUnnamed: showUnnamed
309
+ )
310
+ r["user"]["publicRepls"]["items"].map { |repl| Repl.new(@client, repl) }
311
+ end
312
+
209
313
  def to_s
210
314
  @username
211
315
  end
@@ -231,11 +335,11 @@ class Client
231
335
  "connect.sid": @sid
232
336
  )
233
337
  .headers(
234
- referer: "https://repl.it/@CodingCactus/repltalk",
338
+ referer: "#{$BASE_URL}/@CodingCactus/repltalk",
235
339
  "X-Requested-With": "ReplTalk"
236
340
  )
237
341
  .post(
238
- "https://repl.it/graphql",
342
+ "#{$BASE_URL}/graphql",
239
343
  form: payload
240
344
  )
241
345
  begin data = JSON.parse(r)
@@ -243,6 +347,10 @@ class Client
243
347
  puts "\e[31mERROR\n#{r}\e[0m"
244
348
  return nil
245
349
  end
350
+ if data.include?("errors")
351
+ puts "\e[31mERROR\n#{r}\e[0m"
352
+ return nil
353
+ end
246
354
  data = data["data"] if data.include?("data")
247
355
  data
248
356
  end
@@ -282,4 +390,27 @@ class Client
282
390
  )
283
391
  Comment.new(self, c["comment"])
284
392
  end
393
+
394
+ def get_repl(url)
395
+ r = graphql(
396
+ "ReplView",
397
+ Queries.get_repl,
398
+ url: url
399
+ )
400
+ Repl.new(self, r["repl"])
401
+ end
402
+
403
+ def get_posts(board: "all", order: "new", count: nil, after: nil, search: nil, languages: nil)
404
+ p = graphql(
405
+ "PostsFeed",
406
+ Queries.get_posts,
407
+ baordSlugs: [board],
408
+ order: order,
409
+ count: count,
410
+ after: after,
411
+ searchQuery: search,
412
+ languages: languages
413
+ )
414
+ p["posts"]["items"].map { |post| Post.new(self, post) }
415
+ end
285
416
  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: 0.3.0
4
+ version: 0.5.0
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-04 00:00:00.000000000 Z
11
+ date: 2021-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -48,7 +48,8 @@ files:
48
48
  - lib/queries.rb
49
49
  - lib/repltalk.rb
50
50
  homepage:
51
- licenses: []
51
+ licenses:
52
+ - MIT
52
53
  metadata:
53
54
  source_code_uri: https://github.com/Coding-Cactus/repltalk
54
55
  post_install_message: