repltalk 0.1.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/queries.rb +144 -264
  3. data/lib/repltalk.rb +99 -20
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f693b0e2f8cc3d1bcf1b646f02c8a551053f35b37f42aa5a6849a1cefcb086b
4
- data.tar.gz: 29a598f83669519a169a2b7717e01cb53531b87e7651349e181f59b01558888a
3
+ metadata.gz: cb325d2217b8b9e4a283dce8405cc1288fb430377d030f7fb201d344e8348f23
4
+ data.tar.gz: 3f35941f2a9d0542bc6c6fb205d9d1bd97c570921b6ab666b4b49aeef9f40c8a
5
5
  SHA512:
6
- metadata.gz: 9ec56f08034f1a82e343d4bca650a418ad2fba543e89e9d12ccf7c0d4e9435bffe5856194b4352c8de6cb0f28de22f884135399ba66d9eb5165050a947779481
7
- data.tar.gz: 7fdcd18d242c366c0a249e31e5fb7b20b6e900e2dfeefa0c583772d13d161ebf171414721418179cc2ec63fc18facf0bbdf166843f4ba0e88d0fe9a4ceca1fb3
6
+ metadata.gz: 20f4e65ddc1174889fb2767a1b87a1bf3d7ee418094b665e3b8b3de77884f0ddad956aa417b4db134f0fa9a57266dc4f5f6727aa26710a9ca4242fc3a0b79f56
7
+ data.tar.gz: 03d580505be28f0aa190d417ef6a33c4a71f154e15c0a26e196b0fe8e38a3efe4661a53d28a5a0a82cb6a2b0a6ff667e9da57c53bd17f329d6523b5da7075fef
data/lib/queries.rb CHANGED
@@ -1,306 +1,186 @@
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
+ isPrivate
54
+ isAlwaysOn
55
+ lang {
56
+ #{@@language}
57
+ }
58
+ user {
59
+ #{@@user}
60
+ }
61
+ "
62
+
63
+ @@post = "
64
+ id
65
+ title
66
+ body
67
+ preview(removeMarkdown: true, length: 150)
68
+ url
69
+ commentCount
70
+ isHidden
71
+ isPinned
72
+ isLocked
73
+ isAnnouncement
74
+ timeCreated
75
+ isAnswered
76
+ isAnswerable
77
+ voteCount
78
+ canVote
79
+ hasVoted
80
+ user {
81
+ #{@@user}
82
+ }
83
+ repl {
84
+ #{@@repl}
85
+ }
86
+ board {
87
+ #{@@board}
88
+ }
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 {
16
104
  id
17
- fullName
18
- username
19
- image
20
- bio
21
- karma
22
- isHacker
23
- roles {
24
- id
25
- name
26
- key
27
- tagline
28
- __typename
29
- }
30
- organization {
31
- id
32
- name
33
- __typename
34
- }
35
- languages {
36
- id
37
- key
38
- displayName
39
- tagline
40
- icon
41
- __typename
105
+ }
106
+ "
107
+
108
+
109
+ def Queries.get_user
110
+ "query userByUsername($username: String!) {
111
+ user: userByUsername(username: $username) {
112
+ #{@@user}
42
113
  }
43
- __typename
44
114
  }"
45
115
  end
46
116
 
47
117
  def Queries.get_user_by_id
48
118
  "query user($user_id: Int!) {
49
119
  user: user(id: $user_id) {
50
- id
51
- username
52
- fullName
53
- image
54
- url
55
- ...ProfileHeaderUser
56
- __typename
57
- }
58
- }
59
-
60
- fragment ProfileHeaderUser on User {
61
- id
62
- fullName
63
- username
64
- image
65
- bio
66
- karma
67
- isHacker
68
- roles {
69
- id
70
- name
71
- key
72
- tagline
73
- __typename
120
+ #{@@user}
74
121
  }
75
- organization {
76
- id
77
- name
78
- __typename
79
- }
80
- languages {
81
- id
82
- key
83
- displayName
84
- tagline
85
- icon
86
- __typename
87
- }
88
- __typename
89
122
  }"
90
123
  end
91
124
 
92
125
  def Queries.get_user_posts
93
126
  "query ProfilePosts($username: String!, $after: String, $order: String, $count: Int) {
94
127
  user: userByUsername(username: $username) {
95
- id
96
- displayName
97
128
  posts(after: $after, order: $order, count: $count) {
98
129
  items {
99
- id
100
- isHidden
101
- ...PostsFeedItemPost
102
- board {
103
- id
104
- name
105
- url
106
- color
107
- __typename
108
- }
109
- __typename
110
- }
111
- pageInfo {
112
- nextCursor
113
- __typename
130
+ #{@@post}
114
131
  }
115
- __typename
116
- }
117
- __typename
118
- }
119
- }
120
-
121
- fragment PostsFeedItemPost on Post {
122
- id
123
- title
124
- body
125
- preview(removeMarkdown: true, length: 150)
126
- url
127
- commentCount
128
- isPinned
129
- isLocked
130
- isAnnouncement
131
- timeCreated
132
- isAnswered
133
- isAnswerable
134
- ...PostVoteControlPost
135
- ...PostLinkPost
136
- user {
137
- id
138
- username
139
- isHacker
140
- image
141
- ...UserLabelUser
142
- ...UserLinkUser
143
- __typename
144
- }
145
- repl {
146
- id
147
- url
148
- title
149
- description
150
- isPrivate
151
- isAlwaysOn
152
- lang {
153
- id
154
- icon
155
- key
156
- displayName
157
- tagline
158
- __typename
159
132
  }
160
- __typename
161
- }
162
- board {
163
- id
164
- name
165
- color
166
- __typename
167
133
  }
168
- }
169
-
170
- fragment PostVoteControlPost on Post {
171
- id
172
- voteCount
173
- canVote
174
- hasVoted
175
- __typename
176
- }
177
-
178
- fragment PostLinkPost on Post {
179
- id
180
- url
181
- __typename
182
- }
183
-
184
- fragment UserLabelUser on User {
185
- id
186
- username
187
- karma
188
- ...UserLinkUser
189
- __typename
190
- }
191
-
192
- fragment UserLinkUser on User {
193
- id
194
- url
195
- username
196
- roles {
197
- id
198
- name
199
- key
200
- tagline
201
- __typename
202
- }
203
- organization {
204
- id
205
- name
206
- __typename
207
- }
208
- languages {
209
- id
210
- key
211
- displayName
212
- tagline
213
- icon
214
- __typename
215
- }
216
- __typename
217
134
  }"
218
135
  end
219
136
 
220
137
  def Queries.get_user_comments
221
138
  "query ProfileComments($username: String!, $after: String, $order: String, $count: Int) {
222
139
  user: userByUsername(username: $username) {
223
- id
224
- displayName
225
140
  comments(after: $after, order: $order, count: $count) {
226
141
  items {
227
- id
228
- ...ProfileCommentsComment
229
- __typename
142
+ #{@@comment}
230
143
  }
231
- pageInfo {
232
- nextCursor
233
- __typename
234
- }
235
- __typename
236
144
  }
237
- __typename
238
145
  }
239
- }
146
+ }"
147
+ end
240
148
 
241
- fragment ProfileCommentsComment on Comment {
242
- id
243
- body
244
- timeCreated
245
- url
246
- ...CommentVoteControlComment
247
- user {
248
- id
249
- fullName
250
- username
251
- image
252
- bio
253
- karma
254
- isHacker
255
- roles {
256
- id
257
- name
258
- key
259
- tagline
260
- __typename
261
- }
262
- organization {
263
- id
264
- name
265
- __typename
266
- }
267
- languages {
268
- id
269
- key
270
- displayName
271
- tagline
272
- icon
273
- __typename
274
- }
149
+ def Queries.get_post
150
+ "query post($id: Int!) {
151
+ post(id: $id) {
152
+ #{@@post}
275
153
  }
276
- post {
277
- id
278
- title
279
- url
280
- user {
281
- id
282
- username
283
- url
284
- __typename
285
- }
286
- board {
287
- id
288
- name
289
- url
290
- slug
291
- __typename
154
+ }"
155
+ end
156
+
157
+ def Queries.get_posts_comments
158
+ "query post($postId: Int!, $order: String, $count: Int, $after: String) {
159
+ post(id: $postId) {
160
+ comments(order: $order, count: $count, after: $after) {
161
+ items {
162
+ #{@@comment}
163
+ }
292
164
  }
293
- __typename
294
165
  }
295
- __typename
296
- }
166
+ }"
167
+ end
297
168
 
298
- fragment CommentVoteControlComment on Comment {
299
- id
300
- voteCount
301
- canVote
302
- hasVoted
303
- __typename
169
+ def Queries.get_comment
170
+ "query comment ($id: Int!) {
171
+ comment(id: $id) {
172
+ #{@@comment}
173
+ }
174
+ }"
175
+ end
176
+
177
+ def Queries.get_posts
178
+ "query PostsFeed($order: String, $after: String, $searchQuery: String, $languages: [String!], $count: Int, $boardSlugs: [String!], $pinAnnouncements: Boolean, $pinPinned: Boolean) {
179
+ posts(order: $order, after: $after, searchQuery: $searchQuery, languages: $languages, count: $count, boardSlugs: $boardSlugs, pinAnnouncements: $pinAnnouncements, pinPinned: $pinPinned) {
180
+ items {
181
+ #{@@post}
182
+ }
183
+ }
304
184
  }"
305
185
  end
306
186
  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
 
@@ -16,6 +18,8 @@ class Role
16
18
  end
17
19
  end
18
20
 
21
+
22
+
19
23
  class Organization
20
24
  attr_reader :id, :name
21
25
 
@@ -29,6 +33,8 @@ class Organization
29
33
  end
30
34
  end
31
35
 
36
+
37
+
32
38
  class Language
33
39
  attr_reader :id, :key, :name, :tagline, :icon
34
40
 
@@ -45,13 +51,18 @@ class Language
45
51
  end
46
52
  end
47
53
 
54
+
55
+
48
56
  class Repl
49
- attr_reader :id, :url, :title, :description, :language, :is_private, :is_always_on
57
+ attr_reader :id, :url, :title, :author, :description, :language, :is_private, :is_always_on
58
+
59
+ def initialize(client, repl)
60
+ @client = client
50
61
 
51
- def initialize(repl)
52
62
  @id = repl["id"]
53
- @url = repl["url"]
63
+ @url = $BASE_URL + repl["url"]
54
64
  @title = repl["title"]
65
+ @author = User.new(@client, repl["user"])
55
66
  @description = repl["description"]
56
67
  @language = Language.new(repl["lang"])
57
68
 
@@ -64,6 +75,8 @@ class Repl
64
75
  end
65
76
  end
66
77
 
78
+
79
+
67
80
  class Board
68
81
  attr_reader :id, :name, :color
69
82
 
@@ -78,43 +91,60 @@ class Board
78
91
  end
79
92
  end
80
93
 
94
+
95
+
81
96
  class Comment
82
- attr_reader :id, :url, :author, :content, :vote_count, :can_vote, :has_voted
97
+ attr_reader :id, :url, :author, :content, :post_id, :is_answer, :vote_count, :timestamp, :comments, :can_vote, :has_voted
83
98
 
84
99
  def initialize(client, comment)
85
100
  @client = client
86
101
 
87
102
  @id = comment["id"]
88
- @url = comment["url"]
89
- @author = User.new(@client, comment["user"])
103
+ @url = $BASE_URL + comment["url"]
104
+ @author = comment["user"] == nil ? "[deleted user]" : User.new(@client, comment["user"])
90
105
  @content = comment["body"]
106
+ @post_id = comment["post"]["id"]
107
+ @is_answer = comment["isAnswer"]
91
108
  @vote_count = comment["voteCount"]
109
+ @timestamp = comment["timeCreated"]
110
+ @comments = comment.include?("comments") ? comment["comments"].map { |c| Comment.new(@client, c)} : Array.new
92
111
 
93
112
  @can_vote = comment["canVote"]
94
113
  @has_voted = comment["hasVoted"]
95
114
  end
96
115
 
116
+ def get_post
117
+ p = @client.graphql(
118
+ "post",
119
+ Queries.get_post,
120
+ id: @post_id
121
+ )
122
+ Post.new(self, p["post"])
123
+ end
124
+
97
125
  def to_s
98
126
  @content
99
127
  end
100
128
  end
101
129
 
130
+
131
+
102
132
  class Post
103
- attr_reader :id, :url, :repl, :board, :title, :author, :content, :preview, :timestamp, :vote_count, :comment_count, :can_vote, :has_voted, :is_anwered, :is_answerable, :is_hidden, :is_pinned, :is_locked, :is_announcement
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
104
134
 
105
135
  def initialize(client, post)
106
136
  @client = client
107
137
 
108
138
  @id = post["id"]
109
- @url = post["url"]
139
+ @url = $BASE_URL + post["url"]
110
140
  @title = post["title"]
111
141
  @content = post["body"]
112
142
  @preview = post["preview"]
113
143
  @timestamp = post["timeCreated"]
114
144
 
115
145
  @board = Board.new(post["board"])
116
- @author = User.new(@client, post["user"])
117
- @repl = post["repl"] == nil ? nil : Repl.new(post["repl"])
146
+ @repl = post["repl"] == nil ? nil : Repl.new(@client, post["repl"])
147
+ @author = post["user"] == nil ? "[deleted user]" : User.new(@client, post["user"])
118
148
 
119
149
  @vote_count = post["voteCount"]
120
150
  @comment_count = post["commentCount"]
@@ -131,13 +161,27 @@ class Post
131
161
  @is_announcement = post["isAnnouncement"]
132
162
  end
133
163
 
164
+ def get_comments(order: "new", count: nil, after: nil)
165
+ c = @client.graphql(
166
+ "post",
167
+ Queries.get_posts_comments,
168
+ postId: @id,
169
+ order: order,
170
+ count: count,
171
+ after: after
172
+ )
173
+ c["post"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
174
+ end
175
+
134
176
  def to_s
135
177
  @title
136
178
  end
137
179
  end
138
180
 
181
+
182
+
139
183
  class User
140
- attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :roles, :organization, :languages
184
+ attr_reader :id, :username, :name, :pfp, :bio, :cycles, :is_hacker, :timestamp, :roles, :organization, :languages
141
185
 
142
186
  def initialize(client, user)
143
187
  @client = client
@@ -149,6 +193,7 @@ class User
149
193
  @bio = user["bio"]
150
194
  @cycles = user["karma"]
151
195
  @is_hacker = user["isHacker"]
196
+ @timestamp = user["timeCreated"]
152
197
  @roles = user["roles"].map { |role| Role.new(role) }
153
198
  @organization = user["organization"] == nil ? nil : Organization.new(user["organization"])
154
199
  @languages = user["languages"].map { |lang| Language.new(lang) }
@@ -163,9 +208,7 @@ class User
163
208
  count: count,
164
209
  after: after
165
210
  )
166
- posts = Array.new
167
- p["user"]["posts"]["items"].each { |post| posts << Post.new(@client, post) }
168
- posts
211
+ p["user"]["posts"]["items"].map { |post| Post.new(@client, post) }
169
212
  end
170
213
 
171
214
  def get_comments(order: "new", count: nil, after: nil)
@@ -177,9 +220,7 @@ class User
177
220
  count: count,
178
221
  after: after
179
222
  )
180
- comments = Array.new
181
- c["user"]["comments"]["items"].each { |comment| comments << Comment.new(@client, comment) }
182
- comments
223
+ c["user"]["comments"]["items"].map { |comment| Comment.new(@client, comment) }
183
224
  end
184
225
 
185
226
  def to_s
@@ -187,6 +228,8 @@ class User
187
228
  end
188
229
  end
189
230
 
231
+
232
+
190
233
  class Client
191
234
  attr_writer :sid
192
235
 
@@ -205,11 +248,11 @@ class Client
205
248
  "connect.sid": @sid
206
249
  )
207
250
  .headers(
208
- referer: "https://repl.it/@CodingCactus/repltalk",
251
+ referer: "#{$BASE_URL}/@CodingCactus/repltalk",
209
252
  "X-Requested-With": "ReplTalk"
210
253
  )
211
254
  .post(
212
- "https://repl.it/graphql",
255
+ "#{$BASE_URL}/graphql",
213
256
  form: payload
214
257
  )
215
258
  begin data = JSON.parse(r)
@@ -217,6 +260,10 @@ class Client
217
260
  puts "\e[31mERROR\n#{r}\e[0m"
218
261
  return nil
219
262
  end
263
+ if data.include?("errors")
264
+ puts "\e[31mERROR\n#{r}\e[0m"
265
+ return nil
266
+ end
220
267
  data = data["data"] if data.include?("data")
221
268
  data
222
269
  end
@@ -236,6 +283,38 @@ class Client
236
283
  Queries.get_user_by_id,
237
284
  user_id: id
238
285
  )
239
- User.new(u["user"])
286
+ User.new(self, u["user"])
287
+ end
288
+
289
+ def get_post(id)
290
+ p = graphql(
291
+ "post",
292
+ Queries.get_post,
293
+ id: id
294
+ )
295
+ Post.new(self, p["post"])
296
+ end
297
+
298
+ def get_comment(id)
299
+ c = graphql(
300
+ "comment",
301
+ Queries.get_comment,
302
+ id: id
303
+ )
304
+ Comment.new(self, c["comment"])
305
+ end
306
+
307
+ def get_posts(board: "all", order: "new", count: nil, after: nil, search: nil, languages: nil)
308
+ p = graphql(
309
+ "PostsFeed",
310
+ Queries.get_posts,
311
+ baordSlugs: [board],
312
+ order: order,
313
+ count: count,
314
+ after: after,
315
+ searchQuery: search,
316
+ languages: languages
317
+ )
318
+ p["posts"]["items"].map { |post| Post.new(self, post) }
240
319
  end
241
320
  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.1.1
4
+ version: 0.4.2
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-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http