repltalk 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/repltalk.rb +6 -651
- data/lib/repltalk/client.rb +164 -0
- data/lib/repltalk/graphql.rb +472 -0
- data/lib/repltalk/structures.rb +490 -0
- metadata +8 -6
- data/lib/queries.rb +0 -467
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b29fd09750ab59ab7fea6a85c0e8e4d1c92e92384345a8eae78bc9bf66ba04cc
|
4
|
+
data.tar.gz: 450fe16b28f0472b7b6a1dba9c7c352ce60e8905ad47a4606b0d56d0e247fddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e384d3d6e95b775ab7ca7325f79397b0bce57cbaa88d0d756064f99787ed5221ab6ac508754ead20d9761fd53e4e5e26e0eddb83e598a418fce96618a4b8ffc4
|
7
|
+
data.tar.gz: 0af84b33627e30b00cb0f27f776331221ec5bac5e5034746625a7dd31d55b31cb31b4787e71277a75f72b20a105500fcacb86bcf6e88ea5e11a00227d3085899
|
data/lib/repltalk.rb
CHANGED
@@ -1,653 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require_relative "
|
1
|
+
require_relative "repltalk/client"
|
2
|
+
require_relative "repltalk/graphql"
|
3
|
+
require_relative "repltalk/structures"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
attr_reader :name, :key, :tagline
|
9
|
-
|
10
|
-
def initialize(role)
|
11
|
-
@name = role["name"]
|
12
|
-
@key = role["key"]
|
13
|
-
@tagline = role["tagline"]
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_s
|
17
|
-
@name
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
class Organization
|
24
|
-
attr_reader :id, :name, :country, :postal_code, :state, :city, :timestamp
|
25
|
-
|
26
|
-
def initialize(organization)
|
27
|
-
@id = organization["id"]
|
28
|
-
@name = organization["name"]
|
29
|
-
@country = organization["country"]
|
30
|
-
@postal_code = organization["postalCode"]
|
31
|
-
@state = organization["state"]
|
32
|
-
@city = organization["city"]
|
33
|
-
@timestamp = organization["timeCreated"]
|
34
|
-
end
|
35
|
-
|
36
|
-
def to_s
|
37
|
-
@name
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
class Subscription
|
44
|
-
attr_reader :id, :plan_id, :quantity, :timestamp
|
45
|
-
|
46
|
-
def initialize(subscription)
|
47
|
-
@id = subscription["id"]
|
48
|
-
@plan_id = subscription["planId"]
|
49
|
-
@quantity = subscription["quantity"]
|
50
|
-
@timestamp = subscription["timeCreated"]
|
51
|
-
end
|
52
|
-
|
53
|
-
def to_s
|
54
|
-
@plan_id
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
class Language
|
61
|
-
attr_reader :id, :key, :name, :tagline, :icon, :category
|
62
|
-
|
63
|
-
def initialize(lang)
|
64
|
-
@id = lang["id"]
|
65
|
-
@key = lang["key"]
|
66
|
-
@name = lang["displayName"]
|
67
|
-
@tagline = lang["tagline"]
|
68
|
-
@icon = lang["icon"]
|
69
|
-
@category = lang["category"]
|
70
|
-
end
|
71
|
-
|
72
|
-
def to_s
|
73
|
-
@id
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
|
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
|
-
|
96
|
-
class ReplComment
|
97
|
-
attr_reader :id, :content, :author, :repl, :replies
|
98
|
-
|
99
|
-
def initialize(client, comment)
|
100
|
-
@client = client
|
101
|
-
|
102
|
-
@id = comment["id"]
|
103
|
-
@content = comment["body"]
|
104
|
-
@author = comment["user"] == nil ? nil : User.new(@client, comment["user"])
|
105
|
-
@repl = comment["repl"] == nil ? nil : Repl.new(@client, comment["repl"])
|
106
|
-
@replies = comment["replies"] == nil ? nil : comment["replies"].map { |c| ReplComment.new(@client, c) }
|
107
|
-
end
|
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
|
-
|
142
|
-
def to_s
|
143
|
-
@content
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
class Repl
|
150
|
-
attr_reader :id, :url, :title, :author, :description, :timestamp, :size, :language, :img_url, :origin_url, :is_private, :is_always_on
|
151
|
-
|
152
|
-
def initialize(client, repl)
|
153
|
-
@client = client
|
154
|
-
|
155
|
-
@id = repl["id"]
|
156
|
-
@url = $BASE_URL + repl["url"]
|
157
|
-
@title = repl["title"]
|
158
|
-
@author = User.new(@client, repl["user"])
|
159
|
-
@description = repl["description"]
|
160
|
-
@timestamp = repl["timeCreated"]
|
161
|
-
@size = repl["size"]
|
162
|
-
@language = Language.new(repl["lang"])
|
163
|
-
@image_url = repl["imageUrl"]
|
164
|
-
@origin_url = repl["origin"] == nil ? nil : $BASE_URL + repl["origin"]["url"]
|
165
|
-
|
166
|
-
@is_private = repl["isPrivate"]
|
167
|
-
@is_always_on = repl["isAlwaysOn"]
|
168
|
-
end
|
169
|
-
|
170
|
-
def get_forks(count: 100, after: nil)
|
171
|
-
f = @client.graphql(
|
172
|
-
"ReplViewForks",
|
173
|
-
Queries.get_repl_forks,
|
174
|
-
url: @url,
|
175
|
-
count: count,
|
176
|
-
after: after
|
177
|
-
)
|
178
|
-
f["repl"]["publicForks"]["items"].map { |repl| Repl.new(@client, repl) }
|
179
|
-
end
|
180
|
-
|
181
|
-
def get_comments(count: nil, after: nil)
|
182
|
-
c = @client.graphql(
|
183
|
-
"ReplViewComments",
|
184
|
-
Queries.get_repl_comments,
|
185
|
-
url: @url,
|
186
|
-
count: count,
|
187
|
-
after: after
|
188
|
-
)
|
189
|
-
c["repl"]["comments"]["items"].map { |comment| ReplComment.new(@client, comment) }
|
190
|
-
end
|
191
|
-
|
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"])
|
202
|
-
end
|
203
|
-
|
204
|
-
def to_s
|
205
|
-
@title
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
class Comment
|
212
|
-
attr_reader :id, :url, :author, :content, :post_id, :is_answer, :vote_count, :timestamp, :can_vote, :has_voted
|
213
|
-
|
214
|
-
def initialize(client, comment)
|
215
|
-
@client = client
|
216
|
-
|
217
|
-
@id = comment["id"]
|
218
|
-
@url = $BASE_URL + comment["url"]
|
219
|
-
@author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
|
220
|
-
@content = comment["body"]
|
221
|
-
@post_id = comment["post"]["id"]
|
222
|
-
@is_answer = comment["isAnswer"]
|
223
|
-
@vote_count = comment["voteCount"]
|
224
|
-
@timestamp = comment["timeCreated"]
|
225
|
-
|
226
|
-
@can_vote = comment["canVote"]
|
227
|
-
@has_voted = comment["hasVoted"]
|
228
|
-
end
|
229
|
-
|
230
|
-
def get_post
|
231
|
-
p = @client.graphql(
|
232
|
-
"post",
|
233
|
-
Queries.get_post,
|
234
|
-
id: @post_id
|
235
|
-
)
|
236
|
-
Post.new(@client, p["post"])
|
237
|
-
end
|
238
|
-
|
239
|
-
def get_comments
|
240
|
-
c = @client.graphql(
|
241
|
-
"comment",
|
242
|
-
Queries.get_comments_comments,
|
243
|
-
id: @id
|
244
|
-
)
|
245
|
-
c["comment"]["comments"].map { |comment| Comment.new(@client, comment) }
|
246
|
-
end
|
247
|
-
|
248
|
-
def get_parent
|
249
|
-
c = @client.graphql(
|
250
|
-
"comment",
|
251
|
-
Queries.get_parent_comment,
|
252
|
-
id: @id
|
253
|
-
)
|
254
|
-
c["comment"]["parentComment"] == nil ? nil : Comment.new(@client, c["comment"]["parentComment"])
|
255
|
-
end
|
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
|
-
|
301
|
-
def to_s
|
302
|
-
@content
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
class Post
|
309
|
-
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
|
310
|
-
|
311
|
-
def initialize(client, post)
|
312
|
-
@client = client
|
313
|
-
|
314
|
-
@id = post["id"]
|
315
|
-
@url = $BASE_URL + post["url"]
|
316
|
-
@title = post["title"]
|
317
|
-
@content = post["body"]
|
318
|
-
@preview = post["preview"]
|
319
|
-
@timestamp = post["timeCreated"]
|
320
|
-
|
321
|
-
@board = Board.new(post["board"])
|
322
|
-
@repl = post["repl"] == nil ? nil : Repl.new(@client, post["repl"])
|
323
|
-
@author = post["user"] == nil ? nil : User.new(@client, post["user"])
|
324
|
-
@answer = post["answer"] == nil ? nil : Comment.new(@client, post["answer"])
|
325
|
-
|
326
|
-
@vote_count = post["voteCount"]
|
327
|
-
@comment_count = post["commentCount"]
|
328
|
-
|
329
|
-
@can_vote = post["canVote"]
|
330
|
-
@has_voted = post["hasVoted"]
|
331
|
-
|
332
|
-
@is_answered = post["isAnswered"]
|
333
|
-
@is_answerable = post["isAnswerable"]
|
334
|
-
|
335
|
-
@is_hidden = post["isHidden"]
|
336
|
-
@is_pinned = post["isPinned"]
|
337
|
-
@is_locked = post["isLocked"]
|
338
|
-
@is_announcement = post["isAnnouncement"]
|
339
|
-
end
|
340
|
-
|
341
|
-
def get_comments(order: "new", count: nil, after: nil)
|
342
|
-
c = @client.graphql(
|
343
|
-
"post",
|
344
|
-
Queries.get_posts_comments,
|
345
|
-
postId: @id,
|
346
|
-
order: order,
|
347
|
-
count: count,
|
348
|
-
after: after
|
349
|
-
)
|
350
|
-
c["post"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
|
351
|
-
end
|
352
|
-
|
353
|
-
def get_upvotes(count: nil)
|
354
|
-
u = @client.graphql(
|
355
|
-
"post",
|
356
|
-
Queries.get_posts_upvoters,
|
357
|
-
id: @id,
|
358
|
-
count: count
|
359
|
-
)
|
360
|
-
u["post"]["votes"]["items"].map { |vote| User.new(@client, vote["user"]) }
|
361
|
-
end
|
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
|
-
|
409
|
-
def to_s
|
410
|
-
@title
|
411
|
-
end
|
5
|
+
module ReplTalk
|
6
|
+
$BASE_URL = "https://repl.it"
|
7
|
+
VERSION = "3.0.0"
|
412
8
|
end
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
class User
|
417
|
-
attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :timestamp, :subscription, :roles, :organization, :languages
|
418
|
-
|
419
|
-
def initialize(client, user)
|
420
|
-
return nil if user == nil
|
421
|
-
@client = client
|
422
|
-
|
423
|
-
@id = user["id"]
|
424
|
-
@username = user["username"]
|
425
|
-
@name = user["fullName"]
|
426
|
-
@pfp = user["image"]
|
427
|
-
@bio = user["bio"]
|
428
|
-
@cycles = user["karma"]
|
429
|
-
@is_hacker = user["isHacker"]
|
430
|
-
@timestamp = user["timeCreated"]
|
431
|
-
@subscription = user["subscription"] == nil ? nil : Subscription.new(user["subscription"])
|
432
|
-
@roles = user["roles"].map { |role| Role.new(role) }
|
433
|
-
@organization = user["organization"] == nil ? nil : Organization.new(user["organization"])
|
434
|
-
@languages = user["languages"].map { |lang| Language.new(lang) }
|
435
|
-
end
|
436
|
-
|
437
|
-
def get_posts(order: "new", count: nil, after: nil)
|
438
|
-
p = @client.graphql(
|
439
|
-
"user",
|
440
|
-
Queries.get_user_posts,
|
441
|
-
username: @username,
|
442
|
-
order: order,
|
443
|
-
count: count,
|
444
|
-
after: after
|
445
|
-
)
|
446
|
-
p["user"]["posts"]["items"].map { |post| Post.new(@client, post) }
|
447
|
-
end
|
448
|
-
|
449
|
-
def get_comments(order: "new", count: nil, after: nil)
|
450
|
-
c = @client.graphql(
|
451
|
-
"user",
|
452
|
-
Queries.get_user_comments,
|
453
|
-
username: @username,
|
454
|
-
order: order,
|
455
|
-
count: count,
|
456
|
-
after: after
|
457
|
-
)
|
458
|
-
c["user"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
|
459
|
-
end
|
460
|
-
|
461
|
-
def get_repls(count: nil, order: nil, direction: nil, before: nil, after: nil, pinnedReplsFirst: nil, showUnnamed: nil)
|
462
|
-
r = @client.graphql(
|
463
|
-
"user",
|
464
|
-
Queries.get_user_repls,
|
465
|
-
username: @username,
|
466
|
-
order: order,
|
467
|
-
count: count,
|
468
|
-
direction: direction,
|
469
|
-
before: before,
|
470
|
-
after: after,
|
471
|
-
pinnedReplsFirst: pinnedReplsFirst,
|
472
|
-
showUnnamed: showUnnamed
|
473
|
-
)
|
474
|
-
r["user"]["publicRepls"]["items"].map { |repl| Repl.new(@client, repl) }
|
475
|
-
end
|
476
|
-
|
477
|
-
def to_s
|
478
|
-
@username
|
479
|
-
end
|
480
|
-
end
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
class LeaderboardUser < User
|
485
|
-
attr_reader :cycles_since
|
486
|
-
|
487
|
-
def initialize(client, user)
|
488
|
-
super(client, user)
|
489
|
-
@cycles_since = user["karmaSince"]
|
490
|
-
end
|
491
|
-
end
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
class Client
|
496
|
-
attr_writer :sid
|
497
|
-
|
498
|
-
def initialize(sid=nil)
|
499
|
-
@sid = sid
|
500
|
-
end
|
501
|
-
|
502
|
-
def graphql(name, query, **variables)
|
503
|
-
payload = {
|
504
|
-
operationName: name,
|
505
|
-
query: query,
|
506
|
-
variables: variables.to_json
|
507
|
-
}
|
508
|
-
r = HTTP
|
509
|
-
.cookies(
|
510
|
-
"connect.sid": @sid
|
511
|
-
)
|
512
|
-
.headers(
|
513
|
-
referer: "#{$BASE_URL}/@CodingCactus/repltalk",
|
514
|
-
"X-Requested-With": "ReplTalk"
|
515
|
-
)
|
516
|
-
.post(
|
517
|
-
"#{$BASE_URL}/graphql",
|
518
|
-
form: payload
|
519
|
-
)
|
520
|
-
begin data = JSON.parse(r)
|
521
|
-
rescue
|
522
|
-
puts "\e[31mERROR\n#{r}\e[0m"
|
523
|
-
return nil
|
524
|
-
end
|
525
|
-
if data.include?("errors")
|
526
|
-
puts "\e[31mERROR\n#{r}\e[0m"
|
527
|
-
return nil
|
528
|
-
end
|
529
|
-
data = data["data"] if data.include?("data")
|
530
|
-
data
|
531
|
-
end
|
532
|
-
|
533
|
-
def get_user(name)
|
534
|
-
u = graphql(
|
535
|
-
"userByUsername",
|
536
|
-
Queries.get_user,
|
537
|
-
username: name
|
538
|
-
)
|
539
|
-
return nil if u == nil || u["user"] == nil
|
540
|
-
User.new(self, u["user"])
|
541
|
-
end
|
542
|
-
|
543
|
-
def get_user_by_id(id)
|
544
|
-
u = graphql(
|
545
|
-
"user",
|
546
|
-
Queries.get_user_by_id,
|
547
|
-
user_id: id
|
548
|
-
)
|
549
|
-
return nil if u == nil || u["user"] == nil
|
550
|
-
User.new(self, u["user"])
|
551
|
-
end
|
552
|
-
|
553
|
-
def search_user(username, count: 10)
|
554
|
-
u = graphql(
|
555
|
-
"usernameSearch",
|
556
|
-
Queries.user_search,
|
557
|
-
username: username,
|
558
|
-
count: count
|
559
|
-
)
|
560
|
-
return nil if u["usernameSearch"] == nil
|
561
|
-
u["usernameSearch"].map { |user| User.new(self, user) }
|
562
|
-
end
|
563
|
-
|
564
|
-
def get_post(id)
|
565
|
-
p = graphql(
|
566
|
-
"post",
|
567
|
-
Queries.get_post,
|
568
|
-
id: id
|
569
|
-
)
|
570
|
-
return nil if p == nil || p["post"] == nil
|
571
|
-
Post.new(self, p["post"])
|
572
|
-
end
|
573
|
-
|
574
|
-
def get_comment(id)
|
575
|
-
c = graphql(
|
576
|
-
"comment",
|
577
|
-
Queries.get_comment,
|
578
|
-
id: id
|
579
|
-
)
|
580
|
-
return nil if c == nil || c["comment"] == nil
|
581
|
-
Comment.new(self, c["comment"])
|
582
|
-
end
|
583
|
-
|
584
|
-
def get_repl(url)
|
585
|
-
r = graphql(
|
586
|
-
"ReplView",
|
587
|
-
Queries.get_repl,
|
588
|
-
url: url
|
589
|
-
)
|
590
|
-
return nil if r == nil || r["repl"] == nil
|
591
|
-
Repl.new(self, r["repl"])
|
592
|
-
end
|
593
|
-
|
594
|
-
def get_repl_comment(id)
|
595
|
-
c = graphql(
|
596
|
-
"ReplViewComment",
|
597
|
-
Queries.get_repl_comment,
|
598
|
-
id: id
|
599
|
-
)
|
600
|
-
return nil if c == nil || c["replComment"] == nil
|
601
|
-
ReplComment.new(self, c["replComment"])
|
602
|
-
end
|
603
|
-
|
604
|
-
def get_board(name)
|
605
|
-
b = graphql(
|
606
|
-
"boardBySlug",
|
607
|
-
Queries.get_board,
|
608
|
-
slug: name
|
609
|
-
)
|
610
|
-
return nil if b == nil || b["board"] == nil
|
611
|
-
Board.new(b["board"])
|
612
|
-
end
|
613
|
-
|
614
|
-
def get_leaderboard(count: nil, since: nil, after: nil)
|
615
|
-
u = graphql(
|
616
|
-
"LeaderboardQuery",
|
617
|
-
Queries.get_leaderboard,
|
618
|
-
count: count,
|
619
|
-
since: since,
|
620
|
-
after: after
|
621
|
-
)
|
622
|
-
u["leaderboard"]["items"].map { |user| LeaderboardUser.new(self, user) }
|
623
|
-
end
|
624
|
-
|
625
|
-
def get_posts(board: "all", order: "new", count: nil, after: nil, search: nil, languages: nil)
|
626
|
-
p = graphql(
|
627
|
-
"PostsFeed",
|
628
|
-
Queries.get_posts,
|
629
|
-
boardSlugs: [board],
|
630
|
-
order: order,
|
631
|
-
count: count,
|
632
|
-
after: after,
|
633
|
-
searchQuery: search,
|
634
|
-
languages: languages
|
635
|
-
)
|
636
|
-
p["posts"]["items"].map { |post| Post.new(self, post) }
|
637
|
-
end
|
638
|
-
|
639
|
-
def create_post(board_name, title, content, repl_id: nil, show_hosted: false)
|
640
|
-
p = graphql(
|
641
|
-
"createPost",
|
642
|
-
Mutations.create_post,
|
643
|
-
input: {
|
644
|
-
boardId: get_board(board_name).id,
|
645
|
-
title: title,
|
646
|
-
body: content,
|
647
|
-
replId: repl_id,
|
648
|
-
showHosted: show_hosted
|
649
|
-
}
|
650
|
-
)
|
651
|
-
Post.new(self, p["createPost"]["post"])
|
652
|
-
end
|
653
|
-
end
|