repltalk 0.4.2 → 1.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 +153 -18
  3. data/lib/repltalk.rb +156 -11
  4. metadata +21 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb325d2217b8b9e4a283dce8405cc1288fb430377d030f7fb201d344e8348f23
4
- data.tar.gz: 3f35941f2a9d0542bc6c6fb205d9d1bd97c570921b6ab666b4b49aeef9f40c8a
3
+ metadata.gz: 74d0fb4fc93b281bb6c09286ef8b892019295e7f223861c699fbdc4525a25951
4
+ data.tar.gz: 6532d944f19ac0aaaa7f4229fff5a5402b8ec114af6ad09158015e019af5e4f2
5
5
  SHA512:
6
- metadata.gz: 20f4e65ddc1174889fb2767a1b87a1bf3d7ee418094b665e3b8b3de77884f0ddad956aa417b4db134f0fa9a57266dc4f5f6727aa26710a9ca4242fc3a0b79f56
7
- data.tar.gz: 03d580505be28f0aa190d417ef6a33c4a71f154e15c0a26e196b0fe8e38a3efe4661a53d28a5a0a82cb6a2b0a6ff667e9da57c53bd17f329d6523b5da7075fef
6
+ metadata.gz: 30fcdd93403ec9802117b93a7fad9fb106e883d30554988f0d67ef1f0edff706a0ae4fd1eb46de785df116bb0fee99ca3814d3b903dd54a337b31350b25d43df
7
+ data.tar.gz: 846e42e9b4665420458dc1c97fd028ae95814a09c78d0a26011ad96547b71ade0ee12ae83dd957c51fcb9a53bd3f29c98c57040ddd6596ff892005f721ca9827
data/lib/queries.rb CHANGED
@@ -9,6 +9,18 @@ class Queries
9
9
  @@organization = "
10
10
  id
11
11
  name
12
+ country
13
+ postalCode
14
+ state
15
+ city
16
+ timeCreated
17
+ "
18
+
19
+ @@subscription = "
20
+ id
21
+ planId
22
+ quantity
23
+ timeCreated
12
24
  "
13
25
 
14
26
  @@language = "
@@ -17,12 +29,14 @@ class Queries
17
29
  displayName
18
30
  tagline
19
31
  icon
32
+ category
20
33
  "
21
34
 
22
35
  @@board = "
23
36
  id
24
37
  name
25
38
  color
39
+ description
26
40
  "
27
41
 
28
42
  @@user = "
@@ -40,6 +54,9 @@ class Queries
40
54
  organization {
41
55
  #{@@organization}
42
56
  }
57
+ subscription {
58
+ #{@@subscription}
59
+ }
43
60
  languages {
44
61
  #{@@language}
45
62
  }
@@ -50,6 +67,8 @@ class Queries
50
67
  url
51
68
  title
52
69
  description
70
+ size
71
+ imageUrl
53
72
  isPrivate
54
73
  isAlwaysOn
55
74
  lang {
@@ -58,6 +77,38 @@ class Queries
58
77
  user {
59
78
  #{@@user}
60
79
  }
80
+ origin {
81
+ url
82
+ }
83
+ "
84
+
85
+ @@comment = "
86
+ id
87
+ body
88
+ timeCreated
89
+ url
90
+ isAnswer
91
+ voteCount
92
+ canVote
93
+ hasVoted
94
+ user {
95
+ #{@@user}
96
+ }
97
+ post {
98
+ id
99
+ }
100
+ "
101
+
102
+ @@repl_comment = "
103
+ id
104
+ body
105
+ timeCreated
106
+ user {
107
+ #{@@user}
108
+ }
109
+ repl {
110
+ #{@@repl}
111
+ }
61
112
  "
62
113
 
63
114
  @@post = "
@@ -86,22 +137,8 @@ class Queries
86
137
  board {
87
138
  #{@@board}
88
139
  }
89
- "
90
-
91
- @@comment = "
92
- id
93
- body
94
- timeCreated
95
- url
96
- isAnswer
97
- voteCount
98
- canVote
99
- hasVoted
100
- user {
101
- #{@@user}
102
- }
103
- post {
104
- id
140
+ answer {
141
+ #{@@comment}
105
142
  }
106
143
  "
107
144
 
@@ -123,7 +160,7 @@ class Queries
123
160
  end
124
161
 
125
162
  def Queries.get_user_posts
126
- "query ProfilePosts($username: String!, $after: String, $order: String, $count: Int) {
163
+ "query user($username: String!, $after: String, $order: String, $count: Int) {
127
164
  user: userByUsername(username: $username) {
128
165
  posts(after: $after, order: $order, count: $count) {
129
166
  items {
@@ -135,7 +172,7 @@ class Queries
135
172
  end
136
173
 
137
174
  def Queries.get_user_comments
138
- "query ProfileComments($username: String!, $after: String, $order: String, $count: Int) {
175
+ "query user($username: String!, $after: String, $order: String, $count: Int) {
139
176
  user: userByUsername(username: $username) {
140
177
  comments(after: $after, order: $order, count: $count) {
141
178
  items {
@@ -146,6 +183,18 @@ class Queries
146
183
  }"
147
184
  end
148
185
 
186
+ def Queries.get_user_repls
187
+ "query user($username: String!, $count: Int, $order: String, $direction: String, $before: String, $after: String, $pinnedReplsFirst: Boolean, $showUnnamed: Boolean) {
188
+ user: userByUsername(username: $username) {
189
+ publicRepls(count: $count, order: $order, direction: $direction, before: $before, after: $after, pinnedReplsFirst: $pinnedReplsFirst, showUnnamed: $showUnnamed) {
190
+ items {
191
+ #{@@repl}
192
+ }
193
+ }
194
+ }
195
+ }"
196
+ end
197
+
149
198
  def Queries.get_post
150
199
  "query post($id: Int!) {
151
200
  post(id: $id) {
@@ -166,6 +215,20 @@ class Queries
166
215
  }"
167
216
  end
168
217
 
218
+ def Queries.get_posts_upvoters
219
+ "query post($id: Int!, $count: Int) {
220
+ post(id: $id) {
221
+ votes(count: $count) {
222
+ items {
223
+ user {
224
+ #{@@user}
225
+ }
226
+ }
227
+ }
228
+ }
229
+ }"
230
+ end
231
+
169
232
  def Queries.get_comment
170
233
  "query comment ($id: Int!) {
171
234
  comment(id: $id) {
@@ -174,6 +237,67 @@ class Queries
174
237
  }"
175
238
  end
176
239
 
240
+ def Queries.get_comments_comments
241
+ "query comment ($id: Int!) {
242
+ comment(id: $id) {
243
+ comments {
244
+ #{@@comment}
245
+ }
246
+ }
247
+ }"
248
+ end
249
+
250
+ def Queries.get_parent_comment
251
+ "query comment ($id: Int!) {
252
+ comment(id: $id) {
253
+ parentComment {
254
+ #{@@comment}
255
+ }
256
+ }
257
+ }"
258
+ end
259
+
260
+ def Queries.get_repl
261
+ "query ReplView($url: String!) {
262
+ repl(url: $url) {
263
+ ... on Repl {
264
+ #{@@repl}
265
+ }
266
+ }
267
+ }"
268
+ end
269
+
270
+ def Queries.get_repl_forks
271
+ "query ReplViewForks($url: String!, $count: Int!, $after: String) {
272
+ repl(url: $url) {
273
+ ... on Repl {
274
+ publicForks(count: $count, after: $after) {
275
+ items {
276
+ #{@@repl}
277
+ }
278
+ }
279
+ }
280
+ }
281
+ }"
282
+ end
283
+
284
+ def Queries.get_repl_comments
285
+ "query ReplViewComments($url: String!, $count: Int, $after: String) {
286
+ repl(url: $url) {
287
+ ... on Repl {
288
+ comments(count: $count, after: $after) {
289
+ items {
290
+ #{@@repl_comment}
291
+ replies {
292
+ #{@@repl_comment}
293
+ }
294
+ }
295
+ }
296
+ }
297
+ }
298
+ }"
299
+ end
300
+
177
301
  def Queries.get_posts
178
302
  "query PostsFeed($order: String, $after: String, $searchQuery: String, $languages: [String!], $count: Int, $boardSlugs: [String!], $pinAnnouncements: Boolean, $pinPinned: Boolean) {
179
303
  posts(order: $order, after: $after, searchQuery: $searchQuery, languages: $languages, count: $count, boardSlugs: $boardSlugs, pinAnnouncements: $pinAnnouncements, pinPinned: $pinPinned) {
@@ -183,4 +307,15 @@ class Queries
183
307
  }
184
308
  }"
185
309
  end
310
+
311
+ def Queries.get_leaderboard
312
+ "query LeaderboardQuery($count: Int, $after: String, $since: KarmaSince) {
313
+ leaderboard(count: $count, after: $after, since: $since) {
314
+ items {
315
+ #{@@user}
316
+ karmaSince: karma(since: $since)
317
+ }
318
+ }
319
+ }"
320
+ end
186
321
  end
data/lib/repltalk.rb CHANGED
@@ -21,11 +21,16 @@ end
21
21
 
22
22
 
23
23
  class Organization
24
- attr_reader :id, :name
24
+ attr_reader :id, :name, :country, :postal_code, :state, :city, :timestamp
25
25
 
26
26
  def initialize(organization)
27
27
  @id = organization["id"]
28
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"]
29
34
  end
30
35
 
31
36
  def to_s
@@ -35,8 +40,25 @@ end
35
40
 
36
41
 
37
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
+
38
60
  class Language
39
- attr_reader :id, :key, :name, :tagline, :icon
61
+ attr_reader :id, :key, :name, :tagline, :icon, :category
40
62
 
41
63
  def initialize(lang)
42
64
  @id = lang["id"]
@@ -44,6 +66,7 @@ class Language
44
66
  @name = lang["displayName"]
45
67
  @tagline = lang["tagline"]
46
68
  @icon = lang["icon"]
69
+ @category = lang["category"]
47
70
  end
48
71
 
49
72
  def to_s
@@ -53,8 +76,28 @@ end
53
76
 
54
77
 
55
78
 
79
+ class ReplComment
80
+ attr_reader :id, :content, :author, :repl, :replies
81
+
82
+ def initialize(client, comment)
83
+ @client = client
84
+
85
+ @id = comment["id"]
86
+ @content = comment["body"]
87
+ @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
88
+ @repl = Repl.new(@client, comment["repl"])
89
+ @replies = comment["replies"] == nil ? nil : comment["replies"].map { |c| ReplComment.new(@client, c) }
90
+ end
91
+
92
+ def to_s
93
+ @content
94
+ end
95
+ end
96
+
97
+
98
+
56
99
  class Repl
57
- attr_reader :id, :url, :title, :author, :description, :language, :is_private, :is_always_on
100
+ attr_reader :id, :url, :title, :author, :description, :size, :language, :img_url, :origin_url, :is_private, :is_always_on
58
101
 
59
102
  def initialize(client, repl)
60
103
  @client = client
@@ -64,12 +107,37 @@ class Repl
64
107
  @title = repl["title"]
65
108
  @author = User.new(@client, repl["user"])
66
109
  @description = repl["description"]
110
+ @size = repl["size"]
67
111
  @language = Language.new(repl["lang"])
112
+ @image_url = repl["imageUrl"]
113
+ @origin_url = repl["origin"] == nil ? nil : $BASE_URL + repl["origin"]["url"]
68
114
 
69
115
  @is_private = repl["isPrivate"]
70
116
  @is_always_on = repl["isAlwaysOn"]
71
117
  end
72
118
 
119
+ def get_forks(count: 100, after: nil)
120
+ f = @client.graphql(
121
+ "ReplViewForks",
122
+ Queries.get_repl_forks,
123
+ url: @url,
124
+ count: count,
125
+ after: after
126
+ )
127
+ f["repl"]["publicForks"]["items"].map { |repl| Repl.new(@client, repl) }
128
+ end
129
+
130
+ def get_comments(count: nil, after: nil)
131
+ c = @client.graphql(
132
+ "ReplViewComments",
133
+ Queries.get_repl_comments,
134
+ url: @url,
135
+ count: count,
136
+ after: after
137
+ )
138
+ c["repl"]["comments"]["items"].map { |comment| ReplComment.new(@client, comment) }
139
+ end
140
+
73
141
  def to_s
74
142
  @title
75
143
  end
@@ -78,12 +146,13 @@ end
78
146
 
79
147
 
80
148
  class Board
81
- attr_reader :id, :name, :color
149
+ attr_reader :id, :name, :color, :description
82
150
 
83
151
  def initialize(board)
84
152
  @id = board["id"]
85
153
  @name = board["name"]
86
154
  @color = board["color"]
155
+ @description = board["description"]
87
156
  end
88
157
 
89
158
  def to_s
@@ -94,7 +163,7 @@ end
94
163
 
95
164
 
96
165
  class Comment
97
- attr_reader :id, :url, :author, :content, :post_id, :is_answer, :vote_count, :timestamp, :comments, :can_vote, :has_voted
166
+ attr_reader :id, :url, :author, :content, :post_id, :is_answer, :vote_count, :timestamp, :can_vote, :has_voted
98
167
 
99
168
  def initialize(client, comment)
100
169
  @client = client
@@ -107,7 +176,6 @@ class Comment
107
176
  @is_answer = comment["isAnswer"]
108
177
  @vote_count = comment["voteCount"]
109
178
  @timestamp = comment["timeCreated"]
110
- @comments = comment.include?("comments") ? comment["comments"].map { |c| Comment.new(@client, c)} : Array.new
111
179
 
112
180
  @can_vote = comment["canVote"]
113
181
  @has_voted = comment["hasVoted"]
@@ -119,7 +187,25 @@ class Comment
119
187
  Queries.get_post,
120
188
  id: @post_id
121
189
  )
122
- Post.new(self, p["post"])
190
+ Post.new(@client, p["post"])
191
+ end
192
+
193
+ def get_comments
194
+ c = @client.graphql(
195
+ "comment",
196
+ Queries.get_comments_comments,
197
+ id: @id
198
+ )
199
+ c["comment"]["comments"].map { |comment| Comment.new(@client, comment) }
200
+ end
201
+
202
+ def get_parent
203
+ c = @client.graphql(
204
+ "comment",
205
+ Queries.get_parent_comment,
206
+ id: @id
207
+ )
208
+ c["comment"]["parentComment"] == nil ? nil : Comment.new(@client, c["comment"]["parentComment"])
123
209
  end
124
210
 
125
211
  def to_s
@@ -130,7 +216,7 @@ end
130
216
 
131
217
 
132
218
  class Post
133
- 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
219
+ 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
134
220
 
135
221
  def initialize(client, post)
136
222
  @client = client
@@ -145,6 +231,7 @@ class Post
145
231
  @board = Board.new(post["board"])
146
232
  @repl = post["repl"] == nil ? nil : Repl.new(@client, post["repl"])
147
233
  @author = post["user"] == nil ? "[deleted user]" : User.new(@client, post["user"])
234
+ @answer = post["answer"] == nil ? nil : Comment.new(@client, post["answer"])
148
235
 
149
236
  @vote_count = post["voteCount"]
150
237
  @comment_count = post["commentCount"]
@@ -173,6 +260,16 @@ class Post
173
260
  c["post"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
174
261
  end
175
262
 
263
+ def get_upvotes(count: nil)
264
+ u = @client.graphql(
265
+ "post",
266
+ Queries.get_posts_upvoters,
267
+ id: @id,
268
+ count: count
269
+ )
270
+ u["post"]["votes"]["items"].map { |vote| User.new(@client, vote["user"]) }
271
+ end
272
+
176
273
  def to_s
177
274
  @title
178
275
  end
@@ -181,7 +278,7 @@ end
181
278
 
182
279
 
183
280
  class User
184
- attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :timestamp, :roles, :organization, :languages
281
+ attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :timestamp, :subscription, :roles, :organization, :languages
185
282
 
186
283
  def initialize(client, user)
187
284
  @client = client
@@ -194,6 +291,7 @@ class User
194
291
  @cycles = user["karma"]
195
292
  @is_hacker = user["isHacker"]
196
293
  @timestamp = user["timeCreated"]
294
+ @subscription = user["subscription"] == nil ? nil : Subscription.new(user["subscription"])
197
295
  @roles = user["roles"].map { |role| Role.new(role) }
198
296
  @organization = user["organization"] == nil ? nil : Organization.new(user["organization"])
199
297
  @languages = user["languages"].map { |lang| Language.new(lang) }
@@ -201,7 +299,7 @@ class User
201
299
 
202
300
  def get_posts(order: "new", count: nil, after: nil)
203
301
  p = @client.graphql(
204
- "ProfilePosts",
302
+ "user",
205
303
  Queries.get_user_posts,
206
304
  username: @username,
207
305
  order: order,
@@ -213,7 +311,7 @@ class User
213
311
 
214
312
  def get_comments(order: "new", count: nil, after: nil)
215
313
  c = @client.graphql(
216
- "ProfileComments",
314
+ "user",
217
315
  Queries.get_user_comments,
218
316
  username: @username,
219
317
  order: order,
@@ -223,6 +321,22 @@ class User
223
321
  c["user"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
224
322
  end
225
323
 
324
+ def get_repls(count: nil, order: nil, direction: nil, before: nil, after: nil, pinnedReplsFirst: nil, showUnnamed: nil)
325
+ r = @client.graphql(
326
+ "user",
327
+ Queries.get_user_repls,
328
+ username: @username,
329
+ order: order,
330
+ count: count,
331
+ direction: direction,
332
+ before: before,
333
+ after: after,
334
+ pinnedReplsFirst: pinnedReplsFirst,
335
+ showUnnamed: showUnnamed
336
+ )
337
+ r["user"]["publicRepls"]["items"].map { |repl| Repl.new(@client, repl) }
338
+ end
339
+
226
340
  def to_s
227
341
  @username
228
342
  end
@@ -230,6 +344,17 @@ end
230
344
 
231
345
 
232
346
 
347
+ class LeaderboardUser < User
348
+ attr_reader :cycles_since
349
+
350
+ def initialize(client, user)
351
+ super(client, user)
352
+ @cycles_since = user["karmaSince"]
353
+ end
354
+ end
355
+
356
+
357
+
233
358
  class Client
234
359
  attr_writer :sid
235
360
 
@@ -303,6 +428,26 @@ class Client
303
428
  )
304
429
  Comment.new(self, c["comment"])
305
430
  end
431
+
432
+ def get_repl(url)
433
+ r = graphql(
434
+ "ReplView",
435
+ Queries.get_repl,
436
+ url: url
437
+ )
438
+ Repl.new(self, r["repl"])
439
+ end
440
+
441
+ def get_leaderboard(count: nil, since: nil, after: nil)
442
+ u = graphql(
443
+ "LeaderboardQuery",
444
+ Queries.get_leaderboard,
445
+ count: count,
446
+ since: since,
447
+ after: after
448
+ )
449
+ u["leaderboard"]["items"].map { |user| LeaderboardUser.new(self, user) }
450
+ end
306
451
 
307
452
  def get_posts(board: "all", order: "new", count: nil, after: nil, search: nil, languages: nil)
308
453
  p = graphql(
metadata CHANGED
@@ -1,43 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repltalk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 1.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-05 00:00:00.000000000 Z
11
+ date: 2021-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.4'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
- version: '0'
22
+ version: 4.4.1
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.4'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: '0'
32
+ version: 4.4.1
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: json
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.5'
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
33
- version: '0'
42
+ version: 2.5.1
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.5'
38
50
  - - ">="
39
51
  - !ruby/object:Gem::Version
40
- version: '0'
52
+ version: 2.5.1
41
53
  description: With the repltalk gem, you can easily interect with the repltalk graphql
42
54
  api. See https://github.com/Coding-Cactus/repltalk for documentation
43
55
  email: codingcactus.cc@gmail.com
@@ -47,8 +59,9 @@ extra_rdoc_files: []
47
59
  files:
48
60
  - lib/queries.rb
49
61
  - lib/repltalk.rb
50
- homepage:
51
- licenses: []
62
+ homepage: https://github.com/Coding-Cactus/repltalk
63
+ licenses:
64
+ - MIT
52
65
  metadata:
53
66
  source_code_uri: https://github.com/Coding-Cactus/repltalk
54
67
  post_install_message: